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.view"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.grid._grid.view"] = true;
3
dojo.provide("dojox.grid._grid.view");
4
dojo.require("dijit._Widget");
5
dojo.require("dijit._Templated");
6
dojo.require("dojox.grid._grid.builder");
7
 
8
dojo.declare('dojox.GridView', [dijit._Widget, dijit._Templated], {
9
	// summary:
10
	//	A collection of grid columns. A grid is comprised of a set of views that stack horizontally.
11
	//	Grid creates views automatically based on grid's layout structure.
12
	//	Users should typically not need to access individual views directly.
13
	defaultWidth: "18em",
14
	// viewWidth: string
15
	// width for the view, in valid css unit
16
	viewWidth: "",
17
	templateString: '<div class="dojoxGrid-view"><div class="dojoxGrid-header" dojoAttachPoint="headerNode"><div style="width: 9000em"><div dojoAttachPoint="headerContentNode"></div></div></div><input type="checkbox" class="dojoxGrid-hidden-focus" dojoAttachPoint="hiddenFocusNode" /><input type="checkbox" class="dojoxGrid-hidden-focus" /><div class="dojoxGrid-scrollbox" dojoAttachPoint="scrollboxNode"><div class="dojoxGrid-content" dojoAttachPoint="contentNode" hidefocus="hidefocus"></div></div></div>',
18
	themeable: false,
19
	classTag: 'dojoxGrid',
20
	marginBottom: 0,
21
	rowPad: 2,
22
	postMixInProperties: function(){
23
		this.rowNodes = [];
24
	},
25
	postCreate: function(){
26
		dojo.connect(this.scrollboxNode, "onscroll", dojo.hitch(this, "doscroll"));
27
		dojox.grid.funnelEvents(this.contentNode, this, "doContentEvent", [ 'mouseover', 'mouseout', 'click', 'dblclick', 'contextmenu' ]);
28
		dojox.grid.funnelEvents(this.headerNode, this, "doHeaderEvent", [ 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mousedown', 'click', 'contextmenu' ]);
29
		this.content = new dojox.grid.contentBuilder(this);
30
		this.header = new dojox.grid.headerBuilder(this);
31
	},
32
	destroy: function(){
33
		dojox.grid.removeNode(this.headerNode);
34
		this.inherited("destroy", arguments);
35
	},
36
	// focus
37
	focus: function(){
38
		if(dojo.isSafari || dojo.isOpera){
39
			this.hiddenFocusNode.focus();
40
		}else{
41
			this.scrollboxNode.focus();
42
		}
43
	},
44
	setStructure: function(inStructure){
45
		var vs = this.structure = inStructure;
46
		// FIXME: similar logic is duplicated in layout
47
		if(vs.width && dojo.isNumber(vs.width)){
48
			this.viewWidth = vs.width + 'em';
49
		}else{
50
			this.viewWidth = vs.width || this.viewWidth; //|| this.defaultWidth;
51
		}
52
		this.onBeforeRow = vs.onBeforeRow;
53
		this.noscroll = vs.noscroll;
54
		if(this.noscroll){
55
			this.scrollboxNode.style.overflow = "hidden";
56
		}
57
		// bookkeeping
58
		this.testFlexCells();
59
		// accomodate new structure
60
		this.updateStructure();
61
	},
62
	testFlexCells: function(){
63
		// FIXME: cheater, this function does double duty as initializer and tester
64
		this.flexCells = false;
65
		for(var j=0, row; (row=this.structure.rows[j]); j++){
66
			for(var i=0, cell; (cell=row[i]); i++){
67
				cell.view = this;
68
				this.flexCells = this.flexCells || cell.isFlex();
69
			}
70
		}
71
		return this.flexCells;
72
	},
73
	updateStructure: function(){
74
		// header builder needs to update table map
75
		this.header.update();
76
		// content builder needs to update markup cache
77
		this.content.update();
78
	},
79
	getScrollbarWidth: function(){
80
		return (this.noscroll ? 0 : dojox.grid.getScrollbarWidth());
81
	},
82
	getColumnsWidth: function(){
83
		return this.headerContentNode.firstChild.offsetWidth;
84
	},
85
	getWidth: function(){
86
		return this.viewWidth || (this.getColumnsWidth()+this.getScrollbarWidth()) +'px';
87
	},
88
	getContentWidth: function(){
89
		return Math.max(0, dojo._getContentBox(this.domNode).w - this.getScrollbarWidth()) + 'px';
90
	},
91
	render: function(){
92
		this.scrollboxNode.style.height = '';
93
		this.renderHeader();
94
	},
95
	renderHeader: function(){
96
		this.headerContentNode.innerHTML = this.header.generateHtml(this._getHeaderContent);
97
	},
98
	// note: not called in 'view' context
99
	_getHeaderContent: function(inCell){
100
		var n = inCell.name || inCell.grid.getCellName(inCell);
101
		if(inCell.index != inCell.grid.getSortIndex()){
102
			return n;
103
		}
104
		return [ '<div class="', inCell.grid.sortInfo > 0 ? 'dojoxGrid-sort-down' : 'dojoxGrid-sort-up', '">', n, '</div>' ].join('');
105
	},
106
	resize: function(){
107
		this.resizeHeight();
108
		this.resizeWidth();
109
	},
110
	hasScrollbar: function(){
111
		return (this.scrollboxNode.clientHeight != this.scrollboxNode.offsetHeight);
112
	},
113
	resizeHeight: function(){
114
		if(!this.grid.autoHeight){
115
			var h = this.domNode.clientHeight;
116
			if(!this.hasScrollbar()){ // no scrollbar is rendered
117
				h -= dojox.grid.getScrollbarWidth();
118
			}
119
			dojox.grid.setStyleHeightPx(this.scrollboxNode, h);
120
		}
121
	},
122
	resizeWidth: function(){
123
		if(this.flexCells){
124
			// the view content width
125
			this.contentWidth = this.getContentWidth();
126
			this.headerContentNode.firstChild.style.width = this.contentWidth;
127
		}
128
		// FIXME: it should be easier to get w from this.scrollboxNode.clientWidth,
129
		// but clientWidth seemingly does not include scrollbar width in some cases
130
		var w = this.scrollboxNode.offsetWidth - this.getScrollbarWidth();
131
		w = Math.max(w, this.getColumnsWidth()) + 'px';
132
		with(this.contentNode){
133
			style.width = '';
134
			offsetWidth;
135
			style.width = w;
136
		}
137
	},
138
	setSize: function(w, h){
139
		with(this.domNode.style){
140
			if(w){
141
				width = w;
142
			}
143
			height = (h >= 0 ? h + 'px' : '');
144
		}
145
		with(this.headerNode.style){
146
			if(w){
147
				width = w;
148
			}
149
		}
150
	},
151
	renderRow: function(inRowIndex, inHeightPx){
152
		var rowNode = this.createRowNode(inRowIndex);
153
		this.buildRow(inRowIndex, rowNode, inHeightPx);
154
		this.grid.edit.restore(this, inRowIndex);
155
		return rowNode;
156
	},
157
	createRowNode: function(inRowIndex){
158
		var node = document.createElement("div");
159
		node.className = this.classTag + '-row';
160
		node[dojox.grid.rowIndexTag] = inRowIndex;
161
		this.rowNodes[inRowIndex] = node;
162
		return node;
163
	},
164
	buildRow: function(inRowIndex, inRowNode){
165
		this.buildRowContent(inRowIndex, inRowNode);
166
		this.styleRow(inRowIndex, inRowNode);
167
	},
168
	buildRowContent: function(inRowIndex, inRowNode){
169
		inRowNode.innerHTML = this.content.generateHtml(inRowIndex, inRowIndex);
170
		if(this.flexCells){
171
			// FIXME: accessing firstChild here breaks encapsulation
172
			inRowNode.firstChild.style.width = this.contentWidth;
173
		}
174
	},
175
	rowRemoved:function(inRowIndex){
176
		this.grid.edit.save(this, inRowIndex);
177
		delete this.rowNodes[inRowIndex];
178
	},
179
	getRowNode: function(inRowIndex){
180
		return this.rowNodes[inRowIndex];
181
	},
182
	getCellNode: function(inRowIndex, inCellIndex){
183
		var row = this.getRowNode(inRowIndex);
184
		if(row){
185
			return this.content.getCellNode(row, inCellIndex);
186
		}
187
	},
188
	// styling
189
	styleRow: function(inRowIndex, inRowNode){
190
		inRowNode._style = dojox.grid.getStyleText(inRowNode);
191
		this.styleRowNode(inRowIndex, inRowNode);
192
	},
193
	styleRowNode: function(inRowIndex, inRowNode){
194
		if(inRowNode){
195
			this.doStyleRowNode(inRowIndex, inRowNode);
196
		}
197
	},
198
	doStyleRowNode: function(inRowIndex, inRowNode){
199
		this.grid.styleRowNode(inRowIndex, inRowNode);
200
	},
201
	// updating
202
	updateRow: function(inRowIndex, inHeightPx, inPageNode){
203
		var rowNode = this.getRowNode(inRowIndex);
204
		if(rowNode){
205
			rowNode.style.height = '';
206
			this.buildRow(inRowIndex, rowNode);
207
		}
208
		return rowNode;
209
	},
210
	updateRowStyles: function(inRowIndex){
211
		this.styleRowNode(inRowIndex, this.getRowNode(inRowIndex));
212
	},
213
	// scrolling
214
	lastTop: 0,
215
	doscroll: function(inEvent){
216
		this.headerNode.scrollLeft = this.scrollboxNode.scrollLeft;
217
		// 'lastTop' is a semaphore to prevent feedback-loop with setScrollTop below
218
		var top = this.scrollboxNode.scrollTop;
219
		if(top != this.lastTop){
220
			this.grid.scrollTo(top);
221
		}
222
	},
223
	setScrollTop: function(inTop){
224
		// 'lastTop' is a semaphore to prevent feedback-loop with doScroll above
225
		this.lastTop = inTop;
226
		this.scrollboxNode.scrollTop = inTop;
227
		return this.scrollboxNode.scrollTop;
228
	},
229
	// event handlers (direct from DOM)
230
	doContentEvent: function(e){
231
		if(this.content.decorateEvent(e)){
232
			this.grid.onContentEvent(e);
233
		}
234
	},
235
	doHeaderEvent: function(e){
236
		if(this.header.decorateEvent(e)){
237
			this.grid.onHeaderEvent(e);
238
		}
239
	},
240
	// event dispatch(from Grid)
241
	dispatchContentEvent: function(e){
242
		return this.content.dispatchEvent(e);
243
	},
244
	dispatchHeaderEvent: function(e){
245
		return this.header.dispatchEvent(e);
246
	},
247
	// column resizing
248
	setColWidth: function(inIndex, inWidth){
249
		this.grid.setCellWidth(inIndex, inWidth + 'px');
250
	},
251
	update: function(){
252
		var left = this.scrollboxNode.scrollLeft;
253
		this.content.update();
254
		this.grid.update();
255
		this.scrollboxNode.scrollLeft = left;
256
	}
257
});
258
 
259
}