Settings save when changed only

This commit is contained in:
Mark McDowall 2013-06-13 16:19:24 -07:00
parent 8b8ee912c0
commit bddbc7a0cf
7 changed files with 39 additions and 34 deletions

View File

@ -14,7 +14,8 @@ define(['app',
}, },
initialize: function () { initialize: function () {
NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this); NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this._saveSettings, this);
this.savedCount = 0;
}, },
openSchemaModal: function () { openSchemaModal: function () {
@ -35,12 +36,25 @@ define(['app',
}); });
}, },
saveSettings: function () { _saveSettings: function () {
var self = this;
_.each(this.collection.models, function (model, index, list) { _.each(this.collection.models, function (model, index, list) {
model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({ model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({
errorMessage: 'Failed to save indexer: ' + model.get('name') errorMessage: 'Failed to save indexer: ' + model.get('name'),
successCallback: self._saveSuccessful,
context: self
})); }));
}); });
if (self.savedCount > 0) {
NzbDrone.Shared.Messenger.show({message: 'Indexer settings saved'});
}
this.savedCount = 0;
},
_saveSuccessful: function () {
this.savedCount++;
} }
}); });
}); });

View File

@ -1,5 +1,6 @@
"use strict"; "use strict";
define(['app', 'Mixins/SaveIfChangedModel'], function () { define(['app',
'Mixins/SaveIfChangedModel'], function () {
NzbDrone.Settings.Indexers.Model = Backbone.DeepModel.extend({ NzbDrone.Settings.Indexers.Model = Backbone.DeepModel.extend({
}); });

View File

@ -1,6 +1,9 @@
"use strict"; "use strict";
define(['app'], function () { define(['app',
'Mixins/SaveIfChangedModel'], function () {
NzbDrone.Settings.Naming.NamingModel = Backbone.Model.extend({ NzbDrone.Settings.Naming.NamingModel = Backbone.Model.extend({
url: NzbDrone.Constants.ApiRoot + '/config/naming' url: NzbDrone.Constants.ApiRoot + '/config/naming'
}); });
_.extend(NzbDrone.Settings.Naming.NamingModel.prototype, NzbDrone.Mixins.SaveIfChangedModel);
}); });

View File

@ -1,13 +1,11 @@
'use strict'; 'use strict';
define(['app', 'Settings/Naming/NamingModel'], function () { define(['app',
'Settings/Naming/NamingModel',
'Settings/SyncNotification'], function () {
NzbDrone.Settings.Naming.NamingView = Backbone.Marionette.ItemView.extend({ NzbDrone.Settings.Naming.NamingView = Backbone.Marionette.ItemView.extend({
template : 'Settings/Naming/NamingTemplate', template : 'Settings/Naming/NamingTemplate',
ui: {
tooltip: '[class^="help-inline"] i'
},
initialize: function () { initialize: function () {
this.model = new NzbDrone.Settings.Naming.NamingModel(); this.model = new NzbDrone.Settings.Naming.NamingModel();
this.model.fetch(); this.model.fetch();
@ -15,13 +13,8 @@ define(['app', 'Settings/Naming/NamingModel'], function () {
NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this); NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this);
}, },
onRender: function () {
//TODO: Move this to a mixin
this.ui.tooltip.tooltip({ placement: 'right' });
},
saveSettings: function () { saveSettings: function () {
this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({ this.model.saveIfChanged(undefined, NzbDrone.Settings.SyncNotificaiton.callback({
successMessage: 'Naming Settings saved', successMessage: 'Naming Settings saved',
errorMessage: "Failed to save Naming Settings" errorMessage: "Failed to save Naming Settings"
})); }));

View File

@ -168,19 +168,11 @@ define([
NzbDrone.vent.trigger(NzbDrone.Commands.SaveSettings); NzbDrone.vent.trigger(NzbDrone.Commands.SaveSettings);
this.settings.save(undefined, this.settings.saveIfChanged(undefined, NzbDrone.Settings.SyncNotificaiton.callback({
{ successMessage: 'Settings saved',
success: function () { errorMessage: "Failed to save settings"
window.alert('Saved'); }));
},
error : function () {
window.alert("couldn't save settings");
} }
}); });
});
}
})
;
})
;

View File

@ -4,8 +4,9 @@
<li><a href="#indexers" class="x-indexers-tab no-router">Indexers</a></li> <li><a href="#indexers" class="x-indexers-tab no-router">Indexers</a></li>
<li><a href="#download-client" class="x-download-client-tab no-router">Download Client</a></li> <li><a href="#download-client" class="x-download-client-tab no-router">Download Client</a></li>
<li><a href="#notifications" class="x-notifications-tab no-router">Notifications</a></li> <li><a href="#notifications" class="x-notifications-tab no-router">Notifications</a></li>
<li><a href="#general" class="x-general-tab no-router">general</a></li> <li><a href="#general" class="x-general-tab no-router">General</a></li>
<li><a href="#misc" class="x-misc-tab no-router">Misc</a></li> <li><a href="#misc" class="x-misc-tab no-router">Misc</a></li>
<li class="pull-right"><button class="btn btn-primary x-save-settings">Save</button></li>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
@ -17,5 +18,3 @@
<div class="tab-pane" id="general">general Settings</div> <div class="tab-pane" id="general">general Settings</div>
<div class="tab-pane" id="misc">Misc Settings</div> <div class="tab-pane" id="misc">Misc Settings</div>
</div> </div>
<button class="btn btn-primary x-save-settings">Save</button>

View File

@ -1,6 +1,9 @@
"use strict"; "use strict";
define(['app'], function () { define(['app',
'Mixins/SaveIfChangedModel'], function () {
NzbDrone.Settings.SettingsModel = Backbone.Model.extend({ NzbDrone.Settings.SettingsModel = Backbone.Model.extend({
url: NzbDrone.Constants.ApiRoot + '/settings' url: NzbDrone.Constants.ApiRoot + '/settings'
}); });
_.extend(NzbDrone.Settings.SettingsModel.prototype, NzbDrone.Mixins.SaveIfChangedModel);
}); });