source: Dev/branches/rest-dojo-ui/client/dojox/grid/_Events.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 14.5 KB
Line 
1define([
2        "dojo/keys",
3        "dojo/dom-class",
4        "dojo/_base/declare",
5        "dojo/_base/event",
6        "dojo/_base/sniff"
7], function(keys, domClass, declare, event, has){
8
9return declare("dojox.grid._Events", null, {
10        // summary:
11        //              _Grid mixin that provides default implementations for grid events.
12        // description:
13        //              Default synthetic events dispatched for _Grid. dojo.connect to events to
14        //              retain default implementation or override them for custom handling.
15       
16        // cellOverClass: String
17        //              css class to apply to grid cells over which the cursor is placed.
18        cellOverClass: "dojoxGridCellOver",
19       
20        onKeyEvent: function(e){
21                // summary: top level handler for Key Events
22                this.dispatchKeyEvent(e);
23        },
24
25        onContentEvent: function(e){
26                // summary: Top level handler for Content events
27                this.dispatchContentEvent(e);
28        },
29
30        onHeaderEvent: function(e){
31                // summary: Top level handler for header events
32                this.dispatchHeaderEvent(e);
33        },
34
35        onStyleRow: function(inRow){
36                // summary:
37                //              Perform row styling on a given row. Called whenever row styling is updated.
38                //
39                // inRow: Object
40                //              Object containing row state information: selected, true if the row is selcted; over:
41                //              true of the mouse is over the row; odd: true if the row is odd. Use customClasses and
42                //              customStyles to control row css classes and styles; both properties are strings.
43                //
44                // example: onStyleRow({ selected: true, over:true, odd:false })
45                var i = inRow;
46                i.customClasses += (i.odd?" dojoxGridRowOdd":"") + (i.selected?" dojoxGridRowSelected":"") + (i.over?" dojoxGridRowOver":"");
47                this.focus.styleRow(inRow);
48                this.edit.styleRow(inRow);
49        },
50       
51        onKeyDown: function(e){
52                // summary:
53                //              Grid key event handler. By default enter begins editing and applies edits, escape cancels an edit,
54                //              tab, shift-tab, and arrow keys move grid cell focus.
55                if(e.altKey || e.metaKey){
56                        return;
57                }
58                var colIdx;
59                switch(e.keyCode){
60                        case keys.ESCAPE:
61                                this.edit.cancel();
62                                break;
63                        case keys.ENTER:
64                                if(!this.edit.isEditing()){
65                                        colIdx = this.focus.getHeaderIndex();
66                                        if(colIdx >= 0) {
67                                                this.setSortIndex(colIdx);
68                                                break;
69                                        }else {
70                                                this.selection.clickSelect(this.focus.rowIndex, dojo.isCopyKey(e), e.shiftKey);
71                                        }
72                                        event.stop(e);
73                                }
74                                if(!e.shiftKey){
75                                        var isEditing = this.edit.isEditing();
76                                        this.edit.apply();
77                                        if(!isEditing){
78                                                this.edit.setEditCell(this.focus.cell, this.focus.rowIndex);
79                                        }
80                                }
81                                if (!this.edit.isEditing()){
82                                        var curView = this.focus.focusView || this.views.views[0];  //if no focusView than only one view
83                                        curView.content.decorateEvent(e);
84                                        this.onRowClick(e);
85                                        event.stop(e);
86                                }
87                                break;
88                        case keys.SPACE:
89                                if(!this.edit.isEditing()){
90                                        colIdx = this.focus.getHeaderIndex();
91                                        if(colIdx >= 0) {
92                                                this.setSortIndex(colIdx);
93                                                break;
94                                        }else {
95                                                this.selection.clickSelect(this.focus.rowIndex, dojo.isCopyKey(e), e.shiftKey);
96                                        }
97                                        event.stop(e);
98                                }
99                                break;
100                        case keys.TAB:
101                                this.focus[e.shiftKey ? 'previousKey' : 'nextKey'](e);
102                                break;
103                        case keys.LEFT_ARROW:
104                        case keys.RIGHT_ARROW:
105                                if(!this.edit.isEditing()){
106                                        var keyCode = e.keyCode;  // IE seems to lose after stopEvent when modifier keys
107                                        event.stop(e);
108                                        colIdx = this.focus.getHeaderIndex();
109                                        if (colIdx >= 0 && (e.shiftKey && e.ctrlKey)){
110                                                this.focus.colSizeAdjust(e, colIdx, (keyCode == keys.LEFT_ARROW ? -1 : 1)*5);
111                                        }
112                                        else{
113                                                var offset = (keyCode == keys.LEFT_ARROW) ? 1 : -1;
114                                                if(this.isLeftToRight()){ offset *= -1; }
115                                                this.focus.move(0, offset);
116                                        }
117                                }
118                                break;
119                        case keys.UP_ARROW:
120                                if(!this.edit.isEditing() && this.focus.rowIndex !== 0){
121                                        event.stop(e);
122                                        this.focus.move(-1, 0);
123                                }
124                                break;
125                        case keys.DOWN_ARROW:
126                                if(!this.edit.isEditing() && this.focus.rowIndex+1 != this.rowCount){
127                                        event.stop(e);
128                                        this.focus.move(1, 0);
129                                }
130                                break;
131                        case keys.PAGE_UP:
132                                if(!this.edit.isEditing() && this.focus.rowIndex !== 0){
133                                        event.stop(e);
134                                        if(this.focus.rowIndex != this.scroller.firstVisibleRow+1){
135                                                this.focus.move(this.scroller.firstVisibleRow-this.focus.rowIndex, 0);
136                                        }else{
137                                                this.setScrollTop(this.scroller.findScrollTop(this.focus.rowIndex-1));
138                                                this.focus.move(this.scroller.firstVisibleRow-this.scroller.lastVisibleRow+1, 0);
139                                        }
140                                }
141                                break;
142                        case keys.PAGE_DOWN:
143                                if(!this.edit.isEditing() && this.focus.rowIndex+1 != this.rowCount){
144                                        event.stop(e);
145                                        if(this.focus.rowIndex != this.scroller.lastVisibleRow-1){
146                                                this.focus.move(this.scroller.lastVisibleRow-this.focus.rowIndex-1, 0);
147                                        }else{
148                                                this.setScrollTop(this.scroller.findScrollTop(this.focus.rowIndex+1));
149                                                this.focus.move(this.scroller.lastVisibleRow-this.scroller.firstVisibleRow-1, 0);
150                                        }
151                                }
152                                break;
153                        default:
154                                break;
155                }
156        },
157       
158        onMouseOver: function(e){
159                // summary:
160                //              Event fired when mouse is over the grid.
161                // e: Event
162                //              Decorated event object contains reference to grid, cell, and rowIndex
163                e.rowIndex == -1 ? this.onHeaderCellMouseOver(e) : this.onCellMouseOver(e);
164        },
165       
166        onMouseOut: function(e){
167                // summary:
168                //              Event fired when mouse moves out of the grid.
169                // e: Event
170                //              Decorated event object that contains reference to grid, cell, and rowIndex
171                e.rowIndex == -1 ? this.onHeaderCellMouseOut(e) : this.onCellMouseOut(e);
172        },
173       
174        onMouseDown: function(e){
175                // summary:
176                //              Event fired when mouse is down inside grid.
177                // e: Event
178                //              Decorated event object that contains reference to grid, cell, and rowIndex
179                e.rowIndex == -1 ? this.onHeaderCellMouseDown(e) : this.onCellMouseDown(e);
180        },
181       
182        onMouseOverRow: function(e){
183                // summary:
184                //              Event fired when mouse is over any row (data or header).
185                // e: Event
186                //              Decorated event object contains reference to grid, cell, and rowIndex
187                if(!this.rows.isOver(e.rowIndex)){
188                        this.rows.setOverRow(e.rowIndex);
189                        e.rowIndex == -1 ? this.onHeaderMouseOver(e) : this.onRowMouseOver(e);
190                }
191        },
192        onMouseOutRow: function(e){
193                // summary:
194                //              Event fired when mouse moves out of any row (data or header).
195                // e: Event
196                //              Decorated event object contains reference to grid, cell, and rowIndex
197                if(this.rows.isOver(-1)){
198                        this.onHeaderMouseOut(e);
199                }else if(!this.rows.isOver(-2)){
200                        this.rows.setOverRow(-2);
201                        this.onRowMouseOut(e);
202                }
203        },
204       
205        onMouseDownRow: function(e){
206                // summary:
207                //              Event fired when mouse is down inside grid row
208                // e: Event
209                //              Decorated event object that contains reference to grid, cell, and rowIndex
210                if(e.rowIndex != -1)
211                        this.onRowMouseDown(e);
212        },
213
214        // cell events
215        onCellMouseOver: function(e){
216                // summary:
217                //              Event fired when mouse is over a cell.
218                // e: Event
219                //              Decorated event object contains reference to grid, cell, and rowIndex
220                if(e.cellNode){
221                        domClass.add(e.cellNode, this.cellOverClass);
222                }
223        },
224       
225        onCellMouseOut: function(e){
226                // summary:
227                //              Event fired when mouse moves out of a cell.
228                // e: Event
229                //              Decorated event object which contains reference to grid, cell, and rowIndex
230                if(e.cellNode){
231                        domClass.remove(e.cellNode, this.cellOverClass);
232                }
233        },
234       
235        onCellMouseDown: function(e){
236                // summary:
237                //              Event fired when mouse is down in a header cell.
238                // e: Event
239                //              Decorated event object which contains reference to grid, cell, and rowIndex
240        },
241
242        onCellClick: function(e){
243                // summary:
244                //              Event fired when a cell is clicked.
245                // e: Event
246                //              Decorated event object which contains reference to grid, cell, and rowIndex
247                this._click[0] = this._click[1];
248                this._click[1] = e;
249                if(!this.edit.isEditCell(e.rowIndex, e.cellIndex)){
250                        this.focus.setFocusCell(e.cell, e.rowIndex);
251                }
252                // in some cases click[0] is null which causes false doubeClicks. Fixes #100703
253                if(this._click.length > 1 && this._click[0] == null){
254                        this._click.shift();
255                }
256                this.onRowClick(e);
257        },
258
259        onCellDblClick: function(e){
260                // summary:
261                //              Event fired when a cell is double-clicked.
262                // e: Event
263                //              Decorated event object contains reference to grid, cell, and rowIndex
264                var event;
265                if(this._click.length > 1 && has('ie')){
266                        event = this._click[1];
267                }else if(this._click.length > 1 && this._click[0].rowIndex != this._click[1].rowIndex){
268                        event = this._click[0];
269                }else{
270                        event = e;
271                }
272                this.focus.setFocusCell(event.cell, event.rowIndex);
273                this.onRowClick(event);
274                this.edit.setEditCell(event.cell, event.rowIndex);
275                this.onRowDblClick(e);
276        },
277
278        onCellContextMenu: function(e){
279                // summary:
280                //              Event fired when a cell context menu is accessed via mouse right click.
281                // e: Event
282                //              Decorated event object which contains reference to grid, cell, and rowIndex
283                this.onRowContextMenu(e);
284        },
285
286        onCellFocus: function(inCell, inRowIndex){
287                // summary:
288                //              Event fired when a cell receives focus.
289                // inCell: Object
290                //              Cell object containing properties of the grid column.
291                // inRowIndex: Integer
292                //              Index of the grid row
293                this.edit.cellFocus(inCell, inRowIndex);
294        },
295
296        // row events
297        onRowClick: function(e){
298                // summary:
299                //              Event fired when a row is clicked.
300                // e: Event
301                //              Decorated event object which contains reference to grid, cell, and rowIndex
302                this.edit.rowClick(e);
303                this.selection.clickSelectEvent(e);
304        },
305
306        onRowDblClick: function(e){
307                // summary:
308                //              Event fired when a row is double clicked.
309                // e: Event
310                //              decorated event object which contains reference to grid, cell, and rowIndex
311        },
312
313        onRowMouseOver: function(e){
314                // summary:
315                //              Event fired when mouse moves over a data row.
316                // e: Event
317                //              Decorated event object which contains reference to grid, cell, and rowIndex
318        },
319
320        onRowMouseOut: function(e){
321                // summary:
322                //              Event fired when mouse moves out of a data row.
323                // e: Event
324                //              Decorated event object contains reference to grid, cell, and rowIndex
325        },
326       
327        onRowMouseDown: function(e){
328                // summary:
329                //              Event fired when mouse is down in a row.
330                // e: Event
331                //              Decorated event object which contains reference to grid, cell, and rowIndex
332        },
333
334        onRowContextMenu: function(e){
335                // summary:
336                //              Event fired when a row context menu is accessed via mouse right click.
337                // e: Event
338                //              Decorated event object which contains reference to grid, cell, and rowIndex
339                event.stop(e);
340        },
341
342        // header events
343        onHeaderMouseOver: function(e){
344                // summary:
345                //              Event fired when mouse moves over the grid header.
346                // e: Event
347                //              Decorated event object contains reference to grid, cell, and rowIndex
348        },
349
350        onHeaderMouseOut: function(e){
351                // summary:
352                //              Event fired when mouse moves out of the grid header.
353                // e: Event
354                //              Decorated event object which contains reference to grid, cell, and rowIndex
355        },
356
357        onHeaderCellMouseOver: function(e){
358                // summary:
359                //              Event fired when mouse moves over a header cell.
360                // e: Event
361                //              Decorated event object which contains reference to grid, cell, and rowIndex
362                if(e.cellNode){
363                        domClass.add(e.cellNode, this.cellOverClass);
364                }
365        },
366
367        onHeaderCellMouseOut: function(e){
368                // summary:
369                //              Event fired when mouse moves out of a header cell.
370                // e: Event
371                //              Decorated event object which contains reference to grid, cell, and rowIndex
372                if(e.cellNode){
373                        domClass.remove(e.cellNode, this.cellOverClass);
374                }
375        },
376       
377        onHeaderCellMouseDown: function(e) {
378                // summary:
379                //              Event fired when mouse is down in a header cell.
380                // e: Event
381                //              Decorated event object which contains reference to grid, cell, and rowIndex
382        },
383
384        onHeaderClick: function(e){
385                // summary:
386                //              Event fired when the grid header is clicked.
387                // e: Event
388                // Decorated event object which contains reference to grid, cell, and rowIndex
389        },
390
391        onHeaderCellClick: function(e){
392                // summary:
393                //              Event fired when a header cell is clicked.
394                // e: Event
395                //              Decorated event object which contains reference to grid, cell, and rowIndex
396                this.setSortIndex(e.cell.index);
397                this.onHeaderClick(e);
398        },
399
400        onHeaderDblClick: function(e){
401                // summary:
402                //              Event fired when the grid header is double clicked.
403                // e: Event
404                //              Decorated event object which contains reference to grid, cell, and rowIndex
405        },
406
407        onHeaderCellDblClick: function(e){
408                // summary:
409                //              Event fired when a header cell is double clicked.
410                // e: Event
411                //              Decorated event object which contains reference to grid, cell, and rowIndex
412                this.onHeaderDblClick(e);
413        },
414
415        onHeaderCellContextMenu: function(e){
416                // summary:
417                //              Event fired when a header cell context menu is accessed via mouse right click.
418                // e: Event
419                //              Decorated event object which contains reference to grid, cell, and rowIndex
420                this.onHeaderContextMenu(e);
421        },
422
423        onHeaderContextMenu: function(e){
424                // summary:
425                //              Event fired when the grid header context menu is accessed via mouse right click.
426                // e: Event
427                //              Decorated event object which contains reference to grid, cell, and rowIndex
428                if(!this.headerMenu){
429                        event.stop(e);
430                }
431        },
432
433        // editing
434        onStartEdit: function(inCell, inRowIndex){
435                // summary:
436                //              Event fired when editing is started for a given grid cell
437                // inCell: Object
438                //              Cell object containing properties of the grid column.
439                // inRowIndex: Integer
440                //              Index of the grid row
441        },
442
443        onApplyCellEdit: function(inValue, inRowIndex, inFieldIndex){
444                // summary:
445                //              Event fired when editing is applied for a given grid cell
446                // inValue: String
447                //              Value from cell editor
448                // inRowIndex: Integer
449                //              Index of the grid row
450                // inFieldIndex: Integer
451                //              Index in the grid's data store
452        },
453
454        onCancelEdit: function(inRowIndex){
455                // summary:
456                //              Event fired when editing is cancelled for a given grid cell
457                // inRowIndex: Integer
458                //              Index of the grid row
459        },
460
461        onApplyEdit: function(inRowIndex){
462                // summary:
463                //              Event fired when editing is applied for a given grid row
464                // inRowIndex: Integer
465                //              Index of the grid row
466        },
467
468        onCanSelect: function(inRowIndex){
469                // summary:
470                //              Event to determine if a grid row may be selected
471                // inRowIndex: Integer
472                //              Index of the grid row
473                // returns: Boolean
474                //              true if the row can be selected
475                return true;
476        },
477
478        onCanDeselect: function(inRowIndex){
479                // summary:
480                //              Event to determine if a grid row may be deselected
481                // inRowIndex: Integer
482                //              Index of the grid row
483                // returns: Boolean
484                //              true if the row can be deselected
485                return true;
486        },
487
488        onSelected: function(inRowIndex){
489                // summary:
490                //              Event fired when a grid row is selected
491                // inRowIndex: Integer
492                //              Index of the grid row
493                this.updateRowStyles(inRowIndex);
494        },
495
496        onDeselected: function(inRowIndex){
497                // summary:
498                //              Event fired when a grid row is deselected
499                // inRowIndex: Integer
500                //              Index of the grid row
501                this.updateRowStyles(inRowIndex);
502        },
503
504        onSelectionChanged: function(){
505        }
506});
507});
Note: See TracBrowser for help on using the repository browser.