1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/UI/Settings/Indexers/CollectionView.js

64 lines
2.2 KiB
JavaScript
Raw Normal View History

2013-05-01 02:01:54 +02:00
'use strict';
2013-05-28 02:19:07 +02:00
define(['app',
'Settings/Indexers/ItemView',
'Settings/Indexers/EditView'],
function () {
2013-05-01 02:01:54 +02:00
NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({
itemView : NzbDrone.Settings.Indexers.ItemView,
itemViewContainer : '#x-indexers',
2013-05-28 02:19:07 +02:00
template : 'Settings/Indexers/CollectionTemplate',
events: {
'click .x-add': 'openSchemaModal'
},
2013-05-29 02:44:29 +02:00
initialize: function () {
NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this);
},
2013-05-28 02:19:07 +02:00
openSchemaModal: function () {
2013-05-29 02:44:29 +02:00
var self = this;
2013-05-28 02:19:07 +02:00
//TODO: Is there a better way to deal with changing URLs?
2013-05-28 17:06:36 +02:00
var schemaCollection = new NzbDrone.Settings.Indexers.Collection();
schemaCollection.url = '/api/indexer/schema';
schemaCollection.fetch({
2013-05-28 02:19:07 +02:00
success: function (collection) {
collection.url = '/api/indexer';
var model = _.first(collection.models);
model.set('id', undefined);
model.set('name', '');
2013-05-29 02:44:29 +02:00
var view = new NzbDrone.Settings.Indexers.EditView({ model: model, indexerCollection: self.collection});
2013-05-28 02:19:07 +02:00
NzbDrone.modalRegion.show(view);
}
});
2013-05-29 02:44:29 +02:00
},
saveSettings: function () {
var self = this;
2013-05-31 06:06:52 +02:00
_.each(this.collection.models, function (model, index, list) {
var name = model.get('name');
var error = 'Failed to save indexer: ' + name;
2013-05-31 06:06:52 +02:00
model.saveIfChanged(self.syncNotification(undefined, error));
});
2013-05-29 02:44:29 +02:00
},
2013-05-31 06:06:52 +02:00
syncNotification: function (success, error) {
2013-05-29 02:44:29 +02:00
return {
success: function () {
2013-05-31 06:06:52 +02:00
if (success) {
NzbDrone.Shared.Messenger.show({message: success});
}
2013-05-29 02:44:29 +02:00
},
error : function () {
2013-05-31 06:06:52 +02:00
if (error) {
NzbDrone.Shared.Messenger.show({message: error, type: 'error'});
}
2013-05-29 02:44:29 +02:00
}
};
2013-05-28 02:19:07 +02:00
}
2013-05-01 02:01:54 +02:00
});
2013-05-01 08:43:14 +02:00
});