Web Interface For Lite Argus Control modules
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.

842 lines
28 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.data.Tree"></div>/**
  16. * @class Ext.data.Tree
  17. * @extends Ext.util.Observable
  18. * Represents a tree data structure and bubbles all the events for its nodes. The nodes
  19. * in the tree have most standard DOM functionality.
  20. * @constructor
  21. * @param {Node} root (optional) The root node
  22. */
  23. Ext.data.Tree = Ext.extend(Ext.util.Observable, {
  24. constructor: function(root){
  25. this.nodeHash = {};
  26. <div id="prop-Ext.data.Tree-root"></div>/**
  27. * The root node for this tree
  28. * @type Node
  29. */
  30. this.root = null;
  31. if(root){
  32. this.setRootNode(root);
  33. }
  34. this.addEvents(
  35. <div id="event-Ext.data.Tree-append"></div>/**
  36. * @event append
  37. * Fires when a new child node is appended to a node in this tree.
  38. * @param {Tree} tree The owner tree
  39. * @param {Node} parent The parent node
  40. * @param {Node} node The newly appended node
  41. * @param {Number} index The index of the newly appended node
  42. */
  43. "append",
  44. <div id="event-Ext.data.Tree-remove"></div>/**
  45. * @event remove
  46. * Fires when a child node is removed from a node in this tree.
  47. * @param {Tree} tree The owner tree
  48. * @param {Node} parent The parent node
  49. * @param {Node} node The child node removed
  50. */
  51. "remove",
  52. <div id="event-Ext.data.Tree-move"></div>/**
  53. * @event move
  54. * Fires when a node is moved to a new location in the tree
  55. * @param {Tree} tree The owner tree
  56. * @param {Node} node The node moved
  57. * @param {Node} oldParent The old parent of this node
  58. * @param {Node} newParent The new parent of this node
  59. * @param {Number} index The index it was moved to
  60. */
  61. "move",
  62. <div id="event-Ext.data.Tree-insert"></div>/**
  63. * @event insert
  64. * Fires when a new child node is inserted in a node in this tree.
  65. * @param {Tree} tree The owner tree
  66. * @param {Node} parent The parent node
  67. * @param {Node} node The child node inserted
  68. * @param {Node} refNode The child node the node was inserted before
  69. */
  70. "insert",
  71. <div id="event-Ext.data.Tree-beforeappend"></div>/**
  72. * @event beforeappend
  73. * Fires before a new child is appended to a node in this tree, return false to cancel the append.
  74. * @param {Tree} tree The owner tree
  75. * @param {Node} parent The parent node
  76. * @param {Node} node The child node to be appended
  77. */
  78. "beforeappend",
  79. <div id="event-Ext.data.Tree-beforeremove"></div>/**
  80. * @event beforeremove
  81. * Fires before a child is removed from a node in this tree, return false to cancel the remove.
  82. * @param {Tree} tree The owner tree
  83. * @param {Node} parent The parent node
  84. * @param {Node} node The child node to be removed
  85. */
  86. "beforeremove",
  87. <div id="event-Ext.data.Tree-beforemove"></div>/**
  88. * @event beforemove
  89. * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
  90. * @param {Tree} tree The owner tree
  91. * @param {Node} node The node being moved
  92. * @param {Node} oldParent The parent of the node
  93. * @param {Node} newParent The new parent the node is moving to
  94. * @param {Number} index The index it is being moved to
  95. */
  96. "beforemove",
  97. <div id="event-Ext.data.Tree-beforeinsert"></div>/**
  98. * @event beforeinsert
  99. * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
  100. * @param {Tree} tree The owner tree
  101. * @param {Node} parent The parent node
  102. * @param {Node} node The child node to be inserted
  103. * @param {Node} refNode The child node the node is being inserted before
  104. */
  105. "beforeinsert"
  106. );
  107. Ext.data.Tree.superclass.constructor.call(this);
  108. },
  109. <div id="cfg-Ext.data.Tree-pathSeparator"></div>/**
  110. * @cfg {String} pathSeparator
  111. * The token used to separate paths in node ids (defaults to '/').
  112. */
  113. pathSeparator: "/",
  114. // private
  115. proxyNodeEvent : function(){
  116. return this.fireEvent.apply(this, arguments);
  117. },
  118. <div id="method-Ext.data.Tree-getRootNode"></div>/**
  119. * Returns the root node for this tree.
  120. * @return {Node}
  121. */
  122. getRootNode : function(){
  123. return this.root;
  124. },
  125. <div id="method-Ext.data.Tree-setRootNode"></div>/**
  126. * Sets the root node for this tree.
  127. * @param {Node} node
  128. * @return {Node}
  129. */
  130. setRootNode : function(node){
  131. this.root = node;
  132. node.ownerTree = this;
  133. node.isRoot = true;
  134. this.registerNode(node);
  135. return node;
  136. },
  137. <div id="method-Ext.data.Tree-getNodeById"></div>/**
  138. * Gets a node in this tree by its id.
  139. * @param {String} id
  140. * @return {Node}
  141. */
  142. getNodeById : function(id){
  143. return this.nodeHash[id];
  144. },
  145. // private
  146. registerNode : function(node){
  147. this.nodeHash[node.id] = node;
  148. },
  149. // private
  150. unregisterNode : function(node){
  151. delete this.nodeHash[node.id];
  152. },
  153. toString : function(){
  154. return "[Tree"+(this.id?" "+this.id:"")+"]";
  155. }
  156. });
  157. <div id="cls-Ext.data.Node"></div>/**
  158. * @class Ext.data.Node
  159. * @extends Ext.util.Observable
  160. * @cfg {Boolean} leaf true if this node is a leaf and does not have children
  161. * @cfg {String} id The id for this node. If one is not specified, one is generated.
  162. * @constructor
  163. * @param {Object} attributes The attributes/config for the node
  164. */
  165. Ext.data.Node = Ext.extend(Ext.util.Observable, {
  166. constructor: function(attributes){
  167. /**
  168. * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
  169. * @type {Object}
  170. */
  171. this.attributes = attributes || {};
  172. this.leaf = this.attributes.leaf;
  173. /**
  174. * The node id. @type String
  175. */
  176. this.id = this.attributes.id;
  177. if(!this.id){
  178. this.id = Ext.id(null, "xnode-");
  179. this.attributes.id = this.id;
  180. }
  181. /**
  182. * All child nodes of this node. @type Array
  183. */
  184. this.childNodes = [];
  185. /**
  186. * The parent node for this node. @type Node
  187. */
  188. this.parentNode = null;
  189. /**
  190. * The first direct child node of this node, or null if this node has no child nodes. @type Node
  191. */
  192. this.firstChild = null;
  193. /**
  194. * The last direct child node of this node, or null if this node has no child nodes. @type Node
  195. */
  196. this.lastChild = null;
  197. /**
  198. * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
  199. */
  200. this.previousSibling = null;
  201. /**
  202. * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
  203. */
  204. this.nextSibling = null;
  205. this.addEvents({
  206. /**
  207. * @event append
  208. * Fires when a new child node is appended
  209. * @param {Tree} tree The owner tree
  210. * @param {Node} this This node
  211. * @param {Node} node The newly appended node
  212. * @param {Number} index The index of the newly appended node
  213. */
  214. "append" : true,
  215. /**
  216. * @event remove
  217. * Fires when a child node is removed
  218. * @param {Tree} tree The owner tree
  219. * @param {Node} this This node
  220. * @param {Node} node The removed node
  221. */
  222. "remove" : true,
  223. /**
  224. * @event move
  225. * Fires when this node is moved to a new location in the tree
  226. * @param {Tree} tree The owner tree
  227. * @param {Node} this This node
  228. * @param {Node} oldParent The old parent of this node
  229. * @param {Node} newParent The new parent of this node
  230. * @param {Number} index The index it was moved to
  231. */
  232. "move" : true,
  233. /**
  234. * @event insert
  235. * Fires when a new child node is inserted.
  236. * @param {Tree} tree The owner tree
  237. * @param {Node} this This node
  238. * @param {Node} node The child node inserted
  239. * @param {Node} refNode The child node the node was inserted before
  240. */
  241. "insert" : true,
  242. /**
  243. * @event beforeappend
  244. * Fires before a new child is appended, return false to cancel the append.
  245. * @param {Tree} tree The owner tree
  246. * @param {Node} this This node
  247. * @param {Node} node The child node to be appended
  248. */
  249. "beforeappend" : true,
  250. /**
  251. * @event beforeremove
  252. * Fires before a child is removed, return false to cancel the remove.
  253. * @param {Tree} tree The owner tree
  254. * @param {Node} this This node
  255. * @param {Node} node The child node to be removed
  256. */
  257. "beforeremove" : true,
  258. /**
  259. * @event beforemove
  260. * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
  261. * @param {Tree} tree The owner tree
  262. * @param {Node} this This node
  263. * @param {Node} oldParent The parent of this node
  264. * @param {Node} newParent The new parent this node is moving to
  265. * @param {Number} index The index it is being moved to
  266. */
  267. "beforemove" : true,
  268. /**
  269. * @event beforeinsert
  270. * Fires before a new child is inserted, return false to cancel the insert.
  271. * @param {Tree} tree The owner tree
  272. * @param {Node} this This node
  273. * @param {Node} node The child node to be inserted
  274. * @param {Node} refNode The child node the node is being inserted before
  275. */
  276. "beforeinsert" : true
  277. });
  278. this.listeners = this.attributes.listeners;
  279. Ext.data.Node.superclass.constructor.call(this);
  280. },
  281. // private
  282. fireEvent : function(evtName){
  283. // first do standard event for this node
  284. if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){
  285. return false;
  286. }
  287. // then bubble it up to the tree if the event wasn't cancelled
  288. var ot = this.getOwnerTree();
  289. if(ot){
  290. if(ot.proxyNodeEvent.apply(ot, arguments) === false){
  291. return false;
  292. }
  293. }
  294. return true;
  295. },
  296. /**
  297. * Returns true if this node is a leaf
  298. * @return {Boolean}
  299. */
  300. isLeaf : function(){
  301. return this.leaf === true;
  302. },
  303. // private
  304. setFirstChild : function(node){
  305. this.firstChild = node;
  306. },
  307. //private
  308. setLastChild : function(node){
  309. this.lastChild = node;
  310. },
  311. /**
  312. * Returns true if this node is the last child of its parent
  313. * @return {Boolean}
  314. */
  315. isLast : function(){
  316. return (!this.parentNode ? true : this.parentNode.lastChild == this);
  317. },
  318. /**
  319. * Returns true if this node is the first child of its parent
  320. * @return {Boolean}
  321. */
  322. isFirst : function(){
  323. return (!this.parentNode ? true : this.parentNode.firstChild == this);
  324. },
  325. /**
  326. * Returns true if this node has one or more child nodes, else false.
  327. * @return {Boolean}
  328. */
  329. hasChildNodes : function(){
  330. return !this.isLeaf() && this.childNodes.length > 0;
  331. },
  332. /**
  333. * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>
  334. * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
  335. * @return {Boolean}
  336. */
  337. isExpandable : function(){
  338. return this.attributes.expandable || this.hasChildNodes();
  339. },
  340. /**
  341. * Insert node(s) as the last child node of this node.
  342. * @param {Node/Array} node The node or Array of nodes to append
  343. * @return {Node} The appended node if single append, or null if an array was passed
  344. */
  345. appendChild : function(node){
  346. var multi = false;
  347. if(Ext.isArray(node)){
  348. multi = node;
  349. }else if(arguments.length > 1){
  350. multi = arguments;
  351. }
  352. // if passed an array or multiple args do them one by one
  353. if(multi){
  354. for(var i = 0, len = multi.length; i < len; i++) {
  355. this.appendChild(multi[i]);
  356. }
  357. }else{
  358. if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
  359. return false;
  360. }
  361. var index = this.childNodes.length;
  362. var oldParent = node.parentNode;
  363. // it's a move, make sure we move it cleanly
  364. if(oldParent){
  365. if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
  366. return false;
  367. }
  368. oldParent.removeChild(node);
  369. }
  370. index = this.childNodes.length;
  371. if(index === 0){
  372. this.setFirstChild(node);
  373. }
  374. this.childNodes.push(node);
  375. node.parentNode = this;
  376. var ps = this.childNodes[index-1];
  377. if(ps){
  378. node.previousSibling = ps;
  379. ps.nextSibling = node;
  380. }else{
  381. node.previousSibling = null;
  382. }
  383. node.nextSibling = null;
  384. this.setLastChild(node);
  385. node.setOwnerTree(this.getOwnerTree());
  386. this.fireEvent("append", this.ownerTree, this, node, index);
  387. if(oldParent){
  388. node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
  389. }
  390. return node;
  391. }
  392. },
  393. /**
  394. * Removes a child node from this node.
  395. * @param {Node} node The node to remove
  396. * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
  397. * @return {Node} The removed node
  398. */
  399. removeChild : function(node, destroy){
  400. var index = this.childNodes.indexOf(node);
  401. if(index == -1){
  402. return false;
  403. }
  404. if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
  405. return false;
  406. }
  407. // remove it from childNodes collection
  408. this.childNodes.splice(index, 1);
  409. // update siblings
  410. if(node.previousSibling){
  411. node.previousSibling.nextSibling = node.nextSibling;
  412. }
  413. if(node.nextSibling){
  414. node.nextSibling.previousSibling = node.previousSibling;
  415. }
  416. // update child refs
  417. if(this.firstChild == node){
  418. this.setFirstChild(node.nextSibling);
  419. }
  420. if(this.lastChild == node){
  421. this.setLastChild(node.previousSibling);
  422. }
  423. this.fireEvent("remove", this.ownerTree, this, node);
  424. if(destroy){
  425. node.destroy(true);
  426. }else{
  427. node.clear();
  428. }
  429. return node;
  430. },
  431. // private
  432. clear : function(destroy){
  433. // clear any references from the node
  434. this.setOwnerTree(null, destroy);
  435. this.parentNode = this.previousSibling = this.nextSibling = null;
  436. if(destroy){
  437. this.firstChild = this.lastChild = null;
  438. }
  439. },
  440. /**
  441. * Destroys the node.
  442. */
  443. destroy : function(/* private */ silent){
  444. /*
  445. * Silent is to be used in a number of cases
  446. * 1) When setRootNode is called.
  447. * 2) When destroy on the tree is called
  448. * 3) For destroying child nodes on a node
  449. */
  450. if(silent === true){
  451. this.purgeListeners();
  452. this.clear(true);
  453. Ext.each(this.childNodes, function(n){
  454. n.destroy(true);
  455. });
  456. this.childNodes = null;
  457. }else{
  458. this.remove(true);
  459. }
  460. },
  461. /**
  462. * Inserts the first node before the second node in this nodes childNodes collection.
  463. * @param {Node} node The node to insert
  464. * @param {Node} refNode The node to insert before (if null the node is appended)
  465. * @return {Node} The inserted node
  466. */
  467. insertBefore : function(node, refNode){
  468. if(!refNode){ // like standard Dom, refNode can be null for append
  469. return this.appendChild(node);
  470. }
  471. // nothing to do
  472. if(node == refNode){
  473. return false;
  474. }
  475. if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
  476. return false;
  477. }
  478. var index = this.childNodes.indexOf(refNode);
  479. var oldParent = node.parentNode;
  480. var refIndex = index;
  481. // when moving internally, indexes will change after remove
  482. if(oldParent == this && this.childNodes.indexOf(node) < index){
  483. refIndex--;
  484. }
  485. // it's a move, make sure we move it cleanly
  486. if(oldParent){
  487. if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
  488. return false;
  489. }
  490. oldParent.removeChild(node);
  491. }
  492. if(refIndex === 0){
  493. this.setFirstChild(node);
  494. }
  495. this.childNodes.splice(refIndex, 0, node);
  496. node.parentNode = this;
  497. var ps = this.childNodes[refIndex-1];
  498. if(ps){
  499. node.previousSibling = ps;
  500. ps.nextSibling = node;
  501. }else{
  502. node.previousSibling = null;
  503. }
  504. node.nextSibling = refNode;
  505. refNode.previousSibling = node;
  506. node.setOwnerTree(this.getOwnerTree());
  507. this.fireEvent("insert", this.ownerTree, this, node, refNode);
  508. if(oldParent){
  509. node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
  510. }
  511. return node;
  512. },
  513. /**
  514. * Removes this node from its parent
  515. * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
  516. * @return {Node} this
  517. */
  518. remove : function(destroy){
  519. if (this.parentNode) {
  520. this.parentNode.removeChild(this, destroy);
  521. }
  522. return this;
  523. },
  524. /**
  525. * Removes all child nodes from this node.
  526. * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
  527. * @return {Node} this
  528. */
  529. removeAll : function(destroy){
  530. var cn = this.childNodes,
  531. n;
  532. while((n = cn[0])){
  533. this.removeChild(n, destroy);
  534. }
  535. return this;
  536. },
  537. /**
  538. * Returns the child node at the specified index.
  539. * @param {Number} index
  540. * @return {Node}
  541. */
  542. item : function(index){
  543. return this.childNodes[index];
  544. },
  545. /**
  546. * Replaces one child node in this node with another.
  547. * @param {Node} newChild The replacement node
  548. * @param {Node} oldChild The node to replace
  549. * @return {Node} The replaced node
  550. */
  551. replaceChild : function(newChild, oldChild){
  552. var s = oldChild ? oldChild.nextSibling : null;
  553. this.removeChild(oldChild);
  554. this.insertBefore(newChild, s);
  555. return oldChild;
  556. },
  557. /**
  558. * Returns the index of a child node
  559. * @param {Node} node
  560. * @return {Number} The index of the node or -1 if it was not found
  561. */
  562. indexOf : function(child){
  563. return this.childNodes.indexOf(child);
  564. },
  565. /**
  566. * Returns the tree this node is in.
  567. * @return {Tree}
  568. */
  569. getOwnerTree : function(){
  570. // if it doesn't have one, look for one
  571. if(!this.ownerTree){
  572. var p = this;
  573. while(p){
  574. if(p.ownerTree){
  575. this.ownerTree = p.ownerTree;
  576. break;
  577. }
  578. p = p.parentNode;
  579. }
  580. }
  581. return this.ownerTree;
  582. },
  583. /**
  584. * Returns depth of this node (the root node has a depth of 0)
  585. * @return {Number}
  586. */
  587. getDepth : function(){
  588. var depth = 0;
  589. var p = this;
  590. while(p.parentNode){
  591. ++depth;
  592. p = p.parentNode;
  593. }
  594. return depth;
  595. },
  596. // private
  597. setOwnerTree : function(tree, destroy){
  598. // if it is a move, we need to update everyone
  599. if(tree != this.ownerTree){
  600. if(this.ownerTree){
  601. this.ownerTree.unregisterNode(this);
  602. }
  603. this.ownerTree = tree;
  604. // If we're destroying, we don't need to recurse since it will be called on each child node
  605. if(destroy !== true){
  606. Ext.each(this.childNodes, function(n){
  607. n.setOwnerTree(tree);
  608. });
  609. }
  610. if(tree){
  611. tree.registerNode(this);
  612. }
  613. }
  614. },
  615. /**
  616. * Changes the id of this node.
  617. * @param {String} id The new id for the node.
  618. */
  619. setId: function(id){
  620. if(id !== this.id){
  621. var t = this.ownerTree;
  622. if(t){
  623. t.unregisterNode(this);
  624. }
  625. this.id = this.attributes.id = id;
  626. if(t){
  627. t.registerNode(this);
  628. }
  629. this.onIdChange(id);
  630. }
  631. },
  632. // private
  633. onIdChange: Ext.emptyFn,
  634. /**
  635. * Returns the path for this node. The path can be used to expand or select this node programmatically.
  636. * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
  637. * @return {String} The path
  638. */
  639. getPath : function(attr){
  640. attr = attr || "id";
  641. var p = this.parentNode;
  642. var b = [this.attributes[attr]];
  643. while(p){
  644. b.unshift(p.attributes[attr]);
  645. p = p.parentNode;
  646. }
  647. var sep = this.getOwnerTree().pathSeparator;
  648. return sep + b.join(sep);
  649. },
  650. /**
  651. * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function
  652. * will be the args provided or the current node. If the function returns false at any point,
  653. * the bubble is stopped.
  654. * @param {Function} fn The function to call
  655. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
  656. * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
  657. */
  658. bubble : function(fn, scope, args){
  659. var p = this;
  660. while(p){
  661. if(fn.apply(scope || p, args || [p]) === false){
  662. break;
  663. }
  664. p = p.parentNode;
  665. }
  666. },
  667. /**
  668. * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function
  669. * will be the args provided or the current node. If the function returns false at any point,
  670. * the cascade is stopped on that branch.
  671. * @param {Function} fn The function to call
  672. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
  673. * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
  674. */
  675. cascade : function(fn, scope, args){
  676. if(fn.apply(scope || this, args || [this]) !== false){
  677. var cs = this.childNodes;
  678. for(var i = 0, len = cs.length; i < len; i++) {
  679. cs[i].cascade(fn, scope, args);
  680. }
  681. }
  682. },
  683. /**
  684. * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function
  685. * will be the args provided or the current node. If the function returns false at any point,
  686. * the iteration stops.
  687. * @param {Function} fn The function to call
  688. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node in the iteration.
  689. * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
  690. */
  691. eachChild : function(fn, scope, args){
  692. var cs = this.childNodes;
  693. for(var i = 0, len = cs.length; i < len; i++) {
  694. if(fn.apply(scope || cs[i], args || [cs[i]]) === false){
  695. break;
  696. }
  697. }
  698. },
  699. /**
  700. * Finds the first child that has the attribute with the specified value.
  701. * @param {String} attribute The attribute name
  702. * @param {Mixed} value The value to search for
  703. * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
  704. * @return {Node} The found child or null if none was found
  705. */
  706. findChild : function(attribute, value, deep){
  707. return this.findChildBy(function(){
  708. return this.attributes[attribute] == value;
  709. }, null, deep);
  710. },
  711. /**
  712. * Finds the first child by a custom function. The child matches if the function passed returns <code>true</code>.
  713. * @param {Function} fn A function which must return <code>true</code> if the passed Node is the required Node.
  714. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Node being tested.
  715. * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
  716. * @return {Node} The found child or null if none was found
  717. */
  718. findChildBy : function(fn, scope, deep){
  719. var cs = this.childNodes,
  720. len = cs.length,
  721. i = 0,
  722. n,
  723. res;
  724. for(; i < len; i++){
  725. n = cs[i];
  726. if(fn.call(scope || n, n) === true){
  727. return n;
  728. }else if (deep){
  729. res = n.findChildBy(fn, scope, deep);
  730. if(res != null){
  731. return res;
  732. }
  733. }
  734. }
  735. return null;
  736. },
  737. /**
  738. * Sorts this nodes children using the supplied sort function.
  739. * @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.
  740. * @param {Object} scope (optional)The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  741. */
  742. sort : function(fn, scope){
  743. var cs = this.childNodes;
  744. var len = cs.length;
  745. if(len > 0){
  746. var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
  747. cs.sort(sortFn);
  748. for(var i = 0; i < len; i++){
  749. var n = cs[i];
  750. n.previousSibling = cs[i-1];
  751. n.nextSibling = cs[i+1];
  752. if(i === 0){
  753. this.setFirstChild(n);
  754. }
  755. if(i == len-1){
  756. this.setLastChild(n);
  757. }
  758. }
  759. }
  760. },
  761. /**
  762. * Returns true if this node is an ancestor (at any point) of the passed node.
  763. * @param {Node} node
  764. * @return {Boolean}
  765. */
  766. contains : function(node){
  767. return node.isAncestor(this);
  768. },
  769. /**
  770. * Returns true if the passed node is an ancestor (at any point) of this node.
  771. * @param {Node} node
  772. * @return {Boolean}
  773. */
  774. isAncestor : function(node){
  775. var p = this.parentNode;
  776. while(p){
  777. if(p == node){
  778. return true;
  779. }
  780. p = p.parentNode;
  781. }
  782. return false;
  783. },
  784. toString : function(){
  785. return "[Node"+(this.id?" "+this.id:"")+"]";
  786. }
  787. });</pre>
  788. </body>
  789. </html>