fixed saving settings. now done more generically.
This commit is contained in:
parent
d126c6efc1
commit
806e58ed1f
|
@ -1,24 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
define(['app', 'Mixins/AsModelBoundView'], function (App, AsModelBoundView) {
|
define(['marionette'], function (Marionette) {
|
||||||
|
return Marionette.ItemView.extend({
|
||||||
var view = Backbone.Marionette.ItemView.extend({
|
template: 'Settings/General/GeneralTemplate'
|
||||||
template: 'Settings/General/GeneralTemplate',
|
|
||||||
|
|
||||||
initialize: function () {
|
|
||||||
NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this);
|
|
||||||
},
|
|
||||||
|
|
||||||
saveSettings: function () {
|
|
||||||
if (!this.model.isSaved) {
|
|
||||||
this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({
|
|
||||||
successMessage: 'General Settings saved',
|
|
||||||
errorMessage : "Failed to save General Settings"
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return AsModelBoundView.call(view);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
define(['app',
|
define(['app',
|
||||||
'marionette',
|
'marionette',
|
||||||
'Shared/Messenger',
|
|
||||||
'Settings/Indexers/ItemView',
|
'Settings/Indexers/ItemView',
|
||||||
'Settings/Indexers/EditView',
|
'Settings/Indexers/EditView',
|
||||||
'Settings/Indexers/Collection'],
|
'Settings/Indexers/Collection'],
|
||||||
function (App, Marionette, Messenger, IndexerItemView, IndexerEditView, IndexerCollection) {
|
function (App, Marionette, IndexerItemView, IndexerEditView, IndexerCollection) {
|
||||||
return Marionette.CompositeView.extend({
|
return Marionette.CompositeView.extend({
|
||||||
itemView : IndexerItemView,
|
itemView : IndexerItemView,
|
||||||
itemViewContainer: '#x-indexers',
|
itemViewContainer: '#x-indexers',
|
||||||
|
@ -15,10 +14,6 @@ define(['app',
|
||||||
'click .x-add': 'openSchemaModal'
|
'click .x-add': 'openSchemaModal'
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function () {
|
|
||||||
this.listenTo(App.vent, App.Commands.SaveSettings, this._saveSettings);
|
|
||||||
this.savedCount = 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
openSchemaModal: function () {
|
openSchemaModal: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -36,28 +31,6 @@ define(['app',
|
||||||
App.modalRegion.show(view);
|
App.modalRegion.show(view);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
_saveSettings: function () {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
_.each(this.collection.models, function (model, index, list) {
|
|
||||||
model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({
|
|
||||||
errorMessage : 'Failed to save indexer: ' + model.get('name'),
|
|
||||||
successCallback: self._saveSuccessful,
|
|
||||||
context : self
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (self.savedCount > 0) {
|
|
||||||
Messenger.show({message: 'Indexer settings saved'});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.savedCount = 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
_saveSuccessful: function () {
|
|
||||||
this.savedCount++;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
define([
|
define([
|
||||||
'app',
|
'app',
|
||||||
'marionette',
|
'marionette',
|
||||||
'Shared/Messenger',
|
|
||||||
'Mixins/AsModelBoundView'
|
'Mixins/AsModelBoundView'
|
||||||
|
], function (App, Marionette, AsModelBoundView) {
|
||||||
], function (App, Marionette, Messenger, AsModelBoundView) {
|
|
||||||
|
|
||||||
var view = Marionette.ItemView.extend({
|
var view = Marionette.ItemView.extend({
|
||||||
template: 'Settings/Indexers/EditTemplate',
|
template: 'Settings/Indexers/EditTemplate',
|
||||||
|
@ -20,27 +18,9 @@ define([
|
||||||
},
|
},
|
||||||
|
|
||||||
save: function () {
|
save: function () {
|
||||||
this.model.save(undefined, this.syncNotification("Indexer Saved", "Couldn't Save Indexer", this));
|
this.model.saveSettings();
|
||||||
},
|
|
||||||
|
|
||||||
syncNotification: function (success, error, context) {
|
|
||||||
return {
|
|
||||||
success: function () {
|
|
||||||
Messenger.show({
|
|
||||||
message: success
|
|
||||||
});
|
|
||||||
|
|
||||||
context.indexerCollection.add(context.model);
|
|
||||||
App.modalRegion.closeModal();
|
|
||||||
},
|
|
||||||
|
|
||||||
error: function () {
|
|
||||||
window.alert(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return AsModelBoundView.call(view);
|
return AsModelBoundView.call(view);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
define(['marionette'], function () {
|
define(['marionette', 'Mixins/AsModelBoundView'], function (Marionette, AsModelBoundView) {
|
||||||
|
|
||||||
return Marionette.ItemView.extend({
|
var view = Marionette.ItemView.extend({
|
||||||
template: 'Settings/Indexers/ItemTemplate',
|
template: 'Settings/Indexers/ItemTemplate',
|
||||||
tagName : 'li'
|
tagName : 'li'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return AsModelBoundView.call(view);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
define([
|
define([
|
||||||
'backbone.deepmodel', 'Mixins/AsChangeTrackingModel'], function (DeepModel, AsChangeTrackingModel) {
|
'Settings/SettingsModelBase'], function (ModelBase) {
|
||||||
var model = DeepModel.DeepModel.extend({
|
return ModelBase.extend({
|
||||||
|
|
||||||
|
successMessage: 'Indexer Saved',
|
||||||
|
errorMessage : 'Couldn\'t save indexer'
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return AsChangeTrackingModel.call(model);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
define(['app',
|
define(['app',
|
||||||
'Mixins/AsChangeTrackingModel'], function (App, AsChangeTrackingModel) {
|
'Settings/SettingsModelBase'], function (App, ModelBase) {
|
||||||
var model = Backbone.Model.extend({
|
return ModelBase.extend({
|
||||||
url: App.Constants.ApiRoot + '/config/naming'
|
url : App.Constants.ApiRoot + '/config/naming',
|
||||||
|
successMessage: 'Naming settings saved',
|
||||||
|
errorMessage : 'Couldn\'t save naming settings'
|
||||||
});
|
});
|
||||||
|
|
||||||
return AsChangeTrackingModel.call(model);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
define(['app',
|
define(['app',
|
||||||
'marionette',
|
'marionette',
|
||||||
'Settings/Naming/NamingModel',
|
'Settings/Naming/NamingModel',
|
||||||
'Settings/SyncNotification',
|
'Mixins/AsModelBoundView'], function (App, Marionette, NamingModel, AsModelBoundView) {
|
||||||
'Mixins/AsModelBoundView'], function (App, Marionette, NamingModel, SyncNotification, AsModelBoundView) {
|
|
||||||
|
|
||||||
var view = Marionette.ItemView.extend({
|
var view = Marionette.ItemView.extend({
|
||||||
template: 'Settings/Naming/NamingTemplate',
|
template: 'Settings/Naming/NamingTemplate',
|
||||||
|
@ -11,17 +10,8 @@ define(['app',
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
this.model = new NamingModel();
|
this.model = new NamingModel();
|
||||||
this.model.fetch();
|
this.model.fetch();
|
||||||
|
|
||||||
this.listenTo(App.vent, App.Commands.SaveSettings, this.saveSettings);
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
saveSettings: function () {
|
|
||||||
this.model.saveIfChanged(undefined, SyncNotification.callback({
|
|
||||||
successMessage: 'Naming Settings saved',
|
|
||||||
errorMessage : "Failed to save Naming Settings"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return AsModelBoundView.call(view);
|
return AsModelBoundView.call(view);
|
||||||
|
|
|
@ -5,11 +5,10 @@ define([
|
||||||
'marionette',
|
'marionette',
|
||||||
'Settings/Notifications/Model',
|
'Settings/Notifications/Model',
|
||||||
'Settings/Notifications/DeleteView',
|
'Settings/Notifications/DeleteView',
|
||||||
'Settings/SyncNotification',
|
|
||||||
'Shared/Messenger',
|
'Shared/Messenger',
|
||||||
'Mixins/AsModelBoundView'
|
'Mixins/AsModelBoundView'
|
||||||
|
|
||||||
], function (App, Marionette, NotificationModel, DeleteView, SyncNotification, Messenger, AsModelBoundView) {
|
], function (App, Marionette, NotificationModel, DeleteView, Messenger, AsModelBoundView) {
|
||||||
|
|
||||||
var model = Marionette.ItemView.extend({
|
var model = Marionette.ItemView.extend({
|
||||||
template: 'Settings/Notifications/EditTemplate',
|
template: 'Settings/Notifications/EditTemplate',
|
||||||
|
@ -30,16 +29,11 @@ define([
|
||||||
},
|
},
|
||||||
|
|
||||||
_saveNotification: function () {
|
_saveNotification: function () {
|
||||||
var name = this.model.get('name');
|
var promise = this.model.saveSettings();
|
||||||
var success = 'Notification Saved: ' + name;
|
|
||||||
var fail = 'Failed to save notification: ' + name;
|
|
||||||
|
|
||||||
this.model.save(undefined, SyncNotification.callback({
|
if (promise) {
|
||||||
successMessage : success,
|
promise.done(this._saveSuccess);
|
||||||
errorMessage : fail,
|
}
|
||||||
successCallback: this._saveSuccess,
|
|
||||||
context : this
|
|
||||||
}));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_deleteNotification: function () {
|
_deleteNotification: function () {
|
||||||
|
|
|
@ -13,24 +13,9 @@ define([
|
||||||
'Settings/Notifications/CollectionView',
|
'Settings/Notifications/CollectionView',
|
||||||
'Settings/Notifications/Collection',
|
'Settings/Notifications/Collection',
|
||||||
'Settings/General/GeneralView',
|
'Settings/General/GeneralView',
|
||||||
'Settings/Misc/MiscView',
|
'Settings/Misc/MiscView'
|
||||||
'Settings/SyncNotification'
|
|
||||||
],
|
],
|
||||||
function (App,
|
function (App, Marionette, SettingsModel, GeneralSettingsModel, NamingView, NamingModel, QualityLayout, IndexerCollectionView, IndexerCollection, DownloadClientView, NotificationCollectionView, NotificationCollection, GeneralView, MiscView) {
|
||||||
Marionette,
|
|
||||||
SettingsModel,
|
|
||||||
GeneralSettingsModel,
|
|
||||||
NamingView,
|
|
||||||
NamingModel,
|
|
||||||
QualityLayout,
|
|
||||||
IndexerCollectionView,
|
|
||||||
IndexerCollection,
|
|
||||||
DownloadClientView,
|
|
||||||
NotificationCollectionView,
|
|
||||||
NotificationCollection,
|
|
||||||
GeneralView,
|
|
||||||
MiscView,
|
|
||||||
SyncNotification) {
|
|
||||||
return Marionette.Layout.extend({
|
return Marionette.Layout.extend({
|
||||||
template: 'Settings/SettingsLayoutTemplate',
|
template: 'Settings/SettingsLayoutTemplate',
|
||||||
|
|
||||||
|
@ -185,13 +170,7 @@ define([
|
||||||
},
|
},
|
||||||
|
|
||||||
save: function () {
|
save: function () {
|
||||||
|
|
||||||
App.vent.trigger(App.Commands.SaveSettings);
|
App.vent.trigger(App.Commands.SaveSettings);
|
||||||
|
|
||||||
this.settings.saveIfChanged(undefined, SyncNotification.callback({
|
|
||||||
successMessage: 'Settings saved',
|
|
||||||
errorMessage : "Failed to save settings"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
define(['app',
|
define(['app',
|
||||||
'backbone',
|
'Settings/SettingsModelBase'], function (App, SettingsModelBase) {
|
||||||
'Mixins/SaveIfChangedModel'], function (App, Backbone, AsChangeTrackingModel) {
|
return SettingsModelBase.extend({
|
||||||
var model = Backbone.Model.extend({
|
url : App.Constants.ApiRoot + '/settings',
|
||||||
url: App.Constants.ApiRoot + '/settings'
|
successMessage: 'Settings saved',
|
||||||
|
errorMessage : "Failed to save settings"
|
||||||
});
|
});
|
||||||
|
|
||||||
return AsChangeTrackingModel.call(model);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
"use strict";
|
||||||
|
define(['app',
|
||||||
|
'backbone.deepmodel',
|
||||||
|
'Mixins/AsChangeTrackingModel',
|
||||||
|
'Shared/Messenger'], function (App, DeepModel, AsChangeTrackingModel, Messenger) {
|
||||||
|
var model = DeepModel.DeepModel.extend({
|
||||||
|
|
||||||
|
initialize: function () {
|
||||||
|
|
||||||
|
// App.vent.on(App.Commands.SaveSettings, this.saveSettings, this);
|
||||||
|
this.listenTo(App.vent, App.Commands.SaveSettings, this.saveSettings);
|
||||||
|
},
|
||||||
|
|
||||||
|
saveSettings: function () {
|
||||||
|
|
||||||
|
if (!this.isSaved) {
|
||||||
|
|
||||||
|
var savePromise = this.save();
|
||||||
|
|
||||||
|
Messenger.monitor(
|
||||||
|
{
|
||||||
|
promise : savePromise,
|
||||||
|
successMessage: this.successMessage,
|
||||||
|
errorMessage : this.errorMessage
|
||||||
|
});
|
||||||
|
|
||||||
|
return savePromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return AsChangeTrackingModel.call(model);
|
||||||
|
});
|
|
@ -1,27 +0,0 @@
|
||||||
"use strict";
|
|
||||||
define(['shared/messenger'], function (Messenger) {
|
|
||||||
return {
|
|
||||||
callback: function (options) {
|
|
||||||
return {
|
|
||||||
success: function () {
|
|
||||||
if (options.successMessage) {
|
|
||||||
Messenger.show({message: options.successMessage});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.successCallback) {
|
|
||||||
options.successCallback.call(options.context);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error : function () {
|
|
||||||
if (options.errorMessage) {
|
|
||||||
Messenger.show({message: options.errorMessage, type: 'error'});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.errorCallback) {
|
|
||||||
options.errorCallback.call(options.context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
|
@ -12,7 +12,8 @@ define(function () {
|
||||||
case 'info':
|
case 'info':
|
||||||
options.hideAfter = 5;
|
options.hideAfter = 5;
|
||||||
break;
|
break;
|
||||||
case 'error':
|
|
||||||
|
default :
|
||||||
options.hideAfter = 0;
|
options.hideAfter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,5 +24,35 @@ define(function () {
|
||||||
showCloseButton: true,
|
showCloseButton: true,
|
||||||
hideAfter : options.hideAfter
|
hideAfter : options.hideAfter
|
||||||
});
|
});
|
||||||
}};
|
},
|
||||||
|
|
||||||
|
|
||||||
|
monitor: function (options) {
|
||||||
|
|
||||||
|
if (!options.promise) {
|
||||||
|
throw 'promise is required';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.successMessage) {
|
||||||
|
throw 'success message is required';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.errorMessage) {
|
||||||
|
throw 'error message is required';
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
options.promise.done(function () {
|
||||||
|
self.show({message: options.successMessage});
|
||||||
|
});
|
||||||
|
|
||||||
|
options.promise.fail(function () {
|
||||||
|
self.show({message: options.errorMessage, type: 'error'});
|
||||||
|
});
|
||||||
|
|
||||||
|
return options.promise;
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue