fix model reset
This commit is contained in:
@@ -253,9 +253,9 @@ Espo.define('views/record/base', ['view', 'view-record-helper', 'dynamic-logic']
|
||||
|
||||
this.recordHelper = new ViewRecordHelper();
|
||||
|
||||
this.on('remove', function () {
|
||||
this.once('remove', function () {
|
||||
if (this.isChanged) {
|
||||
this.model.set(this.attributes);
|
||||
this.resetModelChanges();
|
||||
}
|
||||
this.setIsNotChanged();
|
||||
}, this);
|
||||
@@ -302,6 +302,17 @@ Espo.define('views/record/base', ['view', 'view-record-helper', 'dynamic-logic']
|
||||
return !_.isEqual(this.attributes[name], this.model.get(name));
|
||||
},
|
||||
|
||||
resetModelChanges: function () {
|
||||
var attributes = this.model.attributes;
|
||||
for (var attr in attributes) {
|
||||
if (!(attr in this.attributes)) {
|
||||
this.model.unset(attr);
|
||||
}
|
||||
}
|
||||
|
||||
this.model.set(this.attributes);
|
||||
},
|
||||
|
||||
initDynamicLogic: function () {
|
||||
if (!Object.keys(this.dynamicLogicDefs || {}).length) return;
|
||||
|
||||
@@ -474,7 +485,7 @@ Espo.define('views/record/base', ['view', 'view-record-helper', 'dynamic-logic']
|
||||
|
||||
if (xhr.status == 400) {
|
||||
if (!this.isNew) {
|
||||
this.model.set(this.attributes);
|
||||
this.resetModelChanges();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -473,11 +473,23 @@ Espo.define('views/record/detail', ['views/record/base', 'view-record-helper'],
|
||||
},
|
||||
|
||||
cancelEdit: function () {
|
||||
this.model.set(this.attributes);
|
||||
this.resetModelChanges();
|
||||
|
||||
this.setDetailMode();
|
||||
this.setIsNotChanged();
|
||||
},
|
||||
|
||||
resetModelChanges: function () {
|
||||
var attributes = this.model.attributes;
|
||||
for (var attr in attributes) {
|
||||
if (!(attr in this.attributes)) {
|
||||
this.model.unset(attr);
|
||||
}
|
||||
}
|
||||
|
||||
this.model.set(this.attributes);
|
||||
},
|
||||
|
||||
delete: function () {
|
||||
this.confirm({
|
||||
message: this.translate('removeRecordConfirmation', 'messages'),
|
||||
@@ -663,9 +675,9 @@ Espo.define('views/record/detail', ['views/record/base', 'view-record-helper'],
|
||||
}
|
||||
}
|
||||
|
||||
this.on('remove', function () {
|
||||
this.once('remove', function () {
|
||||
if (this.isChanged) {
|
||||
this.model.set(this.attributes);
|
||||
this.resetModelChanges();
|
||||
}
|
||||
this.setIsNotChanged();
|
||||
$(window).off('scroll.detail-' + this.numId);
|
||||
|
||||
Reference in New Issue
Block a user