2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.grid._grid.layout"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.grid._grid.layout"] = true;
|
|
|
3 |
dojo.provide("dojox.grid._grid.layout");
|
|
|
4 |
dojo.require("dojox.grid._grid.cell");
|
|
|
5 |
|
|
|
6 |
dojo.declare("dojox.grid.layout", null, {
|
|
|
7 |
// summary:
|
|
|
8 |
// Controls grid cell layout. Owned by grid and used internally.
|
|
|
9 |
constructor: function(inGrid){
|
|
|
10 |
this.grid = inGrid;
|
|
|
11 |
},
|
|
|
12 |
// flat array of grid cells
|
|
|
13 |
cells: null,
|
|
|
14 |
// structured array of grid cells
|
|
|
15 |
structure: null,
|
|
|
16 |
// default cell width
|
|
|
17 |
defaultWidth: '6em',
|
|
|
18 |
// methods
|
|
|
19 |
setStructure: function(inStructure){
|
|
|
20 |
this.fieldIndex = 0;
|
|
|
21 |
this.cells = [];
|
|
|
22 |
var s = this.structure = [];
|
|
|
23 |
for(var i=0, viewDef, rows; (viewDef=inStructure[i]); i++){
|
|
|
24 |
s.push(this.addViewDef(viewDef));
|
|
|
25 |
}
|
|
|
26 |
this.cellCount = this.cells.length;
|
|
|
27 |
},
|
|
|
28 |
addViewDef: function(inDef){
|
|
|
29 |
this._defaultCellProps = inDef.defaultCell || {};
|
|
|
30 |
return dojo.mixin({}, inDef, {rows: this.addRowsDef(inDef.rows || inDef.cells)});
|
|
|
31 |
},
|
|
|
32 |
addRowsDef: function(inDef){
|
|
|
33 |
var result = [];
|
|
|
34 |
for(var i=0, row; inDef && (row=inDef[i]); i++){
|
|
|
35 |
result.push(this.addRowDef(i, row));
|
|
|
36 |
}
|
|
|
37 |
return result;
|
|
|
38 |
},
|
|
|
39 |
addRowDef: function(inRowIndex, inDef){
|
|
|
40 |
var result = [];
|
|
|
41 |
for(var i=0, def, cell; (def=inDef[i]); i++){
|
|
|
42 |
cell = this.addCellDef(inRowIndex, i, def);
|
|
|
43 |
result.push(cell);
|
|
|
44 |
this.cells.push(cell);
|
|
|
45 |
}
|
|
|
46 |
return result;
|
|
|
47 |
},
|
|
|
48 |
addCellDef: function(inRowIndex, inCellIndex, inDef){
|
|
|
49 |
var w = 0;
|
|
|
50 |
if(inDef.colSpan > 1){
|
|
|
51 |
w = 0;
|
|
|
52 |
}else if(!isNaN(inDef.width)){
|
|
|
53 |
w = inDef.width + "em";
|
|
|
54 |
}else{
|
|
|
55 |
w = inDef.width || this.defaultWidth;
|
|
|
56 |
}
|
|
|
57 |
// fieldIndex progresses linearly from the last indexed field
|
|
|
58 |
// FIXME: support generating fieldIndex based a text field name (probably in Grid)
|
|
|
59 |
var fieldIndex = inDef.field != undefined ? inDef.field : (inDef.get ? -1 : this.fieldIndex);
|
|
|
60 |
if((inDef.field != undefined) || !inDef.get){
|
|
|
61 |
this.fieldIndex = (inDef.field > -1 ? inDef.field : this.fieldIndex) + 1;
|
|
|
62 |
}
|
|
|
63 |
return new dojox.grid.cell(
|
|
|
64 |
dojo.mixin({}, this._defaultCellProps, inDef, {
|
|
|
65 |
grid: this.grid,
|
|
|
66 |
subrow: inRowIndex,
|
|
|
67 |
layoutIndex: inCellIndex,
|
|
|
68 |
index: this.cells.length,
|
|
|
69 |
fieldIndex: fieldIndex,
|
|
|
70 |
unitWidth: w
|
|
|
71 |
}));
|
|
|
72 |
}
|
|
|
73 |
});
|
|
|
74 |
|
|
|
75 |
}
|