refactoring

This commit is contained in:
Yuri Kuznetsov
2021-07-21 15:59:08 +03:00
parent 73c4204ee9
commit eb82a8afda
+20 -12
View File
@@ -602,7 +602,6 @@ define('views/fields/base', 'view', function (Dep) {
inlineEditSave: function () {
var data = this.fetch();
var self = this;
var model = this.model;
var prev = this.initialAttributes;
@@ -610,39 +609,48 @@ define('views/fields/base', 'view', function (Dep) {
data = model.attributes;
var attrs = false;
for (var attr in data) {
if (_.isEqual(prev[attr], data[attr])) {
continue;
}
(attrs || (attrs = {}))[attr] = data[attr];
}
if (!attrs) {
this.inlineEditClose();
return;
}
if (this.validate()) {
this.notify('Not valid', 'error');
model.set(prev, {silent: true});
return;
}
this.notify('Saving...');
model.save(attrs, {
success: function () {
self.trigger('after:save');
model
.save(attrs, {patch: true})
.then(() => {
this.trigger('after:save');
model.trigger('after:save');
self.notify('Saved', 'success');
},
error: function () {
self.notify('Error occurred', 'error');
this.notify('Saved', 'success');
})
.catch(() => {
this.notify('Error occurred', 'error');
model.set(prev, {silent: true});
self.render()
},
patch: true
});
this.render();
});
this.inlineEditClose(true);
},