mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-20 21:54:25 -04:00
109 lines
3.0 KiB
JavaScript
109 lines
3.0 KiB
JavaScript
'use strict';
|
|
|
|
define([
|
|
'vent',
|
|
'AppLayout',
|
|
'marionette',
|
|
'Settings/DownloadClient/Delete/DownloadClientDeleteView',
|
|
'Commands/CommandController',
|
|
'Mixins/AsModelBoundView',
|
|
'Mixins/AsValidatedView',
|
|
'underscore',
|
|
'Form/FormBuilder',
|
|
'Mixins/AutoComplete',
|
|
'bootstrap'
|
|
], function (vent, AppLayout, Marionette, DeleteView, CommandController, AsModelBoundView, AsValidatedView, _) {
|
|
|
|
var view = Marionette.ItemView.extend({
|
|
template: 'Settings/DownloadClient/Edit/DownloadClientEditViewTemplate',
|
|
|
|
ui: {
|
|
path : '.x-path',
|
|
modalBody : '.modal-body',
|
|
indicator : '.x-indicator'
|
|
},
|
|
|
|
events: {
|
|
'click .x-save' : '_save',
|
|
'click .x-save-and-add': '_saveAndAdd',
|
|
'click .x-delete' : '_delete',
|
|
'click .x-back' : '_back',
|
|
'click .x-test' : '_test'
|
|
},
|
|
|
|
initialize: function (options) {
|
|
this.targetCollection = options.targetCollection;
|
|
},
|
|
|
|
onShow: function () {
|
|
//Hack to deal with modals not overflowing
|
|
if (this.ui.path.length > 0) {
|
|
this.ui.modalBody.addClass('modal-overflow');
|
|
}
|
|
|
|
this.ui.path.autoComplete('/directories');
|
|
},
|
|
|
|
_save: function () {
|
|
this.ui.indicator.show();
|
|
|
|
var self = this;
|
|
var promise = this.model.save();
|
|
|
|
if (promise) {
|
|
promise.done(function () {
|
|
self.targetCollection.add(self.model, { merge: true });
|
|
vent.trigger(vent.Commands.CloseModalCommand);
|
|
});
|
|
|
|
promise.fail(function () {
|
|
self.ui.indicator.hide();
|
|
});
|
|
}
|
|
},
|
|
|
|
_saveAndAdd: function () {
|
|
this.ui.indicator.show();
|
|
|
|
var self = this;
|
|
var promise = this.model.save();
|
|
|
|
if (promise) {
|
|
promise.done(function () {
|
|
self.targetCollection.add(self.model, { merge: true });
|
|
|
|
require('Settings/DownloadClient/Add/DownloadClientSchemaModal').open(self.targetCollection);
|
|
});
|
|
|
|
promise.fail(function () {
|
|
self.ui.indicator.hide();
|
|
});
|
|
}
|
|
},
|
|
|
|
_delete: function () {
|
|
var view = new DeleteView({ model: this.model });
|
|
AppLayout.modalRegion.show(view);
|
|
},
|
|
|
|
_back: function () {
|
|
require('Settings/DownloadClient/Add/DownloadClientSchemaModal').open(this.targetCollection);
|
|
},
|
|
|
|
_test: function () {
|
|
var self = this;
|
|
|
|
this.ui.indicator.show();
|
|
|
|
this.model.test().always(function () {
|
|
self.ui.indicator.hide();
|
|
});
|
|
}
|
|
});
|
|
|
|
AsModelBoundView.call(view);
|
|
AsValidatedView.call(view);
|
|
|
|
return view;
|
|
});
|