1 if(!dojo._hasResource["dojox.form.CheckedMultiSelect"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.form.CheckedMultiSelect"] = true;
3 dojo.provide("dojox.form.CheckedMultiSelect");
5 dojo.require("dijit.form.MultiSelect");
6 dojo.require("dijit.form.CheckBox");
8 dojo.declare("dojox.form._CheckedMultiSelectItem",
9 [dijit._Widget, dijit._Templated],
12 // The individual items for a CheckedMultiSelect
14 widgetsInTemplate: true,
15 templateString:"<div class=\"dijitReset ${baseClass}\"\n\t><input class=\"${baseClass}Box\" dojoType=\"dijit.form.CheckBox\" dojoAttachPoint=\"checkBox\" dojoAttachEvent=\"_onClick:_changeBox\" type=\"checkbox\" \n\t><div class=\"dijitInline ${baseClass}Label\" dojoAttachPoint=\"labelNode\" dojoAttachEvent=\"onmousedown:_onMouse,onmouseover:_onMouse,onmouseout:_onMouse,onclick:_onClick\">${option.innerHTML}</div\n></div>\n",
17 baseClass: "dojoxMultiSelectItem",
20 // The option that is associated with this item
25 // Whether or not this widget is disabled
28 _changeBox: function(){
30 // Called to force the select to match the state of the check box
31 // (only on click of the checkbox)
32 this.option.selected = this.checkBox.getValue() && true;
34 // fire the parent's change
35 this.parent._onChange();
41 _labelClick: function(){
43 // Called when the label portion is clicked
48 var cb = this.checkBox;
49 cb.setValue(!cb.getValue());
53 _onMouse: function(e){
55 // Sets the hover state depending on mouse state (passes through
57 this.checkBox._onMouse(e);
60 _onClick: function(e){
62 // Sets the click state (passes through to the check box)
63 this.checkBox._onClick(e);
66 _updateBox: function(){
68 // Called to force the box to match the state of the select
69 this.checkBox.setValue(this.option.selected);
72 setAttribute: function(attr, value){
74 // Disables (or enables) all the children as well
75 this.inherited(arguments);
78 this.checkBox.setAttribute(attr, value);
86 dojo.declare("dojox.form.CheckedMultiSelect", dijit.form.MultiSelect, {
88 // Extends the core dijit MultiSelect to provide a "checkbox" selector
91 templateString:"<div class=\"dijit dijitReset dijitInline\" dojoAttachEvent=\"onmousedown:_mouseDown,onclick:focus\"\n\t><select class=\"${baseClass}Select\" multiple=\"true\" dojoAttachPoint=\"containerNode,focusNode\" dojoAttachEvent=\"onchange: _onChange\"></select\n\t><div dojoAttachPoint=\"wrapperDiv\"></div\n></div>\n",
93 baseClass: "dojoxMultiSelect",
95 // children: dojox.form._CheckedMultiSelectItem[]
96 // Array of all our children (for updating them)
100 dojox.form.__SelectOption = function(){
102 // The value of the option. Setting to empty (or missing) will
103 // place a separator at that location
105 // The label for our option. It can contain html tags.
111 // options: dojox.form.__SelectOption[]
112 // our set of options
115 _mouseDown: function(e){
117 // Cancels the mousedown event to prevent others from stealing
122 _updateChildren: function(){
124 // Called to update the checked states of my children to match me
125 dojo.forEach(this.children,function(child){
130 _addChild: function(/*Element*/ option){
132 // Adds and returns a child for the given option.
133 var item = new dojox.form._CheckedMultiSelectItem({
137 this.wrapperDiv.appendChild(item.domNode);
141 _loadChildren: function(){
143 // Reloads the children to match our box.
145 // Destroy any existing children before loading them again
146 dojo.forEach(this.children, function(child){
147 child.destroyRecursive();
149 this.children = dojo.query("option", this.domNode).map(function(child){
150 return this._addChild(child);
152 this.options = dojo.map(this.children, function(child){
153 var opt = child.option;
154 return { value:opt.value, label: opt.text };
156 // Update the statuses of the children
157 this._updateChildren();
160 addOption: function(/* dojox.form.__SelectOption or string, optional */ value, /* string? */ label){
161 // summary: Adds the given option to the select
163 var o = new Option("","");
164 o.value = value.value || value;
165 o.innerHTML = value.label || label;
166 this.containerNode.appendChild(o);
169 removeOption: function(/*String*/ optionId){
170 dojo.query("option[value=" + optionId + "]", this.domNode).forEach(function(node){
171 node.parentNode.removeChild(node);
175 setOptionLabel: function(/*string*/ optionId, /*string*/ label){
176 dojo.query("option[value=" + optionId + "]", this.domNode).forEach(function(node){
177 node.innerHTML = label;
181 addSelected: function(select){
182 this.inherited(arguments);
184 // Reload my children and the children of the guy pointing to me
185 if(select._loadChildren){
186 select._loadChildren();
188 this._loadChildren();
191 setAttribute: function(attr, value){
193 // Disable (or enable) all the children as well
194 this.inherited(arguments);
197 dojo.forEach(this.children, function(node){
198 if(node && node.setAttribute){
199 node.setAttribute(attr, value);
209 if(this._started){ return; }
210 this.inherited(arguments);
212 // Load children and make connections
213 this._loadChildren();
214 this.connect(this, "setValue", "_updateChildren");
215 this.connect(this, "invertSelection", "_updateChildren");
216 this.connect(this, "addOption", "_loadChildren");
217 this.connect(this, "removeOption", "_loadChildren");
218 this.connect(this, "setOptionLabel", "_loadChildren");
219 this._started = true;