root / trunk / web / dojo / dojox / grid / TreeGrid.js @ 12
History | View | Annotate | Download (16.8 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.grid.TreeGrid"]){ |
||
9 | dojo._hasResource["dojox.grid.TreeGrid"]=true; |
||
10 | dojo.experimental("dojox.grid.TreeGrid");
|
||
11 | dojo.provide("dojox.grid.TreeGrid");
|
||
12 | dojo.require("dojox.grid.DataGrid");
|
||
13 | dojo.require("dojox.grid._TreeView");
|
||
14 | dojo.require("dojox.grid.cells.tree");
|
||
15 | dojo.require("dojox.grid.TreeSelection");
|
||
16 | dojo.declare("dojox.grid._TreeAggregator",null,{cells:[],grid:null,childFields:[],constructor:function(_1){ |
||
17 | this.cells=_1.cells||[];
|
||
18 | this.childFields=_1.childFields||[];
|
||
19 | this.grid=_1.grid;
|
||
20 | this.store=this.grid.store; |
||
21 | },_cacheValue:function(_2,id,_3){ |
||
22 | _2[id]=_3; |
||
23 | return _3;
|
||
24 | },clearSubtotalCache:function(){ |
||
25 | if(this.store){ |
||
26 | delete this.store._cachedAggregates; |
||
27 | } |
||
28 | },cnt:function(_4,_5,_6){ |
||
29 | var _7=0; |
||
30 | var _8=this.store; |
||
31 | var _9=this.childFields; |
||
32 | if(_9[_5]){
|
||
33 | var _a=_8.getValues(_6,_9[_5]);
|
||
34 | if(_4.index<=_5+1){ |
||
35 | _7=_a.length; |
||
36 | }else{
|
||
37 | dojo.forEach(_a,function(c){
|
||
38 | _7+=this.getForCell(_4,_5+1,c,"cnt"); |
||
39 | },this);
|
||
40 | } |
||
41 | }else{
|
||
42 | _7=1;
|
||
43 | } |
||
44 | return _7;
|
||
45 | },sum:function(_b,_c,_d){ |
||
46 | var _e=0; |
||
47 | var _f=this.store; |
||
48 | var _10=this.childFields; |
||
49 | if(_10[_c]){
|
||
50 | dojo.forEach(_f.getValues(_d,_10[_c]),function(c){
|
||
51 | _e+=this.getForCell(_b,_c+1,c,"sum"); |
||
52 | },this);
|
||
53 | }else{
|
||
54 | _e+=_f.getValue(_d,_b.field); |
||
55 | } |
||
56 | return _e;
|
||
57 | },value:function(_11,_12,_13){ |
||
58 | },getForCell:function(_14,_15,_16,_17){ |
||
59 | var _18=this.store; |
||
60 | if(!_18||!_16||!_18.isItem(_16)){
|
||
61 | return ""; |
||
62 | } |
||
63 | var _19=_18._cachedAggregates=_18._cachedAggregates||{};
|
||
64 | var id=_18.getIdentity(_16);
|
||
65 | var _1a=_19[id]=_19[id]||[];
|
||
66 | if(!_14.getOpenState){
|
||
67 | _14=this.grid.getCell(_14.layoutIndex+_15+1); |
||
68 | } |
||
69 | var idx=_14.index;
|
||
70 | var _1b=_1a[idx]=_1a[idx]||{};
|
||
71 | _17=(_17||(_14.parentCell?_14.parentCell.aggregate:"sum"))||"sum"; |
||
72 | var _1c=_14.field;
|
||
73 | if(_1c==_18.getLabelAttributes()[0]){ |
||
74 | _17="cnt";
|
||
75 | } |
||
76 | var _1d=_1b[_17]=_1b[_17]||[];
|
||
77 | if(_1d[_15]!=undefined){ |
||
78 | return _1d[_15];
|
||
79 | } |
||
80 | var _1e=((_14.parentCell&&_14.parentCell.itemAggregates)?_14.parentCell.itemAggregates[_14.idxInParent]:"")||""; |
||
81 | if(_1e&&_18.hasAttribute(_16,_1e)){
|
||
82 | return this._cacheValue(_1d,_15,_18.getValue(_16,_1e)); |
||
83 | }else{
|
||
84 | if(_1e){
|
||
85 | return this._cacheValue(_1d,_15,0); |
||
86 | } |
||
87 | } |
||
88 | return this._cacheValue(_1d,_15,this[_17](_14,_15,_16)); |
||
89 | }}); |
||
90 | dojo.declare("dojox.grid._TreeLayout",dojox.grid._Layout,{_isCollapsable:false,_getInternalStructure:function(_1f){ |
||
91 | var g=this.grid; |
||
92 | var s=_1f;
|
||
93 | var _20=s[0].cells[0]; |
||
94 | var _21={type:"dojox.grid._TreeView",cells:[[]]}; |
||
95 | var _22=[];
|
||
96 | var _23=0; |
||
97 | var _24=function(_25,_26){ |
||
98 | var _27=_25.children;
|
||
99 | var _28=function(_29,idx){ |
||
100 | var k,n={};
|
||
101 | for(k in _29){ |
||
102 | n[k]=_29[k]; |
||
103 | } |
||
104 | n=dojo.mixin(n,{level:_26,idxInParent:_26>0?idx:-1,parentCell:_26>0?_25:null}); |
||
105 | return n;
|
||
106 | }; |
||
107 | var ret=[];
|
||
108 | dojo.forEach(_27,function(c,idx){
|
||
109 | if("children" in c){ |
||
110 | _22.push(c.field); |
||
111 | var _2a=ret[ret.length-1]; |
||
112 | _2a.isCollapsable=true;
|
||
113 | c.level=_26; |
||
114 | ret=ret.concat(_24(c,_26+1));
|
||
115 | }else{
|
||
116 | ret.push(_28(c,idx)); |
||
117 | } |
||
118 | }); |
||
119 | _23=Math.max(_23,_26); |
||
120 | return ret;
|
||
121 | }; |
||
122 | var _2b={children:_20,itemAggregates:[]}; |
||
123 | _21.cells[0]=_24(_2b,0); |
||
124 | g.aggregator=new dojox.grid._TreeAggregator({cells:_21.cells[0],grid:g,childFields:_22}); |
||
125 | if(g.scroller&&g.defaultOpen){
|
||
126 | g.scroller.defaultRowHeight=g.scroller._origDefaultRowHeight*(2*_23+1); |
||
127 | } |
||
128 | return [_21];
|
||
129 | },setStructure:function(_2c){ |
||
130 | var s=_2c;
|
||
131 | var g=this.grid; |
||
132 | if(g&&g.treeModel&&!dojo.every(s,function(i){ |
||
133 | return ("cells" in i); |
||
134 | })){ |
||
135 | s=arguments[0]=[{cells:[s]}]; |
||
136 | } |
||
137 | if(s.length==1&&s[0].cells.length==1){ |
||
138 | if(g&&g.treeModel){
|
||
139 | s[0].type="dojox.grid._TreeView"; |
||
140 | this._isCollapsable=true; |
||
141 | s[0].cells[0][(this.grid.treeModel?this.grid.expandoCell:0)].isCollapsable=true; |
||
142 | }else{
|
||
143 | var _2d=dojo.filter(s[0].cells[0],function(c){ |
||
144 | return ("children" in c); |
||
145 | }); |
||
146 | if(_2d.length===1){ |
||
147 | this._isCollapsable=true; |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | if(this._isCollapsable&&(!g||!g.treeModel)){ |
||
152 | arguments[0]=this._getInternalStructure(s); |
||
153 | } |
||
154 | this.inherited(arguments); |
||
155 | },addCellDef:function(_2e,_2f,_30){ |
||
156 | var obj=this.inherited(arguments); |
||
157 | return dojo.mixin(obj,dojox.grid.cells.TreeCell);
|
||
158 | }}); |
||
159 | dojo.declare("dojox.grid.TreePath",null,{level:0,_str:"",_arr:null,grid:null,store:null,cell:null,item:null,constructor:function(_31,_32){ |
||
160 | if(dojo.isString(_31)){
|
||
161 | this._str=_31;
|
||
162 | this._arr=dojo.map(_31.split("/"),function(_33){ |
||
163 | return parseInt(_33,10); |
||
164 | }); |
||
165 | }else{
|
||
166 | if(dojo.isArray(_31)){
|
||
167 | this._str=_31.join("/"); |
||
168 | this._arr=_31.slice(0); |
||
169 | }else{
|
||
170 | if(typeof _31=="number"){ |
||
171 | this._str=String(_31);
|
||
172 | this._arr=[_31];
|
||
173 | }else{
|
||
174 | this._str=_31._str;
|
||
175 | this._arr=_31._arr.slice(0); |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | this.level=this._arr.length-1; |
||
180 | this.grid=_32;
|
||
181 | this.store=this.grid.store; |
||
182 | if(_32.treeModel){
|
||
183 | this.cell=_32.layout.cells[_32.expandoCell];
|
||
184 | }else{
|
||
185 | this.cell=_32.layout.cells[this.level]; |
||
186 | } |
||
187 | },item:function(){ |
||
188 | if(!this._item){ |
||
189 | this._item=this.grid.getItem(this._arr); |
||
190 | } |
||
191 | return this._item; |
||
192 | },compare:function(_34){ |
||
193 | if(dojo.isString(_34)||dojo.isArray(_34)){
|
||
194 | if(this._str==_34){ |
||
195 | return 0; |
||
196 | } |
||
197 | if(_34.join&&this._str==_34.join("/")){ |
||
198 | return 0; |
||
199 | } |
||
200 | _34=new dojox.grid.TreePath(_34,this.grid); |
||
201 | }else{
|
||
202 | if(_34 instanceof dojox.grid.TreePath){ |
||
203 | if(this._str==_34._str){ |
||
204 | return 0; |
||
205 | } |
||
206 | } |
||
207 | } |
||
208 | for(var i=0,l=(this._arr.length<_34._arr.length?this._arr.length:_34._arr.length);i<l;i++){ |
||
209 | if(this._arr[i]<_34._arr[i]){ |
||
210 | return -1; |
||
211 | } |
||
212 | if(this._arr[i]>_34._arr[i]){ |
||
213 | return 1; |
||
214 | } |
||
215 | } |
||
216 | if(this._arr.length<_34._arr.length){ |
||
217 | return -1; |
||
218 | } |
||
219 | if(this._arr.length>_34._arr.length){ |
||
220 | return 1; |
||
221 | } |
||
222 | return 0; |
||
223 | },isOpen:function(){ |
||
224 | return this.cell.openStates&&this.cell.getOpenState(this.item()); |
||
225 | },previous:function(){ |
||
226 | var _35=this._arr.slice(0); |
||
227 | if(this._str=="0"){ |
||
228 | return null; |
||
229 | } |
||
230 | var _36=_35.length-1; |
||
231 | if(_35[_36]===0){ |
||
232 | _35.pop(); |
||
233 | return new dojox.grid.TreePath(_35,this.grid); |
||
234 | } |
||
235 | _35[_36]--; |
||
236 | var _37=new dojox.grid.TreePath(_35,this.grid); |
||
237 | return _37.lastChild(true); |
||
238 | },next:function(){ |
||
239 | var _38=this._arr.slice(0); |
||
240 | if(this.isOpen()){ |
||
241 | _38.push(0);
|
||
242 | }else{
|
||
243 | _38[_38.length-1]++;
|
||
244 | for(var i=this.level;i>=0;i--){ |
||
245 | var _39=this.grid.getItem(_38.slice(0,i+1)); |
||
246 | if(i>0){ |
||
247 | if(!_39){
|
||
248 | _38.pop(); |
||
249 | _38[i-1]++;
|
||
250 | } |
||
251 | }else{
|
||
252 | if(!_39){
|
||
253 | return null; |
||
254 | } |
||
255 | } |
||
256 | } |
||
257 | } |
||
258 | return new dojox.grid.TreePath(_38,this.grid); |
||
259 | },children:function(_3a){ |
||
260 | if(!this.isOpen()&&!_3a){ |
||
261 | return null; |
||
262 | } |
||
263 | var _3b=[];
|
||
264 | var _3c=this.grid.treeModel; |
||
265 | if(_3c){
|
||
266 | var _3d=this.item(); |
||
267 | var _3e=_3c.store;
|
||
268 | if(!_3c.mayHaveChildren(_3d)){
|
||
269 | return null; |
||
270 | } |
||
271 | dojo.forEach(_3c.childrenAttrs,function(_3f){
|
||
272 | _3b=_3b.concat(_3e.getValues(_3d,_3f)); |
||
273 | }); |
||
274 | }else{
|
||
275 | _3b=this.store.getValues(this.item(),this.grid.layout.cells[this.cell.level+1].parentCell.field); |
||
276 | if(_3b.length>1&&this.grid.sortChildItems){ |
||
277 | var _40=this.grid.getSortProps(); |
||
278 | if(_40&&_40.length){
|
||
279 | var _41=_40[0].attribute,_42=this.grid; |
||
280 | if(_41&&_3b[0][_41]){ |
||
281 | var _43=!!_40[0].descending; |
||
282 | _3b=_3b.slice(0);
|
||
283 | _3b.sort(function(a,b){
|
||
284 | return _42._childItemSorter(a,b,_41,_43);
|
||
285 | }); |
||
286 | } |
||
287 | } |
||
288 | } |
||
289 | } |
||
290 | return _3b;
|
||
291 | },childPaths:function(){ |
||
292 | var _44=this.children(); |
||
293 | if(!_44){
|
||
294 | return [];
|
||
295 | } |
||
296 | return dojo.map(_44,function(_45,_46){ |
||
297 | return new dojox.grid.TreePath(this._str+"/"+_46,this.grid); |
||
298 | },this);
|
||
299 | },parent:function(){ |
||
300 | if(this.level===0){ |
||
301 | return null; |
||
302 | } |
||
303 | return new dojox.grid.TreePath(this._arr.slice(0,this.level),this.grid); |
||
304 | },lastChild:function(_47){ |
||
305 | var _48=this.children(); |
||
306 | if(!_48||!_48.length){
|
||
307 | return this; |
||
308 | } |
||
309 | var _49=new dojox.grid.TreePath(this._str+"/"+String(_48.length-1),this.grid); |
||
310 | if(!_47){
|
||
311 | return _49;
|
||
312 | } |
||
313 | return _49.lastChild(true); |
||
314 | },toString:function(){ |
||
315 | return this._str; |
||
316 | }}); |
||
317 | dojo.declare("dojox.grid._TreeFocusManager",dojox.grid._FocusManager,{setFocusCell:function(_4a,_4b){ |
||
318 | if(_4a&&_4a.getNode(_4b)){
|
||
319 | this.inherited(arguments); |
||
320 | } |
||
321 | },isLastFocusCell:function(){ |
||
322 | if(this.cell&&this.cell.index==this.grid.layout.cellCount-1){ |
||
323 | var _4c=new dojox.grid.TreePath(this.grid.rowCount-1,this.grid); |
||
324 | _4c=_4c.lastChild(true);
|
||
325 | return this.rowIndex==_4c._str; |
||
326 | } |
||
327 | return false; |
||
328 | },next:function(){ |
||
329 | if(this.cell){ |
||
330 | var row=this.rowIndex,col=this.cell.index+1,cc=this.grid.layout.cellCount-1; |
||
331 | var _4d=new dojox.grid.TreePath(this.rowIndex,this.grid); |
||
332 | if(col>cc){
|
||
333 | var _4e=_4d.next();
|
||
334 | if(!_4e){
|
||
335 | col--; |
||
336 | }else{
|
||
337 | col=0;
|
||
338 | _4d=_4e; |
||
339 | } |
||
340 | } |
||
341 | if(this.grid.edit.isEditing()){ |
||
342 | var _4f=this.grid.getCell(col); |
||
343 | if(!this.isLastFocusCell()&&!_4f.editable){ |
||
344 | this._focusifyCellNode(false); |
||
345 | this.cell=_4f;
|
||
346 | this.rowIndex=_4d._str;
|
||
347 | this.next();
|
||
348 | return;
|
||
349 | } |
||
350 | } |
||
351 | this.setFocusIndex(_4d._str,col);
|
||
352 | } |
||
353 | },previous:function(){ |
||
354 | if(this.cell){ |
||
355 | var row=(this.rowIndex||0),col=(this.cell.index||0)-1; |
||
356 | var _50=new dojox.grid.TreePath(row,this.grid); |
||
357 | if(col<0){ |
||
358 | var _51=_50.previous();
|
||
359 | if(!_51){
|
||
360 | col=0;
|
||
361 | }else{
|
||
362 | col=this.grid.layout.cellCount-1; |
||
363 | _50=_51; |
||
364 | } |
||
365 | } |
||
366 | if(this.grid.edit.isEditing()){ |
||
367 | var _52=this.grid.getCell(col); |
||
368 | if(!this.isFirstFocusCell()&&!_52.editable){ |
||
369 | this._focusifyCellNode(false); |
||
370 | this.cell=_52;
|
||
371 | this.rowIndex=_50._str;
|
||
372 | this.previous();
|
||
373 | return;
|
||
374 | } |
||
375 | } |
||
376 | this.setFocusIndex(_50._str,col);
|
||
377 | } |
||
378 | },move:function(_53,_54){ |
||
379 | if(this.isNavHeader()){ |
||
380 | this.inherited(arguments); |
||
381 | return;
|
||
382 | } |
||
383 | if(!this.cell){ |
||
384 | return;
|
||
385 | } |
||
386 | var sc=this.grid.scroller,r=this.rowIndex,rc=this.grid.rowCount-1,_55=new dojox.grid.TreePath(this.rowIndex,this.grid); |
||
387 | if(_53){
|
||
388 | var row;
|
||
389 | if(_53>0){ |
||
390 | _55=_55.next(); |
||
391 | row=_55._arr[0];
|
||
392 | if(row>sc.getLastPageRow(sc.page)){
|
||
393 | this.grid.setScrollTop(this.grid.scrollTop+sc.findScrollTop(row)-sc.findScrollTop(r)); |
||
394 | } |
||
395 | }else{
|
||
396 | if(_53<0){ |
||
397 | _55=_55.previous(); |
||
398 | row=_55._arr[0];
|
||
399 | if(row<=sc.getPageRow(sc.page)){
|
||
400 | this.grid.setScrollTop(this.grid.scrollTop-sc.findScrollTop(r)-sc.findScrollTop(row)); |
||
401 | } |
||
402 | } |
||
403 | } |
||
404 | } |
||
405 | var cc=this.grid.layout.cellCount-1,i=this.cell.index,col=Math.min(cc,Math.max(0,i+_54)); |
||
406 | var _56=this.grid.getCell(col); |
||
407 | var _57=_54<0?-1:1; |
||
408 | while(col>=0&&col<cc&&_56&&_56.hidden===true){ |
||
409 | col+=_57; |
||
410 | _56=this.grid.getCell(col);
|
||
411 | } |
||
412 | if(!_56||_56.hidden===true){ |
||
413 | col=i; |
||
414 | } |
||
415 | if(_53){
|
||
416 | this.grid.updateRow(r);
|
||
417 | } |
||
418 | this.setFocusIndex(_55._str,col);
|
||
419 | }}); |
||
420 | dojo.declare("dojox.grid.TreeGrid",dojox.grid.DataGrid,{defaultOpen:true,sortChildItems:false,openAtLevels:[],treeModel:null,expandoCell:0,aggregator:null,_layoutClass:dojox.grid._TreeLayout,createSelection:function(){ |
||
421 | this.selection=new dojox.grid.TreeSelection(this); |
||
422 | },_childItemSorter:function(a,b,_58,_59){ |
||
423 | var av=this.store.getValue(a,_58); |
||
424 | var bv=this.store.getValue(b,_58); |
||
425 | if(av!=bv){
|
||
426 | return av<bv==_59?1:-1; |
||
427 | } |
||
428 | return 0; |
||
429 | },_onNew:function(_5a,_5b){ |
||
430 | if(!_5b||!_5b.item){
|
||
431 | this.inherited(arguments); |
||
432 | }else{
|
||
433 | var idx=this.getItemIndex(_5b.item); |
||
434 | if(typeof idx=="string"){ |
||
435 | this.updateRow(idx.split("/")[0]); |
||
436 | }else{
|
||
437 | if(idx>-1){ |
||
438 | this.updateRow(idx);
|
||
439 | } |
||
440 | } |
||
441 | } |
||
442 | },_onSet:function(_5c,_5d,_5e,_5f){ |
||
443 | this._checkUpdateStatus();
|
||
444 | if(this.aggregator){ |
||
445 | this.aggregator.clearSubtotalCache();
|
||
446 | } |
||
447 | var idx=this.getItemIndex(_5c); |
||
448 | if(typeof idx=="string"){ |
||
449 | this.updateRow(idx.split("/")[0]); |
||
450 | }else{
|
||
451 | if(idx>-1){ |
||
452 | this.updateRow(idx);
|
||
453 | } |
||
454 | } |
||
455 | },_onDelete:function(_60){ |
||
456 | this._cleanupExpandoCache(this._getItemIndex(_60,true),this.store.getIdentity(_60),_60); |
||
457 | this.inherited(arguments); |
||
458 | },_cleanupExpandoCache:function(_61,_62,_63){ |
||
459 | },_addItem:function(_64,_65,_66,_67){ |
||
460 | if(!_67&&this.model&&dojo.indexOf(this.model.root.children,_64)==-1){ |
||
461 | this.model.root.children[_65]=_64;
|
||
462 | } |
||
463 | this.inherited(arguments); |
||
464 | },getItem:function(idx){ |
||
465 | var _68=dojo.isArray(idx);
|
||
466 | if(dojo.isString(idx)&&idx.indexOf("/")){ |
||
467 | idx=idx.split("/");
|
||
468 | _68=true;
|
||
469 | } |
||
470 | if(_68&&idx.length==1){ |
||
471 | idx=idx[0];
|
||
472 | _68=false;
|
||
473 | } |
||
474 | if(!_68){
|
||
475 | return dojox.grid.DataGrid.prototype.getItem.call(this,idx); |
||
476 | } |
||
477 | var s=this.store; |
||
478 | var itm=dojox.grid.DataGrid.prototype.getItem.call(this,idx[0]); |
||
479 | var cf;
|
||
480 | if(this.aggregator){ |
||
481 | cf=this.aggregator.childFields||[];
|
||
482 | }else{
|
||
483 | if(this.treeModel){ |
||
484 | cf=this.treeModel.childrenAttrs||[];
|
||
485 | } |
||
486 | } |
||
487 | if(cf){
|
||
488 | for(var i=0;i<idx.length-1&&itm;i++){ |
||
489 | if(cf[i]){
|
||
490 | itm=(s.getValues(itm,cf[i])||[])[idx[i+1]];
|
||
491 | }else{
|
||
492 | itm=null;
|
||
493 | } |
||
494 | } |
||
495 | } |
||
496 | return itm||null; |
||
497 | },_getItemIndex:function(_69,_6a){ |
||
498 | if(!_6a&&!this.store.isItem(_69)){ |
||
499 | return -1; |
||
500 | } |
||
501 | var idx=this.inherited(arguments); |
||
502 | if(idx==-1){ |
||
503 | var _6b=this.store.getIdentity(_69); |
||
504 | return this._by_idty_paths[_6b]||-1; |
||
505 | } |
||
506 | return idx;
|
||
507 | },postMixInProperties:function(){ |
||
508 | if(this.treeModel&&!("defaultOpen" in this.params)){ |
||
509 | this.defaultOpen=false; |
||
510 | } |
||
511 | var def=this.defaultOpen; |
||
512 | this.openAtLevels=dojo.map(this.openAtLevels,function(l){ |
||
513 | if(typeof l=="string"){ |
||
514 | switch(l.toLowerCase()){
|
||
515 | case "true": |
||
516 | return true; |
||
517 | break;
|
||
518 | case "false": |
||
519 | return false; |
||
520 | break;
|
||
521 | default:
|
||
522 | var r=parseInt(l,10); |
||
523 | if(isNaN(r)){
|
||
524 | return def;
|
||
525 | } |
||
526 | return r;
|
||
527 | break;
|
||
528 | } |
||
529 | } |
||
530 | return l;
|
||
531 | }); |
||
532 | this._by_idty_paths={};
|
||
533 | this.inherited(arguments); |
||
534 | },postCreate:function(){ |
||
535 | this.inherited(arguments); |
||
536 | if(this.treeModel){ |
||
537 | this._setModel(this.treeModel); |
||
538 | } |
||
539 | },setModel:function(_6c){ |
||
540 | this._setModel(_6c);
|
||
541 | this._refresh(true); |
||
542 | },_setModel:function(_6d){ |
||
543 | if(_6d&&(!dijit.tree.ForestStoreModel||!(_6d instanceof dijit.tree.ForestStoreModel))){ |
||
544 | throw new Error("dojox.grid.TreeGrid: treeModel must be an instance of dijit.tree.ForestStoreModel"); |
||
545 | } |
||
546 | this.treeModel=_6d;
|
||
547 | dojo.toggleClass(this.domNode,"dojoxGridTreeModel",this.treeModel?true:false); |
||
548 | this._setQuery(_6d?_6d.query:null); |
||
549 | this._setStore(_6d?_6d.store:null); |
||
550 | },createScroller:function(){ |
||
551 | this.inherited(arguments); |
||
552 | this.scroller._origDefaultRowHeight=this.scroller.defaultRowHeight; |
||
553 | },createManagers:function(){ |
||
554 | this.rows=new dojox.grid._RowManager(this); |
||
555 | this.focus=new dojox.grid._TreeFocusManager(this); |
||
556 | this.edit=new dojox.grid._EditManager(this); |
||
557 | },_setStore:function(_6e){ |
||
558 | this.inherited(arguments); |
||
559 | if(this.treeModel&&!this.treeModel.root.children){ |
||
560 | this.treeModel.root.children=[];
|
||
561 | } |
||
562 | if(this.aggregator){ |
||
563 | this.aggregator.store=_6e;
|
||
564 | } |
||
565 | },getDefaultOpenState:function(_6f,_70){ |
||
566 | var cf;
|
||
567 | var _71=this.store; |
||
568 | if(this.treeModel){ |
||
569 | return this.defaultOpen; |
||
570 | } |
||
571 | if(!_6f||!_71||!_71.isItem(_70)||!(cf=this.aggregator.childFields[_6f.level])){ |
||
572 | return this.defaultOpen; |
||
573 | } |
||
574 | if(this.openAtLevels.length>_6f.level){ |
||
575 | var _72=this.openAtLevels[_6f.level]; |
||
576 | if(typeof _72=="boolean"){ |
||
577 | return _72;
|
||
578 | }else{
|
||
579 | if(typeof _72=="number"){ |
||
580 | return (_71.getValues(_70,cf).length<=_72);
|
||
581 | } |
||
582 | } |
||
583 | } |
||
584 | return this.defaultOpen; |
||
585 | },onStyleRow:function(row){ |
||
586 | if(!this.layout._isCollapsable){ |
||
587 | this.inherited(arguments); |
||
588 | return;
|
||
589 | } |
||
590 | var _73=dojo.attr(row.node,"dojoxTreeGridBaseClasses"); |
||
591 | if(_73){
|
||
592 | row.customClasses=_73; |
||
593 | } |
||
594 | var i=row;
|
||
595 | var _74=i.node.tagName.toLowerCase();
|
||
596 | i.customClasses+=(i.odd?" dojoxGridRowOdd":"")+(i.selected&&_74=="tr"?" dojoxGridRowSelected":"")+(i.over&&_74=="tr"?" dojoxGridRowOver":""); |
||
597 | this.focus.styleRow(i);
|
||
598 | this.edit.styleRow(i);
|
||
599 | },styleRowNode:function(_75,_76){ |
||
600 | if(_76){
|
||
601 | if(_76.tagName.toLowerCase()=="div"&&this.aggregator){ |
||
602 | dojo.query("tr[dojoxTreeGridPath]",_76).forEach(function(_77){ |
||
603 | this.rows.styleRowNode(dojo.attr(_77,"dojoxTreeGridPath"),_77); |
||
604 | },this);
|
||
605 | } |
||
606 | this.rows.styleRowNode(_75,_76);
|
||
607 | } |
||
608 | },onCanSelect:function(_78){ |
||
609 | var _79=dojo.query("tr[dojoxTreeGridPath='"+_78+"']",this.domNode); |
||
610 | if(_79.length){
|
||
611 | if(dojo.hasClass(_79[0],"dojoxGridSummaryRow")){ |
||
612 | return false; |
||
613 | } |
||
614 | } |
||
615 | return this.inherited(arguments); |
||
616 | },onKeyDown:function(e){ |
||
617 | if(e.altKey||e.metaKey){
|
||
618 | return;
|
||
619 | } |
||
620 | var dk=dojo.keys;
|
||
621 | switch(e.keyCode){
|
||
622 | case dk.UP_ARROW:
|
||
623 | if(!this.edit.isEditing()&&this.focus.rowIndex!="0"){ |
||
624 | dojo.stopEvent(e); |
||
625 | this.focus.move(-1,0); |
||
626 | } |
||
627 | break;
|
||
628 | case dk.DOWN_ARROW:
|
||
629 | var _7a=new dojox.grid.TreePath(this.focus.rowIndex,this); |
||
630 | var _7b=new dojox.grid.TreePath(this.rowCount-1,this); |
||
631 | _7b=_7b.lastChild(true);
|
||
632 | if(!this.edit.isEditing()&&_7a.toString()!=_7b.toString()){ |
||
633 | dojo.stopEvent(e); |
||
634 | this.focus.move(1,0); |
||
635 | } |
||
636 | break;
|
||
637 | default:
|
||
638 | this.inherited(arguments); |
||
639 | break;
|
||
640 | } |
||
641 | },canEdit:function(_7c,_7d){ |
||
642 | var _7e=_7c.getNode(_7d);
|
||
643 | return _7e&&this._canEdit; |
||
644 | },doApplyCellEdit:function(_7f,_80,_81){ |
||
645 | var _82=this.getItem(_80); |
||
646 | var _83=this.store.getValue(_82,_81); |
||
647 | if(typeof _83=="number"){ |
||
648 | _7f=isNaN(_7f)?_7f:parseFloat(_7f); |
||
649 | }else{
|
||
650 | if(typeof _83=="boolean"){ |
||
651 | _7f=_7f=="true"?true:_7f=="false"?false:_7f; |
||
652 | }else{
|
||
653 | if(_83 instanceof Date){ |
||
654 | var _84=new Date(_7f); |
||
655 | _7f=isNaN(_84.getTime())?_7f:_84; |
||
656 | } |
||
657 | } |
||
658 | } |
||
659 | this.store.setValue(_82,_81,_7f);
|
||
660 | this.onApplyCellEdit(_7f,_80,_81);
|
||
661 | }}); |
||
662 | dojox.grid.TreeGrid.markupFactory=function(_85,_86,_87,_88){ |
||
663 | var d=dojo;
|
||
664 | var _89=function(n){ |
||
665 | var w=d.attr(n,"width")||"auto"; |
||
666 | if((w!="auto")&&(w.slice(-2)!="em")&&(w.slice(-1)!="%")){ |
||
667 | w=parseInt(w,10)+"px"; |
||
668 | } |
||
669 | return w;
|
||
670 | }; |
||
671 | var _8a=function(_8b){ |
||
672 | var _8c;
|
||
673 | if(_8b.nodeName.toLowerCase()=="table"&&d.query("> colgroup",_8b).length===0&&(_8c=d.query("> thead > tr",_8b)).length==1){ |
||
674 | var tr=_8c[0]; |
||
675 | return d.query("> th",_8c[0]).map(function(th){ |
||
676 | var _8d={type:d.trim(d.attr(th,"cellType")||""),field:d.trim(d.attr(th,"field")||"")}; |
||
677 | if(_8d.type){
|
||
678 | _8d.type=d.getObject(_8d.type); |
||
679 | } |
||
680 | var _8e=d.query("> table",th)[0]; |
||
681 | if(_8e){
|
||
682 | _8d.name="";
|
||
683 | _8d.children=_8a(_8e); |
||
684 | if(d.hasAttr(th,"itemAggregates")){ |
||
685 | _8d.itemAggregates=d.map(d.attr(th,"itemAggregates").split(","),function(v){ |
||
686 | return d.trim(v);
|
||
687 | }); |
||
688 | }else{
|
||
689 | _8d.itemAggregates=[]; |
||
690 | } |
||
691 | if(d.hasAttr(th,"aggregate")){ |
||
692 | _8d.aggregate=d.attr(th,"aggregate");
|
||
693 | } |
||
694 | _8d.type=_8d.type||dojox.grid.cells.SubtableCell; |
||
695 | }else{
|
||
696 | _8d.name=d.trim(d.attr(th,"name")||th.innerHTML);
|
||
697 | if(d.hasAttr(th,"width")){ |
||
698 | _8d.width=_89(th); |
||
699 | } |
||
700 | if(d.hasAttr(th,"relWidth")){ |
||
701 | _8d.relWidth=window.parseInt(d.attr(th,"relWidth"),10); |
||
702 | } |
||
703 | if(d.hasAttr(th,"hidden")){ |
||
704 | _8d.hidden=d.attr(th,"hidden")=="true"; |
||
705 | } |
||
706 | _8d.field=_8d.field||_8d.name; |
||
707 | dojox.grid.DataGrid.cell_markupFactory(_88,th,_8d); |
||
708 | _8d.type=_8d.type||dojox.grid.cells.Cell; |
||
709 | } |
||
710 | if(_8d.type&&_8d.type.markupFactory){
|
||
711 | _8d.type.markupFactory(th,_8d); |
||
712 | } |
||
713 | return _8d;
|
||
714 | }); |
||
715 | } |
||
716 | return [];
|
||
717 | }; |
||
718 | var _8f;
|
||
719 | if(!_85.structure){
|
||
720 | var row=_8a(_86);
|
||
721 | if(row.length){
|
||
722 | _85.structure=[{__span:Infinity,cells:[row]}]; |
||
723 | } |
||
724 | } |
||
725 | return dojox.grid.DataGrid.markupFactory(_85,_86,_87,_88);
|
||
726 | }; |
||
727 | } |