2013-05-01 00:01:54 +00:00
|
|
|
|
'use strict';
|
2013-05-28 00:19:07 +00:00
|
|
|
|
define(['app',
|
2013-06-19 01:02:23 +00:00
|
|
|
|
'marionette',
|
|
|
|
|
'Shared/Messenger',
|
|
|
|
|
'Settings/Indexers/ItemView',
|
|
|
|
|
'Settings/Indexers/EditView',
|
|
|
|
|
'Settings/Indexers/Collection'],
|
|
|
|
|
function (App, Marionette, Messenger, IndexerItemView, IndexerEditView, IndexerCollection) {
|
|
|
|
|
return Marionette.CompositeView.extend({
|
|
|
|
|
itemView : IndexerItemView,
|
|
|
|
|
itemViewContainer: '#x-indexers',
|
|
|
|
|
template : 'Settings/Indexers/CollectionTemplate',
|
|
|
|
|
|
|
|
|
|
events: {
|
|
|
|
|
'click .x-add': 'openSchemaModal'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
|
this.listenTo(App.vent, App.Commands.SaveSettings, this._saveSettings);
|
|
|
|
|
this.savedCount = 0;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
openSchemaModal: function () {
|
|
|
|
|
var self = this;
|
|
|
|
|
//TODO: Is there a better way to deal with changing URLs?
|
|
|
|
|
var schemaCollection = new IndexerCollection();
|
|
|
|
|
schemaCollection.url = '/api/indexer/schema';
|
|
|
|
|
schemaCollection.fetch({
|
|
|
|
|
success: function (collection) {
|
|
|
|
|
collection.url = '/api/indexer';
|
|
|
|
|
var model = _.first(collection.models);
|
|
|
|
|
model.set('id', undefined);
|
|
|
|
|
model.set('name', '');
|
|
|
|
|
|
|
|
|
|
var view = new IndexerEditView({ model: model, indexerCollection: self.collection});
|
|
|
|
|
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'});
|
2013-05-28 00:19:07 +00:00
|
|
|
|
}
|
2013-06-13 23:19:24 +00:00
|
|
|
|
|
2013-06-19 01:02:23 +00:00
|
|
|
|
this.savedCount = 0;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_saveSuccessful: function () {
|
|
|
|
|
this.savedCount++;
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-05-01 00:01:54 +00:00
|
|
|
|
});
|