add_alert_definition_routes.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. module.exports = App.WizardRoute.extend({
  20. route: '/alerts/add',
  21. enter: function (router) {
  22. if (App.isAccessible('ADMIN')) {
  23. Em.run.next(function () {
  24. var addAlertDefinitionController = router.get('addAlertDefinitionController');
  25. App.router.get('updateController').set('isWorking', false);
  26. var popup = App.ModalPopup.show({
  27. classNames: ['full-width-modal'],
  28. header: Em.I18n.t('alerts.add.header'),
  29. bodyClass: App.AddAlertDefinitionView.extend({
  30. controllerBinding: 'App.router.addAlertDefinitionController'
  31. }),
  32. primary: Em.I18n.t('form.cancel'),
  33. showFooter: false,
  34. secondary: null,
  35. onPrimary: function () {
  36. this.hide();
  37. App.router.transitionTo('main.alerts.index');
  38. },
  39. onClose: function () {
  40. this.set('showCloseButton', false); // prevent user to click "Close" many times
  41. App.router.get('updateController').set('isWorking', true);
  42. router.transitionTo('main.alerts.index');
  43. this.hide();
  44. },
  45. didInsertElement: function () {
  46. this.fitHeight();
  47. }
  48. });
  49. addAlertDefinitionController.set('popup', popup);
  50. router.transitionTo('step' + addAlertDefinitionController.get('currentStep'));
  51. });
  52. } else {
  53. Em.run.next(function () {
  54. App.router.transitionTo('main.alerts');
  55. });
  56. }
  57. },
  58. step1: Em.Route.extend({
  59. route: '/step1',
  60. connectOutlets: function (router) {
  61. var controller = router.get('addAlertDefinitionController');
  62. controller.setCurrentStep('1');
  63. controller.set('content', controller.getDBProperty('content'));
  64. controller.connectOutlet('addAlertDefinitionStep1', controller.get('content'));
  65. },
  66. next: function (router) {
  67. var controller = router.get('addAlertDefinitionController');
  68. controller.setDBProperty('content', controller.get('content'));
  69. router.transitionTo('step2');
  70. }
  71. }),
  72. step2: Em.Route.extend({
  73. route: '/step2',
  74. connectOutlets: function (router) {
  75. var controller = router.get('addAlertDefinitionController');
  76. controller.setCurrentStep('2');
  77. controller.set('content', controller.getDBProperty('content'));
  78. controller.connectOutlet('addAlertDefinitionStep2', controller.get('content'));
  79. },
  80. back: Em.Router.transitionTo('step1'),
  81. next: function (router) {
  82. var controller = router.get('addAlertDefinitionController');
  83. controller.set('content.configs', App.router.get('mainAlertDefinitionConfigsController.configs'));
  84. var newDefinitionData = App.router.get('mainAlertDefinitionConfigsController').getPropertiesToUpdate(false);
  85. newDefinitionData['AlertDefinition/source'].type = controller.get('content.selectedType');
  86. newDefinitionData['AlertDefinition/label'] = newDefinitionData['AlertDefinition/name'];
  87. newDefinitionData['AlertDefinition/name'] = newDefinitionData['AlertDefinition/name'].toLowerCase().replace(/\s+/g, '_');
  88. controller.set('content.formattedToRequestConfigs', newDefinitionData);
  89. controller.setDBProperty('content', controller.get('content'));
  90. router.transitionTo('step3');
  91. }
  92. }),
  93. step3: Em.Route.extend({
  94. route: '/step3',
  95. connectOutlets: function (router) {
  96. var controller = router.get('addAlertDefinitionController');
  97. controller.setCurrentStep('3');
  98. controller.set('content', controller.getDBProperty('content'));
  99. controller.connectOutlet('addAlertDefinitionStep3', controller.get('content'));
  100. },
  101. back: Em.Router.transitionTo('step2'),
  102. done: function (router) {
  103. var controller = router.get('addAlertDefinitionController');
  104. controller.createNewAlertDefinition(Em.get(controller.getDBProperty('content'), 'formattedToRequestConfigs')).done(function () {
  105. controller.get('popup').hide();
  106. controller.setDBProperty('content', {});
  107. controller.finish();
  108. App.clusterStatus.setClusterStatus({
  109. clusterName: controller.get('content.cluster.name'),
  110. clusterState: 'DEFAULT',
  111. localdb: App.db.data
  112. },
  113. {
  114. alwaysCallback: function () {
  115. controller.get('popup').hide();
  116. router.transitionTo('main.alerts');
  117. location.reload();
  118. }
  119. });
  120. });
  121. }
  122. })
  123. });