1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-07-01 00:45:18 +02:00
Files
Sonarr/UI/Settings/Indexers/EditView.js

62 lines
1.8 KiB
JavaScript
Raw Normal View History

2013-07-23 18:15:58 -07:00
'use strict';
2013-05-27 17:19:07 -07:00
define(
[
2013-06-27 18:55:45 -07:00
'app',
'marionette',
'Mixins/AsModelBoundView',
'Mixins/AsValidatedView'
], function (App, Marionette, AsModelBoundView, AsValidatedView) {
2013-05-27 17:19:07 -07:00
var view = Marionette.ItemView.extend({
template: 'Settings/Indexers/EditTemplate',
2013-05-27 17:19:07 -07:00
events: {
2013-07-23 18:15:58 -07:00
'click .x-save' : '_save',
2013-06-27 18:55:45 -07:00
'click .x-save-and-add': '_saveAndAdd'
},
2013-05-27 17:19:07 -07:00
initialize: function (options) {
this.indexerCollection = options.indexerCollection;
},
2013-05-27 17:19:07 -07:00
2013-06-27 18:55:45 -07:00
_save: function () {
var self = this;
var promise = this.model.saveSettings();
if (promise) {
promise.done(function () {
self.indexerCollection.add(self.model, { merge: true });
2013-07-23 18:15:58 -07:00
App.vent.trigger(App.Commands.CloseModalCommand);
2013-06-27 18:55:45 -07:00
});
}
},
_saveAndAdd: function () {
var self = this;
var promise = this.model.saveSettings();
if (promise) {
promise.done(function () {
self.indexerCollection.add(self.model, { merge: true });
self.model.set({
2013-07-23 18:15:58 -07:00
id : undefined,
name : '',
2013-06-27 18:55:45 -07:00
enable: false
});
_.each(self.model.get('fields'), function (value, key, list) {
2013-07-23 18:15:58 -07:00
self.model.set('fields.' + key + '.value', '');
2013-06-27 18:55:45 -07:00
});
});
}
}
});
2013-06-18 18:02:23 -07:00
AsModelBoundView.call(view);
AsValidatedView.call(view);
return view;
});