Last active
December 20, 2015 08:59
-
-
Save ramrrr/6104168 to your computer and use it in GitHub Desktop.
Error message:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var App = require("core/App"); | |
| var HasModal = require("core/HasModal") | |
| var Alert = require("./Alert"); | |
| var AlertController = require("./EventAlertController") | |
| require("./AlertTabView") | |
| require("./AlertSummaryView") | |
| require("./ChannelIconView") | |
| require("core/ui/TimePicker") | |
| require("core/RootMenuView") | |
| require("core/ui/DatePickerView") | |
| require("admin/User") | |
| require("admin/Organization") | |
| function alertBoundValue(defaultValue) { | |
| var values = {} | |
| return function(key, value) { | |
| if (!values[this.get("model")]) { | |
| values[this.get("model")] = defaultValue; | |
| } | |
| if (arguments.length === 1) { | |
| return values[this.get("model")]; | |
| } else { | |
| values[this.get("model")] = value | |
| return value; | |
| } | |
| }.property("model"); | |
| } | |
| module.exports = App.EventController = Ember.ObjectController.extend(HasModal, { | |
| composing: true, | |
| currentAlert: null, | |
| testSendVoice: false, | |
| testSendSms: false, | |
| testSuccess:false, | |
| onContentChange: function() { | |
| if (this.get("model.alerts.length") == 0) { | |
| this.addAlert(); | |
| this.set("testSuccess",false) ; | |
| } | |
| }.observes("model"), | |
| addAlert: function() { | |
| // Calculate the next index to use. | |
| var alertIndex = this.get("model.alerts") | |
| // Get all alert names | |
| .getEach("name") | |
| // Get names matching Alert digits | |
| .filter(function(name) { return /Alert (\d+)/.test(name)}) | |
| // Convert the alert name to a number | |
| .map(function(name) { return parseInt(name.match(/Alert (\d+)/)[1]) }) | |
| // Get the max alert number + 1 | |
| .reduce(function(a, b) { return Math.max(a, b) + 1}, 1); | |
| var alert = Alert.createRecord({ | |
| name: "Alert " + (alertIndex) | |
| }); | |
| this.get("model.alerts").pushObject(alert); | |
| alert.set("simulation", this.get("simuluation")); | |
| this.selectAlert(alert) ; | |
| }, | |
| renameAlert: function(alert) { | |
| this.set("editAlert", alert); | |
| }, | |
| saveAlertName: function() { | |
| this.set("editAlert", null); | |
| }, | |
| removeAlert: function(alert) { | |
| if (this.get("model.alerts.length") > 1) { | |
| this.set("alertToDelete", alert); | |
| this.set("activeModal", "confirmDeleteAlert"); | |
| } | |
| }, | |
| removeSelectedAlert: function(alert) { | |
| this.set("alertToDelete", alert); | |
| this.set("activeModal", "confirmDeleteAlert"); | |
| }, | |
| confirmedRemoveAlert: function(alert) { | |
| this.set("activeModal", "none"); | |
| if (this.get("model.alerts.length") > 1) { | |
| this.get("model.alerts").removeObject(alert); | |
| if (this.get("activeAlert") == alert) { | |
| this.selectAlert(this.get("model.alerts").objectAt(0)); | |
| } | |
| } | |
| }, | |
| cancelAlert:function(){ | |
| this.set("activeModal", "confirmDeleteAllAlert"); | |
| }, | |
| confirmedRemoveAllAlert:function(){ | |
| history.go(0); | |
| }, | |
| singleAlert: function() { | |
| return this.get("model.alerts.length") < 2; | |
| }.property("model.alerts.length"), | |
| activeAlert: function() { | |
| return this.get("model.alerts").objectAt(0); | |
| }.property("model.alerts"), | |
| selectAlert:function(alert){ | |
| this.set("activeAlert", alert); | |
| this.set("editAlert", null); | |
| }, | |
| simulation: function(key, value) { | |
| if (arguments.length === 1) { | |
| return this.get("model.alerts").everyProperty("simulation") | |
| } else { | |
| this.get("model.alerts").setEach("simulation", value) | |
| return value; | |
| } | |
| }.property("model.alerts.@each.simulation"), | |
| simulationOptions: [ | |
| {state: false, name: Ember.I18n.t("composer.mode.live")}, | |
| {state: true, name: Ember.I18n.t("composer.mode.training")} | |
| ], | |
| alertsExpanded: alertBoundValue(true), | |
| toggleAlerts: function() { | |
| this.set("alertsExpanded", !this.get("alertsExpanded")) | |
| }, | |
| // Verify | |
| verify: function() { | |
| var self = this; | |
| this.get("model").validate(function(ok) { | |
| // Leave composing if the validation was ok | |
| self.set("composing", !ok); | |
| }); | |
| }, | |
| edit: function(alert) { | |
| this.set("composing", true); | |
| this.selectAlert(alert) ; | |
| }, | |
| sendAlert: function() { | |
| this.get("model.alerts").forEach(function(alert) { | |
| alert.get("recipients").pushObjects(alert.get("draftRecipients").toArray()); | |
| }) | |
| $.ajax({ | |
| url:App.get("baseUrl") + "/sendDirect/ajax", | |
| type:"POST", | |
| data:JSON.stringify(this.get("model").serialize()), | |
| contentType:"application/json; charset=utf-8", | |
| dataType:"json", | |
| success: function(data, textStatus, jqXHR) { | |
| window.location = App.get("baseUrl") + "/monitor/status/event/" + data | |
| } | |
| }).fail(function(data) { | |
| // TODO | |
| }); | |
| } , | |
| setAlertModal: function(alert){ | |
| this.set('currentAlert',alert) | |
| this.setModal('testSend') | |
| }, | |
| sendTestAlert: function(currentAlert) { | |
| this.setModal('none'); | |
| var data = { voiceChannel: currentAlert.getChannel(VoiceChannel).serialize(), testSendVoice: this.get("testSendVoice"), voiceAddress: currentAlert.get("testVoicePhone")} | |
| alert(data); | |
| $.ajax({ | |
| url:App.get("baseUrl") + "/sendDirect/testSend", | |
| type:"POST", | |
| data: data, | |
| contentType:"application/json; charset=utf-8", | |
| dataType:"json", | |
| success: function(data, textStatus, jqXHR) { | |
| this.set("testSuccess",true) ; | |
| } | |
| }).fail(function(data) { | |
| // TODO | |
| }); | |
| }, | |
| getChannel : function(type) { | |
| return this.get("channel").find(function(coffee) { | |
| return c instanceof type; | |
| }); | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment