root / trunk / web / dojo / dojox / form / CheckedMultiSelect.js
History | View | Annotate | Download (3.62 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.form.CheckedMultiSelect"]){ |
||
9 | dojo._hasResource["dojox.form.CheckedMultiSelect"]=true; |
||
10 | dojo.provide("dojox.form.CheckedMultiSelect");
|
||
11 | dojo.require("dijit.form.CheckBox");
|
||
12 | dojo.require("dijit.form._FormSelectWidget");
|
||
13 | dojo.declare("dojox.form._CheckedMultiSelectItem",[dijit._Widget,dijit._Templated],{widgetsInTemplate:true,templateString:dojo.cache("dojox.form","resources/_CheckedMultiSelectItem.html","<div class=\"dijitReset ${baseClass}\"\n\t><input class=\"${baseClass}Box\" dojoType=\"dijit.form.CheckBox\" dojoAttachPoint=\"checkBox\" \n\t\tdojoAttachEvent=\"_onClick:_changeBox\" type=\"${_type.type}\" baseClass=\"${_type.baseClass}\"\n\t/><div class=\"dijitInline ${baseClass}Label\" dojoAttachPoint=\"labelNode\" dojoAttachEvent=\"onclick:_onClick\"></div\n></div>\n"),baseClass:"dojoxMultiSelectItem",option:null,parent:null,disabled:false,readOnly:false,postMixInProperties:function(){ |
||
14 | if(this.parent.multiple){ |
||
15 | this._type={type:"checkbox",baseClass:"dijitCheckBox"}; |
||
16 | }else{
|
||
17 | this._type={type:"radio",baseClass:"dijitRadio"}; |
||
18 | } |
||
19 | this.disabled=this.option.disabled=this.option.disabled||false; |
||
20 | this.inherited(arguments); |
||
21 | },postCreate:function(){ |
||
22 | this.inherited(arguments); |
||
23 | this.labelNode.innerHTML=this.option.label; |
||
24 | },_changeBox:function(){ |
||
25 | if(this.get("disabled")||this.get("readOnly")){ |
||
26 | return;
|
||
27 | } |
||
28 | if(this.parent.multiple){ |
||
29 | this.option.selected=this.checkBox.attr("value")&&true; |
||
30 | }else{
|
||
31 | this.parent.attr("value",this.option.value); |
||
32 | } |
||
33 | this.parent._updateSelection();
|
||
34 | this.parent.focus();
|
||
35 | },_onClick:function(e){ |
||
36 | if(this.get("disabled")||this.get("readOnly")){ |
||
37 | dojo.stopEvent(e); |
||
38 | }else{
|
||
39 | this.checkBox._onClick(e);
|
||
40 | } |
||
41 | },_updateBox:function(){ |
||
42 | this.checkBox.attr("value",this.option.selected); |
||
43 | },_setDisabledAttr:function(_1){ |
||
44 | this.disabled=_1||this.option.disabled; |
||
45 | this.checkBox.attr("disabled",this.disabled); |
||
46 | dojo.toggleClass(this.domNode,"dojoxMultiSelectDisabled",this.disabled); |
||
47 | },_setReadOnlyAttr:function(_2){ |
||
48 | this.checkBox.attr("readOnly",_2); |
||
49 | this.readOnly=_2;
|
||
50 | }}); |
||
51 | dojo.declare("dojox.form.CheckedMultiSelect",dijit.form._FormSelectWidget,{templateString:dojo.cache("dojox.form","resources/CheckedMultiSelect.html","<div class=\"dijit dijitReset dijitInline\" dojoAttachEvent=\"onmousedown:_onMouseDown,onclick:focus\"\n\t><select class=\"${baseClass}Select\" multiple=\"true\" dojoAttachPoint=\"containerNode,focusNode\"></select\n\t><div dojoAttachPoint=\"wrapperDiv\"></div\n></div>\n"),baseClass:"dojoxMultiSelect",_onMouseDown:function(e){ |
||
52 | dojo.stopEvent(e); |
||
53 | },_addOptionItem:function(_3){ |
||
54 | this.wrapperDiv.appendChild(new dojox.form._CheckedMultiSelectItem({option:_3,parent:this}).domNode); |
||
55 | },_updateSelection:function(){ |
||
56 | this.inherited(arguments); |
||
57 | dojo.forEach(this._getChildren(),function(c){ |
||
58 | c._updateBox(); |
||
59 | }); |
||
60 | },_getChildren:function(){ |
||
61 | return dojo.map(this.wrapperDiv.childNodes,function(n){ |
||
62 | return dijit.byNode(n);
|
||
63 | }); |
||
64 | },invertSelection:function(_4){ |
||
65 | dojo.forEach(this.options,function(i){ |
||
66 | i.selected=!i.selected; |
||
67 | }); |
||
68 | this._updateSelection();
|
||
69 | },_setDisabledAttr:function(_5){ |
||
70 | this.inherited(arguments); |
||
71 | dojo.forEach(this._getChildren(),function(_6){ |
||
72 | if(_6&&_6.attr){
|
||
73 | _6.attr("disabled",_5);
|
||
74 | } |
||
75 | }); |
||
76 | },_setReadOnlyAttr:function(_7){ |
||
77 | if("readOnly" in this.attributeMap){ |
||
78 | this._attrToDom("readOnly",_7); |
||
79 | } |
||
80 | this.readOnly=_7;
|
||
81 | dojo.forEach(this._getChildren(),function(_8){ |
||
82 | if(_8&&_8.attr){
|
||
83 | _8.attr("readOnly",_7);
|
||
84 | } |
||
85 | }); |
||
86 | },uninitialize:function(){ |
||
87 | dojo.forEach(this._getChildren(),function(_9){ |
||
88 | _9.destroyRecursive(); |
||
89 | }); |
||
90 | this.inherited(arguments); |
||
91 | }}); |
||
92 | } |