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.edit"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.grid._grid.edit"] = true;
3
dojo.provide("dojox.grid._grid.edit");
4
 
5
dojo.declare("dojox.grid.edit", null, {
6
	// summary:
7
	//	Controls grid cell editing process. Owned by grid and used internally for editing.
8
	constructor: function(inGrid){
9
		this.grid = inGrid;
10
		this.connections = [];
11
		if(dojo.isIE){
12
			this.connections.push(dojo.connect(document.body, "onfocus", dojo.hitch(this, "_boomerangFocus")));
13
		}
14
	},
15
	info: {},
16
	destroy: function(){
17
		dojo.forEach(this.connections, function(c){
18
			dojo.disconnect(c);
19
		});
20
	},
21
	cellFocus: function(inCell, inRowIndex){
22
		// summary:
23
		//	invoke editing when cell is focused
24
		// inCell: cell object
25
		//	grid cell object
26
		// inRowIndex: int
27
		//	grid row index
28
		if(this.grid.singleClickEdit || this.isEditRow(inRowIndex)){
29
			// if same row or quick editing, edit
30
			this.setEditCell(inCell, inRowIndex);
31
		}else{
32
			// otherwise, apply any pending row edits
33
			this.apply();
34
		}
35
		// if dynamic or static editing...
36
		if(this.isEditing() || (inCell && (inCell.editor||0).alwaysOn)){
37
			// let the editor focus itself as needed
38
			this._focusEditor(inCell, inRowIndex);
39
		}
40
	},
41
	rowClick: function(e){
42
		if(this.isEditing() && !this.isEditRow(e.rowIndex)){
43
			this.apply();
44
		}
45
	},
46
	styleRow: function(inRow){
47
		if(inRow.index == this.info.rowIndex){
48
			inRow.customClasses += ' dojoxGrid-row-editing';
49
		}
50
	},
51
	dispatchEvent: function(e){
52
		var c = e.cell, ed = c && c.editor;
53
		return ed && ed.dispatchEvent(e.dispatch, e);
54
	},
55
	// Editing
56
	isEditing: function(){
57
		// summary:
58
		//	indicates editing state of the grid.
59
		// returns:
60
		//	 true if grid is actively editing
61
		return this.info.rowIndex !== undefined;
62
	},
63
	isEditCell: function(inRowIndex, inCellIndex){
64
		// summary:
65
		//	indicates if the given cell is being edited.
66
		// inRowIndex: int
67
		//	grid row index
68
		// inCellIndex: int
69
		//	grid cell index
70
		// returns:
71
		//	 true if given cell is being edited
72
		return (this.info.rowIndex === inRowIndex) && (this.info.cell.index == inCellIndex);
73
	},
74
	isEditRow: function(inRowIndex){
75
		// summary:
76
		//	indicates if the given row is being edited.
77
		// inRowIndex: int
78
		//	grid row index
79
		// returns:
80
		//	 true if given row is being edited
81
		return this.info.rowIndex === inRowIndex;
82
	},
83
	setEditCell: function(inCell, inRowIndex){
84
		// summary:
85
		//	set the given cell to be edited
86
		// inRowIndex: int
87
		//	grid row index
88
		// inCell: object
89
		//	grid cell object
90
		if(!this.isEditCell(inRowIndex, inCell.index)){
91
			this.start(inCell, inRowIndex, this.isEditRow(inRowIndex) || inCell.editor);
92
		}
93
	},
94
	_focusEditor: function(inCell, inRowIndex){
95
		dojox.grid.fire(inCell.editor, "focus", [inRowIndex]);
96
	},
97
	focusEditor: function(){
98
		if(this.isEditing()){
99
			this._focusEditor(this.info.cell, this.info.rowIndex);
100
		}
101
	},
102
	// implement fix for focus boomerang effect on IE
103
	_boomerangWindow: 500,
104
	_shouldCatchBoomerang: function(){
105
		return this._catchBoomerang > new Date().getTime();
106
	},
107
	_boomerangFocus: function(){
108
		//console.log("_boomerangFocus");
109
		if(this._shouldCatchBoomerang()){
110
			// make sure we don't utterly lose focus
111
			this.grid.focus.focusGrid();
112
			// let the editor focus itself as needed
113
			this.focusEditor();
114
			// only catch once
115
			this._catchBoomerang = 0;
116
		}
117
	},
118
	_doCatchBoomerang: function(){
119
		// give ourselves a few ms to boomerang IE focus effects
120
		if(dojo.isIE){this._catchBoomerang = new Date().getTime() + this._boomerangWindow;}
121
	},
122
	// end boomerang fix API
123
	start: function(inCell, inRowIndex, inEditing){
124
		this.grid.beginUpdate();
125
		this.editorApply();
126
		if(this.isEditing() && !this.isEditRow(inRowIndex)){
127
			this.applyRowEdit();
128
			this.grid.updateRow(inRowIndex);
129
		}
130
		if(inEditing){
131
			this.info = { cell: inCell, rowIndex: inRowIndex };
132
			this.grid.doStartEdit(inCell, inRowIndex);
133
			this.grid.updateRow(inRowIndex);
134
		}else{
135
			this.info = {};
136
		}
137
		this.grid.endUpdate();
138
		// make sure we don't utterly lose focus
139
		this.grid.focus.focusGrid();
140
		// let the editor focus itself as needed
141
		this._focusEditor(inCell, inRowIndex);
142
		// give ourselves a few ms to boomerang IE focus effects
143
		this._doCatchBoomerang();
144
	},
145
	_editorDo: function(inMethod){
146
		var c = this.info.cell
147
		//c && c.editor && c.editor[inMethod](c, this.info.rowIndex);
148
		c && c.editor && c.editor[inMethod](this.info.rowIndex);
149
	},
150
	editorApply: function(){
151
		this._editorDo("apply");
152
	},
153
	editorCancel: function(){
154
		this._editorDo("cancel");
155
	},
156
	applyCellEdit: function(inValue, inCell, inRowIndex){
157
		this.grid.doApplyCellEdit(inValue, inRowIndex, inCell.fieldIndex);
158
	},
159
	applyRowEdit: function(){
160
		this.grid.doApplyEdit(this.info.rowIndex);
161
	},
162
	apply: function(){
163
		// summary:
164
		//	apply a grid edit
165
		if(this.isEditing()){
166
			this.grid.beginUpdate();
167
			this.editorApply();
168
			this.applyRowEdit();
169
			this.info = {};
170
			this.grid.endUpdate();
171
			this.grid.focus.focusGrid();
172
			this._doCatchBoomerang();
173
		}
174
	},
175
	cancel: function(){
176
		// summary:
177
		//	cancel a grid edit
178
		if(this.isEditing()){
179
			this.grid.beginUpdate();
180
			this.editorCancel();
181
			this.info = {};
182
			this.grid.endUpdate();
183
			this.grid.focus.focusGrid();
184
			this._doCatchBoomerang();
185
		}
186
	},
187
	save: function(inRowIndex, inView){
188
		// summary:
189
		//	save the grid editing state
190
		// inRowIndex: int
191
		//	grid row index
192
		// inView: object
193
		//	grid view
194
		var c = this.info.cell;
195
		if(this.isEditRow(inRowIndex) && (!inView || c.view==inView) && c.editor){
196
			c.editor.save(c, this.info.rowIndex);
197
		}
198
	},
199
	restore: function(inView, inRowIndex){
200
		// summary:
201
		//	restores the grid editing state
202
		// inRowIndex: int
203
		//	grid row index
204
		// inView: object
205
		//	grid view
206
		var c = this.info.cell;
207
		if(this.isEditRow(inRowIndex) && c.view == inView && c.editor){
208
			c.editor.restore(c, this.info.rowIndex);
209
		}
210
	}
211
});
212
 
213
}