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 @todo Document the create method.
37 this.inherited(arguments);
40 disabledChanged: function () {
41 this.inherited(arguments);
42 this.$.label.addRemoveClass("disabled", this.getDisabled());
45 @todo Document the inputChanged method.
47 inputChanged: function (inSender, inEvent) {
48 var input = this.$.input.getValue();
52 @todo Document the labelChanged method.
54 labelChanged: function () {
55 var label = (this.getLabel() || ("_" + this.attr || "").loc()) + ":";
56 this.$.label.setContent(label);
59 @todo Document the valueChanged method.
61 valueChanged: function (value) {
62 this.$.input.setValue(value);
68 @name XV.StickyCheckboxWidget
69 @class An input control consisting of fittable columns:
70 label, decorator, and checkbox.<br />
71 Use to implement a styled checkbox
72 which is made up of a checkbox input control and its label.
73 Remembers last checked setting using cookies. Not to be
75 The object should be given a unique name as the name of the
76 object will be used for the cookie name.
79 enyo.kind(/** @lends XV.StickyCheckboxWidget# */{
80 name: "XV.StickyCheckboxWidget",
81 classes: "xv-input xv-checkboxwidget",
91 {controlClasses: 'enyo-inline', components: [
92 {name: "label", classes: "xv-label"},
93 {kind: "onyx.InputDecorator", components: [
94 {name: "input", kind: "onyx.Checkbox", onchange: "inputChanged"}
99 @todo Document the clear method.
102 this.$.input.setValue(false);
105 @todo Document the create method.
107 create: function () {
109 toBoolean = function (val) {
110 if (_.isString(val)) {
111 return val === "true" ? true : false;
116 this.inherited(arguments);
118 if (this.name === "stickyCheckboxWidget") {
120 throw "Sticky Checkbox Widget should have a unique name.";
122 value = toBoolean(enyo.getCookie(this.name));
123 value = _.isBoolean(value) ? value : this.checked;
124 this.checked = value;
125 this.$.input.setValue(value);
128 disabledChanged: function () {
129 var disabled = this.getDisabled();
130 this.$.input.setDisabled(disabled);
131 this.$.label.addRemoveClass("disabled", disabled);
134 @todo Document the focus method.
137 this.$.input.focus();
139 inputChanged: function (inSender, inEvent) {
140 this.setChecked(this.$.input.checked);
142 isChecked: function () {
143 return this.$.input.checked;
146 @todo Document the labelChanged method.
148 labelChanged: function () {
149 var label = (this.getLabel() || ("_" + this.attr || "").loc()) + ":";
150 this.$.label.setContent(label);
152 checkedChanged: function () {
153 this.$.input.setChecked(this.checked);
155 enyo.setCookie(this.name, this.checked);
157 this.doValueChange({value: this.checked});