1 /*jshint node:true, indent:2, curly:true, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
2 regexp:true, undef:true, trailing:true, white:true */
3 /*global XT:true, Globalize:true, enyo:true, _:true */
8 @name XV.CheckboxWidget
9 @class An input control consisting of fittable columns:
10 label, decorator, and checkbox.<br />
11 Use to implement a styled checkbox
12 which is made up of a checkbox input control and its label.
16 name: "XV.CheckboxWidget",
17 kind: "XV.InputWidget",
18 classes: "xv-checkboxwidget",
20 {controlClasses: 'enyo-inline', components: [
21 {name: "label", classes: "xv-label"},
22 {kind: "onyx.InputDecorator", components: [
23 {name: "input", kind: "onyx.Checkbox", onchange: "inputChanged"}
28 @todo Document the clear method.
30 clear: function (options) {
31 this.setValue(false, options);
34 inputChanged: function (inSender, inEvent) {
35 var input = this.$.input.getValue();
39 @todo Document the valueChanged method.
41 valueChanged: function (value) {
42 this.$.input.setValue(value);
48 @name XV.StickyCheckboxWidget
49 @class An input control consisting of fittable columns:
50 label, decorator, and checkbox.<br />
51 Use to implement a styled checkbox
52 which is made up of a checkbox input control and its label.
53 Remembers last checked setting using cookies. Not to be
55 The object should be given a unique name as the name of the
56 object will be used for the cookie name.
59 enyo.kind(/** @lends XV.StickyCheckboxWidget# */{
60 name: "XV.StickyCheckboxWidget",
61 classes: "xv-input xv-checkboxwidget",
71 {controlClasses: 'enyo-inline', components: [
72 {name: "label", classes: "xv-label"},
73 {kind: "onyx.InputDecorator", components: [
74 {name: "input", kind: "onyx.Checkbox", onchange: "inputChanged"}
79 @todo Document the clear method.
82 this.$.input.setValue(false);
85 @todo Document the create method.
89 toBoolean = function (val) {
90 if (_.isString(val)) {
91 return val === "true" ? true : false;
96 this.inherited(arguments);
98 if (this.name === "stickyCheckboxWidget") {
100 throw "Sticky Checkbox Widget should have a unique name.";
102 value = toBoolean(enyo.getCookie(this.name));
103 value = _.isBoolean(value) ? value : this.checked;
104 this.checked = value;
105 this.$.input.setValue(value);
108 disabledChanged: function () {
109 var disabled = this.getDisabled();
110 this.$.input.setDisabled(disabled);
111 this.$.label.addRemoveClass("disabled", disabled);
114 @todo Document the focus method.
117 this.$.input.focus();
119 inputChanged: function (inSender, inEvent) {
120 this.setChecked(this.$.input.checked);
122 isChecked: function () {
123 return this.$.input.checked;
126 @todo Document the labelChanged method.
128 labelChanged: function () {
129 var label = (this.getLabel() || ("_" + this.attr || "").loc()) + ":";
130 this.$.label.setContent(label);
132 checkedChanged: function () {
133 this.$.input.setChecked(this.checked);
135 enyo.setCookie(this.name, this.checked);
137 this.doValueChange({value: this.checked});