Issue #23853: Stable check-in of widget refactor
authorLinda Nichols <lynnaloo@gmail.com>
Sun, 15 Jun 2014 22:34:07 +0000 (22:34 +0000)
committerLinda Nichols <lynnaloo@gmail.com>
Sun, 15 Jun 2014 22:34:07 +0000 (22:34 +0000)
enyo-client/application/source/widgets/number.js
enyo-client/application/source/widgets/parameter.js
lib/enyo-x/source/widgets/combobox.js
lib/enyo-x/source/widgets/date.js
lib/enyo-x/source/widgets/input.js
lib/enyo-x/source/widgets/number.js
lib/enyo-x/source/widgets/text_area.js
lib/enyo-x/source/widgets/toggle_button.js

index b8007c7..475a804 100644 (file)
@@ -8,12 +8,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // COST
   //
 
-  enyo.kind({
-    name: "XV.Cost",
-    kind: "XV.Number",
-    scale: XT.COST_SCALE
-  });
-
   enyo.kind({
     name: "XV.CostWidget",
     kind: "XV.NumberWidget",
@@ -24,12 +18,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // EXTENDED PRICE
   //
 
-  enyo.kind({
-    name: "XV.ExtendedPrice",
-    kind: "XV.Number",
-    scale: XT.EXTENDED_PRICE_SCALE
-  });
-
   enyo.kind({
     name: "XV.ExtendedPriceWidget",
     kind: "XV.NumberWidget",
@@ -40,13 +28,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // HOURS
   //
 
-  enyo.kind({
-    name: "XV.Hours",
-    kind: "XV.Number",
-    maxlength: 12,
-    scale: XT.HOURS_SCALE
-  });
-
   enyo.kind({
     name: "XV.HoursWidget",
     kind: "XV.NumberWidget",
@@ -58,28 +39,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // PERCENT
   //
 
-  enyo.kind({
-    name: "XV.Percent",
-    kind: "XV.Number",
-    scale: XT.PERCENT_SCALE,
-    validate: function (value) {
-      // this takes the string from the input field and parses it (including understanding commas, which isNaN cannot)
-      // if it cannot parse the value, it returns NaN
-      value = Globalize.parseFloat(value);
-      // use isNaN here because parseFloat could return NaN
-      // if you pass NaN into _.isNumber, it will misleadingly return true
-      // only bad string and null/undefined cases do we want to fail validation
-      return !isNaN(value) ? value / 100 : false;
-    },
-    valueChanged: function (value) {
-      // use isNaN here because this value may be a number string and _isNaN requires
-      // a separate falsy check.
-      // In this case, it is ok for 0 to fall to the true case, just not null or a bad string
-      value = !isNaN(value) ? value * 100 : value;
-      XV.Number.prototype.valueChanged.call(this, value);
-    }
-  });
-
   enyo.kind({
     name: "XV.PercentWidget",
     kind: "XV.NumberWidget",
@@ -106,12 +65,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // PURCHASE PRICE
   //
 
-  enyo.kind({
-    name: "XV.PurchasePrice",
-    kind: "XV.Number",
-    scale: XT.PURCHASE_PRICE_SCALE
-  });
-
   enyo.kind({
     name: "XV.PurchasePriceWidget",
     kind: "XV.NumberWidget",
@@ -122,13 +75,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // QUANTITY
   //
 
-  enyo.kind({
-    name: "XV.Quantity",
-    kind: "XV.Number",
-    maxlength: 12,
-    scale: XT.QTY_SCALE
-  });
-
   enyo.kind({
     name: "XV.QuantityWidget",
     kind: "XV.NumberWidget",
@@ -140,12 +86,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // QUANTITY PER
   //
 
-  enyo.kind({
-    name: "XV.QuantityPer",
-    kind: "XV.Number",
-    scale: XT.QTY_PER_SCALE
-  });
-
   enyo.kind({
     name: "XV.QuantityPerWidget",
     kind: "XV.NumberWidget",
@@ -156,12 +96,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // SALES PRICE
   //
 
-  enyo.kind({
-    name: "XV.SalesPrice",
-    kind: "XV.Number",
-    scale: XT.SALES_PRICE_SCALE
-  });
-
   enyo.kind({
     name: "XV.SalesPriceWidget",
     kind: "XV.NumberWidget",
@@ -172,12 +106,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // UNIT RATIO
   //
 
-  enyo.kind({
-    name: "XV.UnitRatio",
-    kind: "XV.Number",
-    scale: XT.UNIT_RATIO_SCALE
-  });
-
   enyo.kind({
     name: "XV.UnitRatioWidget",
     kind: "XV.NumberWidget",
@@ -188,12 +116,6 @@ regexp:true, undef:true, trailing:true, white:true */
   // WEIGHT
   //
 
-  enyo.kind({
-    name: "XV.Weight",
-    kind: "XV.Number",
-    scale: XT.WEIGHT_SCALE
-  });
-
   enyo.kind({
     name: "XV.WeightWidget",
     kind: "XV.NumberWidget",
index 5ffc5b4..48ca27a 100644 (file)
@@ -175,7 +175,8 @@ trailing:true, white:true, strict:false*/
       // see if toggle is on and update params
       _.each(keys, function (key) {
         _.each(actTypes[key], function (obj) {
-          if (that.$[_namify(obj)].getValue()) {
+          // the pluralize function in _namify is imperfect
+          if (that.$[_namify(obj)] && that.$[_namify(obj)].getValue()) {
             value.push(obj.type);
           }
         });
index fc8edae..fb840b3 100644 (file)
@@ -14,14 +14,12 @@ regexp:true, undef:true, trailing:true, white:true, browser:true */
   enyo.kind(
     /** @lends XV.CheckboxWidget# */{
     name: "XV.ComboboxWidget",
-    kind: "XV.Input",
+    kind: "XV.InputWidget",
     published: {
       collection: "",
       filter: null,
       disabled: false,
       keyAttribute: "name",
-      label: "",
-      showLabel: true,
       tabStop: true
     },
     classes: "xv-combobox xv-input",
@@ -47,8 +45,6 @@ regexp:true, undef:true, trailing:true, white:true, browser:true */
       this.inherited(arguments);
       this.collectionChanged();
       this.filterChanged();
-      this.labelChanged();
-      this.showLabelChanged();
       this.tabStopChanged();
     },
     /**
@@ -171,21 +167,11 @@ regexp:true, undef:true, trailing:true, white:true, browser:true */
       return models;
     },
     /**
-    @todo Document the labelChanged method.
-    */
-    labelChanged: function () {
-      var label = (this.getLabel() || ("_" + this.attr || "").loc()) + ":";
-      this.$.label.setContent(label);
-    },
-    /**
     @todo Document the receiveBlur method.
     */
     receiveBlur: function (inSender, inEvent) {
       this.autocomplete();
     },
-    showLabelChanged: function () {
-      this.$.label.setShowing(this.getShowLabel());
-    },
     tabStopChanged: function () {
       this.$.input.setAttribute("tabIndex", this.getTabStop() ? null: -1);
     },
index 13f35e7..9ec4211 100644 (file)
@@ -5,7 +5,7 @@ regexp:true, undef:true, trailing:true, white:true */
 (function () {
 
   /**
-    @name XV.Date
+    @name XV.DateWidget
        @class An input control used to specify a date.<br />
        Reformats and sets a date entered either as a date type or a string.
        If a string is not a recognizable date, sets the input to null.<br />
@@ -13,13 +13,62 @@ regexp:true, undef:true, trailing:true, white:true */
        @extends XV.Input
    */
   enyo.kind(
-    /** @lends XV.Date# */{
-    name: "XV.Date",
-    kind: "XV.Input",
+    /** @lends XV.DateWidget# */{
+    name: "XV.DateWidget",
+    kind: "XV.InputWidget",
+    classes: "xv-input xv-datewidget",
     published: {
       nullValue: null,
       nullText: ""
     },
+    components: [
+      {kind: "FittableColumns", components: [
+        {name: "label", content: "", fit: true, classes: "xv-flexible-label"},
+        // setting the tag to "div" on the decorator
+        // so that clicks of button don't get redirected back
+        // to the input field (default behavior)
+        {kind: "onyx.InputDecorator", name: "decorator", tag: "div",
+          classes: "xv-input-decorator", components: [
+          {name: "input", kind: "onyx.Input", onchange: "inputChanged",
+            classes: "xv-subinput", onkeydown: "keyDown"},
+          {name: "icon", kind: "onyx.Icon", ontap: "iconTapped",
+            classes: "icon-calendar"}
+        ]},
+        {name: "datePickPopup", kind: "onyx.Popup", maxHeight: 400, floating: true,
+            centered: true, modal: true, components: [
+          // TODO: get rid of this inline style
+          {kind: "GTS.DatePicker", name: "datePick", style: "min-width:400px;",
+            onChange: "datePicked"}
+        ]}
+      ]}
+    ],
+
+    /**
+     This function handles a date chosen via the
+     datepicker versus text entered into the input field.
+     */
+    datePicked: function (inSender, inEvent) {
+      var date = inEvent, options = {};
+      // mimic the human-typed behavior
+      this.applyTimezoneOffset(date);
+
+      options.silent = true;
+      this.setValue(date, options);
+      this.$.datePickPopup.hide();
+      this.$.input.focus();
+    },
+    disabledChanged: function () {
+      this.inherited(arguments);
+      this.$.label.addRemoveClass("disabled", this.getDisabled());
+    },
+    /**
+      This function handles the click of the calendar icon
+      that opens the datepicker.
+    */
+    iconTapped: function (inSender, inEvent) {
+      this.$.datePickPopup.show();
+      this.$.datePick.render();
+    },
     /**
      Returns the value in the input field of the widget.
      */
@@ -46,7 +95,7 @@ regexp:true, undef:true, trailing:true, white:true */
       } else {
         value = nullValue;
       }
-      XV.Input.prototype.setValue.call(this, value, options);
+      XV.InputWidget.prototype.setValue.call(this, value, options);
     },
     /**
      This function takes the value entered into a DateWidget and returns
@@ -153,107 +202,7 @@ regexp:true, undef:true, trailing:true, white:true */
       } else {
         value = "";
       }
-      return XV.Input.prototype.valueChanged.call(this, value);
-    }
-  });
 
-  /**
-    @name XV.DateWidget
-    @class An input control consisting of fittable columns.<br />
-    Use to implement a styled input field for entering a date
-    including associated popup menu for selecting a date.<br />
-    Creates an HTML input element.
-    @extends XV.Date
-   */
-  enyo.kind(/** @lends XV.DateWidget# */{
-    name: "XV.DateWidget",
-    kind: "XV.Date",
-    classes: "xv-input xv-datewidget",
-    published: {
-      label: "",
-      showLabel: true
-    },
-    components: [
-      {kind: "FittableColumns", components: [
-        {name: "label", content: "", fit: true, classes: "xv-flexible-label"},
-        // setting the tag to "div" on the decorator
-        // so that clicks of button don't get redirected back
-        // to the input field (default behavior)
-        {kind: "onyx.InputDecorator", name: "decorator", tag: "div",
-          classes: "xv-input-decorator", components: [
-          {name: "input", kind: "onyx.Input", onchange: "inputChanged",
-            classes: "xv-subinput", onkeydown: "keyDown"},
-          {name: "icon", kind: "onyx.Icon", ontap: "iconTapped",
-            classes: "icon-calendar"}
-        ]},
-        {name: "datePickPopup", kind: "onyx.Popup", maxHeight: 400, floating: true,
-            centered: true, modal: true, components: [
-          // TODO: get rid of this inline style
-          {kind: "GTS.DatePicker", name: "datePick", style: "min-width:400px;",
-            onChange: "datePicked"}
-        ]}
-      ]}
-    ],
-    /**
-     @todo Document create method.
-     */
-    create: function () {
-      this.inherited(arguments);
-      this.labelChanged();
-      this.showLabelChanged();
-    },
-
-    /**
-     This function handles a date chosen via the
-     datepicker versus text entered into the input field.
-     */
-    datePicked: function (inSender, inEvent) {
-      var date = inEvent, options = {};
-      // mimic the human-typed behavior
-      this.applyTimezoneOffset(date);
-
-      options.silent = true;
-      this.setValue(date, options);
-      this.$.datePickPopup.hide();
-      this.$.input.focus();
-    },
-    disabledChanged: function () {
-      this.inherited(arguments);
-      this.$.label.addRemoveClass("disabled", this.getDisabled());
-    },
-    /**
-      This function handles the click of the calendar icon
-      that opens the datepicker.
-    */
-    iconTapped: function (inSender, inEvent) {
-      this.$.datePickPopup.show();
-      this.$.datePick.render();
-    },
-    /**
-     Sets the label of the Date Widget with text specified in the kind.
-     */
-    labelChanged: function () {
-      var label = (this.getLabel() || ("_" + this.attr || "").loc()) + ":";
-      this.$.label.setContent(label);
-    },
-    /**
-     Sets the visibility of the label of the date widget based on
-     the value specified in the kind.
-     */
-    showLabelChanged: function () {
-      if (this.getShowLabel()) {
-        this.$.label.show();
-      } else {
-        this.$.label.hide();
-      }
-    },
-    /**
-     Set the date value into the input field and the date picker and
-     sets the value to the model.
-     */
-    valueChanged: function (value) {
-      var dateValue = value;
-      value = XV.Date.prototype.valueChanged.call(this, value);
       if (!this.$.input.value && this.$.input.attributes.value) {
         // XXX workaround for incident 19171. Something deep into enyo's
         // setters are causing the attributes value to be updated when
@@ -262,8 +211,11 @@ regexp:true, undef:true, trailing:true, white:true */
         // two-step of turning a inputted value into an actual date.
         this.$.input.attributes.value = "";
       }
-      this.$.datePick.setValue(value ? dateValue : new Date());
+
+      this.$.datePick.setValue(value ? value : new Date());
       this.$.datePick.render();
+
+      return XV.InputWidget.prototype.valueChanged.call(this, value);
     }
   });
 
index 88cd67e..20dc885 100644 (file)
@@ -63,12 +63,13 @@ regexp:true, undef:true, trailing:true, white:true */
     },
     /**
      The disabledChanged method, and many below it, are here to deal with
-     the fact that XV.Input doesvnot inherit from onyx.input or enyo.input,
+     the fact that XV.Input does not inherit from onyx.input or enyo.input,
      and so insofar as it needs to support their APIs, we
      have to redeclare the methods and pass through the data.
     */
     disabledChanged: function () {
       this.$.input.setDisabled(this.getDisabled());
+      this.$.label.addRemoveClass("disabled", this.getDisabled());
     },
     focus: function () {
       this.$.input.focus();
@@ -109,11 +110,12 @@ regexp:true, undef:true, trailing:true, white:true */
       }
     },
     /**
-    @todo Document the placeholderChanged method.
+      Sets the placeholder on the input field.
     */
     placeholderChanged: function () {
-      var placeholder = this.getPlaceholder();
-      this.$.input.setPlaceholder(placeholder);
+      if (_.isFunction(this.$.input.setPlaceholder)) {
+        this.$.input.setPlaceholder(this.placeholder);
+      }
     },
     /**
       Webkit browsers do not always emit the proper change event,
@@ -162,18 +164,15 @@ regexp:true, undef:true, trailing:true, white:true */
       return value;
     },
     /**
-      Pass through attributes intended for onyx input inside.
-    */
-    setInputStyle: function (style) {
-      this.$.input.setStyle(style);
-    },
-    /**
-      Pass through attributes intended for onyx input inside.
+      Sets the type attribute for input field.
     */
     typeChanged: function () {
       this.$.input.setType(this.getType());
     },
 
+    /**
+      Set the maxlength attribute on the input field.
+    */
     maxlengthChanged: function () {
       this.$.input.setAttribute("maxlength", this.maxlength);
     },
@@ -187,14 +186,10 @@ regexp:true, undef:true, trailing:true, white:true */
     },
 
     /**
-    @todo Document the showLabelChanged method.
+      Sets visibility of the widget label.
     */
     showLabelChanged: function () {
-      if (this.getShowLabel()) {
-        this.$.label.show();
-      } else {
-        this.$.label.hide();
-      }
+      this.$.label.setShowing(this.getShowLabel());
     }
   });
 
index 37e00be..71dd003 100644 (file)
@@ -12,11 +12,16 @@ regexp:true, undef:true, trailing:true, white:true */
    */
   enyo.kind(
     /** @lends XV.Number# */{
-    name: "XV.Number",
-    kind: "XV.Input",
+    name: "XV.NumberWidget",
+    kind: "XV.InputWidget",
+    classes: "xv-numberwidget xv-input",
     published: {
+      attr: null,
       scale: 0,
-      formatting: true
+      formatting: true,
+      type: "number",
+      label: "",
+      showLabel: true
     },
     /**
     @todo Document the setValue method.
@@ -25,7 +30,7 @@ regexp:true, undef:true, trailing:true, white:true */
       // use isNaN here because this value could be a number String, 0 value, or null
       // only want to set value as null in cases of bad strings and null/undefined
       value = value !== null && !isNaN(value) ? XT.math.round(value, this.getScale()) : null;
-      XV.Input.prototype.setValue.call(this, value, options);
+      XV.InputWidget.prototype.setValue.call(this, value, options);
     },
     /**
       Determines whether the user input is numeric.
@@ -56,63 +61,7 @@ regexp:true, undef:true, trailing:true, white:true */
       } else {
         value = "";
       }
-      return XV.Input.prototype.valueChanged.call(this, value);
-    }
-  });
-
-  /**
-    @name XV.NumberWidget
-    @class An input control consisting of fittable columns: label, decorator, and input field.<br />
-    Use to implement an input field for strings that represents a number, such as prices.  This widget
-    includes a style to right-justify the text entered into the input field.
-    @extends XV.Number
-   */
-  enyo.kind(/** @lends XV.NumberWidget# */{
-    name: "XV.NumberWidget",
-    kind: "XV.Number",
-    classes: "xv-numberwidget xv-input",
-    published: {
-      label: "",
-      showLabel: true,
-      placeholder: ""
-    },
-    components: [
-      {kind: "FittableColumns", components: [
-        {name: "label", content: "", fit: true, classes: "xv-flexible-label"},
-        {kind: "onyx.InputDecorator", classes: "xv-input-decorator",
-          components: [
-          {name: "input", kind: "onyx.Input", onchange: "inputChanged", onkeydown: "keyDown", type: "number"}
-        ]}
-      ]}
-    ],
-    /**
-     @todo Document the create method.
-     */
-    create: function () {
-      this.inherited(arguments);
-      this.labelChanged();
-      this.showLabelChanged();
-    },
-    disabledChanged: function () {
-      this.inherited(arguments);
-      this.$.label.addRemoveClass("disabled", this.getDisabled());
-    },
-    /**
-     @todo Document the labelChanged method.
-     */
-    labelChanged: function () {
-      var label = (this.getLabel() || ("_" + this.attr + "").loc()) + ":";
-      this.$.label.setContent(label);
-    },
-    /**
-     @todo Document the showLabelChanged method.
-     */
-    showLabelChanged: function () {
-      if (this.getShowLabel()) {
-        this.$.label.show();
-      } else {
-        this.$.label.hide();
-      }
+      return XV.InputWidget.prototype.valueChanged.call(this, value);
     }
   });
 
index 08a6de9..21a4cf5 100644 (file)
@@ -21,8 +21,14 @@ regexp:true, undef:true, trailing:true, white:true */
       showLabel: false
     },
     components: [
-      {name: "input", kind: "onyx.TextArea", classes: "xv-textarea-input",
-        onchange: "inputChanged", onkeydown: "keyDown"}
+      {kind: "FittableColumns", components: [
+        {name: "label", content: "", fit: true, classes: "xv-flexible-label"},
+        {kind: "onyx.InputDecorator", classes: "xv-input-decorator",
+          components: [
+          {name: "input", kind: "onyx.TextArea", classes: "xv-textarea-input",
+            onchange: "inputChanged", onkeydown: "keyDown"}
+        ]}
+      ]}
     ]
   });
 
index e094c27..d266be3 100644 (file)
@@ -5,15 +5,17 @@ regexp:true, undef:true, trailing:true, white:true */
 (function () {
 
   /**
-    @name XV.ToggleButton
-    @class A control that looks like a switch with labels for two states.<br />
-    Derived from <a href="http://enyojs.com/api/#onyx.ToggleButton">onyx.ToggleButton</a>.
-    @extends onyx.ToggleButton
+    @name XV.ToggleButtonWidget
+    @class An input control consisting of fittable columns:
+     label, decorator, and toggle button.<br />
+    Use to implement a toggle button, a switch with labels for two states.<br />
+    Creates an HTML input element.
+    @extends XV.Input
    */
-  enyo.kind(
-    /** @lends XV.ToggleButton# */{
-    name: "XV.ToggleButton",
-    kind: "onyx.ToggleButton",
+  enyo.kind({
+    name: "XV.ToggleButtonWidget",
+    kind: "XV.InputWidget",
+    classes: "xv-inputwidget xv-checkboxwidget",
     published: {
       attr: null
     },
@@ -23,12 +25,15 @@ regexp:true, undef:true, trailing:true, white:true */
     handlers: {
       onChange: "changed"
     },
-    /**
-     @todo Document the clear method.
-     */
-    clear: function (options) {
-      this.setValue(false, options);
-    },
+    components: [
+      {kind: "FittableColumns", components: [
+        {name: "label", content: "", classes: "xv-label"},
+        {kind: "onyx.InputDecorator", classes: "xv-input-decorator",
+          components: [
+          {name: "input", kind: "onyx.ToggleButton", onChange: "inputChanged"}
+        ]}
+      ]}
+    ],
     /**
      @todo Document the setValue method.
      */
@@ -46,33 +51,7 @@ regexp:true, undef:true, trailing:true, white:true */
         inEvent.value = this.getValue();
         this.doValueChange(inEvent);
       }
-    }
-  });
-
-  /**
-    @name XV.ToggleButtonWidget
-    @class An input control consisting of fittable columns:
-     label, decorator, and toggle button.<br />
-    Use to implement a toggle button, a switch with labels for two states.<br />
-    Creates an HTML input element.
-    @extends XV.Input
-   */
-  enyo.kind(/** @lends XV.ToggleButtonWidget# */{
-    name: "XV.ToggleButtonWidget",
-    kind: "XV.Input",
-    classes: "xv-inputwidget xv-checkboxwidget",
-    published: {
-      label: ""
     },
-    components: [
-      {kind: "FittableColumns", components: [
-        {name: "label", content: "", classes: "xv-label"},
-        {kind: "onyx.InputDecorator", classes: "xv-input-decorator",
-          components: [
-          {name: "input", kind: "onyx.ToggleButton", onChange: "inputChanged"}
-        ]}
-      ]}
-    ],
     /**
      @todo Document the clear method.
      */
@@ -89,10 +68,6 @@ regexp:true, undef:true, trailing:true, white:true */
       var options = {silent: true};
       this.valueChanged(this.getValue(), options);
     },
-    disabledChanged: function () {
-      this.inherited(arguments);
-      this.$.label.addRemoveClass("disabled", this.getDisabled());
-    },
     /**
      @todo Document the inputChanged method.
      */
@@ -100,20 +75,6 @@ regexp:true, undef:true, trailing:true, white:true */
       var input = this.$.input.getValue();
       this.setValue(input);
     },
-    /**
-     @todo Document the labelChanged method.
-     */
-    labelChanged: function () {
-      var label = (this.getLabel() || ("_" + this.attr || "").loc()) + ":";
-      this.$.label.setContent(label);
-    },
-    /**
-      Not applicable in the context of a toggle button,
-      even though it is available to input widgets generally.
-     */
-    placeholderChanged: function () {
-      // Not applicable
-    },
     /**
      @todo Document the valueChanged method.
      */