2013-05-01 00:01:54 +00:00
|
|
|
|
'use strict';
|
2013-05-28 00:19:07 +00:00
|
|
|
|
define(['app',
|
|
|
|
|
'Settings/Indexers/ItemView',
|
|
|
|
|
'Settings/Indexers/EditView'],
|
|
|
|
|
function () {
|
2013-05-01 00:01:54 +00:00
|
|
|
|
NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({
|
|
|
|
|
itemView : NzbDrone.Settings.Indexers.ItemView,
|
|
|
|
|
itemViewContainer : '#x-indexers',
|
2013-05-28 00:19:07 +00:00
|
|
|
|
template : 'Settings/Indexers/CollectionTemplate',
|
|
|
|
|
|
|
|
|
|
events: {
|
|
|
|
|
'click .x-add': 'openSchemaModal'
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-29 00:44:29 +00:00
|
|
|
|
initialize: function () {
|
|
|
|
|
NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this);
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-28 00:19:07 +00:00
|
|
|
|
openSchemaModal: function () {
|
2013-05-29 00:44:29 +00:00
|
|
|
|
var self = this;
|
2013-05-28 00:19:07 +00:00
|
|
|
|
//TODO: Is there a better way to deal with changing URLs?
|
2013-05-28 15:06:36 +00:00
|
|
|
|
var schemaCollection = new NzbDrone.Settings.Indexers.Collection();
|
|
|
|
|
schemaCollection.url = '/api/indexer/schema';
|
|
|
|
|
schemaCollection.fetch({
|
2013-05-28 00:19:07 +00:00
|
|
|
|
success: function (collection) {
|
|
|
|
|
collection.url = '/api/indexer';
|
|
|
|
|
var model = _.first(collection.models);
|
|
|
|
|
model.set('id', undefined);
|
|
|
|
|
model.set('name', '');
|
|
|
|
|
|
2013-05-29 00:44:29 +00:00
|
|
|
|
var view = new NzbDrone.Settings.Indexers.EditView({ model: model, indexerCollection: self.collection});
|
2013-05-28 00:19:07 +00:00
|
|
|
|
NzbDrone.modalRegion.show(view);
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-05-29 00:44:29 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
saveSettings: function () {
|
|
|
|
|
//TODO: check if any models in the collection have changed and sync them only
|
|
|
|
|
// this.collection.sync();
|
|
|
|
|
// if (!this.model.isSaved) {
|
|
|
|
|
// this.model.save(undefined, this.syncNotification("Naming Settings Saved", "Couldn't Save Naming Settings"));
|
|
|
|
|
// }
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
syncNotification: function (success, error) {
|
|
|
|
|
return {
|
|
|
|
|
success: function () {
|
|
|
|
|
NzbDrone.Shared.Messenger.show({message: 'General Settings Saved'});
|
|
|
|
|
},
|
|
|
|
|
error : function () {
|
|
|
|
|
NzbDrone.Shared.Messenger.show({message: "Couldn't Save General Settings", type: 'error'});
|
|
|
|
|
}
|
|
|
|
|
};
|
2013-05-28 00:19:07 +00:00
|
|
|
|
}
|
2013-05-01 00:01:54 +00:00
|
|
|
|
});
|
2013-05-01 06:43:14 +00:00
|
|
|
|
});
|