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.

334 lines
12 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-tree-TreeDropZone-method-constructor'><span id='Ext-tree-TreeDropZone'>/**
  19. </span></span> * @class Ext.tree.TreeDropZone
  20. * @extends Ext.dd.DropZone
  21. * @constructor
  22. * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dropping
  23. * @param {Object} config
  24. */
  25. if(Ext.dd.DropZone){
  26. Ext.tree.TreeDropZone = function(tree, config){
  27. <span id='Ext-tree-TreeDropZone-cfg-allowParentInsert'> /**
  28. </span> * @cfg {Boolean} allowParentInsert
  29. * Allow inserting a dragged node between an expanded parent node and its first child that will become a
  30. * sibling of the parent when dropped (defaults to false)
  31. */
  32. this.allowParentInsert = config.allowParentInsert || false;
  33. <span id='Ext-tree-TreeDropZone-cfg-allowContainerDrop'> /**
  34. </span> * @cfg {String} allowContainerDrop
  35. * True if drops on the tree container (outside of a specific tree node) are allowed (defaults to false)
  36. */
  37. this.allowContainerDrop = config.allowContainerDrop || false;
  38. <span id='Ext-tree-TreeDropZone-cfg-appendOnly'> /**
  39. </span> * @cfg {String} appendOnly
  40. * True if the tree should only allow append drops (use for trees which are sorted, defaults to false)
  41. */
  42. this.appendOnly = config.appendOnly || false;
  43. Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.getTreeEl(), config);
  44. <span id='Ext-tree-TreeDropZone-property-tree'> /**
  45. </span> * The TreePanel for this drop zone
  46. * @type Ext.tree.TreePanel
  47. * @property
  48. */
  49. this.tree = tree;
  50. <span id='Ext-tree-TreeDropZone-property-dragOverData'> /**
  51. </span> * Arbitrary data that can be associated with this tree and will be included in the event object that gets
  52. * passed to any nodedragover event handler (defaults to {})
  53. * @type Ext.tree.TreePanel
  54. * @property
  55. */
  56. this.dragOverData = {};
  57. // private
  58. this.lastInsertClass = &quot;x-tree-no-status&quot;;
  59. };
  60. Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, {
  61. <span id='Ext-tree-TreeDropZone-cfg-ddGroup'> /**
  62. </span> * @cfg {String} ddGroup
  63. * A named drag drop group to which this object belongs. If a group is specified, then this object will only
  64. * interact with other drag drop objects in the same group (defaults to 'TreeDD').
  65. */
  66. ddGroup : &quot;TreeDD&quot;,
  67. <span id='Ext-tree-TreeDropZone-cfg-expandDelay'> /**
  68. </span> * @cfg {String} expandDelay
  69. * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node
  70. * over the target (defaults to 1000)
  71. */
  72. expandDelay : 1000,
  73. // private
  74. expandNode : function(node){
  75. if(node.hasChildNodes() &amp;&amp; !node.isExpanded()){
  76. node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
  77. }
  78. },
  79. // private
  80. queueExpand : function(node){
  81. this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
  82. },
  83. // private
  84. cancelExpand : function(){
  85. if(this.expandProcId){
  86. clearTimeout(this.expandProcId);
  87. this.expandProcId = false;
  88. }
  89. },
  90. // private
  91. isValidDropPoint : function(n, pt, dd, e, data){
  92. if(!n || !data){ return false; }
  93. var targetNode = n.node;
  94. var dropNode = data.node;
  95. // default drop rules
  96. if(!(targetNode &amp;&amp; targetNode.isTarget &amp;&amp; pt)){
  97. return false;
  98. }
  99. if(pt == &quot;append&quot; &amp;&amp; targetNode.allowChildren === false){
  100. return false;
  101. }
  102. if((pt == &quot;above&quot; || pt == &quot;below&quot;) &amp;&amp; (targetNode.parentNode &amp;&amp; targetNode.parentNode.allowChildren === false)){
  103. return false;
  104. }
  105. if(dropNode &amp;&amp; (targetNode == dropNode || dropNode.contains(targetNode))){
  106. return false;
  107. }
  108. // reuse the object
  109. var overEvent = this.dragOverData;
  110. overEvent.tree = this.tree;
  111. overEvent.target = targetNode;
  112. overEvent.data = data;
  113. overEvent.point = pt;
  114. overEvent.source = dd;
  115. overEvent.rawEvent = e;
  116. overEvent.dropNode = dropNode;
  117. overEvent.cancel = false;
  118. var result = this.tree.fireEvent(&quot;nodedragover&quot;, overEvent);
  119. return overEvent.cancel === false &amp;&amp; result !== false;
  120. },
  121. // private
  122. getDropPoint : function(e, n, dd){
  123. var tn = n.node;
  124. if(tn.isRoot){
  125. return tn.allowChildren !== false ? &quot;append&quot; : false; // always append for root
  126. }
  127. var dragEl = n.ddel;
  128. var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
  129. var y = Ext.lib.Event.getPageY(e);
  130. var noAppend = tn.allowChildren === false || tn.isLeaf();
  131. if(this.appendOnly || tn.parentNode.allowChildren === false){
  132. return noAppend ? false : &quot;append&quot;;
  133. }
  134. var noBelow = false;
  135. if(!this.allowParentInsert){
  136. noBelow = tn.hasChildNodes() &amp;&amp; tn.isExpanded();
  137. }
  138. var q = (b - t) / (noAppend ? 2 : 3);
  139. if(y &gt;= t &amp;&amp; y &lt; (t + q)){
  140. return &quot;above&quot;;
  141. }else if(!noBelow &amp;&amp; (noAppend || y &gt;= b-q &amp;&amp; y &lt;= b)){
  142. return &quot;below&quot;;
  143. }else{
  144. return &quot;append&quot;;
  145. }
  146. },
  147. // private
  148. onNodeEnter : function(n, dd, e, data){
  149. this.cancelExpand();
  150. },
  151. onContainerOver : function(dd, e, data) {
  152. if (this.allowContainerDrop &amp;&amp; this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, &quot;append&quot;, dd, e, data)) {
  153. return this.dropAllowed;
  154. }
  155. return this.dropNotAllowed;
  156. },
  157. // private
  158. onNodeOver : function(n, dd, e, data){
  159. var pt = this.getDropPoint(e, n, dd);
  160. var node = n.node;
  161. // auto node expand check
  162. if(!this.expandProcId &amp;&amp; pt == &quot;append&quot; &amp;&amp; node.hasChildNodes() &amp;&amp; !n.node.isExpanded()){
  163. this.queueExpand(node);
  164. }else if(pt != &quot;append&quot;){
  165. this.cancelExpand();
  166. }
  167. // set the insert point style on the target node
  168. var returnCls = this.dropNotAllowed;
  169. if(this.isValidDropPoint(n, pt, dd, e, data)){
  170. if(pt){
  171. var el = n.ddel;
  172. var cls;
  173. if(pt == &quot;above&quot;){
  174. returnCls = n.node.isFirst() ? &quot;x-tree-drop-ok-above&quot; : &quot;x-tree-drop-ok-between&quot;;
  175. cls = &quot;x-tree-drag-insert-above&quot;;
  176. }else if(pt == &quot;below&quot;){
  177. returnCls = n.node.isLast() ? &quot;x-tree-drop-ok-below&quot; : &quot;x-tree-drop-ok-between&quot;;
  178. cls = &quot;x-tree-drag-insert-below&quot;;
  179. }else{
  180. returnCls = &quot;x-tree-drop-ok-append&quot;;
  181. cls = &quot;x-tree-drag-append&quot;;
  182. }
  183. if(this.lastInsertClass != cls){
  184. Ext.fly(el).replaceClass(this.lastInsertClass, cls);
  185. this.lastInsertClass = cls;
  186. }
  187. }
  188. }
  189. return returnCls;
  190. },
  191. // private
  192. onNodeOut : function(n, dd, e, data){
  193. this.cancelExpand();
  194. this.removeDropIndicators(n);
  195. },
  196. // private
  197. onNodeDrop : function(n, dd, e, data){
  198. var point = this.getDropPoint(e, n, dd);
  199. var targetNode = n.node;
  200. targetNode.ui.startDrop();
  201. if(!this.isValidDropPoint(n, point, dd, e, data)){
  202. targetNode.ui.endDrop();
  203. return false;
  204. }
  205. // first try to find the drop node
  206. var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
  207. return this.processDrop(targetNode, data, point, dd, e, dropNode);
  208. },
  209. onContainerDrop : function(dd, e, data){
  210. if (this.allowContainerDrop &amp;&amp; this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, &quot;append&quot;, dd, e, data)) {
  211. var targetNode = this.tree.getRootNode();
  212. targetNode.ui.startDrop();
  213. var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, 'append', e) : null);
  214. return this.processDrop(targetNode, data, 'append', dd, e, dropNode);
  215. }
  216. return false;
  217. },
  218. // private
  219. processDrop: function(target, data, point, dd, e, dropNode){
  220. var dropEvent = {
  221. tree : this.tree,
  222. target: target,
  223. data: data,
  224. point: point,
  225. source: dd,
  226. rawEvent: e,
  227. dropNode: dropNode,
  228. cancel: !dropNode,
  229. dropStatus: false
  230. };
  231. var retval = this.tree.fireEvent(&quot;beforenodedrop&quot;, dropEvent);
  232. if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
  233. target.ui.endDrop();
  234. return dropEvent.dropStatus;
  235. }
  236. target = dropEvent.target;
  237. if(point == 'append' &amp;&amp; !target.isExpanded()){
  238. target.expand(false, null, function(){
  239. this.completeDrop(dropEvent);
  240. }.createDelegate(this));
  241. }else{
  242. this.completeDrop(dropEvent);
  243. }
  244. return true;
  245. },
  246. // private
  247. completeDrop : function(de){
  248. var ns = de.dropNode, p = de.point, t = de.target;
  249. if(!Ext.isArray(ns)){
  250. ns = [ns];
  251. }
  252. var n;
  253. for(var i = 0, len = ns.length; i &lt; len; i++){
  254. n = ns[i];
  255. if(p == &quot;above&quot;){
  256. t.parentNode.insertBefore(n, t);
  257. }else if(p == &quot;below&quot;){
  258. t.parentNode.insertBefore(n, t.nextSibling);
  259. }else{
  260. t.appendChild(n);
  261. }
  262. }
  263. n.ui.focus();
  264. if(Ext.enableFx &amp;&amp; this.tree.hlDrop){
  265. n.ui.highlight();
  266. }
  267. t.ui.endDrop();
  268. this.tree.fireEvent(&quot;nodedrop&quot;, de);
  269. },
  270. // private
  271. afterNodeMoved : function(dd, data, e, targetNode, dropNode){
  272. if(Ext.enableFx &amp;&amp; this.tree.hlDrop){
  273. dropNode.ui.focus();
  274. dropNode.ui.highlight();
  275. }
  276. this.tree.fireEvent(&quot;nodedrop&quot;, this.tree, targetNode, data, dd, e);
  277. },
  278. // private
  279. getTree : function(){
  280. return this.tree;
  281. },
  282. // private
  283. removeDropIndicators : function(n){
  284. if(n &amp;&amp; n.ddel){
  285. var el = n.ddel;
  286. Ext.fly(el).removeClass([
  287. &quot;x-tree-drag-insert-above&quot;,
  288. &quot;x-tree-drag-insert-below&quot;,
  289. &quot;x-tree-drag-append&quot;]);
  290. this.lastInsertClass = &quot;_noclass&quot;;
  291. }
  292. },
  293. // private
  294. beforeDragDrop : function(target, e, id){
  295. this.cancelExpand();
  296. return true;
  297. },
  298. // private
  299. afterRepair : function(data){
  300. if(data &amp;&amp; Ext.enableFx){
  301. data.node.ui.highlight();
  302. }
  303. this.hideProxy();
  304. }
  305. });
  306. }</pre>
  307. </body>
  308. </html>