fix model reset

This commit is contained in:
yuri
2018-02-08 16:02:12 +02:00
parent f28585e245
commit 1bb0439f19
2 changed files with 29 additions and 6 deletions
+14 -3
View File
@@ -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();
}
}
+15 -3
View File
@@ -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);