Fixed: Cancelling editing a modal will reset to previous saved state

This commit is contained in:
Mark McDowall
2014-08-14 23:06:17 -07:00
parent 39c66b7951
commit d76e3d2ed6
16 changed files with 216 additions and 285 deletions

View File

@@ -1,4 +1,4 @@
'use strict';
 'use strict';
define([
'vent',
@@ -8,71 +8,34 @@ define([
'Commands/CommandController',
'Mixins/AsModelBoundView',
'Mixins/AsValidatedView',
'Mixins/AsEditModalView',
'Form/FormBuilder',
'Mixins/AutoComplete',
'bootstrap'
], function (vent, AppLayout, Marionette, DeleteView, CommandController, AsModelBoundView, AsValidatedView) {
], function (vent, AppLayout, Marionette, DeleteView, CommandController, AsModelBoundView, AsValidatedView, AsEditModalView) {
var view = Marionette.ItemView.extend({
template: 'Settings/Indexers/Edit/IndexerEditViewTemplate',
ui: {
indicator : '.x-indicator'
events: {
'click .x-back' : '_back'
},
events: {
'click .x-save' : '_save',
'click .x-save-and-add' : '_saveAndAdd',
'click .x-delete' : '_delete',
'click .x-back' : '_back',
'click .x-close' : '_close',
'click .x-test' : '_test'
},
_deleteView: DeleteView,
initialize: function (options) {
this.targetCollection = options.targetCollection;
},
_save: function () {
this.ui.indicator.show();
var self = this;
var promise = this.model.save();
if (promise) {
promise.done(function () {
self.targetCollection.add(self.model, { merge: true });
vent.trigger(vent.Commands.CloseModalCommand);
});
promise.fail(function () {
self.ui.indicator.hide();
});
}
_onAfterSave: function () {
this.targetCollection.add(this.model, { merge: true });
vent.trigger(vent.Commands.CloseModalCommand);
},
_saveAndAdd: function () {
this.ui.indicator.show();
_onAfterSaveAndAdd: function () {
this.targetCollection.add(this.model, { merge: true });
var self = this;
var promise = this.model.save();
if (promise) {
promise.done(function () {
self.targetCollection.add(self.model, { merge: true });
require('Settings/Indexers/Add/IndexerSchemaModal').open(self.targetCollection);
});
promise.fail(function () {
self.ui.indicator.hide();
});
}
},
_delete: function () {
var view = new DeleteView({ model: this.model });
AppLayout.modalRegion.show(view);
require('Settings/Indexers/Add/IndexerSchemaModal').open(this.targetCollection);
},
_back: function () {
@@ -81,34 +44,12 @@ define([
}
require('Settings/Indexers/Add/IndexerSchemaModal').open(this.targetCollection);
},
_close: function () {
if (this.model.isNew()) {
this.model.destroy();
}
else {
this.model.fetch();
}
vent.trigger(vent.Commands.CloseModalCommand);
},
_test: function () {
var self = this;
this.ui.indicator.show();
this.model.test().always(function () {
self.ui.indicator.hide();
});
}
});
AsModelBoundView.call(view);
AsValidatedView.call(view);
AsEditModalView.call(view);
return view;
});