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");
5 dojo.declare("dojox.grid.edit", null, {
7 // Controls grid cell editing process. Owned by grid and used internally for editing.
8 constructor: function(inGrid){
10 // The dojox.Grid this editor should be attached to
12 this.connections = [];
14 this.connections.push(dojo.connect(document.body, "onfocus", dojo.hitch(this, "_boomerangFocus")));
21 dojo.forEach(this.connections,dojo.disconnect);
24 cellFocus: function(inCell, inRowIndex){
26 // Invoke editing when cell is focused
27 // inCell: cell object
29 // inRowIndex: Integer
31 if(this.grid.singleClickEdit || this.isEditRow(inRowIndex)){
32 // if same row or quick editing, edit
33 this.setEditCell(inCell, inRowIndex);
35 // otherwise, apply any pending row edits
38 // if dynamic or static editing...
39 if(this.isEditing() || (inCell && (inCell.editor||0).alwaysOn)){
40 // let the editor focus itself as needed
41 this._focusEditor(inCell, inRowIndex);
45 rowClick: function(e){
46 if(this.isEditing() && !this.isEditRow(e.rowIndex)){
51 styleRow: function(inRow){
52 if(inRow.index == this.info.rowIndex){
53 inRow.customClasses += ' dojoxGrid-row-editing';
57 dispatchEvent: function(e){
58 var c = e.cell, ed = c && c.editor;
59 return ed && ed.dispatchEvent(e.dispatch, e);
63 isEditing: function(){
65 // Indicates editing state of the grid.
67 // True if grid is actively editing
68 return this.info.rowIndex !== undefined;
71 isEditCell: function(inRowIndex, inCellIndex){
73 // Indicates if the given cell is being edited.
74 // inRowIndex: Integer
76 // inCellIndex: Integer
79 // True if given cell is being edited
80 return (this.info.rowIndex === inRowIndex) && (this.info.cell.index == inCellIndex);
83 isEditRow: function(inRowIndex){
85 // Indicates if the given row is being edited.
86 // inRowIndex: Integer
89 // True if given row is being edited
90 return this.info.rowIndex === inRowIndex;
93 setEditCell: function(inCell, inRowIndex){
95 // Set the given cell to be edited
96 // inRowIndex: Integer
100 if(!this.isEditCell(inRowIndex, inCell.index) && this.grid.canEdit(inCell, inRowIndex)){
101 this.start(inCell, inRowIndex, this.isEditRow(inRowIndex) || inCell.editor);
105 _focusEditor: function(inCell, inRowIndex){
106 dojox.grid.fire(inCell.editor, "focus", [inRowIndex]);
109 focusEditor: function(){
110 if(this.isEditing()){
111 this._focusEditor(this.info.cell, this.info.rowIndex);
115 // implement fix for focus boomerang effect on IE
116 _boomerangWindow: 500,
117 _shouldCatchBoomerang: function(){
118 return this._catchBoomerang > new Date().getTime();
120 _boomerangFocus: function(){
121 //console.log("_boomerangFocus");
122 if(this._shouldCatchBoomerang()){
123 // make sure we don't utterly lose focus
124 this.grid.focus.focusGrid();
125 // let the editor focus itself as needed
128 this._catchBoomerang = 0;
131 _doCatchBoomerang: function(){
132 // give ourselves a few ms to boomerang IE focus effects
133 if(dojo.isIE){this._catchBoomerang = new Date().getTime() + this._boomerangWindow;}
135 // end boomerang fix API
137 start: function(inCell, inRowIndex, inEditing){
138 this.grid.beginUpdate();
140 if(this.isEditing() && !this.isEditRow(inRowIndex)){
142 this.grid.updateRow(inRowIndex);
145 this.info = { cell: inCell, rowIndex: inRowIndex };
146 this.grid.doStartEdit(inCell, inRowIndex);
147 this.grid.updateRow(inRowIndex);
151 this.grid.endUpdate();
152 // make sure we don't utterly lose focus
153 this.grid.focus.focusGrid();
154 // let the editor focus itself as needed
155 this._focusEditor(inCell, inRowIndex);
156 // give ourselves a few ms to boomerang IE focus effects
157 this._doCatchBoomerang();
160 _editorDo: function(inMethod){
161 var c = this.info.cell
162 //c && c.editor && c.editor[inMethod](c, this.info.rowIndex);
163 c && c.editor && c.editor[inMethod](this.info.rowIndex);
166 editorApply: function(){
167 this._editorDo("apply");
170 editorCancel: function(){
171 this._editorDo("cancel");
174 applyCellEdit: function(inValue, inCell, inRowIndex){
175 if(this.grid.canEdit(inCell, inRowIndex)){
176 this.grid.doApplyCellEdit(inValue, inRowIndex, inCell.fieldIndex);
180 applyRowEdit: function(){
181 this.grid.doApplyEdit(this.info.rowIndex);
187 if(this.isEditing()){
188 this.grid.beginUpdate();
192 this.grid.endUpdate();
193 this.grid.focus.focusGrid();
194 this._doCatchBoomerang();
200 // Cancel a grid edit
201 if(this.isEditing()){
202 this.grid.beginUpdate();
205 this.grid.endUpdate();
206 this.grid.focus.focusGrid();
207 this._doCatchBoomerang();
211 save: function(inRowIndex, inView){
213 // Save the grid editing state
214 // inRowIndex: Integer
218 var c = this.info.cell;
219 if(this.isEditRow(inRowIndex) && (!inView || c.view==inView) && c.editor){
220 c.editor.save(c, this.info.rowIndex);
224 restore: function(inView, inRowIndex){
226 // Restores the grid editing state
227 // inRowIndex: Integer
231 var c = this.info.cell;
232 if(this.isEditRow(inRowIndex) && c.view == inView && c.editor){
233 c.editor.restore(c, this.info.rowIndex);