Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / grid / _TreeView.js @ 9

History | View | Annotate | Download (10.8 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.grid._TreeView"]){
9
dojo._hasResource["dojox.grid._TreeView"]=true;
10
dojo.provide("dojox.grid._TreeView");
11
dojo.require("dijit._Widget");
12
dojo.require("dijit._Templated");
13
dojo.require("dojox.grid._View");
14
dojo.declare("dojox.grid._Expando",[dijit._Widget,dijit._Templated],{open:false,toggleClass:"",itemId:"",cellIdx:-1,view:null,rowNode:null,rowIdx:-1,expandoCell:null,level:0,templateString:"<div class=\"dojoxGridExpando\"\n\t><div class=\"dojoxGridExpandoNode\" dojoAttachEvent=\"onclick:onToggle\"\n\t\t><div class=\"dojoxGridExpandoNodeInner\" dojoAttachPoint=\"expandoInner\"></div\n\t></div\n></div>\n",_toggleRows:function(_1,_2){
15
if(!_1||!this.rowNode){
16
return;
17
}
18
if(dojo.query("table.dojoxGridRowTableNeedsRowUpdate").length){
19
if(this._initialized){
20
this.view.grid.updateRow(this.rowIdx);
21
}
22
return;
23
}
24
var _3=this;
25
var g=this.view.grid;
26
if(g.treeModel){
27
var p=this._tableRow?dojo.attr(this._tableRow,"dojoxTreeGridPath"):"";
28
if(p){
29
dojo.query("tr[dojoxTreeGridPath^=\""+p+"/\"]",this.rowNode).forEach(function(n){
30
var en=dojo.query(".dojoxGridExpando",n)[0];
31
if(en&&en.parentNode&&en.parentNode.parentNode&&!dojo.hasClass(en.parentNode.parentNode,"dojoxGridNoChildren")){
32
var ew=dijit.byNode(en);
33
if(ew){
34
ew._toggleRows(_1,ew.open&&_2);
35
}
36
}
37
n.style.display=_2?"":"none";
38
});
39
}
40
}else{
41
dojo.query("tr."+_1,this.rowNode).forEach(function(n){
42
if(dojo.hasClass(n,"dojoxGridExpandoRow")){
43
var en=dojo.query(".dojoxGridExpando",n)[0];
44
if(en){
45
var ew=dijit.byNode(en);
46
var _4=ew?ew.toggleClass:en.getAttribute("toggleClass");
47
var _5=ew?ew.open:_3.expandoCell.getOpenState(en.getAttribute("itemId"));
48
_3._toggleRows(_4,_5&&_2);
49
}
50
}
51
n.style.display=_2?"":"none";
52
});
53
}
54
},setOpen:function(_6){
55
if(_6&&dojo.hasClass(this.domNode,"dojoxGridExpandoLoading")){
56
_6=false;
57
}
58
var _7=this.view;
59
var _8=_7.grid;
60
var _9=_8.store;
61
var _a=_8.treeModel;
62
var d=this;
63
var _b=this.rowIdx;
64
var me=_8._by_idx[_b];
65
if(!me){
66
return;
67
}
68
if(_a&&!this._loadedChildren){
69
if(_6){
70
var _c=_8.getItem(dojo.attr(this._tableRow,"dojoxTreeGridPath"));
71
if(_c){
72
this.expandoInner.innerHTML="o";
73
dojo.addClass(this.domNode,"dojoxGridExpandoLoading");
74
_a.getChildren(_c,function(_d){
75
d._loadedChildren=true;
76
d._setOpen(_6);
77
});
78
}else{
79
this._setOpen(_6);
80
}
81
}else{
82
this._setOpen(_6);
83
}
84
}else{
85
if(!_a&&_9){
86
if(_6){
87
var _e=_8._by_idx[this.rowIdx];
88
if(_e&&!_9.isItemLoaded(_e.item)){
89
this.expandoInner.innerHTML="o";
90
dojo.addClass(this.domNode,"dojoxGridExpandoLoading");
91
_9.loadItem({item:_e.item,onItem:dojo.hitch(this,function(i){
92
var _f=_9.getIdentity(i);
93
_8._by_idty[_f]=_8._by_idx[this.rowIdx]={idty:_f,item:i};
94
this._setOpen(_6);
95
})});
96
}else{
97
this._setOpen(_6);
98
}
99
}else{
100
this._setOpen(_6);
101
}
102
}else{
103
this._setOpen(_6);
104
}
105
}
106
},_setOpen:function(_10){
107
if(_10&&this._tableRow&&dojo.hasClass(this._tableRow,"dojoxGridNoChildren")){
108
this._setOpen(false);
109
return;
110
}
111
this.expandoInner.innerHTML=_10?"-":"+";
112
dojo.removeClass(this.domNode,"dojoxGridExpandoLoading");
113
dojo.toggleClass(this.domNode,"dojoxGridExpandoOpened",_10);
114
if(this._tableRow){
115
dojo.toggleClass(this._tableRow,"dojoxGridRowCollapsed",!_10);
116
var _11=dojo.attr(this._tableRow,"dojoxTreeGridBaseClasses");
117
var _12="";
118
if(_10){
119
_12=dojo.trim((" "+_11+" ").replace(" dojoxGridRowCollapsed "," "));
120
}else{
121
if((" "+_11+" ").indexOf(" dojoxGridRowCollapsed ")<0){
122
_12=_11+(_11?" ":"")+"dojoxGridRowCollapsed";
123
}else{
124
_12=_11;
125
}
126
}
127
dojo.attr(this._tableRow,"dojoxTreeGridBaseClasses",_12);
128
}
129
var _13=(this.open!==_10);
130
this.open=_10;
131
if(this.expandoCell&&this.itemId){
132
this.expandoCell.openStates[this.itemId]=_10;
133
}
134
var v=this.view;
135
var g=v.grid;
136
if(this.toggleClass&&_13){
137
if(!this._tableRow||!this._tableRow.style.display){
138
this._toggleRows(this.toggleClass,_10);
139
}
140
}
141
if(v&&this._initialized&&this.rowIdx>=0){
142
g.rowHeightChanged(this.rowIdx);
143
g.postresize();
144
v.hasVScrollbar(true);
145
}
146
this._initialized=true;
147
},onToggle:function(e){
148
this.setOpen(!this.open);
149
dojo.stopEvent(e);
150
},setRowNode:function(_14,_15,_16){
151
if(this.cellIdx<0||!this.itemId){
152
return false;
153
}
154
this._initialized=false;
155
this.view=_16;
156
this.rowNode=_15;
157
this.rowIdx=_14;
158
this.expandoCell=_16.structure.cells[0][this.cellIdx];
159
var d=this.domNode;
160
if(d&&d.parentNode&&d.parentNode.parentNode){
161
this._tableRow=d.parentNode.parentNode;
162
}
163
this.open=this.expandoCell.getOpenState(this.itemId);
164
if(_16.grid.treeModel){
165
dojo.style(this.domNode,"marginLeft",(this.level*18)+"px");
166
if(this.domNode.parentNode){
167
dojo.style(this.domNode.parentNode,"backgroundPosition",((this.level*18)+(3))+"px");
168
}
169
}
170
this.setOpen(this.open);
171
return true;
172
}});
173
dojo.declare("dojox.grid._TreeContentBuilder",dojox.grid._ContentBuilder,{generateHtml:function(_17,_18){
174
var _19=this.getTableArray(),v=this.view,row=v.structure.cells[0],_1a=this.grid.getItem(_18),_1b=this.grid,_1c=this.grid.store;
175
dojox.grid.util.fire(this.view,"onBeforeRow",[_18,[row]]);
176
var _1d=function(_1e,_1f,_20,_21,_22,_23){
177
if(!_23){
178
if(_19[0].indexOf("dojoxGridRowTableNeedsRowUpdate")==-1){
179
_19[0]=_19[0].replace("dojoxGridRowTable","dojoxGridRowTable dojoxGridRowTableNeedsRowUpdate");
180
}
181
return;
182
}
183
var _24=_19.length;
184
_21=_21||[];
185
var _25=_21.join("|");
186
var _26=_21[_21.length-1];
187
var _27=_26+(_20?" dojoxGridSummaryRow":"");
188
var _28="";
189
if(_1b.treeModel&&_1f&&!_1b.treeModel.mayHaveChildren(_1f)){
190
_27+=" dojoxGridNoChildren";
191
}
192
_19.push("<tr style=\""+_28+"\" class=\""+_27+"\" dojoxTreeGridPath=\""+_22.join("/")+"\" dojoxTreeGridBaseClasses=\""+_27+"\">");
193
var _29=_1e+1;
194
var _2a=null;
195
for(var i=0,_2b;(_2b=row[i]);i++){
196
var m=_2b.markup,cc=_2b.customClasses=[],cs=_2b.customStyles=[];
197
m[5]=_2b.formatAtLevel(_22,_1f,_1e,_20,_26,cc);
198
m[1]=cc.join(" ");
199
m[3]=cs.join(";");
200
_19.push.apply(_19,m);
201
if(!_2a&&_2b.level===_29&&_2b.parentCell){
202
_2a=_2b.parentCell;
203
}
204
}
205
_19.push("</tr>");
206
if(_1f&&_1c&&_1c.isItem(_1f)){
207
var _2c=_1c.getIdentity(_1f);
208
if(typeof _1b._by_idty_paths[_2c]=="undefined"){
209
_1b._by_idty_paths[_2c]=_22.join("/");
210
}
211
}
212
var _2d;
213
var _2e;
214
var _2f;
215
var _30;
216
var _31=_22.concat([]);
217
if(_1b.treeModel&&_1f){
218
if(_1b.treeModel.mayHaveChildren(_1f)){
219
_2d=v.structure.cells[0][_1b.expandoCell||0];
220
_2e=_2d.getOpenState(_1f)&&_23;
221
_2f=new dojox.grid.TreePath(_22.join("/"),_1b);
222
_30=_2f.children(true)||[];
223
dojo.forEach(_30,function(_32,idx){
224
var _33=_25.split("|");
225
_33.push(_33[_33.length-1]+"-"+idx);
226
_31.push(idx);
227
_1d(_29,_32,false,_33,_31,_2e);
228
_31.pop();
229
});
230
}
231
}else{
232
if(_1f&&_2a&&!_20){
233
_2d=v.structure.cells[0][_2a.level];
234
_2e=_2d.getOpenState(_1f)&&_23;
235
if(_1c.hasAttribute(_1f,_2a.field)){
236
var _34=_25.split("|");
237
_34.pop();
238
_2f=new dojox.grid.TreePath(_22.join("/"),_1b);
239
_30=_2f.children(true)||[];
240
if(_30.length){
241
_19[_24]="<tr class=\""+_34.join(" ")+" dojoxGridExpandoRow\" dojoxTreeGridPath=\""+_22.join("/")+"\">";
242
dojo.forEach(_30,function(_35,idx){
243
var _36=_25.split("|");
244
_36.push(_36[_36.length-1]+"-"+idx);
245
_31.push(idx);
246
_1d(_29,_35,false,_36,_31,_2e);
247
_31.pop();
248
});
249
_31.push(_30.length);
250
_1d(_1e,_1f,true,_21,_31,_2e);
251
}else{
252
_19[_24]="<tr class=\""+_26+" dojoxGridNoChildren\" dojoxTreeGridPath=\""+_22.join("/")+"\">";
253
}
254
}else{
255
if(!_1c.isItemLoaded(_1f)){
256
_19[0]=_19[0].replace("dojoxGridRowTable","dojoxGridRowTable dojoxGridRowTableNeedsRowUpdate");
257
}else{
258
_19[_24]="<tr class=\""+_26+" dojoxGridNoChildren\" dojoxTreeGridPath=\""+_22.join("/")+"\">";
259
}
260
}
261
}else{
262
if(_1f&&!_20&&_21.length>1){
263
_19[_24]="<tr class=\""+_21[_21.length-2]+"\" dojoxTreeGridPath=\""+_22.join("/")+"\">";
264
}
265
}
266
}
267
};
268
_1d(0,_1a,false,["dojoxGridRowToggle-"+_18],[_18],true);
269
_19.push("</table>");
270
return _19.join("");
271
},findTarget:function(_37,_38){
272
var n=_37;
273
while(n&&(n!=this.domNode)){
274
if(n.tagName&&n.tagName.toLowerCase()=="tr"){
275
break;
276
}
277
n=n.parentNode;
278
}
279
return (n!=this.domNode)?n:null;
280
},getCellNode:function(_39,_3a){
281
var _3b=dojo.query("td[idx='"+_3a+"']",_39)[0];
282
if(_3b&&_3b.parentNode&&!dojo.hasClass(_3b.parentNode,"dojoxGridSummaryRow")){
283
return _3b;
284
}
285
},decorateEvent:function(e){
286
e.rowNode=this.findRowTarget(e.target);
287
if(!e.rowNode){
288
return false;
289
}
290
e.rowIndex=dojo.attr(e.rowNode,"dojoxTreeGridPath");
291
this.baseDecorateEvent(e);
292
e.cell=this.grid.getCell(e.cellIndex);
293
return true;
294
}});
295
dojo.declare("dojox.grid._TreeView",[dojox.grid._View],{_contentBuilderClass:dojox.grid._TreeContentBuilder,_onDndDrop:function(_3c,_3d,_3e){
296
if(this.grid&&this.grid.aggregator){
297
this.grid.aggregator.clearSubtotalCache();
298
}
299
this.inherited(arguments);
300
},postCreate:function(){
301
this.inherited(arguments);
302
this.connect(this.grid,"_cleanupExpandoCache","_cleanupExpandoCache");
303
},_cleanupExpandoCache:function(_3f,_40,_41){
304
if(_3f==-1){
305
return;
306
}
307
dojo.forEach(this.grid.layout.cells,function(_42){
308
if(typeof _42["openStates"]!="undefined"){
309
if(_40 in _42.openStates){
310
delete _42.openStates[_40];
311
}
312
}
313
});
314
if(typeof _3f=="string"&&_3f.indexOf("/")>-1){
315
var _43=new dojox.grid.TreePath(_3f,this.grid);
316
var _44=_43.parent();
317
while(_44){
318
_43=_44;
319
_44=_43.parent();
320
}
321
var _45=_43.item();
322
if(!_45){
323
return;
324
}
325
var _46=this.grid.store.getIdentity(_45);
326
if(typeof this._expandos[_46]!="undefined"){
327
for(var i in this._expandos[_46]){
328
var exp=this._expandos[_46][i];
329
if(exp){
330
exp.destroy();
331
}
332
delete this._expandos[_46][i];
333
}
334
delete this._expandos[_46];
335
}
336
}else{
337
for(var i in this._expandos){
338
if(typeof this._expandos[i]!="undefined"){
339
for(var j in this._expandos[i]){
340
var exp=this._expandos[i][j];
341
if(exp){
342
exp.destroy();
343
}
344
}
345
}
346
}
347
this._expandos={};
348
}
349
},postMixInProperties:function(){
350
this.inherited(arguments);
351
this._expandos={};
352
},onBeforeRow:function(_47,_48){
353
var g=this.grid;
354
if(g._by_idx&&g._by_idx[_47]&&g._by_idx[_47].idty){
355
var _49=g._by_idx[_47].idty;
356
this._expandos[_49]=this._expandos[_49]||{};
357
}
358
this.inherited(arguments);
359
},onAfterRow:function(_4a,_4b,_4c){
360
dojo.forEach(dojo.query("span.dojoxGridExpando",_4c),function(n){
361
if(n&&n.parentNode){
362
var tc=n.getAttribute("toggleClass");
363
var _4d;
364
var _4e;
365
var g=this.grid;
366
if(g._by_idx&&g._by_idx[_4a]&&g._by_idx[_4a].idty){
367
_4d=g._by_idx[_4a].idty;
368
_4e=this._expandos[_4d][tc];
369
}
370
if(_4e){
371
dojo.place(_4e.domNode,n,"replace");
372
_4e.itemId=n.getAttribute("itemId");
373
_4e.cellIdx=parseInt(n.getAttribute("cellIdx"),10);
374
if(isNaN(_4e.cellIdx)){
375
_4e.cellIdx=-1;
376
}
377
}else{
378
_4e=dojo.parser.parse(n.parentNode)[0];
379
if(_4d){
380
this._expandos[_4d][tc]=_4e;
381
}
382
}
383
if(!_4e.setRowNode(_4a,_4c,this)){
384
_4e.domNode.parentNode.removeChild(_4e.domNode);
385
}
386
}
387
},this);
388
var alt=false;
389
var _4f=this;
390
dojo.query("tr[dojoxTreeGridPath]",_4c).forEach(function(n){
391
dojo.toggleClass(n,"dojoxGridSubRowAlt",alt);
392
dojo.attr(n,"dojoxTreeGridBaseClasses",n.className);
393
alt=!alt;
394
_4f.grid.rows.styleRowNode(dojo.attr(n,"dojoxTreeGridPath"),n);
395
});
396
this.inherited(arguments);
397
},updateRowStyles:function(_50){
398
var _51=dojo.query("tr[dojoxTreeGridPath='"+_50+"']",this.domNode);
399
if(_51.length){
400
this.styleRowNode(_50,_51[0]);
401
}
402
},getCellNode:function(_52,_53){
403
var row=dojo.query("tr[dojoxTreeGridPath='"+_52+"']",this.domNode)[0];
404
if(row){
405
return this.content.getCellNode(row,_53);
406
}
407
}});
408
}