From bddbc7a0cf44e6be84b9a45c4a7479fa70637499 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 13 Jun 2013 16:19:24 -0700 Subject: [PATCH] Settings save when changed only --- UI/Settings/Indexers/CollectionView.js | 20 +++++++++++++++++--- UI/Settings/Indexers/Model.js | 3 ++- UI/Settings/Naming/NamingModel.js | 5 ++++- UI/Settings/Naming/NamingView.js | 15 ++++----------- UI/Settings/SettingsLayout.js | 20 ++++++-------------- UI/Settings/SettingsLayoutTemplate.html | 5 ++--- UI/Settings/SettingsModel.js | 5 ++++- 7 files changed, 39 insertions(+), 34 deletions(-) diff --git a/UI/Settings/Indexers/CollectionView.js b/UI/Settings/Indexers/CollectionView.js index 78ab9cab8..3820fbe65 100644 --- a/UI/Settings/Indexers/CollectionView.js +++ b/UI/Settings/Indexers/CollectionView.js @@ -14,7 +14,8 @@ define(['app', }, 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 () { @@ -35,12 +36,25 @@ define(['app', }); }, - saveSettings: function () { + _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') + 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++; } }); }); diff --git a/UI/Settings/Indexers/Model.js b/UI/Settings/Indexers/Model.js index ba12b5537..acde63869 100644 --- a/UI/Settings/Indexers/Model.js +++ b/UI/Settings/Indexers/Model.js @@ -1,5 +1,6 @@ "use strict"; -define(['app', 'Mixins/SaveIfChangedModel'], function () { +define(['app', + 'Mixins/SaveIfChangedModel'], function () { NzbDrone.Settings.Indexers.Model = Backbone.DeepModel.extend({ }); diff --git a/UI/Settings/Naming/NamingModel.js b/UI/Settings/Naming/NamingModel.js index 9d596e6f2..1ab8c691e 100644 --- a/UI/Settings/Naming/NamingModel.js +++ b/UI/Settings/Naming/NamingModel.js @@ -1,6 +1,9 @@ "use strict"; -define(['app'], function () { +define(['app', + 'Mixins/SaveIfChangedModel'], function () { NzbDrone.Settings.Naming.NamingModel = Backbone.Model.extend({ url: NzbDrone.Constants.ApiRoot + '/config/naming' }); + + _.extend(NzbDrone.Settings.Naming.NamingModel.prototype, NzbDrone.Mixins.SaveIfChangedModel); }); diff --git a/UI/Settings/Naming/NamingView.js b/UI/Settings/Naming/NamingView.js index e68f2f88b..fa2de8b49 100644 --- a/UI/Settings/Naming/NamingView.js +++ b/UI/Settings/Naming/NamingView.js @@ -1,13 +1,11 @@ 'use strict'; -define(['app', 'Settings/Naming/NamingModel'], function () { +define(['app', + 'Settings/Naming/NamingModel', + 'Settings/SyncNotification'], function () { NzbDrone.Settings.Naming.NamingView = Backbone.Marionette.ItemView.extend({ template : 'Settings/Naming/NamingTemplate', - ui: { - tooltip: '[class^="help-inline"] i' - }, - initialize: function () { this.model = new NzbDrone.Settings.Naming.NamingModel(); this.model.fetch(); @@ -15,13 +13,8 @@ define(['app', 'Settings/Naming/NamingModel'], function () { 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 () { - this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({ + this.model.saveIfChanged(undefined, NzbDrone.Settings.SyncNotificaiton.callback({ successMessage: 'Naming Settings saved', errorMessage: "Failed to save Naming Settings" })); diff --git a/UI/Settings/SettingsLayout.js b/UI/Settings/SettingsLayout.js index 5479d931e..9cf1c0371 100644 --- a/UI/Settings/SettingsLayout.js +++ b/UI/Settings/SettingsLayout.js @@ -168,19 +168,11 @@ define([ NzbDrone.vent.trigger(NzbDrone.Commands.SaveSettings); - this.settings.save(undefined, - { - success: function () { - window.alert('Saved'); - }, - error : function () { - window.alert("couldn't save settings"); - } - }); - + this.settings.saveIfChanged(undefined, NzbDrone.Settings.SyncNotificaiton.callback({ + successMessage: 'Settings saved', + errorMessage: "Failed to save settings" + })); } - }) - ; - }) -; + }); + }); diff --git a/UI/Settings/SettingsLayoutTemplate.html b/UI/Settings/SettingsLayoutTemplate.html index dadc85908..85712618f 100644 --- a/UI/Settings/SettingsLayoutTemplate.html +++ b/UI/Settings/SettingsLayoutTemplate.html @@ -4,8 +4,9 @@
  • Indexers
  • Download Client
  • Notifications
  • -
  • general
  • +
  • General
  • Misc
  • +
  • @@ -17,5 +18,3 @@
    general Settings
    Misc Settings
    - - diff --git a/UI/Settings/SettingsModel.js b/UI/Settings/SettingsModel.js index bb76512e4..56caa1ad0 100644 --- a/UI/Settings/SettingsModel.js +++ b/UI/Settings/SettingsModel.js @@ -1,6 +1,9 @@ "use strict"; -define(['app'], function () { +define(['app', + 'Mixins/SaveIfChangedModel'], function () { NzbDrone.Settings.SettingsModel = Backbone.Model.extend({ url: NzbDrone.Constants.ApiRoot + '/settings' }); + + _.extend(NzbDrone.Settings.SettingsModel.prototype, NzbDrone.Mixins.SaveIfChangedModel); });