root / trunk / web / dojo / dojox / grid / _ViewManager.js @ 13
History | View | Annotate | Download (4.22 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._ViewManager"]){ |
9 |
dojo._hasResource["dojox.grid._ViewManager"]=true; |
10 |
dojo.provide("dojox.grid._ViewManager");
|
11 |
dojo.declare("dojox.grid._ViewManager",null,{constructor:function(_1){ |
12 |
this.grid=_1;
|
13 |
},defaultWidth:200,views:[],resize:function(){ |
14 |
this.onEach("resize"); |
15 |
},render:function(){ |
16 |
this.onEach("render"); |
17 |
},addView:function(_2){ |
18 |
_2.idx=this.views.length;
|
19 |
this.views.push(_2);
|
20 |
},destroyViews:function(){ |
21 |
for(var i=0,v;v=this.views[i];i++){ |
22 |
v.destroy(); |
23 |
} |
24 |
this.views=[];
|
25 |
},getContentNodes:function(){ |
26 |
var _3=[];
|
27 |
for(var i=0,v;v=this.views[i];i++){ |
28 |
_3.push(v.contentNode); |
29 |
} |
30 |
return _3;
|
31 |
},forEach:function(_4){ |
32 |
for(var i=0,v;v=this.views[i];i++){ |
33 |
_4(v,i); |
34 |
} |
35 |
},onEach:function(_5,_6){ |
36 |
_6=_6||[]; |
37 |
for(var i=0,v;v=this.views[i];i++){ |
38 |
if(_5 in v){ |
39 |
v[_5].apply(v,_6); |
40 |
} |
41 |
} |
42 |
},normalizeHeaderNodeHeight:function(){ |
43 |
var _7=[];
|
44 |
for(var i=0,v;(v=this.views[i]);i++){ |
45 |
if(v.headerContentNode.firstChild){
|
46 |
_7.push(v.headerContentNode); |
47 |
} |
48 |
} |
49 |
this.normalizeRowNodeHeights(_7);
|
50 |
},normalizeRowNodeHeights:function(_8){ |
51 |
var h=0; |
52 |
var _9=[];
|
53 |
if(this.grid.rowHeight){ |
54 |
h=this.grid.rowHeight;
|
55 |
}else{
|
56 |
if(_8.length<=1){ |
57 |
return;
|
58 |
} |
59 |
for(var i=0,n;(n=_8[i]);i++){ |
60 |
if(!dojo.hasClass(n,"dojoxGridNonNormalizedCell")){ |
61 |
_9[i]=n.firstChild.offsetHeight; |
62 |
h=Math.max(h,_9[i]); |
63 |
} |
64 |
} |
65 |
h=(h>=0?h:0); |
66 |
if(dojo.isMoz&&h){
|
67 |
h++; |
68 |
} |
69 |
} |
70 |
for(i=0;(n=_8[i]);i++){ |
71 |
if(_9[i]!=h){
|
72 |
n.firstChild.style.height=h+"px";
|
73 |
} |
74 |
} |
75 |
},resetHeaderNodeHeight:function(){ |
76 |
for(var i=0,v,n;(v=this.views[i]);i++){ |
77 |
n=v.headerContentNode.firstChild; |
78 |
if(n){
|
79 |
n.style.height="";
|
80 |
} |
81 |
} |
82 |
},renormalizeRow:function(_a){ |
83 |
var _b=[];
|
84 |
for(var i=0,v,n;(v=this.views[i])&&(n=v.getRowNode(_a));i++){ |
85 |
n.firstChild.style.height="";
|
86 |
_b.push(n); |
87 |
} |
88 |
this.normalizeRowNodeHeights(_b);
|
89 |
},getViewWidth:function(_c){ |
90 |
return this.views[_c].getWidth()||this.defaultWidth; |
91 |
},measureHeader:function(){ |
92 |
this.resetHeaderNodeHeight();
|
93 |
this.forEach(function(_d){ |
94 |
_d.headerContentNode.style.height="";
|
95 |
}); |
96 |
var h=0; |
97 |
this.forEach(function(_e){ |
98 |
h=Math.max(_e.headerNode.offsetHeight,h); |
99 |
}); |
100 |
return h;
|
101 |
},measureContent:function(){ |
102 |
var h=0; |
103 |
this.forEach(function(_f){ |
104 |
h=Math.max(_f.domNode.offsetHeight,h); |
105 |
}); |
106 |
return h;
|
107 |
},findClient:function(_10){ |
108 |
var c=this.grid.elasticView||-1; |
109 |
if(c<0){ |
110 |
for(var i=1,v;(v=this.views[i]);i++){ |
111 |
if(v.viewWidth){
|
112 |
for(i=1;(v=this.views[i]);i++){ |
113 |
if(!v.viewWidth){
|
114 |
c=i; |
115 |
break;
|
116 |
} |
117 |
} |
118 |
break;
|
119 |
} |
120 |
} |
121 |
} |
122 |
if(c<0){ |
123 |
c=Math.floor(this.views.length/2); |
124 |
} |
125 |
return c;
|
126 |
},arrange:function(l,w){ |
127 |
var i,v,vw,len=this.views.length; |
128 |
var c=(w<=0?len:this.findClient()); |
129 |
var _11=function(v,l){ |
130 |
var ds=v.domNode.style;
|
131 |
var hs=v.headerNode.style;
|
132 |
if(!dojo._isBodyLtr()){
|
133 |
ds.right=l+"px";
|
134 |
if(dojo.isMoz){
|
135 |
hs.right=l+v.getScrollbarWidth()+"px";
|
136 |
hs.width=parseInt(hs.width,10)-v.getScrollbarWidth()+"px"; |
137 |
}else{
|
138 |
hs.right=l+"px";
|
139 |
} |
140 |
}else{
|
141 |
ds.left=l+"px";
|
142 |
hs.left=l+"px";
|
143 |
} |
144 |
ds.top=0+"px"; |
145 |
hs.top=0;
|
146 |
}; |
147 |
for(i=0;(v=this.views[i])&&(i<c);i++){ |
148 |
vw=this.getViewWidth(i);
|
149 |
v.setSize(vw,0);
|
150 |
_11(v,l); |
151 |
if(v.headerContentNode&&v.headerContentNode.firstChild){
|
152 |
vw=v.getColumnsWidth()+v.getScrollbarWidth(); |
153 |
}else{
|
154 |
vw=v.domNode.offsetWidth; |
155 |
} |
156 |
l+=vw; |
157 |
} |
158 |
i++; |
159 |
var r=w;
|
160 |
for(var j=len-1;(v=this.views[j])&&(i<=j);j--){ |
161 |
vw=this.getViewWidth(j);
|
162 |
v.setSize(vw,0);
|
163 |
vw=v.domNode.offsetWidth; |
164 |
r-=vw; |
165 |
_11(v,r); |
166 |
} |
167 |
if(c<len){
|
168 |
v=this.views[c];
|
169 |
vw=Math.max(1,r-l);
|
170 |
v.setSize(vw+"px",0); |
171 |
_11(v,l); |
172 |
} |
173 |
return l;
|
174 |
},renderRow:function(_12,_13,_14){ |
175 |
var _15=[];
|
176 |
for(var i=0,v,n,_16;(v=this.views[i])&&(n=_13[i]);i++){ |
177 |
_16=v.renderRow(_12); |
178 |
n.appendChild(_16); |
179 |
_15.push(_16); |
180 |
} |
181 |
if(!_14){
|
182 |
this.normalizeRowNodeHeights(_15);
|
183 |
} |
184 |
},rowRemoved:function(_17){ |
185 |
this.onEach("rowRemoved",[_17]); |
186 |
},updateRow:function(_18,_19){ |
187 |
for(var i=0,v;v=this.views[i];i++){ |
188 |
v.updateRow(_18); |
189 |
} |
190 |
if(!_19){
|
191 |
this.renormalizeRow(_18);
|
192 |
} |
193 |
},updateRowStyles:function(_1a){ |
194 |
this.onEach("updateRowStyles",[_1a]); |
195 |
},setScrollTop:function(_1b){ |
196 |
var top=_1b;
|
197 |
for(var i=0,v;v=this.views[i];i++){ |
198 |
top=v.setScrollTop(_1b); |
199 |
if(dojo.isIE&&v.headerNode&&v.scrollboxNode){
|
200 |
v.headerNode.scrollLeft=v.scrollboxNode.scrollLeft; |
201 |
} |
202 |
} |
203 |
return top;
|
204 |
},getFirstScrollingView:function(){ |
205 |
for(var i=0,v;(v=this.views[i]);i++){ |
206 |
if(v.hasHScrollbar()||v.hasVScrollbar()){
|
207 |
return v;
|
208 |
} |
209 |
} |
210 |
return null; |
211 |
}}); |
212 |
} |