1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-10 04:52:42 +01:00
Radarr/UI/Settings/Notifications/EditView.js

94 lines
2.8 KiB
JavaScript
Raw Normal View History

2013-06-22 08:24:24 +02:00
'use strict';
define([
'app',
2013-06-19 03:02:23 +02:00
'marionette',
2013-05-29 09:20:41 +02:00
'Settings/Notifications/Model',
2013-06-19 03:02:23 +02:00
'Settings/Notifications/DeleteView',
'Shared/Messenger',
'Mixins/AsModelBoundView'
], function (App, Marionette, NotificationModel, DeleteView, Messenger, AsModelBoundView) {
2013-06-19 03:02:23 +02:00
var model = Marionette.ItemView.extend({
template: 'Settings/Notifications/EditTemplate',
events: {
2013-06-19 03:02:23 +02:00
'click .x-save' : '_saveNotification',
'click .x-remove': '_deleteNotification',
'click .x-test' : '_test'
2013-06-13 04:55:11 +02:00
},
ui: {
2013-06-19 03:02:23 +02:00
testButton: '.x-test',
testIcon : '.x-test-icon'
},
2013-05-29 04:49:17 +02:00
initialize: function (options) {
this.notificationCollection = options.notificationCollection;
},
2013-05-29 09:20:41 +02:00
_saveNotification: function () {
var promise = this.model.saveSettings();
if (promise) {
promise.done(this._saveSuccess);
}
},
2013-05-29 09:20:41 +02:00
_deleteNotification: function () {
2013-06-19 03:02:23 +02:00
var view = new DeleteView({ model: this.model });
App.modalRegion.show(view);
2013-05-29 09:20:41 +02:00
},
2013-06-01 02:22:47 +02:00
_saveSuccess: function () {
this.notificationCollection.add(this.model, { merge: true });
2013-06-19 03:02:23 +02:00
App.modalRegion.closeModal();
2013-06-13 04:55:11 +02:00
},
_test: function () {
2013-06-13 17:21:38 +02:00
var testCommand = this.model.get('testCommand');
if (testCommand) {
2013-06-13 04:55:11 +02:00
this.idle = false;
this.ui.testButton.addClass('disabled');
this.ui.testIcon.addClass('icon-spinner icon-spin');
var properties = {};
2013-06-13 17:21:38 +02:00
_.each(this.model.get('fields'), function (field) {
2013-06-13 04:55:11 +02:00
properties[field.name] = field.value;
});
var self = this;
2013-06-19 03:02:23 +02:00
var commandPromise = App.Commands.Execute(testCommand, properties);
2013-06-13 04:55:11 +02:00
commandPromise.done(function () {
2013-06-19 03:02:23 +02:00
Messenger.show({
2013-06-13 04:55:11 +02:00
message: 'Notification settings tested successfully'
});
});
commandPromise.fail(function (options) {
if (options.readyState === 0 || options.status === 0) {
return;
}
2013-06-19 03:02:23 +02:00
Messenger.show({
2013-06-13 04:55:11 +02:00
message: 'Failed to test notification settings',
type : 'error'
});
});
commandPromise.always(function () {
if (!self.isClosed) {
self.ui.testButton.removeClass('disabled');
self.ui.testIcon.removeClass('icon-spinner icon-spin');
self.idle = true;
}
});
}
}
});
2013-06-19 03:02:23 +02:00
return AsModelBoundView.call(model);
});