Sonarr/UI/Settings/Indexers/EditView.js

58 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
define(
[
'app',
'marionette',
'Mixins/AsModelBoundView'
], function (App, Marionette, AsModelBoundView) {
var view = Marionette.ItemView.extend({
template: 'Settings/Indexers/EditTemplate',
events: {
'click .x-save': '_save',
'click .x-save-and-add': '_saveAndAdd'
},
initialize: function (options) {
this.indexerCollection = options.indexerCollection;
},
_save: function () {
var self = this;
var promise = this.model.saveSettings();
if (promise) {
promise.done(function () {
self.indexerCollection.add(self.model, { merge: true });
App.modalRegion.closeModal();
});
}
},
_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({
id: undefined,
name: '',
enable: false
});
_.each(self.model.get('fields'), function (value, key, list) {
self.model.set('fields.' + key +'.value', '');
});
});
}
}
});
return AsModelBoundView.call(view);
});