add_widget.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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: '/widget/add',
  21. enter: function (router, context) {
  22. router.get('mainController').dataLoading().done(function () {
  23. var widgetWizardController = router.get('widgetWizardController');
  24. App.router.get('updateController').set('isWorking', false);
  25. var popup = App.ModalPopup.show({
  26. classNames: ['full-width-modal'],
  27. header: Em.I18n.t('widget.create.wizard.header'),
  28. bodyClass: App.WidgetWizardView.extend({
  29. controller: widgetWizardController
  30. }),
  31. primary: Em.I18n.t('form.cancel'),
  32. showFooter: false,
  33. secondary: null,
  34. onClose: function () {
  35. var self = this;
  36. widgetWizardController.finish();
  37. if (App.testMode) {
  38. self.hide();
  39. var serviceName = widgetWizardController.get('content.widgetService');
  40. var service = App.Service.find().findProperty('serviceName', serviceName);
  41. router.transitionTo('main.services.service', service);
  42. } else {
  43. App.clusterStatus.setClusterStatus({
  44. clusterName: App.router.getClusterName(),
  45. clusterState: 'DEFAULT',
  46. localdb: App.db.data
  47. }, {
  48. alwaysCallback: function () {
  49. self.hide();
  50. var serviceName = widgetWizardController.get('content.widgetService');
  51. var service = App.Service.find().findProperty('serviceName', serviceName);
  52. router.transitionTo('main.services.service', service);
  53. }
  54. });
  55. }
  56. },
  57. didInsertElement: function () {
  58. this.fitHeight();
  59. }
  60. });
  61. widgetWizardController.set('popup', popup);
  62. var currentClusterStatus = App.clusterStatus.get('value');
  63. if (currentClusterStatus) {
  64. if (App.get('testMode')) {
  65. widgetWizardController.setCurrentStep(App.db.data.WidgetWizard.currentStep);
  66. } else {
  67. var currStep = App.get('router.widgetWizardController.currentStep');
  68. widgetWizardController.setCurrentStep(currStep);
  69. }
  70. }
  71. Em.run.next(function () {
  72. router.transitionTo('step' + widgetWizardController.get('currentStep'));
  73. });
  74. });
  75. },
  76. step1: Em.Route.extend({
  77. route: '/step1',
  78. connectOutlets: function (router) {
  79. var controller = router.get('widgetWizardController');
  80. controller.dataLoading().done(function () {
  81. router.get('widgetWizardController').setCurrentStep('1');
  82. controller.loadAllPriorSteps();
  83. controller.connectOutlet('widgetWizardStep1', controller.get('content'));
  84. });
  85. },
  86. unroutePath: function () {
  87. return false;
  88. },
  89. next: function (router) {
  90. var widgetWizardController = router.get('widgetWizardController');
  91. var widgetStep1controller = router.get('widgetWizardStep1Controller');
  92. widgetWizardController.saveWidgetType(widgetStep1controller.get('widgetType'));
  93. widgetWizardController.setDBProperty('widgetProperties', []);
  94. widgetWizardController.setDBProperty('widgetMetrics', []);
  95. widgetWizardController.setDBProperty('widgetValues', []);
  96. router.transitionTo('step2');
  97. }
  98. }),
  99. step2: Em.Route.extend({
  100. route: '/step2',
  101. connectOutlets: function (router) {
  102. var controller = router.get('widgetWizardController');
  103. controller.dataLoading().done(function () {
  104. router.get('widgetWizardController').setCurrentStep('2');
  105. controller.loadAllPriorSteps();
  106. controller.connectOutlet('widgetWizardStep2', controller.get('content'));
  107. });
  108. },
  109. unroutePath: function () {
  110. return false;
  111. },
  112. back: Em.Router.transitionTo('step1'),
  113. next: function (router) {
  114. var widgetWizardController = router.get('widgetWizardController');
  115. var widgetStep2controller = router.get('widgetWizardStep2Controller');
  116. widgetWizardController.saveWidgetProperties(widgetStep2controller.get('widgetProperties'));
  117. widgetWizardController.saveWidgetMetrics(widgetStep2controller.get('widgetMetrics'));
  118. widgetWizardController.saveWidgetValues(widgetStep2controller.get('widgetValues'));
  119. widgetWizardController.setDBProperty('widgetName', null);
  120. widgetWizardController.setDBProperty('widgetDescription', null);
  121. widgetWizardController.setDBProperty('widgetScope', null);
  122. router.transitionTo('step3');
  123. }
  124. }),
  125. step3: Em.Route.extend({
  126. route: '/step3',
  127. connectOutlets: function (router) {
  128. var controller = router.get('widgetWizardController');
  129. controller.dataLoading().done(function () {
  130. router.get('widgetWizardController').setCurrentStep('3');
  131. controller.loadAllPriorSteps();
  132. controller.connectOutlet('widgetWizardStep3', controller.get('content'));
  133. });
  134. },
  135. unroutePath: function () {
  136. return false;
  137. },
  138. back: Em.Router.transitionTo('step2'),
  139. complete: function (router, context) {
  140. var controller = router.get('widgetWizardStep3Controller');
  141. if (!controller.get('isSubmitDisabled')) {
  142. $(context.currentTarget).parents("#modal").find(".close").trigger('click');
  143. }
  144. }
  145. })
  146. });