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