Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.grid._grid.views"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.grid._grid.views"] = true;
3
dojo.provide("dojox.grid._grid.views");
4
 
5
dojo.declare('dojox.grid.views', null, {
6
	// summary:
7
	//	A collection of grid views. Owned by grid and used internally for managing grid views.
8
	//	Grid creates views automatically based on grid's layout structure.
9
	//	Users should typically not need to access individual views or the views collection directly.
10
	constructor: function(inGrid){
11
		this.grid = inGrid;
12
	},
13
	defaultWidth: 200,
14
	views: [],
15
	// operations
16
	resize: function(){
17
		this.onEach("resize");
18
	},
19
	render: function(){
20
		this.onEach("render");
21
		this.normalizeHeaderNodeHeight();
22
	},
23
	// views
24
	addView: function(inView){
25
		inView.idx = this.views.length;
26
		this.views.push(inView);
27
	},
28
	destroyViews: function(){
29
		for (var i=0, v; v=this.views[i]; i++)
30
			v.destroy();
31
		this.views = [];
32
	},
33
	getContentNodes: function(){
34
		var nodes = [];
35
		for(var i=0, v; v=this.views[i]; i++){
36
			nodes.push(v.contentNode);
37
		}
38
		return nodes;
39
	},
40
	forEach: function(inCallback){
41
		for(var i=0, v; v=this.views[i]; i++){
42
			inCallback(v, i);
43
		}
44
	},
45
	onEach: function(inMethod, inArgs){
46
		inArgs = inArgs || [];
47
		for(var i=0, v; v=this.views[i]; i++){
48
			if(inMethod in v){
49
				v[inMethod].apply(v, inArgs);
50
			}
51
		}
52
	},
53
	// layout
54
	normalizeHeaderNodeHeight: function(){
55
		var rowNodes = [];
56
		for(var i=0, v; (v=this.views[i]); i++){
57
			if(v.headerContentNode.firstChild){
58
				rowNodes.push(v.headerContentNode)
59
			};
60
		}
61
		this.normalizeRowNodeHeights(rowNodes);
62
	},
63
	normalizeRowNodeHeights: function(inRowNodes){
64
		var h = 0;
65
		for(var i=0, n, o; (n=inRowNodes[i]); i++){
66
			h = Math.max(h, (n.firstChild.clientHeight)||(n.firstChild.offsetHeight));
67
		}
68
		h = (h >= 0 ? h : 0);
69
		//
70
		var hpx = h + 'px';
71
		for(var i=0, n; (n=inRowNodes[i]); i++){
72
			if(n.firstChild.clientHeight!=h){
73
				n.firstChild.style.height = hpx;
74
			}
75
		}
76
		//
77
		//console.log('normalizeRowNodeHeights ', h);
78
		//
79
		// querying the height here seems to help scroller measure the page on IE
80
		if(inRowNodes&&inRowNodes[0]){
81
			inRowNodes[0].parentNode.offsetHeight;
82
		}
83
	},
84
	renormalizeRow: function(inRowIndex){
85
		var rowNodes = [];
86
		for(var i=0, v, n; (v=this.views[i])&&(n=v.getRowNode(inRowIndex)); i++){
87
			n.firstChild.style.height = '';
88
			rowNodes.push(n);
89
		}
90
		this.normalizeRowNodeHeights(rowNodes);
91
	},
92
	getViewWidth: function(inIndex){
93
		return this.views[inIndex].getWidth() || this.defaultWidth;
94
	},
95
	measureHeader: function(){
96
		this.forEach(function(inView){
97
			inView.headerContentNode.style.height = '';
98
		});
99
		var h = 0;
100
		this.forEach(function(inView){
101
			//console.log('headerContentNode', inView.headerContentNode.offsetHeight, inView.headerContentNode.offsetWidth);
102
			h = Math.max(inView.headerNode.offsetHeight, h);
103
		});
104
		return h;
105
	},
106
	measureContent: function(){
107
		var h = 0;
108
		this.forEach(function(inView) {
109
			h = Math.max(inView.domNode.offsetHeight, h);
110
		});
111
		return h;
112
	},
113
	findClient: function(inAutoWidth){
114
		// try to use user defined client
115
		var c = this.grid.elasticView || -1;
116
		// attempt to find implicit client
117
		if(c < 0){
118
			for(var i=1, v; (v=this.views[i]); i++){
119
				if(v.viewWidth){
120
					for(i=1; (v=this.views[i]); i++){
121
						if(!v.viewWidth){
122
							c = i;
123
							break;
124
						}
125
					}
126
					break;
127
				}
128
			}
129
		}
130
		// client is in the middle by default
131
		if(c < 0){
132
			c = Math.floor(this.views.length / 2);
133
		}
134
		return c;
135
	},
136
	_arrange: function(l, t, w, h){
137
		var i, v, vw, len = this.views.length;
138
		// find the client
139
		var c = (w <= 0 ? len : this.findClient());
140
		// layout views
141
		var setPosition = function(v, l, t){
142
			with(v.domNode.style){
143
				left = l + 'px';
144
				top = t + 'px';
145
			}
146
			with(v.headerNode.style){
147
				left = l + 'px';
148
				top = 0;
149
			}
150
		}
151
		// for views left of the client
152
		for(i=0; (v=this.views[i])&&(i<c); i++){
153
			// get width
154
			vw = this.getViewWidth(i);
155
			// process boxes
156
			v.setSize(vw, h);
157
			setPosition(v, l, t);
158
			vw = v.domNode.offsetWidth;
159
			// update position
160
			l += vw;
161
		}
162
		// next view (is the client, i++ == c)
163
		i++;
164
		// start from the right edge
165
		var r = w;
166
		// for views right of the client (iterated from the right)
167
		for(var j=len-1; (v=this.views[j])&&(i<=j); j--){
168
			// get width
169
			vw = this.getViewWidth(j);
170
			// set size
171
			v.setSize(vw, h);
172
			// measure in pixels
173
			vw = v.domNode.offsetWidth;
174
			// update position
175
			r -= vw;
176
			// set position
177
			setPosition(v, r, t);
178
		}
179
		if(c<len){
180
			v = this.views[c];
181
			// position the client box between left and right boxes
182
			vw = Math.max(1, r-l);
183
			// set size
184
			v.setSize(vw + 'px', h);
185
			setPosition(v, l, t);
186
		}
187
		return l;
188
	},
189
	arrange: function(l, t, w, h){
190
		var w = this._arrange(l, t, w, h);
191
		this.resize();
192
		return w;
193
	},
194
	// rendering
195
	renderRow: function(inRowIndex, inNodes){
196
		var rowNodes = [];
197
		for(var i=0, v, n, rowNode; (v=this.views[i])&&(n=inNodes[i]); i++){
198
			rowNode = v.renderRow(inRowIndex);
199
			n.appendChild(rowNode);
200
			rowNodes.push(rowNode);
201
		}
202
		this.normalizeRowNodeHeights(rowNodes);
203
	},
204
	rowRemoved: function(inRowIndex){
205
		this.onEach("rowRemoved", [ inRowIndex ]);
206
	},
207
	// updating
208
	updateRow: function(inRowIndex, inHeight){
209
		for(var i=0, v; v=this.views[i]; i++){
210
			v.updateRow(inRowIndex, inHeight);
211
		}
212
		this.renormalizeRow(inRowIndex);
213
	},
214
	updateRowStyles: function(inRowIndex){
215
		this.onEach("updateRowStyles", [ inRowIndex ]);
216
	},
217
	// scrolling
218
	setScrollTop: function(inTop){
219
		var top = inTop;
220
		for(var i=0, v; v=this.views[i]; i++){
221
			top = v.setScrollTop(inTop);
222
		}
223
		return top;
224
		//this.onEach("setScrollTop", [ inTop ]);
225
	},
226
	getFirstScrollingView: function(){
227
		for(var i=0, v; (v=this.views[i]); i++){
228
			if(v.hasScrollbar()){
229
				return v;
230
			}
231
		}
232
	}
233
});
234
 
235
}