2013-05-01 03:01:54 +03:00
|
|
|
'use strict';
|
2013-05-28 03:19:07 +03:00
|
|
|
define(['app',
|
|
|
|
'Settings/Indexers/ItemView',
|
2013-06-01 03:22:47 +03:00
|
|
|
'Settings/Indexers/EditView',
|
|
|
|
'Settings/SyncNotification'],
|
2013-05-28 03:19:07 +03:00
|
|
|
function () {
|
2013-05-01 03:01:54 +03:00
|
|
|
NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({
|
|
|
|
itemView : NzbDrone.Settings.Indexers.ItemView,
|
|
|
|
itemViewContainer : '#x-indexers',
|
2013-05-28 03:19:07 +03:00
|
|
|
template : 'Settings/Indexers/CollectionTemplate',
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .x-add': 'openSchemaModal'
|
|
|
|
},
|
|
|
|
|
2013-05-29 03:44:29 +03:00
|
|
|
initialize: function () {
|
2013-06-14 02:19:24 +03:00
|
|
|
NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this._saveSettings, this);
|
|
|
|
this.savedCount = 0;
|
2013-05-29 03:44:29 +03:00
|
|
|
},
|
|
|
|
|
2013-05-28 03:19:07 +03:00
|
|
|
openSchemaModal: function () {
|
2013-05-29 03:44:29 +03:00
|
|
|
var self = this;
|
2013-05-28 03:19:07 +03:00
|
|
|
//TODO: Is there a better way to deal with changing URLs?
|
2013-05-28 18:06:36 +03:00
|
|
|
var schemaCollection = new NzbDrone.Settings.Indexers.Collection();
|
|
|
|
schemaCollection.url = '/api/indexer/schema';
|
|
|
|
schemaCollection.fetch({
|
2013-05-28 03:19:07 +03:00
|
|
|
success: function (collection) {
|
|
|
|
collection.url = '/api/indexer';
|
|
|
|
var model = _.first(collection.models);
|
|
|
|
model.set('id', undefined);
|
|
|
|
model.set('name', '');
|
|
|
|
|
2013-05-29 03:44:29 +03:00
|
|
|
var view = new NzbDrone.Settings.Indexers.EditView({ model: model, indexerCollection: self.collection});
|
2013-05-28 03:19:07 +03:00
|
|
|
NzbDrone.modalRegion.show(view);
|
|
|
|
}
|
|
|
|
});
|
2013-05-29 03:44:29 +03:00
|
|
|
},
|
|
|
|
|
2013-06-14 02:19:24 +03:00
|
|
|
_saveSettings: function () {
|
|
|
|
var self = this;
|
|
|
|
|
2013-05-31 04:03:37 +03:00
|
|
|
_.each(this.collection.models, function (model, index, list) {
|
2013-06-01 03:22:47 +03:00
|
|
|
model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({
|
2013-06-14 02:19:24 +03:00
|
|
|
errorMessage: 'Failed to save indexer: ' + model.get('name'),
|
|
|
|
successCallback: self._saveSuccessful,
|
|
|
|
context: self
|
2013-06-01 03:22:47 +03:00
|
|
|
}));
|
2013-05-31 04:03:37 +03:00
|
|
|
});
|
2013-06-14 02:19:24 +03:00
|
|
|
|
|
|
|
if (self.savedCount > 0) {
|
|
|
|
NzbDrone.Shared.Messenger.show({message: 'Indexer settings saved'});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.savedCount = 0;
|
|
|
|
},
|
|
|
|
_saveSuccessful: function () {
|
|
|
|
this.savedCount++;
|
2013-05-28 03:19:07 +03:00
|
|
|
}
|
2013-05-01 03:01:54 +03:00
|
|
|
});
|
2013-05-01 09:43:14 +03:00
|
|
|
});
|