Web UI for ARGUS server
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.

330 lines
11 KiB

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