You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
14 KiB

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