root / trunk / web / dojo / dojox / form / manager / _Mixin.js
History | View | Annotate | Download (6.06 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.manager._Mixin"]){ |
||
9 | dojo._hasResource["dojox.form.manager._Mixin"]=true; |
||
10 | dojo.provide("dojox.form.manager._Mixin");
|
||
11 | dojo.require("dijit._Widget");
|
||
12 | (function(){
|
||
13 | var fm=dojox.form.manager,aa=fm.actionAdapter=function(_1){ |
||
14 | return function(_2,_3,_4){ |
||
15 | if(dojo.isArray(_3)){
|
||
16 | dojo.forEach(_3,function(_5){
|
||
17 | _1.call(this,_2,_5,_4);
|
||
18 | },this);
|
||
19 | }else{
|
||
20 | _1.apply(this,arguments); |
||
21 | } |
||
22 | }; |
||
23 | },ia=fm.inspectorAdapter=function(_6){ |
||
24 | return function(_7,_8,_9){ |
||
25 | return _6.call(this,_7,dojo.isArray(_8)?_8[0]:_8,_9); |
||
26 | }; |
||
27 | },_a={domNode:1,containerNode:1,srcNodeRef:1,bgIframe:1},_b=fm._keys=function(o){ |
||
28 | var _c=[],_d;
|
||
29 | for(_d in o){ |
||
30 | if(o.hasOwnProperty(_d)){
|
||
31 | _c.push(_d); |
||
32 | } |
||
33 | } |
||
34 | return _c;
|
||
35 | },_e=function(_f){ |
||
36 | var _10=_f.get("name"); |
||
37 | if(_10&&_f instanceof dijit.form._FormWidget){ |
||
38 | if(_10 in this.formWidgets){ |
||
39 | var a=this.formWidgets[_10].widget; |
||
40 | if(dojo.isArray(a)){
|
||
41 | a.push(_f); |
||
42 | }else{
|
||
43 | this.formWidgets[_10].widget=[a,_f];
|
||
44 | } |
||
45 | }else{
|
||
46 | this.formWidgets[_10]={widget:_f,connections:[]}; |
||
47 | } |
||
48 | }else{
|
||
49 | _10=null;
|
||
50 | } |
||
51 | return _10;
|
||
52 | },_11=function(_12){ |
||
53 | var _13={};
|
||
54 | aa(function(_14,w){
|
||
55 | var o=w.get("observer"); |
||
56 | if(o&&typeof o=="string"){ |
||
57 | dojo.forEach(o.split(","),function(o){ |
||
58 | o=dojo.trim(o); |
||
59 | if(o&&dojo.isFunction(this[o])){ |
||
60 | _13[o]=1;
|
||
61 | } |
||
62 | },this);
|
||
63 | } |
||
64 | }).call(this,null,this.formWidgets[_12].widget); |
||
65 | return _b(_13);
|
||
66 | },_15=function(_16,_17){ |
||
67 | var t=this.formWidgets[_16],w=t.widget,c=t.connections; |
||
68 | if(c.length){
|
||
69 | dojo.forEach(c,dojo.disconnect); |
||
70 | c=t.connections=[]; |
||
71 | } |
||
72 | if(dojo.isArray(w)){
|
||
73 | dojo.forEach(w,function(w){
|
||
74 | dojo.forEach(_17,function(o){
|
||
75 | c.push(dojo.connect(w,"onChange",this,function(evt){ |
||
76 | if(this.watch&&dojo.attr(w.focusNode,"checked")){ |
||
77 | this[o](w.get("value"),_16,w,evt); |
||
78 | } |
||
79 | })); |
||
80 | },this);
|
||
81 | },this);
|
||
82 | }else{
|
||
83 | var _18=w.declaredClass=="dijit.form.Button"?"onClick":"onChange"; |
||
84 | dojo.forEach(_17,function(o){
|
||
85 | c.push(dojo.connect(w,_18,this,function(evt){ |
||
86 | if(this.watch){ |
||
87 | this[o](w.get("value"),_16,w,evt); |
||
88 | } |
||
89 | })); |
||
90 | },this);
|
||
91 | } |
||
92 | }; |
||
93 | dojo.declare("dojox.form.manager._Mixin",null,{watch:true,startup:function(){ |
||
94 | if(this._started){ |
||
95 | return;
|
||
96 | } |
||
97 | this.formWidgets={};
|
||
98 | this.formNodes={};
|
||
99 | this.registerWidgetDescendants(this); |
||
100 | this.inherited(arguments); |
||
101 | },destroy:function(){ |
||
102 | for(var _19 in this.formWidgets){ |
||
103 | dojo.forEach(this.formWidgets[_19].connections,dojo.disconnect);
|
||
104 | } |
||
105 | this.formWidgets={};
|
||
106 | this.inherited(arguments); |
||
107 | },registerWidget:function(_1a){ |
||
108 | if(typeof _1a=="string"){ |
||
109 | _1a=dijit.byId(_1a); |
||
110 | }else{
|
||
111 | if(_1a.tagName&&_1a.cloneNode){
|
||
112 | _1a=dijit.byNode(_1a); |
||
113 | } |
||
114 | } |
||
115 | var _1b=_e.call(this,_1a); |
||
116 | if(_1b){
|
||
117 | _15.call(this,_1b,_11.call(this,_1b)); |
||
118 | } |
||
119 | return this; |
||
120 | },unregisterWidget:function(_1c){ |
||
121 | if(_1c in this.formWidgets){ |
||
122 | dojo.forEach(this.formWidgets[_1c].connections,this.disconnect,this); |
||
123 | delete this.formWidgets[_1c]; |
||
124 | } |
||
125 | return this; |
||
126 | },registerWidgetDescendants:function(_1d){ |
||
127 | if(typeof _1d=="string"){ |
||
128 | _1d=dijit.byId(_1d); |
||
129 | }else{
|
||
130 | if(_1d.tagName&&_1d.cloneNode){
|
||
131 | _1d=dijit.byNode(_1d); |
||
132 | } |
||
133 | } |
||
134 | var _1e=dojo.map(_1d.getDescendants(),_e,this); |
||
135 | dojo.forEach(_1e,function(_1f){
|
||
136 | if(_1f){
|
||
137 | _15.call(this,_1f,_11.call(this,_1f)); |
||
138 | } |
||
139 | },this);
|
||
140 | return this.registerNodeDescendants?this.registerNodeDescendants(_1d.domNode):this; |
||
141 | },unregisterWidgetDescendants:function(_20){ |
||
142 | if(typeof _20=="string"){ |
||
143 | _20=dijit.byId(_20); |
||
144 | }else{
|
||
145 | if(_20.tagName&&_20.cloneNode){
|
||
146 | _20=dijit.byNode(_20); |
||
147 | } |
||
148 | } |
||
149 | dojo.forEach(dojo.map(_20.getDescendants(),function(w){
|
||
150 | return w instanceof dijit.form._FormWidget&&w.get("name")||null; |
||
151 | }),function(_21){
|
||
152 | if(_21){
|
||
153 | this.unregisterNode(_21);
|
||
154 | } |
||
155 | },this);
|
||
156 | return this.unregisterNodeDescendants?this.unregisterNodeDescendants(_20.domNode):this; |
||
157 | },formWidgetValue:function(_22,_23){ |
||
158 | var _24=arguments.length==2&&_23!==undefined,_25; |
||
159 | if(typeof _22=="string"){ |
||
160 | _22=this.formWidgets[_22];
|
||
161 | if(_22){
|
||
162 | _22=_22.widget; |
||
163 | } |
||
164 | } |
||
165 | if(!_22){
|
||
166 | return null; |
||
167 | } |
||
168 | if(dojo.isArray(_22)){
|
||
169 | if(_24){
|
||
170 | dojo.forEach(_22,function(_26){
|
||
171 | _26.set("checked",false,!this.watch); |
||
172 | }); |
||
173 | dojo.forEach(_22,function(_27){
|
||
174 | _27.set("checked",_27.value===_23,!this.watch); |
||
175 | }); |
||
176 | return this; |
||
177 | } |
||
178 | dojo.some(_22,function(_28){
|
||
179 | if(dojo.attr(_28.focusNode,"checked")){ |
||
180 | _25=_28; |
||
181 | return true; |
||
182 | } |
||
183 | return false; |
||
184 | }); |
||
185 | return _25?_25.get("value"):""; |
||
186 | } |
||
187 | if(_22.declaredClass=="dijit.form.CheckBox"){ |
||
188 | if(_24){
|
||
189 | _22.set("value",Boolean(_23),!this.watch); |
||
190 | return this; |
||
191 | } |
||
192 | return Boolean(_22.get("value")); |
||
193 | } |
||
194 | if(_24){
|
||
195 | _22.set("value",_23,!this.watch); |
||
196 | return this; |
||
197 | } |
||
198 | return _22.get("value"); |
||
199 | },formPointValue:function(_29,_2a){ |
||
200 | if(_29&&typeof _29=="string"){ |
||
201 | _29=this[_29];
|
||
202 | } |
||
203 | if(!_29||!_29.tagName||!_29.cloneNode){
|
||
204 | return null; |
||
205 | } |
||
206 | if(!dojo.hasClass(_29,"dojoFormValue")){ |
||
207 | return null; |
||
208 | } |
||
209 | if(arguments.length==2&&_2a!==undefined){ |
||
210 | _29.innerHTML=_2a; |
||
211 | return this; |
||
212 | } |
||
213 | return _29.innerHTML;
|
||
214 | },inspectFormWidgets:function(_2b,_2c,_2d){ |
||
215 | var _2e,_2f={};
|
||
216 | if(_2c){
|
||
217 | if(dojo.isArray(_2c)){
|
||
218 | dojo.forEach(_2c,function(_30){
|
||
219 | if(_30 in this.formWidgets){ |
||
220 | _2f[_30]=_2b.call(this,_30,this.formWidgets[_30].widget,_2d); |
||
221 | } |
||
222 | },this);
|
||
223 | }else{
|
||
224 | for(_2e in _2c){ |
||
225 | if(_2e in this.formWidgets){ |
||
226 | _2f[_2e]=_2b.call(this,_2e,this.formWidgets[_2e].widget,_2c[_2e]); |
||
227 | } |
||
228 | } |
||
229 | } |
||
230 | }else{
|
||
231 | for(_2e in this.formWidgets){ |
||
232 | _2f[_2e]=_2b.call(this,_2e,this.formWidgets[_2e].widget,_2d); |
||
233 | } |
||
234 | } |
||
235 | return _2f;
|
||
236 | },inspectAttachedPoints:function(_31,_32,_33){ |
||
237 | var _34,_35={};
|
||
238 | if(_32){
|
||
239 | if(dojo.isArray(_32)){
|
||
240 | dojo.forEach(_32,function(_36){
|
||
241 | var _37=this[_36]; |
||
242 | if(_37&&_37.tagName&&_37.cloneNode){
|
||
243 | _35[_36]=_31.call(this,_36,_37,_33);
|
||
244 | } |
||
245 | },this);
|
||
246 | }else{
|
||
247 | for(_34 in _32){ |
||
248 | var _38=this[_34]; |
||
249 | if(_38&&_38.tagName&&_38.cloneNode){
|
||
250 | _35[_34]=_31.call(this,_34,_38,_32[_34]);
|
||
251 | } |
||
252 | } |
||
253 | } |
||
254 | }else{
|
||
255 | for(_34 in this){ |
||
256 | if(!(_34 in _a)){ |
||
257 | var _38=this[_34]; |
||
258 | if(_38&&_38.tagName&&_38.cloneNode){
|
||
259 | _35[_34]=_31.call(this,_34,_38,_33);
|
||
260 | } |
||
261 | } |
||
262 | } |
||
263 | } |
||
264 | return _35;
|
||
265 | },inspect:function(_39,_3a,_3b){ |
||
266 | var _3c=this.inspectFormWidgets(function(_3d,_3e,_3f){ |
||
267 | if(dojo.isArray(_3e)){
|
||
268 | return _39.call(this,_3d,dojo.map(_3e,function(w){ |
||
269 | return w.domNode;
|
||
270 | }),_3f); |
||
271 | } |
||
272 | return _39.call(this,_3d,_3e.domNode,_3f); |
||
273 | },_3a,_3b); |
||
274 | if(this.inspectFormNodes){ |
||
275 | dojo.mixin(_3c,this.inspectFormNodes(_39,_3a,_3b));
|
||
276 | } |
||
277 | return dojo.mixin(_3c,this.inspectAttachedPoints(_39,_3a,_3b)); |
||
278 | }}); |
||
279 | })(); |
||
280 | dojo.extend(dijit._Widget,{observer:""}); |
||
281 | } |