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"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.grid.Grid"] = true;
3
dojo.provide("dojox.grid.Grid");
4
dojo.require("dojox.grid.VirtualGrid");
5
dojo.require("dojox.grid._data.model");
6
dojo.require("dojox.grid._data.editors");
7
 
8
dojo.declare('dojox.Grid', dojox.VirtualGrid, {
9
	//	summary:
10
	//		A grid widget with virtual scrolling, cell editing, complex rows,
11
	//		sorting, fixed columns, sizeable columns, etc.
12
	//	description:
13
	//		Grid is a subclass of VirtualGrid, providing binding to a data
14
	//		store.
15
	//	example:
16
	//		define the grid structure:
17
	//	|	var structure = [ // array of view objects
18
	//	|		{ cells: [// array of rows, a row is an array of cells
19
	//	|			[	{ name: "Alpha", width: 6 },
20
	//	|				{ name: "Beta" },
21
	//	|				{ name: "Gamma", get: formatFunction }
22
	//	|			]
23
	//	|		]}
24
	//	|	];
25
	//
26
	//		define a grid data model
27
	//	|	var model = new dojox.grid.data.table(null, data);
28
	//	|
29
	//	|	<div id="grid" model="model" structure="structure"
30
	//	|		dojoType="dojox.VirtualGrid"></div>
31
	//
32
 
33
	//	model:
34
	//		string or object grid data model
35
	model: 'dojox.grid.data.Table',
36
	// life cycle
37
	postCreate: function(){
38
		if(this.model){
39
			var m = this.model;
40
			if(dojo.isString(m)){
41
				m = dojo.getObject(m);
42
			}
43
			this.model = (dojo.isFunction(m)) ? new m() : m;
44
			this._setModel(this.model);
45
		}
46
		this.inherited(arguments);
47
	},
48
	destroy: function(){
49
		this.setModel(null);
50
		this.inherited(arguments);
51
	},
52
	// structure
53
	_structureChanged: function() {
54
		this.indexCellFields();
55
		this.inherited(arguments);
56
	},
57
	// model
58
	_setModel: function(inModel){
59
		// if(!inModel){ return; }
60
		this.model = inModel;
61
		if(this.model){
62
			this.model.observer(this);
63
			this.model.measure();
64
			this.indexCellFields();
65
		}
66
	},
67
	setModel: function(inModel){
68
		// summary:
69
		//		set the grid's data model
70
		// inModel:
71
		//		model object, usually an instance of a dojox.grid.data.Model
72
		//		subclass
73
		if(this.model){
74
			this.model.notObserver(this);
75
		}
76
		this._setModel(inModel);
77
	},
78
	// data socket (called in cell's context)
79
	get: function(inRowIndex){
80
		return this.grid.model.getDatum(inRowIndex, this.fieldIndex);
81
	},
82
	// model modifications
83
	modelAllChange: function(){
84
		this.rowCount = (this.model ? this.model.getRowCount() : 0);
85
		this.updateRowCount(this.rowCount);
86
	},
87
	modelRowChange: function(inData, inRowIndex){
88
		this.updateRow(inRowIndex);
89
	},
90
	modelDatumChange: function(inDatum, inRowIndex, inFieldIndex){
91
		this.updateRow(inRowIndex);
92
	},
93
	modelFieldsChange: function() {
94
		this.indexCellFields();
95
		this.render();
96
	},
97
	// model insertion
98
	modelInsertion: function(inRowIndex){
99
		this.updateRowCount(this.model.getRowCount());
100
	},
101
	// model removal
102
	modelRemoval: function(inKeys){
103
		this.updateRowCount(this.model.getRowCount());
104
	},
105
	// cells
106
	getCellName: function(inCell){
107
		var v = this.model.fields.values, i = inCell.fieldIndex;
108
		return i>=0 && i<v.length && v[i].name || this.inherited(arguments);
109
	},
110
	indexCellFields: function(){
111
		var cells = this.layout.cells;
112
		for(var i=0, c; cells && (c=cells[i]); i++){
113
			if(dojo.isString(c.field)){
114
				c.fieldIndex = this.model.fields.indexOf(c.field);
115
			}
116
		}
117
	},
118
	// utility
119
	refresh: function(){
120
		// summary:
121
		//	re-render the grid, getting new data from the model
122
		this.edit.cancel();
123
		this.model.measure();
124
	},
125
	// sorting
126
	canSort: function(inSortInfo){
127
		var f = this.getSortField(inSortInfo);
128
		// 0 is not a valid sort field
129
		return f && this.model.canSort(f);
130
	},
131
	getSortField: function(inSortInfo){
132
		// summary:
133
		//	retrieves the model field on which to sort data.
134
		// inSortInfo: int
135
		//	1-based grid column index; positive if sort is ascending, otherwise negative
136
		var c = this.getCell(this.getSortIndex(inSortInfo));
137
		// we expect c.fieldIndex == -1 for non model fields
138
		// that yields a getSortField value of 0, which can be detected as invalid
139
		return (c.fieldIndex+1) * (this.sortInfo > 0 ? 1 : -1);
140
	},
141
	sort: function(){
142
		this.edit.apply();
143
		this.model.sort(this.getSortField());
144
	},
145
	// row editing
146
	addRow: function(inRowData, inIndex){
147
		this.edit.apply();
148
		var i = inIndex || -1;
149
		if(i<0){
150
			i = this.selection.getFirstSelected() || 0;
151
		}
152
		if(i<0){
153
			i = 0;
154
		}
155
		this.model.insert(inRowData, i);
156
		this.model.beginModifyRow(i);
157
		// begin editing row
158
		// FIXME: add to edit
159
		for(var j=0, c; ((c=this.getCell(j)) && !c.editor); j++){}
160
		if(c&&c.editor){
161
			this.edit.setEditCell(c, i);
162
		}
163
	},
164
	removeSelectedRows: function(){
165
		this.edit.apply();
166
		var s = this.selection.getSelected();
167
		if(s.length){
168
			this.model.remove(s);
169
			this.selection.clear();
170
		}
171
	},
172
	//: protected
173
	// editing
174
	canEdit: function(inCell, inRowIndex){
175
		// summary:
176
		//	determines if a given cell may be edited
177
		//	inCell: grid cell
178
		// inRowIndex: grid row index
179
		// returns: true if given cell may be edited
180
		return (this.model.canModify ? this.model.canModify(inRowIndex) : true);
181
	},
182
	doStartEdit: function(inCell, inRowIndex){
183
		var edit = this.canEdit(inCell, inRowIndex);
184
		if(edit){
185
			this.model.beginModifyRow(inRowIndex);
186
			this.onStartEdit(inCell, inRowIndex);
187
		}
188
		return edit;
189
	},
190
	doApplyCellEdit: function(inValue, inRowIndex, inFieldIndex){
191
		this.model.setDatum(inValue, inRowIndex, inFieldIndex);
192
		this.onApplyCellEdit(inValue, inRowIndex, inFieldIndex);
193
	},
194
	doCancelEdit: function(inRowIndex){
195
		this.model.cancelModifyRow(inRowIndex);
196
		this.onCancelEdit.apply(this, arguments);
197
	},
198
	doApplyEdit: function(inRowIndex){
199
		this.model.endModifyRow(inRowIndex);
200
		this.onApplyEdit(inRowIndex);
201
	},
202
	// Perform row styling
203
	styleRowState: function(inRow){
204
		if(this.model.getState){
205
			var states=this.model.getState(inRow.index), c='';
206
			for(var i=0, ss=["inflight", "error", "inserting"], s; s=ss[i]; i++){
207
				if(states[s]){
208
					c = ' dojoxGrid-row-' + s;
209
					break;
210
				}
211
			}
212
			inRow.customClasses += c;
213
		}
214
	},
215
	onStyleRow: function(inRow){
216
		this.styleRowState(inRow);
217
		this.inherited(arguments);
218
	},
219
	junk: 0
220
});
221
 
222
}