edit_widget.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/edit',
  21. enter: function (router, context) {
  22. router.get('mainController').dataLoading().done(function () {
  23. var widgetEditController = router.get('widgetEditController');
  24. var popup = App.ModalPopup.show({
  25. classNames: ['full-width-modal'],
  26. header: Em.I18n.t('widget.edit.wizard.header'),
  27. bodyClass: App.WidgetEditView.extend({
  28. controller: widgetEditController
  29. }),
  30. primary: Em.I18n.t('form.cancel'),
  31. showFooter: false,
  32. secondary: null,
  33. onClose: function () {
  34. widgetEditController.cancel();
  35. },
  36. didInsertElement: function () {
  37. this.fitHeight();
  38. }
  39. });
  40. widgetEditController.set('popup', popup);
  41. var currentClusterStatus = App.clusterStatus.get('value');
  42. if (currentClusterStatus) {
  43. if (App.get('testMode')) {
  44. widgetEditController.setCurrentStep(App.db.data.WidgetWizard.currentStep);
  45. } else {
  46. var currStep = App.get('router.widgetEditController.currentStep');
  47. widgetEditController.setCurrentStep(currStep);
  48. }
  49. }
  50. Em.run.next(function () {
  51. router.transitionTo('step' + widgetEditController.get('currentStep'));
  52. });
  53. });
  54. },
  55. step1: Em.Route.extend({
  56. route: '/step1',
  57. connectOutlets: function (router) {
  58. var controller = router.get('widgetEditController');
  59. controller.dataLoading().done(function () {
  60. router.get('widgetEditController').setCurrentStep('1');
  61. controller.loadAllPriorSteps();
  62. controller.connectOutlet('widgetWizardStep2', controller.get('content'));
  63. });
  64. },
  65. unroutePath: function () {
  66. return false;
  67. },
  68. next: function (router) {
  69. var widgetEditController = router.get('widgetEditController');
  70. var widgetStep2controller = router.get('widgetWizardStep2Controller');
  71. widgetEditController.save('widgetProperties', widgetStep2controller.get('widgetProperties'));
  72. widgetEditController.save('widgetMetrics', widgetStep2controller.get('widgetMetrics'));
  73. widgetEditController.save('widgetValues', widgetStep2controller.get('widgetValues'));
  74. widgetEditController.save('expressions', widgetStep2controller.get('expressions'));
  75. widgetEditController.save('dataSets', widgetStep2controller.get('dataSets'));
  76. widgetEditController.save('templateValue', widgetStep2controller.get('templateValue'));
  77. router.transitionTo('step2');
  78. }
  79. }),
  80. step2: Em.Route.extend({
  81. route: '/step2',
  82. connectOutlets: function (router) {
  83. var controller = router.get('widgetEditController');
  84. controller.dataLoading().done(function () {
  85. router.get('widgetEditController').setCurrentStep('2');
  86. controller.loadAllPriorSteps();
  87. controller.connectOutlet('widgetWizardStep3', controller.get('content'));
  88. });
  89. },
  90. unroutePath: function () {
  91. return false;
  92. },
  93. back: Em.Router.transitionTo('step1'),
  94. complete: function (router, context) {
  95. router.get('widgetEditController').putWidgetDefinition(context);
  96. }
  97. })
  98. });