_Events.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. define("dojox/grid/enhanced/_Events", [
  2. "dojo/_base/kernel",
  3. "dojo/_base/declare",
  4. "dojo/keys",
  5. "dojo/_base/html",
  6. "dojo/_base/event",
  7. "dojox/grid/_Events"
  8. ], function(dojo, declare, keys, html, event, _Events){
  9. return declare("dojox.grid.enhanced._Events", null, {
  10. // summary:
  11. // Overwrite some default events of DataGrid
  12. //
  13. // description:
  14. // Methods are copied or replaced for overwriting, this might be refined once
  15. // an overall plugin architecture is set up for DataGrid.
  16. //_events: Object
  17. // Method map cached from dojox.grid._Events().
  18. _events: null,
  19. // headerCellActiveClass: String
  20. // css class to apply to grid header cells when activated(mouse down)
  21. headerCellActiveClass: 'dojoxGridHeaderActive',
  22. // cellActiveClass: String
  23. // css class to apply to grid content cells when activated(mouse down)
  24. cellActiveClass: 'dojoxGridCellActive',
  25. // rowActiveClass: String
  26. // css class to apply to grid rows when activated(mouse down)
  27. rowActiveClass: 'dojoxGridRowActive',
  28. constructor: function(inGrid){
  29. //TODO - extend dojox.grid._Events rather than mixin for 1.8
  30. this._events = new _Events();
  31. //mixin "this" to Grid
  32. inGrid.mixin(inGrid, this);
  33. },
  34. dokeyup: function(e){
  35. // summary:
  36. // Grid key up event handler.
  37. // e: Event
  38. // Un-decorated event object
  39. this.focus.currentArea().keyup(e);
  40. },
  41. onKeyDown: function(e){
  42. // summary:
  43. // Overwritten, see dojox.grid._Events.onKeyDown();
  44. if(e.altKey || e.metaKey){ return; }
  45. var focus = this.focus;
  46. var editing = this.edit.isEditing();
  47. switch(e.keyCode){
  48. case keys.TAB:
  49. if(e.ctrlKey){ return; }
  50. focus.tab(e.shiftKey ? -1:1,e);
  51. break;
  52. case keys.UP_ARROW:
  53. case keys.DOWN_ARROW:
  54. if(editing){ return; }
  55. focus.currentArea().move(e.keyCode == keys.UP_ARROW ? -1 : 1, 0, e);
  56. break;
  57. case keys.LEFT_ARROW:
  58. case keys.RIGHT_ARROW:
  59. if(editing){ return; }
  60. var offset = (e.keyCode == keys.LEFT_ARROW) ? 1 : -1;
  61. if(html._isBodyLtr()){ offset *= -1; }
  62. focus.currentArea().move(0, offset, e);
  63. break;
  64. case keys.F10:
  65. if(this.menus && e.shiftKey){
  66. this.onRowContextMenu(e);
  67. }
  68. break;
  69. default:
  70. focus.currentArea().keydown(e);
  71. break;
  72. }
  73. },
  74. //TODO - make the following events more reasonalble - e.g. more accurate conditions
  75. //events for row selectors
  76. domouseup: function(e){
  77. if(e.cellNode){
  78. this.onMouseUp(e);
  79. }else{
  80. this.onRowSelectorMouseUp(e);
  81. }
  82. },
  83. domousedown: function(e){
  84. if(!e.cellNode){
  85. this.onRowSelectorMouseDown(e);
  86. }
  87. },
  88. onMouseUp: function(e){
  89. // summary:
  90. // New - Event fired when mouse is up inside grid.
  91. // e: Event
  92. // Decorated event object that contains reference to grid, cell, and rowIndex
  93. this[e.rowIndex == -1 ? "onHeaderCellMouseUp" : "onCellMouseUp"](e);
  94. },
  95. onCellMouseDown: function(e){
  96. // summary:
  97. // Overwritten, see dojox.grid._Events.onCellMouseDown()
  98. html.addClass(e.cellNode, this.cellActiveClass);
  99. html.addClass(e.rowNode, this.rowActiveClass);
  100. },
  101. onCellMouseUp: function(e){
  102. // summary:
  103. // New - Event fired when mouse is up inside content cell.
  104. // e: Event
  105. // Decorated event object that contains reference to grid, cell, and rowIndex
  106. html.removeClass(e.cellNode, this.cellActiveClass);
  107. html.removeClass(e.rowNode, this.rowActiveClass);
  108. },
  109. onCellClick: function(e){
  110. // summary:
  111. // Overwritten, see dojox.grid._Events.onCellClick()
  112. //invoke dojox.grid._Events.onCellClick()
  113. this._events.onCellClick.call(this, e);
  114. //move mouse events to the focus manager.
  115. this.focus.contentMouseEvent(e);//TODO
  116. },
  117. onCellDblClick: function(e){
  118. // summary:
  119. // Overwritten, see dojox.grid._Events.onCellDblClick()
  120. if(this.pluginMgr.isFixedCell(e.cell)){ return; }
  121. if(this._click.length > 1 && (!this._click[0] || !this._click[1])){
  122. this._click[0] = this._click[1] = e;
  123. }
  124. //invoke dojox.grid._Events.onCellDblClick()
  125. this._events.onCellDblClick.call(this, e);
  126. },
  127. onRowClick: function(e){
  128. // summary:
  129. // Overwritten, see dojox.grid._Events.onRowClick()
  130. this.edit.rowClick(e);
  131. if(!e.cell || !this.plugin('indirectSelection')){
  132. this.selection.clickSelectEvent(e);
  133. }
  134. },
  135. onRowContextMenu: function(e){
  136. // summary:
  137. // Overwritten, see dojox.grid._Events.onRowContextMenu()
  138. if(!this.edit.isEditing() && this.menus){
  139. this.showMenu(e);
  140. }
  141. },
  142. onSelectedRegionContextMenu: function(e){
  143. // summary:
  144. // New - Event fired when a selected region context menu is accessed via mouse right click.
  145. // e: Event
  146. // Decorated event object which contains reference to grid and info of selected
  147. // regions(selection type - row|column, selected index - [...])
  148. if(this.selectedRegionMenu){
  149. this.selectedRegionMenu._openMyself({
  150. target: e.target,
  151. coords: e.keyCode !== keys.F10 && "pageX" in e ? {
  152. x: e.pageX,
  153. y: e.pageY
  154. } : null
  155. });
  156. event.stop(e);
  157. }
  158. },
  159. onHeaderCellMouseOut: function(e){
  160. // summary:
  161. // Overwritten, see dojox.grid._Events.onHeaderCellMouseOut()
  162. if(e.cellNode){
  163. html.removeClass(e.cellNode, this.cellOverClass);
  164. html.removeClass(e.cellNode, this.headerCellActiveClass);
  165. }
  166. },
  167. onHeaderCellMouseDown: function(e){
  168. // summary:
  169. // Overwritten, see dojox.grid._Events.onHeaderCellMouseDown()
  170. if(e.cellNode){//TBD - apply to selection region for nested sorting?
  171. html.addClass(e.cellNode, this.headerCellActiveClass);
  172. }
  173. },
  174. onHeaderCellMouseUp: function(e){
  175. // summary:
  176. // New event
  177. if(e.cellNode){
  178. html.removeClass(e.cellNode, this.headerCellActiveClass);
  179. }
  180. },
  181. onHeaderCellClick: function(e){
  182. // summary:
  183. // Overwritten, see dojox.grid._Events.onHeaderCellClick()
  184. //move focus to header.
  185. this.focus.currentArea("header");
  186. //invoke dojox.grid._Events.onHeaderCellClick()
  187. if(!e.cell.isRowSelector){
  188. this._events.onHeaderCellClick.call(this, e);
  189. }
  190. //move mouse events to the focus manager.
  191. this.focus.headerMouseEvent(e);
  192. },
  193. onRowSelectorMouseDown: function(e){
  194. this.focus.focusArea("rowHeader", e);
  195. },
  196. onRowSelectorMouseUp: function(e){},
  197. //triggered in _View, see Selector plugin
  198. onMouseUpRow: function(e){
  199. if(e.rowIndex != -1){
  200. this.onRowMouseUp(e);
  201. }
  202. },
  203. onRowMouseUp: function(e){}
  204. });
  205. });