2013-06-22 06:24:24 +00:00
|
|
|
|
'use strict';
|
2013-05-21 06:16:19 +00:00
|
|
|
|
|
|
|
|
|
define([
|
|
|
|
|
'app',
|
2013-06-19 01:02:23 +00:00
|
|
|
|
'marionette',
|
2013-05-29 07:20:41 +00:00
|
|
|
|
'Settings/Notifications/Model',
|
2013-06-19 01:02:23 +00:00
|
|
|
|
'Settings/Notifications/DeleteView',
|
|
|
|
|
'Shared/Messenger',
|
2013-09-12 00:42:15 +00:00
|
|
|
|
'Commands/CommandController',
|
2013-06-26 00:34:33 +00:00
|
|
|
|
'Mixins/AsModelBoundView',
|
|
|
|
|
'Form/FormBuilder'
|
2013-05-21 06:16:19 +00:00
|
|
|
|
|
2013-09-12 00:42:15 +00:00
|
|
|
|
], function (App, Marionette, NotificationModel, DeleteView, Messenger, CommandController, AsModelBoundView) {
|
2013-05-21 06:16:19 +00:00
|
|
|
|
|
2013-06-19 01:02:23 +00:00
|
|
|
|
var model = Marionette.ItemView.extend({
|
|
|
|
|
template: 'Settings/Notifications/EditTemplate',
|
2013-05-21 06:16:19 +00:00
|
|
|
|
|
|
|
|
|
events: {
|
2013-06-28 01:55:45 +00:00
|
|
|
|
'click .x-save' : '_saveNotification',
|
|
|
|
|
'click .x-save-and-add' : '_saveAndAddNotification',
|
|
|
|
|
'click .x-delete' : '_deleteNotification',
|
|
|
|
|
'click .x-back' : '_back',
|
|
|
|
|
'click .x-test' : '_test'
|
2013-06-13 02:55:11 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ui: {
|
2013-06-19 01:02:23 +00:00
|
|
|
|
testButton: '.x-test',
|
|
|
|
|
testIcon : '.x-test-icon'
|
2013-05-21 06:16:19 +00:00
|
|
|
|
},
|
|
|
|
|
|
2013-05-29 02:49:17 +00:00
|
|
|
|
initialize: function (options) {
|
|
|
|
|
this.notificationCollection = options.notificationCollection;
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-29 07:20:41 +00:00
|
|
|
|
_saveNotification: function () {
|
2013-06-26 00:34:33 +00:00
|
|
|
|
var self = this;
|
2013-06-19 04:27:41 +00:00
|
|
|
|
var promise = this.model.saveSettings();
|
2013-05-21 06:16:19 +00:00
|
|
|
|
|
2013-06-19 04:27:41 +00:00
|
|
|
|
if (promise) {
|
2013-06-26 00:34:33 +00:00
|
|
|
|
promise.done(function () {
|
|
|
|
|
self.notificationCollection.add(self.model, { merge: true });
|
2013-07-24 01:15:58 +00:00
|
|
|
|
App.vent.trigger(App.Commands.CloseModalCommand);
|
2013-06-26 00:34:33 +00:00
|
|
|
|
});
|
2013-06-19 04:27:41 +00:00
|
|
|
|
}
|
2013-05-21 06:16:19 +00:00
|
|
|
|
},
|
|
|
|
|
|
2013-06-28 01:55:45 +00:00
|
|
|
|
_saveAndAddNotification: function () {
|
|
|
|
|
var self = this;
|
|
|
|
|
var promise = this.model.saveSettings();
|
|
|
|
|
|
|
|
|
|
if (promise) {
|
|
|
|
|
promise.done(function () {
|
|
|
|
|
self.notificationCollection.add(self.model, { merge: true });
|
|
|
|
|
|
|
|
|
|
require('Settings/Notifications/SchemaModal').open(self.notificationCollection);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-29 07:20:41 +00:00
|
|
|
|
_deleteNotification: function () {
|
2013-06-19 01:02:23 +00:00
|
|
|
|
var view = new DeleteView({ model: this.model });
|
|
|
|
|
App.modalRegion.show(view);
|
2013-05-29 07:20:41 +00:00
|
|
|
|
},
|
|
|
|
|
|
2013-06-28 01:55:45 +00:00
|
|
|
|
_back: function () {
|
|
|
|
|
require('Settings/Notifications/SchemaModal').open(this.notificationCollection);
|
2013-06-13 02:55:11 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_test: function () {
|
2013-06-13 15:21:38 +00:00
|
|
|
|
var testCommand = this.model.get('testCommand');
|
|
|
|
|
if (testCommand) {
|
2013-06-13 02:55:11 +00:00
|
|
|
|
this.idle = false;
|
|
|
|
|
var properties = {};
|
|
|
|
|
|
2013-06-13 15:21:38 +00:00
|
|
|
|
_.each(this.model.get('fields'), function (field) {
|
2013-06-13 02:55:11 +00:00
|
|
|
|
properties[field.name] = field.value;
|
|
|
|
|
});
|
|
|
|
|
|
2013-09-12 00:42:15 +00:00
|
|
|
|
|
|
|
|
|
CommandController.Execute(testCommand, properties);
|
2013-08-31 03:08:19 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2013-06-13 02:55:11 +00:00
|
|
|
|
|
2013-08-31 03:08:19 +00:00
|
|
|
|
_testOnAlways: function () {
|
|
|
|
|
if (!this.isClosed) {
|
|
|
|
|
this.idle = true;
|
2013-06-13 02:55:11 +00:00
|
|
|
|
}
|
2013-05-21 06:16:19 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2013-06-19 01:02:23 +00:00
|
|
|
|
|
|
|
|
|
return AsModelBoundView.call(model);
|
2013-05-21 06:16:19 +00:00
|
|
|
|
});
|