Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / grid / _Builder.js @ 10

History | View | Annotate | Download (14.3 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._Builder"]){
9
dojo._hasResource["dojox.grid._Builder"]=true;
10
dojo.provide("dojox.grid._Builder");
11
dojo.require("dojox.grid.util");
12
dojo.require("dojo.dnd.Moveable");
13
(function(){
14
var dg=dojox.grid;
15
var _1=function(td){
16
return td.cellIndex>=0?td.cellIndex:dojo.indexOf(td.parentNode.cells,td);
17
};
18
var _2=function(tr){
19
return tr.rowIndex>=0?tr.rowIndex:dojo.indexOf(tr.parentNode.childNodes,tr);
20
};
21
var _3=function(_4,_5){
22
return _4&&((_4.rows||0)[_5]||_4.childNodes[_5]);
23
};
24
var _6=function(_7){
25
for(var n=_7;n&&n.tagName!="TABLE";n=n.parentNode){
26
}
27
return n;
28
};
29
var _8=function(_9,_a){
30
for(var n=_9;n&&_a(n);n=n.parentNode){
31
}
32
return n;
33
};
34
var _b=function(_c){
35
var _d=_c.toUpperCase();
36
return function(_e){
37
return _e.tagName!=_d;
38
};
39
};
40
var _f=dojox.grid.util.rowIndexTag;
41
var _10=dojox.grid.util.gridViewTag;
42
dg._Builder=dojo.extend(function(_11){
43
if(_11){
44
this.view=_11;
45
this.grid=_11.grid;
46
}
47
},{view:null,_table:"<table class=\"dojoxGridRowTable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" role=\"presentation\"",getTableArray:function(){
48
var _12=[this._table];
49
if(this.view.viewWidth){
50
_12.push([" style=\"width:",this.view.viewWidth,";\""].join(""));
51
}
52
_12.push(">");
53
return _12;
54
},generateCellMarkup:function(_13,_14,_15,_16){
55
var _17=[],_18;
56
if(_16){
57
var _19=_13.index!=_13.grid.getSortIndex()?"":_13.grid.sortInfo>0?"aria-sort=\"ascending\"":"aria-sort=\"descending\"";
58
if(!_13.id){
59
_13.id=this.grid.id+"Hdr"+_13.index;
60
}
61
_18=["<th tabIndex=\"-1\" aria-readonly=\"true\" role=\"columnheader\"",_19,"id=\"",_13.id,"\""];
62
}else{
63
var _1a=this.grid.editable&&!_13.editable?"aria-readonly=\"true\"":"";
64
_18=["<td tabIndex=\"-1\" role=\"gridcell\"",_1a];
65
}
66
if(_13.colSpan){
67
_18.push(" colspan=\"",_13.colSpan,"\"");
68
}
69
if(_13.rowSpan){
70
_18.push(" rowspan=\"",_13.rowSpan,"\"");
71
}
72
_18.push(" class=\"dojoxGridCell ");
73
if(_13.classes){
74
_18.push(_13.classes," ");
75
}
76
if(_15){
77
_18.push(_15," ");
78
}
79
_17.push(_18.join(""));
80
_17.push("");
81
_18=["\" idx=\"",_13.index,"\" style=\""];
82
if(_14&&_14[_14.length-1]!=";"){
83
_14+=";";
84
}
85
_18.push(_13.styles,_14||"",_13.hidden?"display:none;":"");
86
if(_13.unitWidth){
87
_18.push("width:",_13.unitWidth,";");
88
}
89
_17.push(_18.join(""));
90
_17.push("");
91
_18=["\""];
92
if(_13.attrs){
93
_18.push(" ",_13.attrs);
94
}
95
_18.push(">");
96
_17.push(_18.join(""));
97
_17.push("");
98
_17.push(_16?"</th>":"</td>");
99
return _17;
100
},isCellNode:function(_1b){
101
return Boolean(_1b&&_1b!=dojo.doc&&dojo.attr(_1b,"idx"));
102
},getCellNodeIndex:function(_1c){
103
return _1c?Number(dojo.attr(_1c,"idx")):-1;
104
},getCellNode:function(_1d,_1e){
105
for(var i=0,row;(row=_3(_1d.firstChild,i));i++){
106
for(var j=0,_1f;(_1f=row.cells[j]);j++){
107
if(this.getCellNodeIndex(_1f)==_1e){
108
return _1f;
109
}
110
}
111
}
112
return null;
113
},findCellTarget:function(_20,_21){
114
var n=_20;
115
while(n&&(!this.isCellNode(n)||(n.offsetParent&&_10 in n.offsetParent.parentNode&&n.offsetParent.parentNode[_10]!=this.view.id))&&(n!=_21)){
116
n=n.parentNode;
117
}
118
return n!=_21?n:null;
119
},baseDecorateEvent:function(e){
120
e.dispatch="do"+e.type;
121
e.grid=this.grid;
122
e.sourceView=this.view;
123
e.cellNode=this.findCellTarget(e.target,e.rowNode);
124
e.cellIndex=this.getCellNodeIndex(e.cellNode);
125
e.cell=(e.cellIndex>=0?this.grid.getCell(e.cellIndex):null);
126
},findTarget:function(_22,_23){
127
var n=_22;
128
while(n&&(n!=this.domNode)&&(!(_23 in n)||(_10 in n&&n[_10]!=this.view.id))){
129
n=n.parentNode;
130
}
131
return (n!=this.domNode)?n:null;
132
},findRowTarget:function(_24){
133
return this.findTarget(_24,_f);
134
},isIntraNodeEvent:function(e){
135
try{
136
return (e.cellNode&&e.relatedTarget&&dojo.isDescendant(e.relatedTarget,e.cellNode));
137
}
138
catch(x){
139
return false;
140
}
141
},isIntraRowEvent:function(e){
142
try{
143
var row=e.relatedTarget&&this.findRowTarget(e.relatedTarget);
144
return !row&&(e.rowIndex==-1)||row&&(e.rowIndex==row.gridRowIndex);
145
}
146
catch(x){
147
return false;
148
}
149
},dispatchEvent:function(e){
150
if(e.dispatch in this){
151
return this[e.dispatch](e);
152
}
153
return false;
154
},domouseover:function(e){
155
if(e.cellNode&&(e.cellNode!=this.lastOverCellNode)){
156
this.lastOverCellNode=e.cellNode;
157
this.grid.onMouseOver(e);
158
}
159
this.grid.onMouseOverRow(e);
160
},domouseout:function(e){
161
if(e.cellNode&&(e.cellNode==this.lastOverCellNode)&&!this.isIntraNodeEvent(e,this.lastOverCellNode)){
162
this.lastOverCellNode=null;
163
this.grid.onMouseOut(e);
164
if(!this.isIntraRowEvent(e)){
165
this.grid.onMouseOutRow(e);
166
}
167
}
168
},domousedown:function(e){
169
if(e.cellNode){
170
this.grid.onMouseDown(e);
171
}
172
this.grid.onMouseDownRow(e);
173
}});
174
dg._ContentBuilder=dojo.extend(function(_25){
175
dg._Builder.call(this,_25);
176
},dg._Builder.prototype,{update:function(){
177
this.prepareHtml();
178
},prepareHtml:function(){
179
var _26=this.grid.get,_27=this.view.structure.cells;
180
for(var j=0,row;(row=_27[j]);j++){
181
for(var i=0,_28;(_28=row[i]);i++){
182
_28.get=_28.get||(_28.value==undefined)&&_26;
183
_28.markup=this.generateCellMarkup(_28,_28.cellStyles,_28.cellClasses,false);
184
if(!this.grid.editable&&_28.editable){
185
this.grid.editable=true;
186
}
187
}
188
}
189
},generateHtml:function(_29,_2a){
190
var _2b=this.getTableArray(),v=this.view,_2c=v.structure.cells,_2d=this.grid.getItem(_2a);
191
dojox.grid.util.fire(this.view,"onBeforeRow",[_2a,_2c]);
192
for(var j=0,row;(row=_2c[j]);j++){
193
if(row.hidden||row.header){
194
continue;
195
}
196
_2b.push(!row.invisible?"<tr>":"<tr class=\"dojoxGridInvisible\">");
197
for(var i=0,_2e,m,cc,cs;(_2e=row[i]);i++){
198
m=_2e.markup;
199
cc=_2e.customClasses=[];
200
cs=_2e.customStyles=[];
201
m[5]=_2e.format(_2a,_2d);
202
m[1]=cc.join(" ");
203
m[3]=cs.join(";");
204
_2b.push.apply(_2b,m);
205
}
206
_2b.push("</tr>");
207
}
208
_2b.push("</table>");
209
return _2b.join("");
210
},decorateEvent:function(e){
211
e.rowNode=this.findRowTarget(e.target);
212
if(!e.rowNode){
213
return false;
214
}
215
e.rowIndex=e.rowNode[_f];
216
this.baseDecorateEvent(e);
217
e.cell=this.grid.getCell(e.cellIndex);
218
return true;
219
}});
220
dg._HeaderBuilder=dojo.extend(function(_2f){
221
this.moveable=null;
222
dg._Builder.call(this,_2f);
223
},dg._Builder.prototype,{_skipBogusClicks:false,overResizeWidth:4,minColWidth:1,update:function(){
224
if(this.tableMap){
225
this.tableMap.mapRows(this.view.structure.cells);
226
}else{
227
this.tableMap=new dg._TableMap(this.view.structure.cells);
228
}
229
},generateHtml:function(_30,_31){
230
var _32=this.getTableArray(),_33=this.view.structure.cells;
231
dojox.grid.util.fire(this.view,"onBeforeRow",[-1,_33]);
232
for(var j=0,row;(row=_33[j]);j++){
233
if(row.hidden){
234
continue;
235
}
236
_32.push(!row.invisible?"<tr>":"<tr class=\"dojoxGridInvisible\">");
237
for(var i=0,_34,_35;(_34=row[i]);i++){
238
_34.customClasses=[];
239
_34.customStyles=[];
240
if(this.view.simpleStructure){
241
if(_34.draggable){
242
if(_34.headerClasses){
243
if(_34.headerClasses.indexOf("dojoDndItem")==-1){
244
_34.headerClasses+=" dojoDndItem";
245
}
246
}else{
247
_34.headerClasses="dojoDndItem";
248
}
249
}
250
if(_34.attrs){
251
if(_34.attrs.indexOf("dndType='gridColumn_")==-1){
252
_34.attrs+=" dndType='gridColumn_"+this.grid.id+"'";
253
}
254
}else{
255
_34.attrs="dndType='gridColumn_"+this.grid.id+"'";
256
}
257
}
258
_35=this.generateCellMarkup(_34,_34.headerStyles,_34.headerClasses,true);
259
_35[5]=(_31!=undefined?_31:_30(_34));
260
_35[3]=_34.customStyles.join(";");
261
_35[1]=_34.customClasses.join(" ");
262
_32.push(_35.join(""));
263
}
264
_32.push("</tr>");
265
}
266
_32.push("</table>");
267
return _32.join("");
268
},getCellX:function(e){
269
var n,x=e.layerX;
270
if(dojo.isMoz){
271
n=_8(e.target,_b("th"));
272
x-=(n&&n.offsetLeft)||0;
273
var t=e.sourceView.getScrollbarWidth();
274
if(!dojo._isBodyLtr()){
275
table=_8(n,_b("table"));
276
x-=(table&&table.offsetLeft)||0;
277
}
278
}
279
n=_8(e.target,function(){
280
if(!n||n==e.cellNode){
281
return false;
282
}
283
x+=(n.offsetLeft<0?0:n.offsetLeft);
284
return true;
285
});
286
return x;
287
},decorateEvent:function(e){
288
this.baseDecorateEvent(e);
289
e.rowIndex=-1;
290
e.cellX=this.getCellX(e);
291
return true;
292
},prepareResize:function(e,mod){
293
do{
294
var i=_1(e.cellNode);
295
e.cellNode=(i?e.cellNode.parentNode.cells[i+mod]:null);
296
e.cellIndex=(e.cellNode?this.getCellNodeIndex(e.cellNode):-1);
297
}while(e.cellNode&&e.cellNode.style.display=="none");
298
return Boolean(e.cellNode);
299
},canResize:function(e){
300
if(!e.cellNode||e.cellNode.colSpan>1){
301
return false;
302
}
303
var _36=this.grid.getCell(e.cellIndex);
304
return !_36.noresize&&_36.canResize();
305
},overLeftResizeArea:function(e){
306
if(dojo.hasClass(dojo.body(),"dojoDndMove")){
307
return false;
308
}
309
if(dojo.isIE){
310
var tN=e.target;
311
if(dojo.hasClass(tN,"dojoxGridArrowButtonNode")||dojo.hasClass(tN,"dojoxGridArrowButtonChar")){
312
return false;
313
}
314
}
315
if(dojo._isBodyLtr()){
316
return (e.cellIndex>0)&&(e.cellX<this.overResizeWidth)&&this.prepareResize(e,-1);
317
}
318
var t=e.cellNode&&(e.cellX<this.overResizeWidth);
319
return t;
320
},overRightResizeArea:function(e){
321
if(dojo.hasClass(dojo.body(),"dojoDndMove")){
322
return false;
323
}
324
if(dojo.isIE){
325
var tN=e.target;
326
if(dojo.hasClass(tN,"dojoxGridArrowButtonNode")||dojo.hasClass(tN,"dojoxGridArrowButtonChar")){
327
return false;
328
}
329
}
330
if(dojo._isBodyLtr()){
331
return e.cellNode&&(e.cellX>=e.cellNode.offsetWidth-this.overResizeWidth);
332
}
333
return (e.cellIndex>0)&&(e.cellX>=e.cellNode.offsetWidth-this.overResizeWidth)&&this.prepareResize(e,-1);
334
},domousemove:function(e){
335
if(!this.moveable){
336
var c=(this.overRightResizeArea(e)?"dojoxGridColResize":(this.overLeftResizeArea(e)?"dojoxGridColResize":""));
337
if(c&&!this.canResize(e)){
338
c="dojoxGridColNoResize";
339
}
340
dojo.toggleClass(e.sourceView.headerNode,"dojoxGridColNoResize",(c=="dojoxGridColNoResize"));
341
dojo.toggleClass(e.sourceView.headerNode,"dojoxGridColResize",(c=="dojoxGridColResize"));
342
if(dojo.isIE){
343
var t=e.sourceView.headerNode.scrollLeft;
344
e.sourceView.headerNode.scrollLeft=t;
345
}
346
if(c){
347
dojo.stopEvent(e);
348
}
349
}
350
},domousedown:function(e){
351
if(!this.moveable){
352
if((this.overRightResizeArea(e)||this.overLeftResizeArea(e))&&this.canResize(e)){
353
this.beginColumnResize(e);
354
}else{
355
this.grid.onMouseDown(e);
356
this.grid.onMouseOverRow(e);
357
}
358
}
359
},doclick:function(e){
360
if(this._skipBogusClicks){
361
dojo.stopEvent(e);
362
return true;
363
}
364
return false;
365
},colResizeSetup:function(e,_37){
366
var _38=dojo.contentBox(e.sourceView.headerNode);
367
if(_37){
368
this.lineDiv=document.createElement("div");
369
var vw=(dojo.position||dojo._abs)(e.sourceView.headerNode,true);
370
var _39=dojo.contentBox(e.sourceView.domNode);
371
var l=e.clientX;
372
if(!dojo._isBodyLtr()&&dojo.isIE<8){
373
l-=dojox.html.metrics.getScrollbar().w;
374
}
375
dojo.style(this.lineDiv,{top:vw.y+"px",left:l+"px",height:(_39.h+_38.h)+"px"});
376
dojo.addClass(this.lineDiv,"dojoxGridResizeColLine");
377
this.lineDiv._origLeft=l;
378
dojo.body().appendChild(this.lineDiv);
379
}
380
var _3a=[],_3b=this.tableMap.findOverlappingNodes(e.cellNode);
381
for(var i=0,_3c;(_3c=_3b[i]);i++){
382
_3a.push({node:_3c,index:this.getCellNodeIndex(_3c),width:_3c.offsetWidth});
383
}
384
var _3d=e.sourceView;
385
var adj=dojo._isBodyLtr()?1:-1;
386
var _3e=e.grid.views.views;
387
var _3f=[];
388
for(var j=_3d.idx+adj,_40;(_40=_3e[j]);j=j+adj){
389
_3f.push({node:_40.headerNode,left:window.parseInt(_40.headerNode.style.left)});
390
}
391
var _41=_3d.headerContentNode.firstChild;
392
var _42={scrollLeft:e.sourceView.headerNode.scrollLeft,view:_3d,node:e.cellNode,index:e.cellIndex,w:dojo.contentBox(e.cellNode).w,vw:_38.w,table:_41,tw:dojo.contentBox(_41).w,spanners:_3a,followers:_3f};
393
return _42;
394
},beginColumnResize:function(e){
395
this.moverDiv=document.createElement("div");
396
dojo.style(this.moverDiv,{position:"absolute",left:0});
397
dojo.body().appendChild(this.moverDiv);
398
dojo.addClass(this.grid.domNode,"dojoxGridColumnResizing");
399
var m=(this.moveable=new dojo.dnd.Moveable(this.moverDiv));
400
var _43=this.colResizeSetup(e,true);
401
m.onMove=dojo.hitch(this,"doResizeColumn",_43);
402
dojo.connect(m,"onMoveStop",dojo.hitch(this,function(){
403
this.endResizeColumn(_43);
404
if(_43.node.releaseCapture){
405
_43.node.releaseCapture();
406
}
407
this.moveable.destroy();
408
delete this.moveable;
409
this.moveable=null;
410
dojo.removeClass(this.grid.domNode,"dojoxGridColumnResizing");
411
}));
412
if(e.cellNode.setCapture){
413
e.cellNode.setCapture();
414
}
415
m.onMouseDown(e);
416
},doResizeColumn:function(_44,_45,_46){
417
var _47=_46.l;
418
var _48={deltaX:_47,w:_44.w+(dojo._isBodyLtr()?_47:-_47),vw:_44.vw+_47,tw:_44.tw+_47};
419
this.dragRecord={inDrag:_44,mover:_45,leftTop:_46};
420
if(_48.w>=this.minColWidth){
421
if(!_45){
422
this.doResizeNow(_44,_48);
423
}else{
424
dojo.style(this.lineDiv,"left",(this.lineDiv._origLeft+_48.deltaX)+"px");
425
}
426
}
427
},endResizeColumn:function(_49){
428
if(this.dragRecord){
429
var _4a=this.dragRecord.leftTop;
430
var _4b=dojo._isBodyLtr()?_4a.l:-_4a.l;
431
_4b+=Math.max(_49.w+_4b,this.minColWidth)-(_49.w+_4b);
432
if(dojo.isWebKit&&_49.spanners.length){
433
_4b+=dojo._getPadBorderExtents(_49.spanners[0].node).w;
434
}
435
var _4c={deltaX:_4b,w:_49.w+_4b,vw:_49.vw+_4b,tw:_49.tw+_4b};
436
this.doResizeNow(_49,_4c);
437
}
438
dojo.destroy(this.lineDiv);
439
dojo.destroy(this.moverDiv);
440
dojo.destroy(this.moverDiv);
441
delete this.moverDiv;
442
this._skipBogusClicks=true;
443
_49.view.update();
444
this._skipBogusClicks=false;
445
this.grid.onResizeColumn(_49.index);
446
},doResizeNow:function(_4d,_4e){
447
_4d.view.convertColPctToFixed();
448
if(_4d.view.flexCells&&!_4d.view.testFlexCells()){
449
var t=_6(_4d.node);
450
if(t){
451
(t.style.width="");
452
}
453
}
454
var i,s,sw,f,fl;
455
for(i=0;(s=_4d.spanners[i]);i++){
456
sw=s.width+_4e.deltaX;
457
s.node.style.width=sw+"px";
458
_4d.view.setColWidth(s.index,sw);
459
}
460
if(dojo._isBodyLtr()||!dojo.isIE){
461
for(i=0;(f=_4d.followers[i]);i++){
462
fl=f.left+_4e.deltaX;
463
f.node.style.left=fl+"px";
464
}
465
}
466
_4d.node.style.width=_4e.w+"px";
467
_4d.view.setColWidth(_4d.index,_4e.w);
468
_4d.view.headerNode.style.width=_4e.vw+"px";
469
_4d.view.setColumnsWidth(_4e.tw);
470
if(!dojo._isBodyLtr()){
471
_4d.view.headerNode.scrollLeft=_4d.scrollLeft+_4e.deltaX;
472
}
473
}});
474
dg._TableMap=dojo.extend(function(_4f){
475
this.mapRows(_4f);
476
},{map:null,mapRows:function(_50){
477
var _51=_50.length;
478
if(!_51){
479
return;
480
}
481
this.map=[];
482
var row;
483
for(var k=0;(row=_50[k]);k++){
484
this.map[k]=[];
485
}
486
for(var j=0;(row=_50[j]);j++){
487
for(var i=0,x=0,_52,_53,_54;(_52=row[i]);i++){
488
while(this.map[j][x]){
489
x++;
490
}
491
this.map[j][x]={c:i,r:j};
492
_54=_52.rowSpan||1;
493
_53=_52.colSpan||1;
494
for(var y=0;y<_54;y++){
495
for(var s=0;s<_53;s++){
496
this.map[j+y][x+s]=this.map[j][x];
497
}
498
}
499
x+=_53;
500
}
501
}
502
},dumpMap:function(){
503
for(var j=0,row,h="";(row=this.map[j]);j++,h=""){
504
for(var i=0,_55;(_55=row[i]);i++){
505
h+=_55.r+","+_55.c+"   ";
506
}
507
}
508
},getMapCoords:function(_56,_57){
509
for(var j=0,row;(row=this.map[j]);j++){
510
for(var i=0,_58;(_58=row[i]);i++){
511
if(_58.c==_57&&_58.r==_56){
512
return {j:j,i:i};
513
}
514
}
515
}
516
return {j:-1,i:-1};
517
},getNode:function(_59,_5a,_5b){
518
var row=_59&&_59.rows[_5a];
519
return row&&row.cells[_5b];
520
},_findOverlappingNodes:function(_5c,_5d,_5e){
521
var _5f=[];
522
var m=this.getMapCoords(_5d,_5e);
523
for(var j=0,row;(row=this.map[j]);j++){
524
if(j==m.j){
525
continue;
526
}
527
var rw=row[m.i];
528
var n=(rw?this.getNode(_5c,rw.r,rw.c):null);
529
if(n){
530
_5f.push(n);
531
}
532
}
533
return _5f;
534
},findOverlappingNodes:function(_60){
535
return this._findOverlappingNodes(_6(_60),_2(_60.parentNode),_1(_60));
536
}});
537
})();
538
}