root / trunk / web / dojo / dojox / layout / TableContainer.js @ 11
History | View | Annotate | Download (3.65 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.layout.TableContainer"]){ |
9 |
dojo._hasResource["dojox.layout.TableContainer"]=true; |
10 |
dojo.experimental("dojox.layout.TableContainer");
|
11 |
dojo.provide("dojox.layout.TableContainer");
|
12 |
dojo.require("dijit.layout._LayoutWidget");
|
13 |
dojo.declare("dojox.layout.TableContainer",dijit.layout._LayoutWidget,{cols:1,labelWidth:"100",showLabels:true,orientation:"horiz",spacing:1,customClass:"",postCreate:function(){ |
14 |
this.inherited(arguments); |
15 |
this._children=[];
|
16 |
dojo.connect(this,"attr",dojo.hitch(this,function(_1,_2){ |
17 |
if(_2&&(_1=="orientation"||_1=="customClass"||_1=="cols")){ |
18 |
this.layout();
|
19 |
} |
20 |
})); |
21 |
},startup:function(){ |
22 |
if(this._started){ |
23 |
return;
|
24 |
} |
25 |
this.inherited(arguments); |
26 |
if(this._initialized){ |
27 |
return;
|
28 |
} |
29 |
var _3=this.getChildren(); |
30 |
if(_3.length<1){ |
31 |
return;
|
32 |
} |
33 |
this._initialized=true; |
34 |
dojo.addClass(this.domNode,"dijitTableLayout"); |
35 |
dojo.forEach(_3,function(_4){
|
36 |
if(!_4.started&&!_4._started){
|
37 |
_4.startup(); |
38 |
} |
39 |
}); |
40 |
this.resize();
|
41 |
this.layout();
|
42 |
},resize:function(){ |
43 |
dojo.forEach(this.getChildren(),function(_5){ |
44 |
if(typeof _5.resize=="function"){ |
45 |
_5.resize(); |
46 |
} |
47 |
}); |
48 |
},layout:function(){ |
49 |
if(!this._initialized){ |
50 |
return;
|
51 |
} |
52 |
var _6=this.getChildren(); |
53 |
var _7={};
|
54 |
var _8=this; |
55 |
function _9(_a,_b,_c){ |
56 |
if(_8.customClass!=""){ |
57 |
var _d=_8.customClass+"-"+(_b||_a.tagName.toLowerCase()); |
58 |
dojo.addClass(_a,_d); |
59 |
if(arguments.length>2){ |
60 |
dojo.addClass(_a,_d+"-"+_c);
|
61 |
} |
62 |
} |
63 |
}; |
64 |
dojo.forEach(this._children,dojo.hitch(this,function(_e){ |
65 |
_7[_e.id]=_e; |
66 |
})); |
67 |
dojo.forEach(_6,dojo.hitch(this,function(_f,_10){ |
68 |
if(!_7[_f.id]){
|
69 |
this._children.push(_f);
|
70 |
} |
71 |
})); |
72 |
var _11=dojo.create("table",{"width":"100%","class":"tableContainer-table tableContainer-table-"+this.orientation,"cellspacing":this.spacing},this.domNode); |
73 |
var _12=dojo.create("tbody"); |
74 |
_11.appendChild(_12); |
75 |
_9(_11,"table",this.orientation); |
76 |
var _13=Math.floor(100/this.cols)+"%"; |
77 |
var _14=dojo.create("tr",{},_12); |
78 |
var _15=(!this.showLabels||this.orientation=="horiz")?_14:dojo.create("tr",{},_12); |
79 |
var _16=this.cols*(this.showLabels?2:1); |
80 |
var _17=0; |
81 |
dojo.forEach(this._children,dojo.hitch(this,function(_18,_19){ |
82 |
var _1a=_18.colspan||1; |
83 |
if(_1a>1){ |
84 |
_1a=this.showLabels?Math.min(_16-1,_1a*2-1):Math.min(_16,_1a); |
85 |
} |
86 |
if(_17+_1a-1+(this.showLabels?1:0)>=_16){ |
87 |
_17=0;
|
88 |
_14=dojo.create("tr",{},_12);
|
89 |
_15=this.orientation=="horiz"?_14:dojo.create("tr",{},_12); |
90 |
} |
91 |
var _1b;
|
92 |
if(this.showLabels){ |
93 |
_1b=dojo.create("td",{"class":"tableContainer-labelCell"},_14); |
94 |
if(_18.spanLabel){
|
95 |
dojo.attr(_1b,this.orientation=="vert"?"rowspan":"colspan",2); |
96 |
}else{
|
97 |
_9(_1b,"labelCell");
|
98 |
var _1c={"for":_18.attr("id")}; |
99 |
var _1d=dojo.create("label",_1c,_1b); |
100 |
if(Number(this.labelWidth)>-1||String(this.labelWidth).indexOf("%")>-1){ |
101 |
dojo.style(_1b,"width",String(this.labelWidth).indexOf("%")<0?this.labelWidth+"px":this.labelWidth); |
102 |
} |
103 |
_1d.innerHTML=_18.attr("label")||_18.attr("title"); |
104 |
} |
105 |
} |
106 |
var _1e;
|
107 |
if(_18.spanLabel&&_1b){
|
108 |
_1e=_1b; |
109 |
}else{
|
110 |
_1e=dojo.create("td",{"class":"tableContainer-valueCell"},_15); |
111 |
} |
112 |
if(_1a>1){ |
113 |
dojo.attr(_1e,"colspan",_1a);
|
114 |
} |
115 |
_9(_1e,"valueCell",_19);
|
116 |
_1e.appendChild(_18.domNode); |
117 |
_17+=_1a+(this.showLabels?1:0); |
118 |
})); |
119 |
if(this.table){ |
120 |
this.table.parentNode.removeChild(this.table); |
121 |
} |
122 |
dojo.forEach(_6,function(_1f){
|
123 |
if(typeof _1f.layout=="function"){ |
124 |
_1f.layout(); |
125 |
} |
126 |
}); |
127 |
this.table=_11;
|
128 |
this.resize();
|
129 |
},destroyDescendants:function(_20){ |
130 |
dojo.forEach(this._children,function(_21){ |
131 |
_21.destroyRecursive(_20); |
132 |
}); |
133 |
},_setSpacingAttr:function(_22){ |
134 |
this.spacing=_22;
|
135 |
if(this.table){ |
136 |
this.table.cellspacing=Number(_22);
|
137 |
} |
138 |
}}); |
139 |
dojo.extend(dijit._Widget,{label:"",title:"",spanLabel:false,colspan:1}); |
140 |
} |