edit_widget.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. var self = this;
  35. widgetEditController.finish();
  36. self.hide();
  37. var serviceName = widgetEditController.get('content.widgetService');
  38. var service = App.Service.find().findProperty('serviceName', serviceName);
  39. router.transitionTo('main.services.service', service);
  40. },
  41. didInsertElement: function () {
  42. this.fitHeight();
  43. }
  44. });
  45. widgetEditController.set('popup', popup);
  46. var currentClusterStatus = App.clusterStatus.get('value');
  47. if (currentClusterStatus) {
  48. if (App.get('testMode')) {
  49. widgetEditController.setCurrentStep(App.db.data.WidgetWizard.currentStep);
  50. } else {
  51. var currStep = App.get('router.widgetEditController.currentStep');
  52. widgetEditController.setCurrentStep(currStep);
  53. }
  54. }
  55. Em.run.next(function () {
  56. router.transitionTo('step' + widgetEditController.get('currentStep'));
  57. });
  58. });
  59. },
  60. step1: Em.Route.extend({
  61. route: '/step1',
  62. connectOutlets: function (router) {
  63. var controller = router.get('widgetEditController');
  64. controller.dataLoading().done(function () {
  65. router.get('widgetEditController').setCurrentStep('1');
  66. controller.loadAllPriorSteps();
  67. controller.connectOutlet('widgetWizardStep2', controller.get('content'));
  68. });
  69. },
  70. unroutePath: function () {
  71. return false;
  72. },
  73. next: function (router) {
  74. var widgetEditController = router.get('widgetEditController');
  75. var widgetStep2controller = router.get('widgetWizardStep2Controller');
  76. widgetEditController.save('widgetProperties', widgetStep2controller.get('widgetProperties'));
  77. widgetEditController.save('widgetMetrics', widgetStep2controller.get('widgetMetrics'));
  78. widgetEditController.save('widgetValues', widgetStep2controller.get('widgetValues'));
  79. widgetEditController.save('expressions', widgetStep2controller.get('expressions'));
  80. widgetEditController.save('dataSets', widgetStep2controller.get('dataSets'));
  81. widgetEditController.save('templateValue', widgetStep2controller.get('templateValue'));
  82. router.transitionTo('step2');
  83. }
  84. }),
  85. step2: Em.Route.extend({
  86. route: '/step2',
  87. connectOutlets: function (router) {
  88. var controller = router.get('widgetEditController');
  89. controller.dataLoading().done(function () {
  90. router.get('widgetEditController').setCurrentStep('2');
  91. controller.loadAllPriorSteps();
  92. controller.connectOutlet('widgetWizardStep3', controller.get('content'));
  93. });
  94. },
  95. unroutePath: function () {
  96. return false;
  97. },
  98. back: Em.Router.transitionTo('step1'),
  99. complete: function (router, context) {
  100. router.get('widgetEditController').putWidgetDefinition(context);
  101. router.get('widgetEditController.popup').onClose();
  102. }
  103. })
  104. });