create_widget.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/create',
  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. widgetWizardController.cancel();
  36. },
  37. didInsertElement: function () {
  38. this.fitHeight();
  39. }
  40. });
  41. widgetWizardController.set('popup', popup);
  42. var currentClusterStatus = App.clusterStatus.get('value');
  43. if (currentClusterStatus) {
  44. if (App.get('testMode')) {
  45. widgetWizardController.setCurrentStep(App.db.data.WidgetWizard.currentStep);
  46. } else {
  47. var currStep = App.get('router.widgetWizardController.currentStep');
  48. widgetWizardController.setCurrentStep(currStep);
  49. }
  50. }
  51. Em.run.next(function () {
  52. router.transitionTo('step' + widgetWizardController.get('currentStep'));
  53. });
  54. });
  55. },
  56. step1: Em.Route.extend({
  57. route: '/step1',
  58. connectOutlets: function (router) {
  59. var controller = router.get('widgetWizardController');
  60. controller.dataLoading().done(function () {
  61. router.get('widgetWizardController').setCurrentStep('1');
  62. controller.loadAllPriorSteps();
  63. controller.connectOutlet('widgetWizardStep1', controller.get('content'));
  64. });
  65. },
  66. unroutePath: function () {
  67. return false;
  68. },
  69. next: function (router) {
  70. var widgetWizardController = router.get('widgetWizardController');
  71. var widgetStep1controller = router.get('widgetWizardStep1Controller');
  72. widgetWizardController.save('widgetType', widgetStep1controller.get('widgetType'));
  73. widgetWizardController.setDBProperties({
  74. widgetProperties: {},
  75. widgetMetrics: [],
  76. allMetrics: [],
  77. widgetValues: [],
  78. expressions: [],
  79. dataSets: [],
  80. templateValue: ''
  81. });
  82. router.transitionTo('step2');
  83. }
  84. }),
  85. step2: Em.Route.extend({
  86. route: '/step2',
  87. connectOutlets: function (router) {
  88. var controller = router.get('widgetWizardController');
  89. controller.dataLoading().done(function () {
  90. router.get('widgetWizardController').setCurrentStep('2');
  91. controller.loadAllPriorSteps();
  92. controller.connectOutlet('widgetWizardStep2', controller.get('content'));
  93. });
  94. },
  95. unroutePath: function () {
  96. return false;
  97. },
  98. back: Em.Router.transitionTo('step1'),
  99. next: function (router) {
  100. var widgetWizardController = router.get('widgetWizardController');
  101. var widgetStep2controller = router.get('widgetWizardStep2Controller');
  102. widgetWizardController.save('widgetProperties', widgetStep2controller.get('widgetProperties'));
  103. widgetWizardController.save('widgetMetrics', widgetStep2controller.get('widgetMetrics'));
  104. widgetWizardController.save('widgetValues', widgetStep2controller.get('widgetValues'));
  105. widgetWizardController.save('templateValue', widgetStep2controller.get('templateValue'));
  106. widgetWizardController.save('widgetName', "");
  107. widgetWizardController.save('widgetDescription', "");
  108. widgetWizardController.save('widgetScope', null);
  109. router.transitionTo('step3');
  110. }
  111. }),
  112. step3: Em.Route.extend({
  113. route: '/step3',
  114. connectOutlets: function (router) {
  115. var controller = router.get('widgetWizardController');
  116. controller.dataLoading().done(function () {
  117. router.get('widgetWizardController').setCurrentStep('3');
  118. controller.loadAllPriorSteps();
  119. controller.connectOutlet('widgetWizardStep3', controller.get('content'));
  120. });
  121. },
  122. unroutePath: function () {
  123. return false;
  124. },
  125. back: Em.Router.transitionTo('step2'),
  126. complete: function (router, context) {
  127. router.get('widgetWizardController').postWidgetDefinition(context);
  128. }
  129. })
  130. });