1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-19 21:46:50 -04:00

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
@@ -1,6 +1,7 @@
'use strict';
define([
'underscore',
'vent',
'AppLayout',
'marionette',
@@ -8,29 +9,25 @@ define([
'Commands/CommandController',
'Mixins/AsModelBoundView',
'Mixins/AsValidatedView',
'underscore',
'Mixins/AsEditModalView',
'Form/FormBuilder'
], function (vent, AppLayout, Marionette, DeleteView, CommandController, AsModelBoundView, AsValidatedView, _) {
], function (_, vent, AppLayout, Marionette, DeleteView, CommandController, AsModelBoundView, AsValidatedView, AsEditModalView) {
var view = Marionette.ItemView.extend({
template: 'Settings/Notifications/Edit/NotificationEditViewTemplate',
ui: {
onDownloadToggle : '.x-on-download',
onUpgradeSection : '.x-on-upgrade',
indicator : '.x-indicator'
onUpgradeSection : '.x-on-upgrade'
},
events: {
'click .x-save' : '_save',
'click .x-save-and-add': '_saveAndAdd',
'click .x-delete' : '_delete',
'click .x-back' : '_back',
'click .x-cancel' : '_cancel',
'click .x-test' : '_test',
'change .x-on-download': '_onDownloadChanged'
},
_deleteView: DeleteView,
initialize: function (options) {
this.targetCollection = options.targetCollection;
},
@@ -39,46 +36,15 @@ define([
this._onDownloadChanged();
},
_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/Notifications/Add/NotificationSchemaModal').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/Notifications/Add/NotificationSchemaModal').open(this.targetCollection);
},
_back: function () {
@@ -89,22 +55,6 @@ define([
require('Settings/Notifications/Add/NotificationSchemaModal').open(this.targetCollection);
},
_cancel: function () {
if (this.model.isNew()) {
this.model.destroy();
}
},
_test: function () {
var self = this;
this.ui.indicator.show();
this.model.test().always(function () {
self.ui.indicator.hide();
});
},
_onDownloadChanged: function () {
var checked = this.ui.onDownloadToggle.prop('checked');
@@ -120,6 +70,7 @@ define([
AsModelBoundView.call(view);
AsValidatedView.call(view);
AsEditModalView.call(view);
return view;
});