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 */
9 @class An input control that shows or hides a checkmark when clicked.</br >
10 To implement a checkbox, see {@link XV.CheckboxWidget}.<br />
11 Derived from <a href="http://enyojs.com/api/#onyx.Checkbox">onyx.Checkbox</a>.
12 @extends onyx.Checkbox
15 /** @lends XV.Checkbox# */{
17 kind: "onyx.Checkbox",
28 @todo Document the clear method.
30 clear: function (options) {
31 this.setValue(false, options);
34 @todo Document the setValue method.
36 setValue: function (value, options) {
37 options = options || {};
38 this._silent = options.silent;
39 this.inherited(arguments);
43 @todo Document the changed method.
45 changed: function (inSender, inEvent) {
47 inEvent.value = this.getValue();
48 this.doValueChange(inEvent);
54 @name XV.CheckboxWidget
55 @class An input control consisting of fittable columns:
56 label, decorator, and checkbox.<br />
57 Use to implement a styled checkbox
58 which is made up of a checkbox input control and its label.
61 enyo.kind(/** @lends XV.CheckboxWidget# */{
62 name: "XV.CheckboxWidget",
63 kind: "XV.InputWidget",
64 classes: "xv-checkboxwidget",
66 {kind: "FittableColumns", components: [
67 {name: "label", content: "", classes: "xv-label"},
68 {kind: "onyx.InputDecorator", classes: "xv-input-decorator",
70 {name: "input", kind: "onyx.Checkbox", onchange: "inputChanged"}
75 @todo Document the clear method.
77 clear: function (options) {
78 this.setValue(false, options);
81 @todo Document the create method.
84 this.inherited(arguments);
87 disabledChanged: function () {
88 this.inherited(arguments);
89 this.$.label.addRemoveClass("disabled", this.getDisabled());
92 @todo Document the inputChanged method.
94 inputChanged: function (inSender, inEvent) {
95 var input = this.$.input.getValue();
99 @todo Document the labelChanged method.
101 labelChanged: function () {
102 var label = (this.getLabel() || ("_" + this.attr || "").loc()) + ":";
103 this.$.label.setContent(label);
106 @todo Document the valueChanged method.
108 valueChanged: function (value) {
109 this.$.input.setValue(value);
115 @name XV.StickyCheckboxWidget
116 @class An input control consisting of fittable columns:
117 label, decorator, and checkbox.<br />
118 Use to implement a styled checkbox
119 which is made up of a checkbox input control and its label.
120 Remembers last checked setting using cookies. Not to be
122 The object should be given a unique name as the name of the
123 object will be used for the cookie name.
126 enyo.kind(/** @lends XV.StickyCheckboxWidget# */{
127 name: "XV.StickyCheckboxWidget",
128 classes: "xv-input xv-checkboxwidget",
138 {kind: "FittableColumns", components: [
139 {name: "label", content: "", classes: "xv-label"},
140 {kind: "onyx.InputDecorator", classes: "xv-input-decorator",
142 {name: "input", kind: "onyx.Checkbox", onchange: "inputChanged"}
147 @todo Document the clear method.
150 this.$.input.setValue(false);
153 @todo Document the create method.
155 create: function () {
157 toBoolean = function (val) {
158 if (_.isString(val)) {
159 return val === "true" ? true : false;
164 this.inherited(arguments);
166 if (this.name === "stickyCheckboxWidget") {
168 throw "Sticky Checkbox Widget should have a unique name.";
170 value = toBoolean(enyo.getCookie(this.name));
171 value = _.isBoolean(value) ? value : this.checked;
172 this.checked = value;
173 this.$.input.setValue(value);
176 disabledChanged: function () {
177 var disabled = this.getDisabled();
178 this.$.input.setDisabled(disabled);
179 this.$.label.addRemoveClass("disabled", disabled);
182 @todo Document the focus method.
185 this.$.input.focus();
187 inputChanged: function (inSender, inEvent) {
188 this.setChecked(this.$.input.checked);
190 isChecked: function () {
191 return this.$.input.checked;
194 @todo Document the labelChanged method.
196 labelChanged: function () {
197 var label = (this.getLabel() || ("_" + this.attr || "").loc()) + ":";
198 this.$.label.setContent(label);
200 checkedChanged: function () {
201 this.$.input.setChecked(this.checked);
203 enyo.setCookie(this.name, this.checked);
205 this.doValueChange({value: this.checked});