root / trunk / web / dojo / dojox / form / manager / _NodeMixin.js
History | View | Annotate | Download (4.77 KB)
1 |
/*
|
---|---|
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.manager._NodeMixin"]){ |
9 |
dojo._hasResource["dojox.form.manager._NodeMixin"]=true; |
10 |
dojo.provide("dojox.form.manager._NodeMixin");
|
11 |
dojo.require("dojox.form.manager._Mixin");
|
12 |
(function(){
|
13 |
var fm=dojox.form.manager,aa=fm.actionAdapter,_1=fm._keys,ce=fm.changeEvent=function(_2){ |
14 |
var _3="onclick"; |
15 |
switch(_2.tagName.toLowerCase()){
|
16 |
case "textarea": |
17 |
_3="onkeyup";
|
18 |
break;
|
19 |
case "select": |
20 |
_3="onchange";
|
21 |
break;
|
22 |
case "input": |
23 |
switch(_2.type.toLowerCase()){
|
24 |
case "text": |
25 |
case "password": |
26 |
_3="onkeyup";
|
27 |
break;
|
28 |
} |
29 |
break;
|
30 |
} |
31 |
return _3;
|
32 |
},_4=function(_5,_6){ |
33 |
var _7=dojo.attr(_5,"name"); |
34 |
_6=_6||this.domNode;
|
35 |
if(_7&&!(_7 in this.formWidgets)){ |
36 |
for(var n=_5;n&&n!==_6;n=n.parentNode){ |
37 |
if(dojo.attr(n,"widgetId")&&dijit.byNode(n) instanceof dijit.form._FormWidget){ |
38 |
return null; |
39 |
} |
40 |
} |
41 |
if(_5.tagName.toLowerCase()=="input"&&_5.type.toLowerCase()=="radio"){ |
42 |
var a=this.formNodes[_7]; |
43 |
a=a&&a.node; |
44 |
if(a&&dojo.isArray(a)){
|
45 |
a.push(_5); |
46 |
}else{
|
47 |
this.formNodes[_7]={node:[_5],connections:[]}; |
48 |
} |
49 |
}else{
|
50 |
this.formNodes[_7]={node:_5,connections:[]}; |
51 |
} |
52 |
}else{
|
53 |
_7=null;
|
54 |
} |
55 |
return _7;
|
56 |
},_8=function(_9){ |
57 |
var _a={};
|
58 |
aa(function(_b,n){
|
59 |
var o=dojo.attr(n,"observer"); |
60 |
if(o&&typeof o=="string"){ |
61 |
dojo.forEach(o.split(","),function(o){ |
62 |
o=dojo.trim(o); |
63 |
if(o&&dojo.isFunction(this[o])){ |
64 |
_a[o]=1;
|
65 |
} |
66 |
},this);
|
67 |
} |
68 |
}).call(this,null,this.formNodes[_9].node); |
69 |
return _1(_a);
|
70 |
},_c=function(_d,_e){ |
71 |
var t=this.formNodes[_d],c=t.connections; |
72 |
if(c.length){
|
73 |
dojo.forEach(c,dojo.disconnect); |
74 |
c=t.connections=[]; |
75 |
} |
76 |
aa(function(_f,n){
|
77 |
var _10=ce(n);
|
78 |
dojo.forEach(_e,function(o){
|
79 |
c.push(dojo.connect(n,_10,this,function(evt){ |
80 |
if(this.watch){ |
81 |
this[o](this.formNodeValue(_d),_d,n,evt); |
82 |
} |
83 |
})); |
84 |
},this);
|
85 |
}).call(this,null,t.node); |
86 |
}; |
87 |
dojo.declare("dojox.form.manager._NodeMixin",null,{destroy:function(){ |
88 |
for(var _11 in this.formNodes){ |
89 |
dojo.forEach(this.formNodes[_11].connections,dojo.disconnect);
|
90 |
} |
91 |
this.formNodes={};
|
92 |
this.inherited(arguments); |
93 |
},registerNode:function(_12){ |
94 |
if(typeof _12=="string"){ |
95 |
_12=dojo.byId(_12); |
96 |
} |
97 |
var _13=_4.call(this,_12); |
98 |
if(_13){
|
99 |
_c.call(this,_13,_8.call(this,_13)); |
100 |
} |
101 |
return this; |
102 |
},unregisterNode:function(_14){ |
103 |
if(_14 in this.formNodes){ |
104 |
dojo.forEach(this.formNodes[_14].connections,this.disconnect,this); |
105 |
delete this.formNodes[_14]; |
106 |
} |
107 |
return this; |
108 |
},registerNodeDescendants:function(_15){ |
109 |
if(typeof _15=="string"){ |
110 |
_15=dojo.byId(_15); |
111 |
} |
112 |
dojo.query("input, select, textarea, button",_15).map(function(n){ |
113 |
return _4.call(this,n,_15); |
114 |
},this).forEach(function(_16){ |
115 |
if(_16){
|
116 |
_c.call(this,_16,_8.call(this,_16)); |
117 |
} |
118 |
},this);
|
119 |
return this; |
120 |
},unregisterNodeDescendants:function(_17){ |
121 |
if(typeof _17=="string"){ |
122 |
_17=dojo.byId(_17); |
123 |
} |
124 |
dojo.query("input, select, textarea, button",_17).map(function(n){ |
125 |
return dojo.attr(_17,"name")||null; |
126 |
}).forEach(function(_18){
|
127 |
if(_18){
|
128 |
this.unregisterNode(_18);
|
129 |
} |
130 |
},this);
|
131 |
return this; |
132 |
},formNodeValue:function(_19,_1a){ |
133 |
var _1b=arguments.length==2&&_1a!==undefined,_1c; |
134 |
if(typeof _19=="string"){ |
135 |
_19=this.formNodes[_19];
|
136 |
if(_19){
|
137 |
_19=_19.node; |
138 |
} |
139 |
} |
140 |
if(!_19){
|
141 |
return null; |
142 |
} |
143 |
if(dojo.isArray(_19)){
|
144 |
if(_1b){
|
145 |
dojo.forEach(_19,function(_1d){
|
146 |
_1d.checked="";
|
147 |
}); |
148 |
dojo.forEach(_19,function(_1e){
|
149 |
_1e.checked=_1e.value===_1a?"checked":""; |
150 |
}); |
151 |
return this; |
152 |
} |
153 |
dojo.some(_19,function(_1f){
|
154 |
if(_1f.checked){
|
155 |
_1c=_1f; |
156 |
return true; |
157 |
} |
158 |
return false; |
159 |
}); |
160 |
return _1c?_1c.value:""; |
161 |
} |
162 |
switch(_19.tagName.toLowerCase()){
|
163 |
case "select": |
164 |
if(_19.multiple){
|
165 |
if(_1b){
|
166 |
if(dojo.isArray(_1a)){
|
167 |
var _20={};
|
168 |
dojo.forEach(_1a,function(v){
|
169 |
_20[v]=1;
|
170 |
}); |
171 |
dojo.query("> option",_19).forEach(function(opt){ |
172 |
opt.selected=opt.value in _20;
|
173 |
}); |
174 |
return this; |
175 |
} |
176 |
dojo.query("> option",_19).forEach(function(opt){ |
177 |
opt.selected=opt.value===_1a; |
178 |
}); |
179 |
return this; |
180 |
} |
181 |
var _1c=dojo.query("> option",_19).filter(function(opt){ |
182 |
return opt.selected;
|
183 |
}).map(function(opt){
|
184 |
return opt.value;
|
185 |
}); |
186 |
return _1c.length==1?_1c[0]:_1c; |
187 |
} |
188 |
if(_1b){
|
189 |
dojo.query("> option",_19).forEach(function(opt){ |
190 |
opt.selected=opt.value===_1a; |
191 |
}); |
192 |
return this; |
193 |
} |
194 |
return _19.value||""; |
195 |
case "button": |
196 |
if(_1b){
|
197 |
_19.innerHTML=""+_1a;
|
198 |
return this; |
199 |
} |
200 |
return _19.innerHTML;
|
201 |
case "input": |
202 |
if(_19.type.toLowerCase()=="checkbox"){ |
203 |
if(_1b){
|
204 |
_19.checked=_1a?"checked":""; |
205 |
return this; |
206 |
} |
207 |
return Boolean(_19.checked);
|
208 |
} |
209 |
} |
210 |
if(_1b){
|
211 |
_19.value=""+_1a;
|
212 |
return this; |
213 |
} |
214 |
return _19.value;
|
215 |
},inspectFormNodes:function(_21,_22,_23){ |
216 |
var _24,_25={};
|
217 |
if(_22){
|
218 |
if(dojo.isArray(_22)){
|
219 |
dojo.forEach(_22,function(_26){
|
220 |
if(_26 in this.formNodes){ |
221 |
_25[_26]=_21.call(this,_26,this.formNodes[_26].node,_23); |
222 |
} |
223 |
},this);
|
224 |
}else{
|
225 |
for(_24 in _22){ |
226 |
if(_24 in this.formNodes){ |
227 |
_25[_24]=_21.call(this,_24,this.formNodes[_24].node,_22[_24]); |
228 |
} |
229 |
} |
230 |
} |
231 |
}else{
|
232 |
for(_24 in this.formNodes){ |
233 |
_25[_24]=_21.call(this,_24,this.formNodes[_24].node,_23); |
234 |
} |
235 |
} |
236 |
return _25;
|
237 |
}}); |
238 |
})(); |
239 |
} |