manage_alert_groups_controller.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var validator = require('utils/validator');
  20. var numberUtils = require('utils/number_utils');
  21. App.ManageAlertGroupsController = Em.Controller.extend({
  22. name: 'manageAlertGroupsController',
  23. isLoaded: false,
  24. alertGroups: [],
  25. originalAlertGroups: [],
  26. selectedAlertGroup: null,
  27. selectedDefinitions: [],
  28. alertDefinitions: [],
  29. alertNotifications: [],
  30. // load alert definitions for all services
  31. loadAlertDefinitions: function () {
  32. App.ajax.send({
  33. name: 'alerts.load_all_alert_definitions',
  34. sender: this,
  35. success: 'onLoadAlertDefinitionsSuccess',
  36. error: 'onLoadAlertDefinitionsError'
  37. });
  38. },
  39. onLoadAlertDefinitionsSuccess: function (data) {
  40. var alertDefinitions = [];
  41. if (data && data.items) {
  42. data.items.forEach( function(def) {
  43. if (def && def.AlertDefinition) {
  44. alertDefinitions.pushObject (Em.Object.create({
  45. name: def.AlertDefinition.name,
  46. serviceName: def.AlertDefinition.service_name,
  47. serviceNameDisplay:function() {
  48. return App.format.role(this.get('serviceName'));
  49. }.property('serviceName'),
  50. componentName: def.AlertDefinition.component_name,
  51. componentNameDisplay: function() {
  52. return App.format.role(this.get('componentName'));
  53. }.property('componentName'),
  54. label: def.AlertDefinition.label,
  55. id: def.AlertDefinition.id
  56. }));
  57. }
  58. });
  59. }
  60. this.set('alertDefinitions', alertDefinitions);
  61. },
  62. onLoadAlertDefinitionsError: function () {
  63. console.error('Unable to load all alert definitions.');
  64. },
  65. // load all alert notifications
  66. loadAlertNotifications: function () {
  67. App.ajax.send({
  68. name: 'alerts.load_alert_notification',
  69. sender: this,
  70. success: 'onLoadAlertNotificationsSuccess',
  71. error: 'onLoadAlertNotificationsError'
  72. });
  73. },
  74. onLoadAlertNotificationsSuccess: function (data) {
  75. var alertNotifications = [];
  76. if (data && data.items) {
  77. data.items.forEach( function(target) {
  78. if (target && target.AlertTarget) {
  79. alertNotifications.pushObject (Em.Object.create({
  80. name: target.AlertTarget.name,
  81. type: target.AlertTarget.notification_type,
  82. description: target.AlertTarget.description,
  83. global: target.AlertTarget.global,
  84. id: target.AlertTarget.id
  85. }));
  86. }
  87. });
  88. }
  89. this.set('alertNotifications', alertNotifications);
  90. },
  91. onLoadAlertNotificationsError: function () {
  92. console.error('Unable to load all alert notifications.');
  93. },
  94. loadAlertGroups: function () {
  95. this.set('isLoaded', false);
  96. this.set('alertGroups.length', 0);
  97. this.set('originalAlertGroups.length', 0);
  98. App.ajax.send({
  99. name: 'alerts.load_alert_groups',
  100. sender: this,
  101. success: 'onLoadAlertGroupsSuccess',
  102. error: 'onLoadAlertGroupsError'
  103. });
  104. },
  105. onLoadAlertGroupsSuccess: function (data) {
  106. var self = this;
  107. if (data && data.items) {
  108. this.set('alertGroupsCount', data.items.length);
  109. data.items.forEach(function(alert_group) {
  110. App.ajax.send({
  111. name: 'alerts.load_an_alert_group',
  112. sender: self,
  113. data: {
  114. "group_id": alert_group.AlertGroup.id
  115. },
  116. success: 'onLoadAlertGroupSuccess',
  117. error: 'onLoadAlertGroupError'
  118. });
  119. }, this);
  120. }
  121. },
  122. onLoadAlertGroupSuccess: function (data) {
  123. var alertGroups = this.get('alertGroups');
  124. if (data && data.AlertGroup) {
  125. alertGroups.pushObject ( App.AlertGroupComplex.create({
  126. name: data.AlertGroup.name,
  127. default: data.AlertGroup.default,
  128. id: data.AlertGroup.id,
  129. definitions: data.AlertGroup.definitions,
  130. notifications: data.AlertGroup.targets
  131. }));
  132. }
  133. if (this.get('alertGroupsCount') == alertGroups.length) {
  134. this.set('isLoaded', true);
  135. this.set('originalAlertGroups', this.copyAlertGroups(alertGroups));
  136. }
  137. },
  138. onLoadAlertGroupsError: function () {
  139. console.error('Unable to load all alert groups.');
  140. },
  141. onLoadAlertGroupError: function () {
  142. console.error('Unable to load an alert group.');
  143. },
  144. resortAlertGroup: function() {
  145. var alertGroups = Ember.copy(this.get('alertGroups'));
  146. if(alertGroups.length < 2){
  147. return;
  148. }
  149. var defaultGroups = alertGroups.filterProperty('default');
  150. defaultGroups.forEach( function(defaultGroup) {
  151. alertGroups.removeObject(defaultGroup);
  152. });
  153. var sorted = defaultGroups.concat(alertGroups.sortProperty('name'));
  154. // var sorted = alertGroups.sortProperty('name');
  155. this.removeObserver('alertGroups.@each.name', this, 'resortAlertGroup');
  156. this.set('alertGroups', sorted);
  157. this.addObserver('alertGroups.@each.name', this, 'resortAlertGroup');
  158. }.observes('alertGroups.@each.name'),
  159. /**
  160. * remove definitions from group
  161. */
  162. deleteDefinitions: function () {
  163. if (this.get('isDeleteDefinitionsDisabled')) {
  164. return;
  165. }
  166. var groupDefinitions = this.get('selectedAlertGroup.definitions');
  167. this.get('selectedDefinitions').slice().forEach(function (defObj) {
  168. groupDefinitions.removeObject(defObj);
  169. }, this);
  170. this.set('selectedDefinitions', []);
  171. },
  172. isDeleteDefinitionsDisabled: function () {
  173. var selectedGroup = this.get('selectedAlertGroup');
  174. if (selectedGroup) {
  175. return selectedGroup.default || this.get('selectedDefinitions').length === 0;
  176. }
  177. return true;
  178. }.property('selectedAlertGroup', 'selectedAlertGroup.definitions.length', 'selectedDefinitions.length'),
  179. /**
  180. * add alert definitions to a group
  181. */
  182. addDefinitions: function () {
  183. if (this.get('selectedAlertGroup.isAddDefinitionsDisabled')){
  184. return false;
  185. }
  186. var availableDefinitions = this.get('selectedAlertGroup.availableDefinitions');
  187. var popupDescription = {
  188. header: Em.I18n.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.title'),
  189. dialogMessage: Em.I18n.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.message').format(this.get('selectedAlertGroup.displayName'))
  190. };
  191. var validComponents = App.StackServiceComponent.find().map(function (component) {
  192. return Em.Object.create({
  193. componentName: component.get('componentName'),
  194. displayName: App.format.role(component.get('componentName')),
  195. selected: false
  196. });
  197. });
  198. var validServices = App.Service.find().map(function (service) {
  199. return Em.Object.create({
  200. serviceName: service.get('serviceName'),
  201. displayName: App.format.role(service.get('serviceName')),
  202. selected: false
  203. });
  204. });
  205. this.launchDefsSelectionDialog (availableDefinitions, [], validServices, validComponents, this.addDefinitionsCallback.bind(this), popupDescription);
  206. },
  207. /**
  208. * Launch a table view of all available definitions to choose
  209. */
  210. launchDefsSelectionDialog : function(initialDefs, selectedDefs, validServices, validComponents, callback, popupDescription) {
  211. App.ModalPopup.show({
  212. classNames: [ 'sixty-percent-width-modal' ],
  213. header: popupDescription.header,
  214. dialogMessage: popupDescription.dialogMessage,
  215. warningMessage: null,
  216. availableDefs: [],
  217. onPrimary: function () {
  218. this.set('warningMessage', null);
  219. var arrayOfSelectedDefs = this.get('availableDefs').filterProperty('selected', true);
  220. if (arrayOfSelectedDefs.length < 1) {
  221. this.set('warningMessage', Em.I18n.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.message.warning'));
  222. return;
  223. }
  224. callback(arrayOfSelectedDefs);
  225. console.debug('(new-selectedDefs)=', arrayOfSelectedDefs);
  226. this.hide();
  227. },
  228. disablePrimary: function () {
  229. return !this.get('isLoaded');
  230. }.property('isLoaded'),
  231. onSecondary: function () {
  232. callback(null);
  233. this.hide();
  234. },
  235. bodyClass: App.TableView.extend({
  236. templateName: require('templates/main/alerts/add_definition_to_group_popup'),
  237. controllerBinding: 'App.router.manageAlertGroupsController',
  238. isPaginate: true,
  239. filteredContent: function() {
  240. return this.get('parentView.availableDefs').filterProperty('filtered') || [];
  241. }.property('parentView.availableDefs.@each.filtered'),
  242. showOnlySelectedDefs: false,
  243. filterComponents: validComponents,
  244. filterServices: validServices,
  245. filterComponent: null,
  246. filterService: null,
  247. isDisabled: function () {
  248. return !this.get('parentView.isLoaded');
  249. }.property('parentView.isLoaded'),
  250. didInsertElement: function(){
  251. initialDefs.setEach('filtered', true);
  252. this.set('parentView.availableDefs', initialDefs);
  253. this.set('parentView.isLoaded', true);
  254. },
  255. filterDefs: function () {
  256. var showOnlySelectedDefs = this.get('showOnlySelectedDefs');
  257. var filterComponent = this.get('filterComponent');
  258. var filterService = this.get('filterService');
  259. this.get('parentView.availableDefs').forEach(function (defObj) {
  260. var componentOnObj = true;
  261. var serviceOnObj = true;
  262. if (filterComponent) {
  263. componentOnObj = (defObj.componentName == filterComponent.get('componentName'));
  264. }
  265. if (defObj.serviceName && filterService) {
  266. serviceOnObj = (defObj.serviceName == filterService.get('serviceName'));
  267. }
  268. if (showOnlySelectedDefs) {
  269. defObj.set('filtered', componentOnObj && serviceOnObj && defObj.get('selected'));
  270. } else {
  271. defObj.set('filtered', componentOnObj && serviceOnObj);
  272. }
  273. }, this);
  274. this.set('startIndex', 1);
  275. }.observes('parentView.availableDefs', 'filterService', 'filterService.serviceName', 'filterComponent', 'filterComponent.componentName', 'showOnlySelectedDefs'),
  276. defSelectMessage: function () {
  277. var defs = this.get('parentView.availableDefs');
  278. var selectedDefs = defs.filterProperty('selected', true);
  279. return this.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.selectedDefsLink').format(selectedDefs.get('length'), defs.get('length'));
  280. }.property('parentView.availableDefs.@each.selected'),
  281. selectFilterComponent: function (event) {
  282. if (event != null && event.context != null && event.context.componentName != null) {
  283. var currentFilter = this.get('filterComponent');
  284. if (currentFilter != null) {
  285. currentFilter.set('selected', false);
  286. }
  287. if (currentFilter != null && currentFilter.componentName === event.context.componentName) {
  288. // selecting the same filter deselects it.
  289. this.set('filterComponent', null);
  290. } else {
  291. this.set('filterComponent', event.context);
  292. event.context.set('selected', true);
  293. }
  294. }
  295. },
  296. selectFilterService: function (event) {
  297. if (event != null && event.context != null && event.context.serviceName != null) {
  298. var currentFilter = this.get('filterService');
  299. if (currentFilter != null) {
  300. currentFilter.set('selected', false);
  301. }
  302. if (currentFilter != null && currentFilter.serviceName === event.context.serviceName) {
  303. // selecting the same filter deselects it.
  304. this.set('filterService', null);
  305. } else {
  306. this.set('filterService', event.context);
  307. event.context.set('selected', true);
  308. }
  309. }
  310. },
  311. allDefsSelected: false,
  312. toggleSelectAllDefs: function (event) {
  313. this.get('parentView.availableDefs').filterProperty('filtered').setEach('selected', this.get('allDefsSelected'));
  314. }.observes('allDefsSelected'),
  315. toggleShowSelectedDefs: function () {
  316. var filter1 = this.get('filterComponent');
  317. if (filter1 != null) {
  318. filter1.set('selected', false);
  319. }
  320. var filter2 = this.get('filterService');
  321. if (filter2 != null) {
  322. filter2.set('selected', false);
  323. }
  324. this.set('filterComponent', null);
  325. this.set('filterService', null);
  326. this.set('showOnlySelectedDefs', !this.get('showOnlySelectedDefs'));
  327. }
  328. })
  329. });
  330. },
  331. /**
  332. * add alert definitions callback
  333. */
  334. addDefinitionsCallback: function (selectedDefs) {
  335. var group = this.get('selectedAlertGroup');
  336. if (selectedDefs) {
  337. var alertGroupDefs = group.get('definitions');
  338. selectedDefs.forEach(function (defObj) {
  339. alertGroupDefs.pushObject(defObj);
  340. }, this);
  341. }
  342. },
  343. /**
  344. * observes if any group changed including: group name, newly created group, deleted group, group with definitions/notifications changed
  345. */
  346. defsModifiedAlertGroups: function () {
  347. if (!this.get('isLoaded')) {
  348. return false;
  349. }
  350. var groupsToDelete = [];
  351. var groupsToSet = [];
  352. var groupsToCreate = [];
  353. var groups = this.get('alertGroups'); //current alert groups
  354. var originalGroups = this.get('originalAlertGroups'); // original alert groups
  355. var originalGroupsIds = originalGroups.mapProperty('id');
  356. groups.forEach(function (group) {
  357. var originalGroup = originalGroups.findProperty('id', group.get('id'));
  358. if (originalGroup) {
  359. // should update definitions or nitifications
  360. if (!(JSON.stringify(group.get('definitions').slice().sort()) === JSON.stringify(originalGroup.get('definitions').slice().sort()))
  361. || !(JSON.stringify(group.get('notifications').slice().sort()) === JSON.stringify(originalGroup.get('notifications').slice().sort()))) {
  362. groupsToSet.push(group.set('id', originalGroup.get('id')));
  363. } else if (group.get('name') !== originalGroup.get('name') ) {
  364. // should update name
  365. groupsToSet.push(group.set('id', originalGroup.get('id')));
  366. }
  367. originalGroupsIds = originalGroupsIds.without(group.get('id'));
  368. } else {
  369. // should add new group
  370. groupsToCreate.push(group);
  371. }
  372. });
  373. // should delete groups
  374. originalGroupsIds.forEach(function (id) {
  375. groupsToDelete.push(originalGroups.findProperty('id', id));
  376. }, this);
  377. return {
  378. toDelete: groupsToDelete,
  379. toSet: groupsToSet,
  380. toCreate: groupsToCreate
  381. };
  382. }.property('selectedAlertGroup.definitions.@each', 'selectedAlertGroup.definitions.length', 'selectedAlertGroup.notifications.@each', 'selectedAlertGroup.notifications.length', 'alertGroups', 'isLoaded'),
  383. isDefsModified: function () {
  384. var modifiedGroups = this.get('defsModifiedAlertGroups');
  385. if (!this.get('isLoaded')) {
  386. return false;
  387. }
  388. return !!(modifiedGroups.toSet.length || modifiedGroups.toCreate.length || modifiedGroups.toDelete.length);
  389. }.property('defsModifiedAlertGroups'),
  390. /**
  391. * copy alert groups for backup, to compare with current alert groups, so will know if some groups changed/added/deleted
  392. * @param originGroups
  393. * @return {Array}
  394. */
  395. copyAlertGroups: function (originGroups) {
  396. var alertGroups = [];
  397. originGroups.forEach(function (alertGroup) {
  398. var copiedGroup = App.AlertGroupComplex.create($.extend(true, {}, alertGroup));
  399. alertGroups.pushObject(copiedGroup);
  400. });
  401. return alertGroups;
  402. },
  403. /**
  404. * ==============on API side: following are four functions to an alert group: create, delete, update definitions/notificationss/label of a group ===========
  405. */
  406. /**
  407. * Create a new alert group
  408. * @param newAlertGroupData
  409. * @param callback Callback function for Success or Error handling
  410. * @return Returns the created alert group
  411. */
  412. postNewAlertGroup: function (newAlertGroupData, callback) {
  413. // create a new group with name , definition and notifications
  414. var data = {
  415. 'name': newAlertGroupData.get('name')
  416. };
  417. if (newAlertGroupData.get('definitions').length > 0) {
  418. data.definitions = newAlertGroupData.get('definitions').mapProperty('id');
  419. }
  420. if (newAlertGroupData.get('notifications').length > 0) {
  421. data.targets = newAlertGroupData.get('notifications').mapProperty('id');
  422. }
  423. var sendData = {
  424. name: 'alert_groups.create',
  425. data: data,
  426. success: 'successFunction',
  427. error: 'errorFunction',
  428. successFunction: function () {
  429. if (callback) {
  430. callback();
  431. }
  432. },
  433. errorFunction: function (xhr, text, errorThrown) {
  434. if (callback) {
  435. callback(xhr, text, errorThrown);
  436. }
  437. console.error('Error in creating new Alert Group');
  438. }
  439. };
  440. sendData.sender = sendData;
  441. App.ajax.send(sendData);
  442. return newAlertGroupData;
  443. },
  444. /**
  445. * PUTs the new alert group information on the server.
  446. * Changes possible here are the name, definitions, notifications
  447. *
  448. * @param {App.AlertGroup} alertGroup
  449. * @param {Function} successCallback
  450. * @param {Function} errorCallback
  451. */
  452. updateAlertGroup: function (alertGroup, successCallback, errorCallback) {
  453. var sendData = {
  454. name: 'alert_groups.update',
  455. data: {
  456. "group_id": alertGroup.id,
  457. 'name': alertGroup.get('name'),
  458. 'definitions': alertGroup.get('definitions').mapProperty('id'),
  459. 'targets': alertGroup.get('notifications').mapProperty('id')
  460. },
  461. success: 'successFunction',
  462. error: 'errorFunction',
  463. successFunction: function () {
  464. if (successCallback) {
  465. successCallback();
  466. }
  467. },
  468. errorFunction: function (xhr, text, errorThrown) {
  469. if (errorCallback) {
  470. errorCallback(xhr, text, errorThrown);
  471. }
  472. }
  473. };
  474. sendData.sender = sendData;
  475. App.ajax.send(sendData);
  476. },
  477. removeAlertGroup: function (alertGroup, successCallback, errorCallback) {
  478. var sendData = {
  479. name: 'alert_groups.delete',
  480. data: {
  481. "group_id": alertGroup.id
  482. },
  483. success: 'successFunction',
  484. error: 'errorFunction',
  485. successFunction: function () {
  486. if (successCallback) {
  487. successCallback();
  488. }
  489. },
  490. errorFunction: function (xhr, text, errorThrown) {
  491. if (errorCallback) {
  492. errorCallback(xhr, text, errorThrown);
  493. }
  494. }
  495. };
  496. sendData.sender = sendData;
  497. App.ajax.send(sendData);
  498. },
  499. /**
  500. * =============on UI side: following are four operations to an alert group: add, remove, rename and duplicate==================
  501. */
  502. /**
  503. * confirm delete alert group
  504. */
  505. confirmDelete : function () {
  506. var self = this;
  507. App.showConfirmationPopup(function() {
  508. self.deleteAlertGroup();
  509. });
  510. },
  511. /**
  512. * delete selected alert group
  513. */
  514. deleteAlertGroup: function () {
  515. var selectedAlertGroup = this.get('selectedAlertGroup');
  516. if (this.get('isDeleteAlertDisabled')) {
  517. return;
  518. }
  519. this.get('alertGroups').removeObject(selectedAlertGroup);
  520. this.set('selectedAlertGroup', this.get('alertGroups')[0]);
  521. },
  522. /**
  523. * rename non-default alert group
  524. */
  525. renameAlertGroup: function () {
  526. if(this.get('selectedAlertGroup.default')) {
  527. return;
  528. }
  529. var self = this;
  530. this.renameGroupPopup = App.ModalPopup.show({
  531. header: Em.I18n.t('alerts.actions.manage_alert_groups_popup.renameButton'),
  532. bodyClass: Ember.View.extend({
  533. templateName: require('templates/main/alerts/create_new_alert_group')
  534. }),
  535. alertGroupName: self.get('selectedAlertGroup.name'),
  536. warningMessage: null,
  537. validate: function () {
  538. var warningMessage = '';
  539. var originalGroup = self.get('selectedAlertGroup');
  540. var groupName = this.get('alertGroupName').trim();
  541. if (originalGroup.get('name').trim() === groupName) {
  542. warningMessage = Em.I18n.t("alerts.actions.manage_alert_groups_popup.addGroup.exist");
  543. } else {
  544. if (self.get('alertGroups').mapProperty('displayName').contains(groupName)) {
  545. warningMessage = Em.I18n.t("alerts.actions.manage_alert_groups_popup.addGroup.exist");
  546. }
  547. else if (groupName && !validator.isValidAlertGroupName(groupName)) {
  548. warningMessage = Em.I18n.t("form.validator.alertGroupName");
  549. }
  550. }
  551. this.set('warningMessage', warningMessage);
  552. }.observes('alertGroupName'),
  553. disablePrimary: function () {
  554. return !(this.get('alertGroupName').trim().length > 0 && (this.get('warningMessage') !== null && !this.get('warningMessage')));
  555. }.property('warningMessage', 'alertGroupName'),
  556. onPrimary: function () {
  557. self.set('selectedAlertGroup.name', this.get('alertGroupName'));
  558. this.hide();
  559. }
  560. });
  561. },
  562. /**
  563. * create new alert group
  564. */
  565. addAlertGroup: function (duplicated) {
  566. duplicated = (duplicated === true);
  567. var self = this;
  568. this.addGroupPopup = App.ModalPopup.show({
  569. header: Em.I18n.t('alerts.actions.manage_alert_groups_popup.addButton'),
  570. bodyClass: Ember.View.extend({
  571. templateName: require('templates/main/alerts/create_new_alert_group')
  572. }),
  573. alertGroupName: duplicated ? self.get('selectedAlertGroup.name') + ' Copy' : "",
  574. warningMessage: '',
  575. didInsertElement: function(){
  576. this.validate();
  577. this.$('input').focus();
  578. },
  579. validate: function () {
  580. var warningMessage = '';
  581. var groupName = this.get('alertGroupName').trim();
  582. if (self.get('alertGroups').mapProperty('displayName').contains(groupName)) {
  583. warningMessage = Em.I18n.t("alerts.actions.manage_alert_groups_popup.addGroup.exist");
  584. }
  585. else if (groupName && !validator.isValidAlertGroupName(groupName)) {
  586. warningMessage = Em.I18n.t("form.validator.alertGroupName");
  587. }
  588. this.set('warningMessage', warningMessage);
  589. }.observes('alertGroupName'),
  590. disablePrimary: function () {
  591. return !(this.get('alertGroupName').trim().length > 0 && !this.get('warningMessage'));
  592. }.property('warningMessage', 'alertGroupName'),
  593. onPrimary: function () {
  594. var newAlertGroup = App.AlertGroupComplex.create({
  595. name: this.get('alertGroupName').trim(),
  596. definitions: [],
  597. notifications: []
  598. });
  599. self.get('alertGroups').pushObject(newAlertGroup);
  600. this.hide();
  601. }
  602. });
  603. },
  604. duplicateAlertGroup: function() {
  605. this.addAlertGroup(true);
  606. }
  607. });