TreeViewDragDrop.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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-tree-plugin-TreeViewDragDrop'>/**
  19. </span> * This plugin provides drag and/or drop functionality for a TreeView.
  20. *
  21. * It creates a specialized instance of {@link Ext.dd.DragZone DragZone} which knows how to drag out of a
  22. * {@link Ext.tree.View TreeView} and loads the data object which is passed to a cooperating
  23. * {@link Ext.dd.DragZone DragZone}'s methods with the following properties:
  24. *
  25. * - copy : Boolean
  26. *
  27. * The value of the TreeView's `copy` property, or `true` if the TreeView was configured with `allowCopy: true` *and*
  28. * the control key was pressed when the drag operation was begun.
  29. *
  30. * - view : TreeView
  31. *
  32. * The source TreeView from which the drag originated.
  33. *
  34. * - ddel : HtmlElement
  35. *
  36. * The drag proxy element which moves with the mouse
  37. *
  38. * - item : HtmlElement
  39. *
  40. * The TreeView node upon which the mousedown event was registered.
  41. *
  42. * - records : Array
  43. *
  44. * An Array of {@link Ext.data.Model Models} representing the selected data being dragged from the source TreeView.
  45. *
  46. * It also creates a specialized instance of {@link Ext.dd.DropZone} which cooperates with other DropZones which are
  47. * members of the same ddGroup which processes such data objects.
  48. *
  49. * Adding this plugin to a view means that two new events may be fired from the client TreeView, {@link #beforedrop} and
  50. * {@link #drop}.
  51. *
  52. * Note that the plugin must be added to the tree view, not to the tree panel. For example using viewConfig:
  53. *
  54. * viewConfig: {
  55. * plugins: { ptype: 'treeviewdragdrop' }
  56. * }
  57. */
  58. Ext.define('Ext.tree.plugin.TreeViewDragDrop', {
  59. extend: 'Ext.AbstractPlugin',
  60. alias: 'plugin.treeviewdragdrop',
  61. uses: [
  62. 'Ext.tree.ViewDragZone',
  63. 'Ext.tree.ViewDropZone'
  64. ],
  65. <span id='Ext-tree-plugin-TreeViewDragDrop-event-beforedrop'> /**
  66. </span> * @event beforedrop
  67. *
  68. * **This event is fired through the TreeView. Add listeners to the TreeView object**
  69. *
  70. * Fired when a drop gesture has been triggered by a mouseup event in a valid drop position in the TreeView.
  71. *
  72. * @param {HTMLElement} node The TreeView node **if any** over which the mouse was positioned.
  73. *
  74. * Returning `false` to this event signals that the drop gesture was invalid, and if the drag proxy will animate
  75. * back to the point from which the drag began.
  76. *
  77. * Returning `0` To this event signals that the data transfer operation should not take place, but that the gesture
  78. * was valid, and that the repair operation should not take place.
  79. *
  80. * Any other return value continues with the data transfer operation.
  81. *
  82. * @param {Object} data The data object gathered at mousedown time by the cooperating
  83. * {@link Ext.dd.DragZone DragZone}'s {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following
  84. * properties:
  85. * @param {Boolean} data.copy The value of the TreeView's `copy` property, or `true` if the TreeView was configured with
  86. * `allowCopy: true` and the control key was pressed when the drag operation was begun
  87. * @param {Ext.tree.View} data.view The source TreeView from which the drag originated.
  88. * @param {HTMLElement} data.ddel The drag proxy element which moves with the mouse
  89. * @param {HTMLElement} data.item The TreeView node upon which the mousedown event was registered.
  90. * @param {Ext.data.Model[]} data.records An Array of {@link Ext.data.Model Model}s representing the selected data being
  91. * dragged from the source TreeView.
  92. *
  93. * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
  94. *
  95. * @param {String} dropPosition `&quot;before&quot;`, `&quot;after&quot;` or `&quot;append&quot;` depending on whether the mouse is above or below
  96. * the midline of the node, or the node is a branch node which accepts new child nodes.
  97. *
  98. * @param {Object} dropHandler An object containing methods to complete/cancel the data transfer operation and either
  99. * move or copy Model instances from the source View's Store to the destination View's Store.
  100. *
  101. * This is useful when you want to perform some kind of asynchronous processing before confirming/cancelling
  102. * the drop, such as an {@link Ext.window.MessageBox#confirm confirm} call, or an Ajax request.
  103. *
  104. * Set dropHandler.wait = true in this event handler to delay processing. When you want to complete the event, call
  105. * dropHandler.processDrop(). To cancel the drop, call dropHandler.cancelDrop.
  106. */
  107. <span id='Ext-tree-plugin-TreeViewDragDrop-event-drop'> /**
  108. </span> * @event drop
  109. *
  110. * **This event is fired through the TreeView. Add listeners to the TreeView object** Fired when a drop operation
  111. * has been completed and the data has been moved or copied.
  112. *
  113. * @param {HTMLElement} node The TreeView node **if any** over which the mouse was positioned.
  114. *
  115. * @param {Object} data The data object gathered at mousedown time by the cooperating
  116. * {@link Ext.dd.DragZone DragZone}'s {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following
  117. * properties:
  118. * @param {Boolean} data.copy The value of the TreeView's `copy` property, or `true` if the TreeView was configured with
  119. * `allowCopy: true` and the control key was pressed when the drag operation was begun
  120. * @param {Ext.tree.View} data.view The source TreeView from which the drag originated.
  121. * @param {HTMLElement} data.ddel The drag proxy element which moves with the mouse
  122. * @param {HTMLElement} data.item The TreeView node upon which the mousedown event was registered.
  123. * @param {Ext.data.Model[]} data.records An Array of {@link Ext.data.Model Model}s representing the selected data being
  124. * dragged from the source TreeView.
  125. *
  126. * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
  127. *
  128. * @param {String} dropPosition `&quot;before&quot;`, `&quot;after&quot;` or `&quot;append&quot;` depending on whether the mouse is above or below
  129. * the midline of the node, or the node is a branch node which accepts new child nodes.
  130. */
  131. //&lt;locale&gt;
  132. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-dragText'> /**
  133. </span> * @cfg
  134. * The text to show while dragging.
  135. *
  136. * Two placeholders can be used in the text:
  137. *
  138. * - `{0}` The number of selected items.
  139. * - `{1}` 's' when more than 1 items (only useful for English).
  140. */
  141. dragText : '{0} selected node{1}',
  142. //&lt;/locale&gt;
  143. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-allowParentInserts'> /**
  144. </span> * @cfg {Boolean} allowParentInserts
  145. * Allow inserting a dragged node between an expanded parent node and its first child that will become a sibling of
  146. * the parent when dropped.
  147. */
  148. allowParentInserts: false,
  149. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-allowContainerDrops'> /**
  150. </span> * @cfg {Boolean} allowContainerDrops
  151. * True if drops on the tree container (outside of a specific tree node) are allowed.
  152. */
  153. allowContainerDrops: false,
  154. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-appendOnly'> /**
  155. </span> * @cfg {Boolean} appendOnly
  156. * True if the tree should only allow append drops (use for trees which are sorted).
  157. */
  158. appendOnly: false,
  159. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-ddGroup'> /**
  160. </span> * @cfg {String} ddGroup
  161. * A named drag drop group to which this object belongs. If a group is specified, then both the DragZones and
  162. * DropZone used by this plugin will only interact with other drag drop objects in the same group.
  163. */
  164. ddGroup : &quot;TreeDD&quot;,
  165. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-dragGroup'> /**
  166. </span> * @cfg {String} dragGroup
  167. * The ddGroup to which the DragZone will belong.
  168. *
  169. * This defines which other DropZones the DragZone will interact with. Drag/DropZones only interact with other
  170. * Drag/DropZones which are members of the same ddGroup.
  171. */
  172. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-dropGroup'> /**
  173. </span> * @cfg {String} dropGroup
  174. * The ddGroup to which the DropZone will belong.
  175. *
  176. * This defines which other DragZones the DropZone will interact with. Drag/DropZones only interact with other
  177. * Drag/DropZones which are members of the same ddGroup.
  178. */
  179. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-expandDelay'> /**
  180. </span> * @cfg {String} expandDelay
  181. * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node over the
  182. * target.
  183. */
  184. expandDelay : 1000,
  185. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-enableDrop'> /**
  186. </span> * @cfg {Boolean} enableDrop
  187. * Set to `false` to disallow the View from accepting drop gestures.
  188. */
  189. enableDrop: true,
  190. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-enableDrag'> /**
  191. </span> * @cfg {Boolean} enableDrag
  192. * Set to `false` to disallow dragging items from the View.
  193. */
  194. enableDrag: true,
  195. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-nodeHighlightColor'> /**
  196. </span> * @cfg {String} nodeHighlightColor
  197. * The color to use when visually highlighting the dragged or dropped node (default value is light blue).
  198. * The color must be a 6 digit hex value, without a preceding '#'. See also {@link #nodeHighlightOnDrop} and
  199. * {@link #nodeHighlightOnRepair}.
  200. */
  201. nodeHighlightColor: 'c3daf9',
  202. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-nodeHighlightOnDrop'> /**
  203. </span> * @cfg {Boolean} nodeHighlightOnDrop
  204. * Whether or not to highlight any nodes after they are
  205. * successfully dropped on their target. Defaults to the value of `Ext.enableFx`.
  206. * See also {@link #nodeHighlightColor} and {@link #nodeHighlightOnRepair}.
  207. */
  208. nodeHighlightOnDrop: Ext.enableFx,
  209. <span id='Ext-tree-plugin-TreeViewDragDrop-cfg-nodeHighlightOnRepair'> /**
  210. </span> * @cfg {Boolean} nodeHighlightOnRepair
  211. * Whether or not to highlight any nodes after they are
  212. * repaired from an unsuccessful drag/drop. Defaults to the value of `Ext.enableFx`.
  213. * See also {@link #nodeHighlightColor} and {@link #nodeHighlightOnDrop}.
  214. */
  215. nodeHighlightOnRepair: Ext.enableFx,
  216. init : function(view) {
  217. view.on('render', this.onViewRender, this, {single: true});
  218. },
  219. <span id='Ext-tree-plugin-TreeViewDragDrop-method-destroy'> /**
  220. </span> * @private
  221. * AbstractComponent calls destroy on all its plugins at destroy time.
  222. */
  223. destroy: function() {
  224. Ext.destroy(this.dragZone, this.dropZone);
  225. },
  226. onViewRender : function(view) {
  227. var me = this;
  228. if (me.enableDrag) {
  229. me.dragZone = new Ext.tree.ViewDragZone({
  230. view: view,
  231. ddGroup: me.dragGroup || me.ddGroup,
  232. dragText: me.dragText,
  233. repairHighlightColor: me.nodeHighlightColor,
  234. repairHighlight: me.nodeHighlightOnRepair
  235. });
  236. }
  237. if (me.enableDrop) {
  238. me.dropZone = new Ext.tree.ViewDropZone({
  239. view: view,
  240. ddGroup: me.dropGroup || me.ddGroup,
  241. allowContainerDrops: me.allowContainerDrops,
  242. appendOnly: me.appendOnly,
  243. allowParentInserts: me.allowParentInserts,
  244. expandDelay: me.expandDelay,
  245. dropHighlightColor: me.nodeHighlightColor,
  246. dropHighlight: me.nodeHighlightOnDrop
  247. });
  248. }
  249. }
  250. });
  251. </pre>
  252. </body>
  253. </html>