Pārlūkot izejas kodu

AMBARI-11102 Widgets: bugs + edits v6. (atkach)

Andrii Tkach 10 gadi atpakaļ
vecāks
revīzija
df3fca0fb5

+ 2 - 9
ambari-web/app/controllers/main/service/widgets/create/step3_controller.js

@@ -141,19 +141,12 @@ App.WidgetWizardStep3Controller = Em.Controller.extend({
   },
   },
 
 
   cancel: function () {
   cancel: function () {
-    var controller = App.router.get('widgetEditController');
+    var controller = App.router.get(this.get('content.controllerName'));
     controller.cancel();
     controller.cancel();
   },
   },
 
 
   complete: function () {
   complete: function () {
     App.router.send('complete', this.collectWidgetData());
     App.router.send('complete', this.collectWidgetData());
-    var editController = App.router.get('widgetEditController');
-    editController.finish();
-    if (editController.get('popup')) {
-      editController.get('popup').hide();
-    }
-    var serviceName = editController.get('content.widgetService');
-    var service = App.Service.find().findProperty('serviceName', serviceName);
-    App.router.transitionTo('main.services.service', service);
+    App.router.get(this.get('content.controllerName')).finishWizard();
   }
   }
 });
 });

+ 47 - 0
ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js

@@ -313,6 +313,53 @@ App.WidgetWizardController = App.WizardController.extend({
     this.saveTasksRequestIds(undefined);
     this.saveTasksRequestIds(undefined);
   },
   },
 
 
+  cancel: function () {
+    var self = this;
+    var step3Controller = App.router.get('widgetWizardStep3Controller');
+    return App.ModalPopup.show({
+      header: Em.I18n.t('common.warning'),
+      bodyClass: Em.View.extend({
+        template: Ember.Handlebars.compile('{{t alerts.saveChanges}}')
+      }),
+      primary: Em.I18n.t('common.save'),
+      secondary: Em.I18n.t('common.discard'),
+      third: Em.I18n.t('common.cancel'),
+      disablePrimary: function () {
+        return !(parseInt(self.get('currentStep')) === self.get('totalSteps') && !step3Controller.get('isSubmitDisabled'));
+      }.property(''),
+      onPrimary: function () {
+        App.router.send('complete', step3Controller.collectWidgetData());
+        this.onSecondary();
+      },
+      onSecondary: function () {
+        this.hide();
+        self.finishWizard();
+      },
+      onThird: function () {
+        this.hide();
+      }
+    });
+  },
+
+  /**
+   * finish wizard
+   */
+  finishWizard: function () {
+    this.finish();
+    this.get('popup').hide();
+    var serviceName = this.get('content.widgetService');
+    var service = App.Service.find().findProperty('serviceName', serviceName);
+    App.router.transitionTo('main.services.service', service);
+    if (!App.get('testMode')) {
+      App.clusterStatus.setClusterStatus({
+        clusterName: App.router.getClusterName(),
+        clusterState: 'DEFAULT',
+        localdb: App.db.data
+      });
+    }
+  },
+
+
   /**
   /**
    * Clear all temporary data
    * Clear all temporary data
    */
    */

+ 0 - 38
ambari-web/app/controllers/main/service/widgets/edit_controller.js

@@ -145,44 +145,6 @@ App.WidgetEditController = App.WidgetWizardController.extend({
 
 
   },
   },
 
 
-  cancel: function () {
-    var self = this;
-    var step3Controller = App.router.get('widgetWizardStep3Controller');
-    return App.ModalPopup.show({
-      header: Em.I18n.t('common.warning'),
-      bodyClass: Em.View.extend({
-        template: Ember.Handlebars.compile('{{t alerts.saveChanges}}')
-      }),
-      primary: Em.I18n.t('common.save'),
-      secondary: Em.I18n.t('common.discard'),
-      third: Em.I18n.t('common.cancel'),
-      disablePrimary: function () {
-        if (self.get('currentStep') == 2 && !step3Controller.get('isSubmitDisabled')) {
-          return false;
-        } else {
-          return true;
-        }
-      }.property(''),
-      onPrimary: function () {
-        if (self.get('currentStep') == 2) {
-          App.router.send('complete', step3Controller.collectWidgetData());
-        }
-        this.onSecondary();
-      },
-      onSecondary: function () {
-        this.hide();
-        self.finish();
-        self.get('popup').hide();
-        var serviceName = self.get('content.widgetService');
-        var service = App.Service.find().findProperty('serviceName', serviceName);
-        App.router.transitionTo('main.services.service', service);
-      },
-      onThird: function () {
-        this.hide();
-      }
-    });
-  },
-
   /**
   /**
    * Clear all temporary data
    * Clear all temporary data
    */
    */

+ 15 - 1
ambari-web/app/mixins/common/widgets/widget_mixin.js

@@ -353,7 +353,7 @@ App.WidgetMixin = Ember.Mixin.create({
    */
    */
   onMetricsLoaded: function () {
   onMetricsLoaded: function () {
     var self = this;
     var self = this;
-    this.set('isLoaded', true);
+    if (!this.get('isLoaded')) this.set('isLoaded', true);
     this.drawWidget();
     this.drawWidget();
     clearTimeout(this.get('timeoutId'));
     clearTimeout(this.get('timeoutId'));
     this.set('timeoutId', setTimeout(function () {
     this.set('timeoutId', setTimeout(function () {
@@ -372,6 +372,20 @@ App.WidgetMixin = Ember.Mixin.create({
     }
     }
   },
   },
 
 
+  /**
+   * initialize tooltips
+   */
+  initTooltip: function () {
+    var self = this;
+
+    if (this.get('isLoaded')) {
+      Em.run.next(function(){
+        App.tooltip(self.$(".corner-icon > .icon-copy"), {title: Em.I18n.t('common.clone')});
+        App.tooltip(self.$(".corner-icon > .icon-edit"), {title: Em.I18n.t('common.edit')});
+      });
+    }
+  }.observes('isLoaded'),
+
   /**
   /**
    * calculate series datasets for graph widgets
    * calculate series datasets for graph widgets
    */
    */

+ 1 - 22
ambari-web/app/routes/add_widget.js

@@ -34,27 +34,7 @@ module.exports = App.WizardRoute.extend({
         secondary: null,
         secondary: null,
 
 
         onClose: function () {
         onClose: function () {
-          var self = this;
-          widgetWizardController.finish();
-          if (App.testMode) {
-            self.hide();
-            var serviceName = widgetWizardController.get('content.widgetService');
-            var service = App.Service.find().findProperty('serviceName', serviceName);
-            router.transitionTo('main.services.service', service);
-          }   else {
-            App.clusterStatus.setClusterStatus({
-              clusterName: App.router.getClusterName(),
-              clusterState: 'DEFAULT',
-              localdb: App.db.data
-            }, {
-              alwaysCallback: function () {
-                self.hide();
-                var serviceName = widgetWizardController.get('content.widgetService');
-                var service = App.Service.find().findProperty('serviceName', serviceName);
-                router.transitionTo('main.services.service', service);
-              }
-            });
-          }
+          widgetWizardController.cancel();
         },
         },
 
 
         didInsertElement: function () {
         didInsertElement: function () {
@@ -158,7 +138,6 @@ module.exports = App.WizardRoute.extend({
     back: Em.Router.transitionTo('step2'),
     back: Em.Router.transitionTo('step2'),
     complete: function (router, context) {
     complete: function (router, context) {
       router.get('widgetWizardController').postWidgetDefinition(context);
       router.get('widgetWizardController').postWidgetDefinition(context);
-      router.get('widgetWizardController.popup').onClose();
     }
     }
   })
   })
 });
 });

+ 2 - 6
ambari-web/app/templates/main/service/widgets/create/step3.hbs

@@ -48,11 +48,7 @@
 
 
   <div class="btn-area">
   <div class="btn-area">
     <button id="add-widget-step3-back" class="btn" {{action back}}>&larr; {{t common.back}}</button>
     <button id="add-widget-step3-back" class="btn" {{action back}}>&larr; {{t common.back}}</button>
-    {{#if controller.isEditController}}
-      <button id="add-widget-step3-save" class="btn btn-success pull-right" {{bindAttr disabled="isSubmitDisabled"}} {{action "complete" target="controller"}}>{{t common.save}}</button>
-      <button id="add-widget-step3-cancel" class="btn pull-right" {{action "cancel" target="controller"}}>{{t common.cancel}}</button>
-    {{else}}
-      <button id="add-widget-step3-complete" class="btn btn-success pull-right" {{bindAttr disabled="isSubmitDisabled"}} {{action "complete" target="controller"}}>{{t common.complete}}</button>
-    {{/if}}
+    <button id="add-widget-step3-save" class="btn btn-success pull-right" {{bindAttr disabled="isSubmitDisabled"}} {{action "complete" target="controller"}}>{{t common.save}}</button>
+    <button id="add-widget-step3-cancel" class="btn pull-right" {{action "cancel" target="controller"}}>{{t common.cancel}}</button>
   </div>
   </div>
 </div>
 </div>