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. id: target.AlertTarget.id
  84. }));
  85. }
  86. });
  87. }
  88. this.set('alertNotifications', alertNotifications);
  89. },
  90. onLoadAlertNotificationsError: function () {
  91. console.error('Unable to load all alert notifications.');
  92. },
  93. loadAlertGroups: function () {
  94. this.set('isLoaded', false);
  95. this.set('alertGroups.length', 0);
  96. this.set('originalAlertGroups.length', 0);
  97. App.ajax.send({
  98. name: 'alerts.load_alert_groups',
  99. sender: this,
  100. success: 'onLoadAlertGroupsSuccess',
  101. error: 'onLoadAlertGroupsError'
  102. });
  103. },
  104. onLoadAlertGroupsSuccess: function (data) {
  105. var self = this;
  106. if (data && data.items) {
  107. this.set('alertGroupsCount', data.items.length);
  108. data.items.forEach(function(alert_group) {
  109. App.ajax.send({
  110. name: 'alerts.load_an_alert_group',
  111. sender: self,
  112. data: {
  113. "group_id": alert_group.AlertGroup.id
  114. },
  115. success: 'onLoadAlertGroupSuccess',
  116. error: 'onLoadAlertGroupError'
  117. });
  118. }, this);
  119. }
  120. },
  121. onLoadAlertGroupSuccess: function (data) {
  122. var alertGroups = this.get('alertGroups');
  123. if (data && data.AlertGroup) {
  124. alertGroups.pushObject ( App.AlertGroupComplex.create({
  125. name: data.AlertGroup.name,
  126. default: data.AlertGroup.default,
  127. id: data.AlertGroup.id,
  128. definitions: data.AlertGroup.definitions,
  129. notifications: data.AlertGroup.targets
  130. }));
  131. }
  132. if (this.get('alertGroupsCount') == alertGroups.length) {
  133. this.set('isLoaded', true);
  134. this.set('originalAlertGroups', this.copyAlertGroups(alertGroups));
  135. }
  136. },
  137. onLoadAlertGroupsError: function () {
  138. console.error('Unable to load all alert groups.');
  139. },
  140. onLoadAlertGroupError: function () {
  141. console.error('Unable to load an alert group.');
  142. },
  143. resortAlertGroup: function() {
  144. var alertGroups = Ember.copy(this.get('alertGroups'));
  145. if(alertGroups.length < 2){
  146. return;
  147. }
  148. var defaultGroups = alertGroups.filterProperty('default');
  149. defaultGroups.forEach( function(defaultGroup) {
  150. alertGroups.removeObject(defaultGroup);
  151. });
  152. var sorted = defaultGroups.concat(alertGroups.sortProperty('name'));
  153. // var sorted = alertGroups.sortProperty('name');
  154. this.removeObserver('alertGroups.@each.name', this, 'resortAlertGroup');
  155. this.set('alertGroups', sorted);
  156. this.addObserver('alertGroups.@each.name', this, 'resortAlertGroup');
  157. }.observes('alertGroups.@each.name'),
  158. /**
  159. * remove definitions from group
  160. */
  161. deleteDefinitions: function () {
  162. if (this.get('isDeleteDefinitionsDisabled')) {
  163. return;
  164. }
  165. var groupDefinitions = this.get('selectedAlertGroup.definitions');
  166. this.get('selectedDefinitions').slice().forEach(function (defObj) {
  167. groupDefinitions.removeObject(defObj);
  168. }, this);
  169. this.set('selectedDefinitions', []);
  170. },
  171. isDeleteDefinitionsDisabled: function () {
  172. var selectedGroup = this.get('selectedAlertGroup');
  173. if (selectedGroup) {
  174. return selectedGroup.default || this.get('selectedDefinitions').length === 0;
  175. }
  176. return true;
  177. }.property('selectedAlertGroup', 'selectedAlertGroup.definitions.length', 'selectedDefinitions.length'),
  178. /**
  179. * add alert definitions to a group
  180. */
  181. addDefinitions: function () {
  182. if (this.get('selectedAlertGroup.isAddDefinitionsDisabled')){
  183. return false;
  184. }
  185. var availableDefinitions = this.get('selectedAlertGroup.availableDefinitions');
  186. var popupDescription = {
  187. header: Em.I18n.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.title'),
  188. dialogMessage: Em.I18n.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.message').format(this.get('selectedAlertGroup.displayName'))
  189. };
  190. var validComponents = App.StackServiceComponent.find().map(function (component) {
  191. return Em.Object.create({
  192. componentName: component.get('componentName'),
  193. displayName: App.format.role(component.get('componentName')),
  194. selected: false
  195. });
  196. });
  197. var validServices = App.Service.find().map(function (service) {
  198. return Em.Object.create({
  199. serviceName: service.get('serviceName'),
  200. displayName: App.format.role(service.get('serviceName')),
  201. selected: false
  202. });
  203. });
  204. this.launchDefsSelectionDialog (availableDefinitions, [], validServices, validComponents, this.addDefinitionsCallback.bind(this), popupDescription);
  205. },
  206. /**
  207. * Launch a table view of all available definitions to choose
  208. */
  209. launchDefsSelectionDialog : function(initialDefs, selectedDefs, validServices, validComponents, callback, popupDescription) {
  210. App.ModalPopup.show({
  211. classNames: [ 'sixty-percent-width-modal' ],
  212. header: popupDescription.header,
  213. dialogMessage: popupDescription.dialogMessage,
  214. warningMessage: null,
  215. availableDefs: [],
  216. onPrimary: function () {
  217. this.set('warningMessage', null);
  218. var arrayOfSelectedDefs = this.get('availableDefs').filterProperty('selected', true);
  219. if (arrayOfSelectedDefs.length < 1) {
  220. this.set('warningMessage', Em.I18n.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.message.warning'));
  221. return;
  222. }
  223. callback(arrayOfSelectedDefs);
  224. console.debug('(new-selectedDefs)=', arrayOfSelectedDefs);
  225. this.hide();
  226. },
  227. disablePrimary: function () {
  228. return !this.get('isLoaded');
  229. }.property('isLoaded'),
  230. onSecondary: function () {
  231. callback(null);
  232. this.hide();
  233. },
  234. bodyClass: App.TableView.extend({
  235. templateName: require('templates/main/alerts/add_definition_to_group_popup'),
  236. controllerBinding: 'App.router.manageAlertGroupsController',
  237. isPaginate: true,
  238. filteredContent: function() {
  239. return this.get('parentView.availableDefs').filterProperty('filtered') || [];
  240. }.property('parentView.availableDefs.@each.filtered'),
  241. showOnlySelectedDefs: false,
  242. filterComponents: validComponents,
  243. filterServices: validServices,
  244. filterComponent: null,
  245. filterService: null,
  246. isDisabled: function () {
  247. return !this.get('parentView.isLoaded');
  248. }.property('parentView.isLoaded'),
  249. didInsertElement: function(){
  250. initialDefs.setEach('filtered', true);
  251. this.set('parentView.availableDefs', initialDefs);
  252. this.set('parentView.isLoaded', true);
  253. },
  254. filterDefs: function () {
  255. var showOnlySelectedDefs = this.get('showOnlySelectedDefs');
  256. var filterComponent = this.get('filterComponent');
  257. var filterService = this.get('filterService');
  258. this.get('parentView.availableDefs').forEach(function (defObj) {
  259. var componentOnObj = true;
  260. var serviceOnObj = true;
  261. if (filterComponent) {
  262. componentOnObj = (defObj.componentName == filterComponent.get('componentName'));
  263. }
  264. if (defObj.serviceName && filterService) {
  265. serviceOnObj = (defObj.serviceName == filterService.get('serviceName'));
  266. }
  267. if (showOnlySelectedDefs) {
  268. defObj.set('filtered', componentOnObj && serviceOnObj && defObj.get('selected'));
  269. } else {
  270. defObj.set('filtered', componentOnObj && serviceOnObj);
  271. }
  272. }, this);
  273. this.set('startIndex', 1);
  274. }.observes('parentView.availableDefs', 'filterService', 'filterService.serviceName', 'filterComponent', 'filterComponent.componentName', 'showOnlySelectedDefs'),
  275. defSelectMessage: function () {
  276. var defs = this.get('parentView.availableDefs');
  277. var selectedDefs = defs.filterProperty('selected', true);
  278. return this.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.selectedDefsLink').format(selectedDefs.get('length'), defs.get('length'));
  279. }.property('parentView.availableDefs.@each.selected'),
  280. selectFilterComponent: function (event) {
  281. if (event != null && event.context != null && event.context.componentName != null) {
  282. var currentFilter = this.get('filterComponent');
  283. if (currentFilter != null) {
  284. currentFilter.set('selected', false);
  285. }
  286. if (currentFilter != null && currentFilter.componentName === event.context.componentName) {
  287. // selecting the same filter deselects it.
  288. this.set('filterComponent', null);
  289. } else {
  290. this.set('filterComponent', event.context);
  291. event.context.set('selected', true);
  292. }
  293. }
  294. },
  295. selectFilterService: function (event) {
  296. if (event != null && event.context != null && event.context.serviceName != null) {
  297. var currentFilter = this.get('filterService');
  298. if (currentFilter != null) {
  299. currentFilter.set('selected', false);
  300. }
  301. if (currentFilter != null && currentFilter.serviceName === event.context.serviceName) {
  302. // selecting the same filter deselects it.
  303. this.set('filterService', null);
  304. } else {
  305. this.set('filterService', event.context);
  306. event.context.set('selected', true);
  307. }
  308. }
  309. },
  310. allDefsSelected: false,
  311. toggleSelectAllDefs: function (event) {
  312. this.get('parentView.availableDefs').filterProperty('filtered').setEach('selected', this.get('allDefsSelected'));
  313. }.observes('allDefsSelected'),
  314. toggleShowSelectedDefs: function () {
  315. var filter1 = this.get('filterComponent');
  316. if (filter1 != null) {
  317. filter1.set('selected', false);
  318. }
  319. var filter2 = this.get('filterService');
  320. if (filter2 != null) {
  321. filter2.set('selected', false);
  322. }
  323. this.set('filterComponent', null);
  324. this.set('filterService', null);
  325. this.set('showOnlySelectedDefs', !this.get('showOnlySelectedDefs'));
  326. }
  327. })
  328. });
  329. },
  330. /**
  331. * add alert definitions callback
  332. */
  333. addDefinitionsCallback: function (selectedDefs) {
  334. var group = this.get('selectedAlertGroup');
  335. if (selectedDefs) {
  336. var alertGroupDefs = group.get('definitions');
  337. selectedDefs.forEach(function (defObj) {
  338. alertGroupDefs.pushObject(defObj);
  339. }, this);
  340. }
  341. },
  342. /**
  343. * observes if any group changed including: group name, newly created group, deleted group, group with definitions changed
  344. */
  345. defsModifiedAlertGroups: function () {
  346. if (!this.get('isLoaded')) {
  347. return false;
  348. }
  349. var groupsToDelete = [];
  350. var groupsToSet = [];
  351. var groupsToCreate = [];
  352. var groups = this.get('alertGroups'); //current alert groups
  353. var originalGroups = this.get('originalAlertGroups'); // original alert groups
  354. // remove default group
  355. originalGroups = originalGroups.filterProperty('default', false);
  356. var originalGroupsIds = originalGroups.mapProperty('id');
  357. groups.forEach(function (group) {
  358. if (!group.get('default')) {
  359. var originalGroup = originalGroups.findProperty('id', group.get('id'));
  360. if (originalGroup) {
  361. if (!(JSON.stringify(group.get('definitions').slice().sort()) === JSON.stringify(originalGroup.get('definitions').slice().sort()))
  362. || !(JSON.stringify(group.get('notifications').slice().sort()) === JSON.stringify(originalGroup.get('notifications').slice().sort()))) {
  363. groupsToSet.push(group.set('id', originalGroup.get('id')));
  364. } else if (group.get('name') !== originalGroup.get('name') ) {
  365. // should update name
  366. groupsToSet.push(group.set('id', originalGroup.get('id')));
  367. }
  368. originalGroupsIds = originalGroupsIds.without(group.get('id'));
  369. } else {
  370. groupsToCreate.push(group);
  371. }
  372. }
  373. });
  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. });