2013-05-21 09:16:19 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
define([
|
|
|
|
'app',
|
2013-05-29 10:20:41 +03:00
|
|
|
'Settings/Notifications/Model',
|
|
|
|
'Settings/Notifications/DeleteView'
|
2013-05-21 09:16:19 +03:00
|
|
|
|
|
|
|
], function () {
|
|
|
|
|
|
|
|
NzbDrone.Settings.Notifications.EditView = Backbone.Marionette.ItemView.extend({
|
|
|
|
template : 'Settings/Notifications/EditTemplate',
|
|
|
|
|
|
|
|
events: {
|
2013-06-13 05:55:11 +03:00
|
|
|
'click .x-save' : '_saveNotification',
|
|
|
|
'click .x-remove' : '_deleteNotification',
|
|
|
|
'click .x-test' : '_test'
|
|
|
|
},
|
|
|
|
|
|
|
|
ui: {
|
|
|
|
testButton : '.x-test',
|
|
|
|
testIcon : '.x-test-icon'
|
2013-05-21 09:16:19 +03:00
|
|
|
},
|
|
|
|
|
2013-05-29 05:49:17 +03:00
|
|
|
initialize: function (options) {
|
|
|
|
this.notificationCollection = options.notificationCollection;
|
|
|
|
},
|
|
|
|
|
2013-05-29 10:20:41 +03:00
|
|
|
_saveNotification: function () {
|
2013-05-29 05:49:17 +03:00
|
|
|
var name = this.model.get('name');
|
|
|
|
var success = 'Notification Saved: ' + name;
|
|
|
|
var fail = 'Failed to save notification: ' + name;
|
2013-05-21 09:16:19 +03:00
|
|
|
|
2013-06-01 03:22:47 +03:00
|
|
|
this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({
|
|
|
|
successMessage: success,
|
|
|
|
errorMessage: fail,
|
|
|
|
successCallback: this._saveSuccess,
|
|
|
|
context: this
|
|
|
|
}));
|
2013-05-21 09:16:19 +03:00
|
|
|
},
|
|
|
|
|
2013-05-29 10:20:41 +03:00
|
|
|
_deleteNotification: function () {
|
|
|
|
var view = new NzbDrone.Settings.Notifications.DeleteView({ model: this.model });
|
|
|
|
NzbDrone.modalRegion.show(view);
|
|
|
|
},
|
|
|
|
|
2013-06-01 03:22:47 +03:00
|
|
|
_saveSuccess: function () {
|
|
|
|
this.notificationCollection.add(this.model, { merge: true });
|
|
|
|
NzbDrone.modalRegion.closeModal();
|
2013-06-13 05:55:11 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_test: function () {
|
|
|
|
var command = this.model.get('command');
|
|
|
|
if (command) {
|
|
|
|
this.idle = false;
|
|
|
|
this.ui.testButton.addClass('disabled');
|
|
|
|
this.ui.testIcon.removeClass('icon-question');
|
|
|
|
this.ui.testIcon.addClass('icon-spinner icon-spin');
|
|
|
|
|
|
|
|
var properties = {};
|
|
|
|
|
|
|
|
_.each(this.model.attributes.fields, function (field) {
|
|
|
|
properties[field.name] = field.value;
|
|
|
|
});
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var commandPromise = NzbDrone.Commands.Execute(command, properties);
|
|
|
|
commandPromise.done(function () {
|
|
|
|
NzbDrone.Shared.Messenger.show({
|
|
|
|
message: 'Notification settings tested successfully'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
commandPromise.fail(function (options) {
|
|
|
|
if (options.readyState === 0 || options.status === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NzbDrone.Shared.Messenger.show({
|
|
|
|
message: 'Failed to test notification settings',
|
|
|
|
type : 'error'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
commandPromise.always(function () {
|
|
|
|
if (!self.isClosed) {
|
|
|
|
self.ui.testButton.removeClass('disabled');
|
|
|
|
self.ui.testIcon.addClass('icon-question');
|
|
|
|
self.ui.testIcon.removeClass('icon-spinner icon-spin');
|
|
|
|
self.idle = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-05-21 09:16:19 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|