PageRenderTime 90ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/rxwandc/application/admin.rxwan.com/extjs/src/dd/DropZone.js

https://bitbucket.org/i1598/caiyun_stat
JavaScript | 254 lines | 63 code | 14 blank | 177 comment | 7 complexity | 50491b403134ed42171e847c739d69ee MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /**
  2. * This class provides a container DD instance that allows dropping on multiple child target nodes.
  3. *
  4. * By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}.
  5. * However a simpler way to allow a DropZone to manage any number of target elements is to configure the
  6. * DropZone with an implementation of {@link #getTargetFromEvent} which interrogates the passed
  7. * mouse event to see if it has taken place within an element, or class of elements. This is easily done
  8. * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
  9. * {@link Ext.DomQuery} selector.
  10. *
  11. * Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over
  12. * a drop target, that target is passed as the first parameter to {@link #onNodeEnter}, {@link #onNodeOver},
  13. * {@link #onNodeOut}, {@link #onNodeDrop}. You may configure the instance of DropZone with implementations
  14. * of these methods to provide application-specific behaviour for these events to update both
  15. * application state, and UI state.
  16. *
  17. * For example to make a GridPanel a cooperating target with the example illustrated in
  18. * {@link Ext.dd.DragZone DragZone}, the following technique might be used:
  19. *
  20. * myGridPanel.on('render', function() {
  21. * myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, {
  22. *
  23. * // If the mouse is over a grid row, return that node. This is
  24. * // provided as the "target" parameter in all "onNodeXXXX" node event handling functions
  25. * getTargetFromEvent: function(e) {
  26. * return e.getTarget(myGridPanel.getView().rowSelector);
  27. * },
  28. *
  29. * // On entry into a target node, highlight that node.
  30. * onNodeEnter : function(target, dd, e, data){
  31. * Ext.fly(target).addCls('my-row-highlight-class');
  32. * },
  33. *
  34. * // On exit from a target node, unhighlight that node.
  35. * onNodeOut : function(target, dd, e, data){
  36. * Ext.fly(target).removeCls('my-row-highlight-class');
  37. * },
  38. *
  39. * // While over a target node, return the default drop allowed class which
  40. * // places a "tick" icon into the drag proxy.
  41. * onNodeOver : function(target, dd, e, data){
  42. * return Ext.dd.DropZone.prototype.dropAllowed;
  43. * },
  44. *
  45. * // On node drop we can interrogate the target to find the underlying
  46. * // application object that is the real target of the dragged data.
  47. * // In this case, it is a Record in the GridPanel's Store.
  48. * // We can use the data set up by the DragZone's getDragData method to read
  49. * // any data we decided to attach in the DragZone's getDragData method.
  50. * onNodeDrop : function(target, dd, e, data){
  51. * var rowIndex = myGridPanel.getView().findRowIndex(target);
  52. * var r = myGridPanel.getStore().getAt(rowIndex);
  53. * Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id +
  54. * ' on Record id ' + r.id);
  55. * return true;
  56. * }
  57. * });
  58. * }
  59. *
  60. * See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which
  61. * cooperates with this DropZone.
  62. */
  63. Ext.define('Ext.dd.DropZone', {
  64. extend: 'Ext.dd.DropTarget',
  65. requires: ['Ext.dd.Registry'],
  66. /**
  67. * Returns a custom data object associated with the DOM node that is the target of the event. By default
  68. * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to
  69. * provide your own custom lookup.
  70. * @param {Event} e The event
  71. * @return {Object} data The custom data
  72. */
  73. getTargetFromEvent : function(e){
  74. return Ext.dd.Registry.getTargetFromEvent(e);
  75. },
  76. /**
  77. * Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node
  78. * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
  79. * This method has no default implementation and should be overridden to provide
  80. * node-specific processing if necessary.
  81. * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
  82. * {@link #getTargetFromEvent} for this node)
  83. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  84. * @param {Event} e The event
  85. * @param {Object} data An object containing arbitrary data supplied by the drag source
  86. */
  87. onNodeEnter : function(n, dd, e, data){
  88. },
  89. /**
  90. * Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node
  91. * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
  92. * The default implementation returns this.dropNotAllowed, so it should be
  93. * overridden to provide the proper feedback.
  94. * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
  95. * {@link #getTargetFromEvent} for this node)
  96. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  97. * @param {Event} e The event
  98. * @param {Object} data An object containing arbitrary data supplied by the drag source
  99. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  100. * underlying {@link Ext.dd.StatusProxy} can be updated
  101. */
  102. onNodeOver : function(n, dd, e, data){
  103. return this.dropAllowed;
  104. },
  105. /**
  106. * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of
  107. * the drop node without dropping. This method has no default implementation and should be overridden to provide
  108. * node-specific processing if necessary.
  109. * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
  110. * {@link #getTargetFromEvent} for this node)
  111. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  112. * @param {Event} e The event
  113. * @param {Object} data An object containing arbitrary data supplied by the drag source
  114. */
  115. onNodeOut : function(n, dd, e, data){
  116. },
  117. /**
  118. * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto
  119. * the drop node. The default implementation returns false, so it should be overridden to provide the
  120. * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
  121. * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
  122. * {@link #getTargetFromEvent} for this node)
  123. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  124. * @param {Event} e The event
  125. * @param {Object} data An object containing arbitrary data supplied by the drag source
  126. * @return {Boolean} True if the drop was valid, else false
  127. */
  128. onNodeDrop : function(n, dd, e, data){
  129. return false;
  130. },
  131. /**
  132. * Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,
  133. * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
  134. * it should be overridden to provide the proper feedback if necessary.
  135. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  136. * @param {Event} e The event
  137. * @param {Object} data An object containing arbitrary data supplied by the drag source
  138. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  139. * underlying {@link Ext.dd.StatusProxy} can be updated
  140. */
  141. onContainerOver : function(dd, e, data){
  142. return this.dropNotAllowed;
  143. },
  144. /**
  145. * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,
  146. * but not on any of its registered drop nodes. The default implementation returns false, so it should be
  147. * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
  148. * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
  149. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  150. * @param {Event} e The event
  151. * @param {Object} data An object containing arbitrary data supplied by the drag source
  152. * @return {Boolean} True if the drop was valid, else false
  153. */
  154. onContainerDrop : function(dd, e, data){
  155. return false;
  156. },
  157. /**
  158. * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over
  159. * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
  160. * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
  161. * you should override this method and provide a custom implementation.
  162. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  163. * @param {Event} e The event
  164. * @param {Object} data An object containing arbitrary data supplied by the drag source
  165. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  166. * underlying {@link Ext.dd.StatusProxy} can be updated
  167. */
  168. notifyEnter : function(dd, e, data){
  169. return this.dropNotAllowed;
  170. },
  171. /**
  172. * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.
  173. * This method will be called on every mouse movement while the drag source is over the drop zone.
  174. * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
  175. * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
  176. * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
  177. * registered node, it will call {@link #onContainerOver}.
  178. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  179. * @param {Event} e The event
  180. * @param {Object} data An object containing arbitrary data supplied by the drag source
  181. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  182. * underlying {@link Ext.dd.StatusProxy} can be updated
  183. */
  184. notifyOver : function(dd, e, data){
  185. var n = this.getTargetFromEvent(e);
  186. if(!n) { // not over valid drop target
  187. if(this.lastOverNode){
  188. this.onNodeOut(this.lastOverNode, dd, e, data);
  189. this.lastOverNode = null;
  190. }
  191. return this.onContainerOver(dd, e, data);
  192. }
  193. if(this.lastOverNode != n){
  194. if(this.lastOverNode){
  195. this.onNodeOut(this.lastOverNode, dd, e, data);
  196. }
  197. this.onNodeEnter(n, dd, e, data);
  198. this.lastOverNode = n;
  199. }
  200. return this.onNodeOver(n, dd, e, data);
  201. },
  202. /**
  203. * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged
  204. * out of the zone without dropping. If the drag source is currently over a registered node, the notification
  205. * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
  206. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
  207. * @param {Event} e The event
  208. * @param {Object} data An object containing arbitrary data supplied by the drag zone
  209. */
  210. notifyOut : function(dd, e, data){
  211. if(this.lastOverNode){
  212. this.onNodeOut(this.lastOverNode, dd, e, data);
  213. this.lastOverNode = null;
  214. }
  215. },
  216. /**
  217. * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has
  218. * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
  219. * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
  220. * otherwise it will call {@link #onContainerDrop}.
  221. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  222. * @param {Event} e The event
  223. * @param {Object} data An object containing arbitrary data supplied by the drag source
  224. * @return {Boolean} False if the drop was invalid.
  225. */
  226. notifyDrop : function(dd, e, data){
  227. if(this.lastOverNode){
  228. this.onNodeOut(this.lastOverNode, dd, e, data);
  229. this.lastOverNode = null;
  230. }
  231. var n = this.getTargetFromEvent(e);
  232. return n ?
  233. this.onNodeDrop(n, dd, e, data) :
  234. this.onContainerDrop(dd, e, data);
  235. },
  236. // private
  237. triggerCacheRefresh : function() {
  238. Ext.dd.DDM.refreshCache(this.groups);
  239. }
  240. });