mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-02-20 12:43:28 +02:00
SaveIfChangedMixin
This commit is contained in:
parent
9a68785c26
commit
c94595b3ae
30
UI/Mixins/SaveIfChangedModel.js
Normal file
30
UI/Mixins/SaveIfChangedModel.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//try to add ajax data as query string to DELETE calls.
|
||||||
|
"use strict";
|
||||||
|
(function () {
|
||||||
|
|
||||||
|
NzbDrone.Mixins.SaveIfChangedModel = {
|
||||||
|
// originalInitialize: this.initialize,
|
||||||
|
|
||||||
|
initialize: function () {
|
||||||
|
this.isSaved = true;
|
||||||
|
|
||||||
|
this.on('change', function () {
|
||||||
|
this.isSaved = false;
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
this.on('sync', function () {
|
||||||
|
this.isSaved = true;
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// if (originalInitialize) {
|
||||||
|
// originalInitialize.call(this);
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
|
||||||
|
saveIfChanged: function (options) {
|
||||||
|
if (!this.isSaved) {
|
||||||
|
this.save(undefined, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}());
|
@ -36,23 +36,26 @@ define(['app',
|
|||||||
|
|
||||||
saveSettings: function () {
|
saveSettings: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
//For now loop through and save all the models
|
|
||||||
|
|
||||||
_.each(this.collection.models, function (model, index, list) {
|
_.each(this.collection.models, function (model, index, list) {
|
||||||
var name = model.get('name');
|
var name = model.get('name');
|
||||||
var error = 'Failed to save indexer: ' + name;
|
var error = 'Failed to save indexer: ' + name;
|
||||||
|
|
||||||
model.save(undefined, self.syncNotification(error));
|
model.saveIfChanged(self.syncNotification(undefined, error));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
syncNotification: function (error) {
|
syncNotification: function (success, error) {
|
||||||
return {
|
return {
|
||||||
success: function () {
|
success: function () {
|
||||||
|
if (success) {
|
||||||
|
NzbDrone.Shared.Messenger.show({message: success});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error : function () {
|
error : function () {
|
||||||
NzbDrone.Shared.Messenger.show({message: "Couldn't Save General Settings", type: 'error'});
|
if (error) {
|
||||||
|
NzbDrone.Shared.Messenger.show({message: error, type: 'error'});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
define(['app'], function () {
|
define(['app', 'Mixins/SaveIfChangedModel'], function () {
|
||||||
NzbDrone.Settings.Indexers.Model = Backbone.DeepModel.extend({
|
NzbDrone.Settings.Indexers.Model = Backbone.DeepModel.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_.extend(NzbDrone.Settings.Indexers.Model.prototype, NzbDrone.Mixins.SaveIfChangedModel);
|
||||||
});
|
});
|
||||||
|
@ -82,6 +82,7 @@ define('app', ['shared/modal/region'], function (ModalRegion) {
|
|||||||
|
|
||||||
window.NzbDrone.Missing = {};
|
window.NzbDrone.Missing = {};
|
||||||
window.NzbDrone.History = {};
|
window.NzbDrone.History = {};
|
||||||
|
window.NzbDrone.Mixins = {};
|
||||||
|
|
||||||
window.NzbDrone.Events = {
|
window.NzbDrone.Events = {
|
||||||
SeriesAdded: 'seriesAdded'
|
SeriesAdded: 'seriesAdded'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user