_Events.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.grid.enhanced._Events"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.grid.enhanced._Events"] = true;
  8. dojo.provide("dojox.grid.enhanced._Events");
  9. dojo.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. //get the default Grid events
  30. this._events = new dojox.grid._Events();
  31. //for methods that won't be overwritten, copy them to "this" scope
  32. for(var p in this._events){
  33. if(!this[p]){
  34. this.p = this._events.p;
  35. }
  36. }
  37. //mixin "this" to Grid
  38. inGrid.mixin(inGrid, this);
  39. },
  40. dokeyup: function(e){
  41. // summary:
  42. // Grid key up event handler.
  43. // e: Event
  44. // Un-decorated event object
  45. this.focus.currentArea().keyup(e);
  46. },
  47. onKeyDown: function(e){
  48. // summary:
  49. // Overwritten, see dojox.grid._Events.onKeyDown();
  50. if(e.altKey || e.metaKey){ return; }
  51. var dk = dojo.keys;
  52. var focus = this.focus;
  53. var editing = this.edit.isEditing();
  54. switch(e.keyCode){
  55. case dk.TAB:
  56. if(e.ctrlKey){ return; }
  57. focus.tab(e.shiftKey ? -1:1,e);
  58. break;
  59. case dk.UP_ARROW:
  60. case dk.DOWN_ARROW:
  61. if(editing){ return; }
  62. focus.currentArea().move(e.keyCode == dk.UP_ARROW ? -1 : 1, 0, e);
  63. break;
  64. case dk.LEFT_ARROW:
  65. case dk.RIGHT_ARROW:
  66. if(editing){ return; }
  67. var offset = (e.keyCode == dk.LEFT_ARROW) ? 1 : -1;
  68. if(dojo._isBodyLtr()){ offset *= -1; }
  69. focus.currentArea().move(0, offset, e);
  70. break;
  71. case dk.F10:
  72. if(this.menus && e.shiftKey){
  73. this.onRowContextMenu(e);
  74. }
  75. break;
  76. default:
  77. focus.currentArea().keydown(e);
  78. break;
  79. }
  80. },
  81. //TODO - make the following events more reasonalble - e.g. more accurate conditions
  82. //events for row selectors
  83. domouseup: function(e){
  84. if(e.cellNode){
  85. this.onMouseUp(e);
  86. }else{
  87. this.onRowSelectorMouseUp(e);
  88. }
  89. },
  90. domousedown: function(e){
  91. if(!e.cellNode){
  92. this.onRowSelectorMouseDown(e);
  93. }
  94. },
  95. onMouseUp: function(e){
  96. // summary:
  97. // New - Event fired when mouse is up inside grid.
  98. // e: Event
  99. // Decorated event object that contains reference to grid, cell, and rowIndex
  100. this[e.rowIndex == -1 ? "onHeaderCellMouseUp" : "onCellMouseUp"](e);
  101. },
  102. onCellMouseDown: function(e){
  103. // summary:
  104. // Overwritten, see dojox.grid._Events.onCellMouseDown()
  105. dojo.addClass(e.cellNode, this.cellActiveClass);
  106. dojo.addClass(e.rowNode, this.rowActiveClass);
  107. },
  108. onCellMouseUp: function(e){
  109. // summary:
  110. // New - Event fired when mouse is up inside content cell.
  111. // e: Event
  112. // Decorated event object that contains reference to grid, cell, and rowIndex
  113. dojo.removeClass(e.cellNode, this.cellActiveClass);
  114. dojo.removeClass(e.rowNode, this.rowActiveClass);
  115. },
  116. onCellClick: function(e){
  117. // summary:
  118. // Overwritten, see dojox.grid._Events.onCellClick()
  119. //invoke dojox.grid._Events.onCellClick()
  120. this._events.onCellClick.call(this, e);
  121. //move mouse events to the focus manager.
  122. this.focus.contentMouseEvent(e);//TODO
  123. },
  124. onCellDblClick: function(e){
  125. // summary:
  126. // Overwritten, see dojox.grid._Events.onCellDblClick()
  127. if(this.pluginMgr.isFixedCell(e.cell)){ return; }
  128. if(this._click.length > 1 && (!this._click[0] || !this._click[1])){
  129. this._click[0] = this._click[1] = e;
  130. }
  131. //invoke dojox.grid._Events.onCellDblClick()
  132. this._events.onCellDblClick.call(this, e);
  133. //now focus.setFocusCell need isEditing info, so call it after that is set.
  134. //this.focus.setFocusCell(e.cell, e.rowIndex);
  135. },
  136. onRowClick: function(e){
  137. // summary:
  138. // Overwritten, see dojox.grid._Events.onRowClick()
  139. this.edit.rowClick(e);
  140. if(!e.cell || (!e.cell.isRowSelector && (!this.rowSelectCell || !this.rowSelectCell.disabled(e.rowIndex)))){
  141. this.selection.clickSelectEvent(e);
  142. }
  143. },
  144. onRowContextMenu: function(e){
  145. // summary:
  146. // Overwritten, see dojox.grid._Events.onRowContextMenu()
  147. if(!this.edit.isEditing() && this.menus){
  148. this.showMenu(e);
  149. }
  150. },
  151. onSelectedRegionContextMenu: function(e){
  152. // summary:
  153. // New - Event fired when a selected region context menu is accessed via mouse right click.
  154. // e: Event
  155. // Decorated event object which contains reference to grid and info of selected
  156. // regions(selection type - row|column, selected index - [...])
  157. if(this.selectedRegionMenu){
  158. this.selectedRegionMenu._openMyself({
  159. target: e.target,
  160. coords: e.keyCode !== dojo.keys.F10 && "pageX" in e ? {
  161. x: e.pageX,
  162. y: e.pageY
  163. } : null
  164. });
  165. dojo.stopEvent(e);
  166. }
  167. },
  168. onHeaderCellMouseOut: function(e){
  169. // summary:
  170. // Overwritten, see dojox.grid._Events.onHeaderCellMouseOut()
  171. if(e.cellNode){
  172. dojo.removeClass(e.cellNode, this.cellOverClass);
  173. dojo.removeClass(e.cellNode, this.headerCellActiveClass);
  174. }
  175. },
  176. onHeaderCellMouseDown: function(e){
  177. // summary:
  178. // Overwritten, see dojox.grid._Events.onHeaderCellMouseDown()
  179. if(e.cellNode){//TBD - apply to selection region for nested sorting?
  180. dojo.addClass(e.cellNode, this.headerCellActiveClass);
  181. }
  182. },
  183. onHeaderCellMouseUp: function(e){
  184. // summary:
  185. // New event
  186. if(e.cellNode){
  187. dojo.removeClass(e.cellNode, this.headerCellActiveClass);
  188. }
  189. },
  190. onHeaderCellClick: function(e){
  191. // summary:
  192. // Overwritten, see dojox.grid._Events.onHeaderCellClick()
  193. //move focus to header.
  194. this.focus.currentArea("header");
  195. //invoke dojox.grid._Events.onHeaderCellClick()
  196. if(!e.cell.isRowSelector){
  197. this._events.onHeaderCellClick.call(this, e);
  198. }
  199. //move mouse events to the focus manager.
  200. this.focus.headerMouseEvent(e);
  201. },
  202. onRowSelectorMouseDown: function(e){
  203. this.focus.focusArea("rowHeader", e);
  204. },
  205. onRowSelectorMouseUp: function(e){},
  206. //triggered in _View, see Selector plugin
  207. onMouseUpRow: function(e){
  208. if(e.rowIndex != -1){
  209. this.onRowMouseUp(e);
  210. }
  211. },
  212. onRowMouseUp: function(e){}
  213. });
  214. }