Repository: ambari
Updated Branches:
  refs/heads/trunk 4a579a72e -> de06e8e08


AMBARI-10824 Cloning a widget should make it a part of the widget layout. 
(atkach)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/de06e8e0
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/de06e8e0
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/de06e8e0

Branch: refs/heads/trunk
Commit: de06e8e0877fe5be8240e24b9f4bc88c8e34efaa
Parents: 4a579a7
Author: Andrii Tkach <[email protected]>
Authored: Wed Apr 29 13:24:02 2015 +0300
Committer: Andrii Tkach <[email protected]>
Committed: Wed Apr 29 15:54:06 2015 +0300

----------------------------------------------------------------------
 .../app/mixins/common/widgets/widget_mixin.js   | 28 +++++++++++++++-----
 1 file changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/de06e8e0/ambari-web/app/mixins/common/widgets/widget_mixin.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/widgets/widget_mixin.js 
b/ambari-web/app/mixins/common/widgets/widget_mixin.js
index bf0a422..3a4d8f8 100644
--- a/ambari-web/app/mixins/common/widgets/widget_mixin.js
+++ b/ambari-web/app/mixins/common/widgets/widget_mixin.js
@@ -39,6 +39,12 @@ App.WidgetMixin = Ember.Mixin.create({
   VALUE_NAME_REGEX: /[\w\.\,\:\=\[\]]+/g,
 
   /**
+   * @type {string}
+   * @const
+   */
+  CLONE_SUFFIX: '(Copy)',
+
+  /**
    * common metrics container
    * @type {Array}
    */
@@ -428,9 +434,9 @@ App.WidgetMixin = Ember.Mixin.create({
     var self = this;
     return App.showConfirmationPopup(
       function () {
-        self.postWidgetDefinition();
+        self.postWidgetDefinition(true);
       },
-      Em.I18n.t('widget.clone.body').format(self.get('content.displayName')),
+      Em.I18n.t('widget.clone.body').format(self.get('content.widgetName')),
       null,
       null,
       Em.I18n.t('common.clone')
@@ -445,7 +451,6 @@ App.WidgetMixin = Ember.Mixin.create({
     return {
       WidgetInfo: {
         widget_name: this.get('content.widgetName'),
-        display_name: this.get('content.displayName'),
         widget_type: this.get('content.widgetType'),
         description: this.get('content.widgetDescription'),
         scope: this.get('content.scope'),
@@ -466,21 +471,30 @@ App.WidgetMixin = Ember.Mixin.create({
 
   /**
    * post widget definition to server
+   * @param {boolean} isClone
    * @returns {$.ajax}
    */
-  postWidgetDefinition: function () {
+  postWidgetDefinition: function (isClone) {
+    var data = this.collectWidgetData();
+    if (isClone) {
+      data.WidgetInfo.widget_name += this.get('CLONE_SUFFIX');
+    }
     return App.ajax.send({
       name: 'widgets.wizard.add',
       sender: this,
       data: {
-        data: this.collectWidgetData()
+        data: data
       },
       success: 'postWidgetDefinitionSuccessCallback'
     });
   },
 
-  postWidgetDefinitionSuccessCallback: function () {
-
+  postWidgetDefinitionSuccessCallback: function (data) {
+    var widgets = this.get('content.layout.widgets').toArray();
+    widgets.pushObject(Em.Object.create({
+      id: data.resources[0].WidgetInfo.id
+    }));
+    
App.router.get('mainServiceInfoSummaryController').saveWidgetLayout(widgets);
   },
 
   /*

Reply via email to