Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (4.18 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._Layout"]){
9
dojo._hasResource["dojox.grid._Layout"]=true;
10
dojo.provide("dojox.grid._Layout");
11
dojo.require("dojox.grid.cells");
12
dojo.require("dojox.grid._RowSelector");
13
dojo.declare("dojox.grid._Layout",null,{constructor:function(_1){
14
this.grid=_1;
15
},cells:[],structure:null,defaultWidth:"6em",moveColumn:function(_2,_3,_4,_5,_6){
16
var _7=this.structure[_2].cells[0];
17
var _8=this.structure[_3].cells[0];
18
var _9=null;
19
var _a=0;
20
var _b=0;
21
for(var i=0,c;c=_7[i];i++){
22
if(c.index==_4){
23
_a=i;
24
break;
25
}
26
}
27
_9=_7.splice(_a,1)[0];
28
_9.view=this.grid.views.views[_3];
29
for(i=0,c=null;c=_8[i];i++){
30
if(c.index==_5){
31
_b=i;
32
break;
33
}
34
}
35
if(!_6){
36
_b+=1;
37
}
38
_8.splice(_b,0,_9);
39
var _c=this.grid.getCell(this.grid.getSortIndex());
40
if(_c){
41
_c._currentlySorted=this.grid.getSortAsc();
42
}
43
this.cells=[];
44
_4=0;
45
var v;
46
for(i=0;v=this.structure[i];i++){
47
for(var j=0,cs;cs=v.cells[j];j++){
48
for(var k=0;c=cs[k];k++){
49
c.index=_4;
50
this.cells.push(c);
51
if("_currentlySorted" in c){
52
var si=_4+1;
53
si*=c._currentlySorted?1:-1;
54
this.grid.sortInfo=si;
55
delete c._currentlySorted;
56
}
57
_4++;
58
}
59
}
60
}
61
this.grid.setupHeaderMenu();
62
},setColumnVisibility:function(_d,_e){
63
var _f=this.cells[_d];
64
if(_f.hidden==_e){
65
_f.hidden=!_e;
66
var v=_f.view,w=v.viewWidth;
67
if(w&&w!="auto"){
68
v._togglingColumn=dojo.marginBox(_f.getHeaderNode()).w||0;
69
}
70
v.update();
71
return true;
72
}else{
73
return false;
74
}
75
},addCellDef:function(_10,_11,_12){
76
var _13=this;
77
var _14=function(_15){
78
var w=0;
79
if(_15.colSpan>1){
80
w=0;
81
}else{
82
w=_15.width||_13._defaultCellProps.width||_13.defaultWidth;
83
if(!isNaN(w)){
84
w=w+"em";
85
}
86
}
87
return w;
88
};
89
var _16={grid:this.grid,subrow:_10,layoutIndex:_11,index:this.cells.length};
90
if(_12&&_12 instanceof dojox.grid.cells._Base){
91
var _17=dojo.clone(_12);
92
_16.unitWidth=_14(_17._props);
93
_17=dojo.mixin(_17,this._defaultCellProps,_12._props,_16);
94
return _17;
95
}
96
var _18=_12.type||this._defaultCellProps.type||dojox.grid.cells.Cell;
97
_16.unitWidth=_14(_12);
98
return new _18(dojo.mixin({},this._defaultCellProps,_12,_16));
99
},addRowDef:function(_19,_1a){
100
var _1b=[];
101
var _1c=0,_1d=0,_1e=true;
102
for(var i=0,def,_1f;(def=_1a[i]);i++){
103
_1f=this.addCellDef(_19,i,def);
104
_1b.push(_1f);
105
this.cells.push(_1f);
106
if(_1e&&_1f.relWidth){
107
_1c+=_1f.relWidth;
108
}else{
109
if(_1f.width){
110
var w=_1f.width;
111
if(typeof w=="string"&&w.slice(-1)=="%"){
112
_1d+=window.parseInt(w,10);
113
}else{
114
if(w=="auto"){
115
_1e=false;
116
}
117
}
118
}
119
}
120
}
121
if(_1c&&_1e){
122
dojo.forEach(_1b,function(_20){
123
if(_20.relWidth){
124
_20.width=_20.unitWidth=((_20.relWidth/_1c)*(100-_1d))+"%";
125
}
126
});
127
}
128
return _1b;
129
},addRowsDef:function(_21){
130
var _22=[];
131
if(dojo.isArray(_21)){
132
if(dojo.isArray(_21[0])){
133
for(var i=0,row;_21&&(row=_21[i]);i++){
134
_22.push(this.addRowDef(i,row));
135
}
136
}else{
137
_22.push(this.addRowDef(0,_21));
138
}
139
}
140
return _22;
141
},addViewDef:function(_23){
142
this._defaultCellProps=_23.defaultCell||{};
143
if(_23.width&&_23.width=="auto"){
144
delete _23.width;
145
}
146
return dojo.mixin({},_23,{cells:this.addRowsDef(_23.rows||_23.cells)});
147
},setStructure:function(_24){
148
this.fieldIndex=0;
149
this.cells=[];
150
var s=this.structure=[];
151
if(this.grid.rowSelector){
152
var sel={type:dojox._scopeName+".grid._RowSelector"};
153
if(dojo.isString(this.grid.rowSelector)){
154
var _25=this.grid.rowSelector;
155
if(_25=="false"){
156
sel=null;
157
}else{
158
if(_25!="true"){
159
sel["width"]=_25;
160
}
161
}
162
}else{
163
if(!this.grid.rowSelector){
164
sel=null;
165
}
166
}
167
if(sel){
168
s.push(this.addViewDef(sel));
169
}
170
}
171
var _26=function(def){
172
return ("name" in def||"field" in def||"get" in def);
173
};
174
var _27=function(def){
175
if(dojo.isArray(def)){
176
if(dojo.isArray(def[0])||_26(def[0])){
177
return true;
178
}
179
}
180
return false;
181
};
182
var _28=function(def){
183
return (def!==null&&dojo.isObject(def)&&("cells" in def||"rows" in def||("type" in def&&!_26(def))));
184
};
185
if(dojo.isArray(_24)){
186
var _29=false;
187
for(var i=0,st;(st=_24[i]);i++){
188
if(_28(st)){
189
_29=true;
190
break;
191
}
192
}
193
if(!_29){
194
s.push(this.addViewDef({cells:_24}));
195
}else{
196
for(i=0;(st=_24[i]);i++){
197
if(_27(st)){
198
s.push(this.addViewDef({cells:st}));
199
}else{
200
if(_28(st)){
201
s.push(this.addViewDef(st));
202
}
203
}
204
}
205
}
206
}else{
207
if(_28(_24)){
208
s.push(this.addViewDef(_24));
209
}
210
}
211
this.cellCount=this.cells.length;
212
this.grid.setupHeaderMenu();
213
}});
214
}