ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srima...@apache.org
Subject ambari git commit: AMBARI-11503. JS error thrown on saving raw config value for list-value widget.
Date Thu, 28 May 2015 19:32:51 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 869709914 -> 3af7d0147


AMBARI-11503. JS error thrown on saving raw config value for list-value widget.


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

Branch: refs/heads/trunk
Commit: 3af7d0147a1ac02948ed547d4b9edfb67758a4cc
Parents: 8697099
Author: Srimanth Gunturi <sgunturi@hortonworks.com>
Authored: Thu May 28 12:14:52 2015 -0700
Committer: Srimanth Gunturi <sgunturi@hortonworks.com>
Committed: Thu May 28 12:32:43 2015 -0700

----------------------------------------------------------------------
 .../configs/widgets/list_config_widget_view.js  | 41 +++++++++++++++-----
 1 file changed, 31 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3af7d014/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js b/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js
index 41bc203..bc814c5 100644
--- a/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js
+++ b/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js
@@ -120,7 +120,9 @@ App.ListConfigWidgetView = App.ConfigWidgetView.extend({
     this._super();
     this.addObserver('options.@each.isSelected', this, this.calculateVal);
     this.addObserver('options.@each.isSelected', this, this.checkSelectedItemsCount);
-    this.calculateVal();
+    if (this.isValueCompatibleWithWidget()) {
+      this.calculateVal();
+    }
     this.checkSelectedItemsCount();
     Em.run.next(function () {
       App.tooltip(this.$('[rel="tooltip"]'));
@@ -150,20 +152,19 @@ App.ListConfigWidgetView = App.ConfigWidgetView.extend({
    * Used on <code>willInsertElement</code> and when user click on "Undo"-button
(to restore default value)
    * @method calculateInitVal
    */
-  calculateInitVal: function () {
+  calculateInitVal: function (configValue) {
     var config = this.get('config'),
       options = this.get('options'),
-      value = config.get('value'),
+      value = configValue || config.get('value'),
       self = this,
       val = [];
-    if (value !== '') {
+    if (value !== '' && this.isOptionExist(value)) {
       if ('string' === Em.typeOf(value)) {
         value = value.split(',');
       }
       options.invoke('setProperties', {isSelected: false, isDisabled: false});
       val = value.map(function (v) {
         var option = options.findProperty('value', v.trim());
-        Em.assert('option with value `%@` is missing for config `%@`'.fmt(v, config.get('name')),
option);
         option.setProperties({
           order: self.get('orderCounter'),
           isSelected: true
@@ -236,7 +237,7 @@ App.ListConfigWidgetView = App.ConfigWidgetView.extend({
    */
   restoreValue: function() {
     this._super();
-    this.calculateInitVal();
+    this.setValue(this.get('config.value'));
   },
 
   /**
@@ -244,7 +245,7 @@ App.ListConfigWidgetView = App.ConfigWidgetView.extend({
    */
   setRecommendedValue: function () {
     this._super();
-    this.calculateInitVal();
+    this.setValue(this.get('config.value'));
   },
 
   /**
@@ -264,12 +265,32 @@ App.ListConfigWidgetView = App.ConfigWidgetView.extend({
     }
   }),
 
-  setValue: function() {
-    this.calculateInitVal();
+  setValue: function(value) {
+    if (value && this.isOptionExist(value)) {
+      this.calculateInitVal(value);
+    } else {
+      this.calculateInitVal();
+    }
+    if (!this.isValueCompatibleWithWidget() && !this.get('config.showAsTextBox'))
{
+      this.set('config.showAsTextBox', true);
+    }
   },
 
   isValueCompatibleWithWidget: function() {
-    return this._super() && this.get('options').someProperty('value', this.get('config.value'));
+    return this._super() && this.isOptionExist(this.get('config.value'));
+  },
+
+  isOptionExist: function(value) {
+    var isExist = false;
+    if (value !== null && value !== undefined) {
+      value = Em.typeOf(value) == 'string' ? value.split(',') : value;
+      value.forEach(function(item) {
+        isExist = this.get('options').mapProperty('value').contains(item);
+      }, this);
+      return isExist;
+    } else {
+      return false;
+    }
   }
 
 });


Mime
View raw message