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.

990 lines
31 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.tree.TreePanel"></div>/**
  16. * @class Ext.tree.TreePanel
  17. * @extends Ext.Panel
  18. * <p>The TreePanel provides tree-structured UI representation of tree-structured data.</p>
  19. * <p>{@link Ext.tree.TreeNode TreeNode}s added to the TreePanel may each contain metadata
  20. * used by your application in their {@link Ext.tree.TreeNode#attributes attributes} property.</p>
  21. * <p><b>A TreePanel must have a {@link #root} node before it is rendered.</b> This may either be
  22. * specified using the {@link #root} config option, or using the {@link #setRootNode} method.
  23. * <p>An example of tree rendered to an existing div:</p><pre><code>
  24. var tree = new Ext.tree.TreePanel({
  25. renderTo: 'tree-div',
  26. useArrows: true,
  27. autoScroll: true,
  28. animate: true,
  29. enableDD: true,
  30. containerScroll: true,
  31. border: false,
  32. // auto create TreeLoader
  33. dataUrl: 'get-nodes.php',
  34. root: {
  35. nodeType: 'async',
  36. text: 'Ext JS',
  37. draggable: false,
  38. id: 'source'
  39. }
  40. });
  41. tree.getRootNode().expand();
  42. * </code></pre>
  43. * <p>The example above would work with a data packet similar to this:</p><pre><code>
  44. [{
  45. "text": "adapter",
  46. "id": "source\/adapter",
  47. "cls": "folder"
  48. }, {
  49. "text": "dd",
  50. "id": "source\/dd",
  51. "cls": "folder"
  52. }, {
  53. "text": "debug.js",
  54. "id": "source\/debug.js",
  55. "leaf": true,
  56. "cls": "file"
  57. }]
  58. * </code></pre>
  59. * <p>An example of tree within a Viewport:</p><pre><code>
  60. new Ext.Viewport({
  61. layout: 'border',
  62. items: [{
  63. region: 'west',
  64. collapsible: true,
  65. title: 'Navigation',
  66. xtype: 'treepanel',
  67. width: 200,
  68. autoScroll: true,
  69. split: true,
  70. loader: new Ext.tree.TreeLoader(),
  71. root: new Ext.tree.AsyncTreeNode({
  72. expanded: true,
  73. children: [{
  74. text: 'Menu Option 1',
  75. leaf: true
  76. }, {
  77. text: 'Menu Option 2',
  78. leaf: true
  79. }, {
  80. text: 'Menu Option 3',
  81. leaf: true
  82. }]
  83. }),
  84. rootVisible: false,
  85. listeners: {
  86. click: function(n) {
  87. Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
  88. }
  89. }
  90. }, {
  91. region: 'center',
  92. xtype: 'tabpanel',
  93. // remaining code not shown ...
  94. }]
  95. });
  96. </code></pre>
  97. *
  98. * @cfg {Ext.tree.TreeNode} root The root node for the tree.
  99. * @cfg {Boolean} rootVisible <tt>false</tt> to hide the root node (defaults to <tt>true</tt>)
  100. * @cfg {Boolean} lines <tt>false</tt> to disable tree lines (defaults to <tt>true</tt>)
  101. * @cfg {Boolean} enableDD <tt>true</tt> to enable drag and drop
  102. * @cfg {Boolean} enableDrag <tt>true</tt> to enable just drag
  103. * @cfg {Boolean} enableDrop <tt>true</tt> to enable just drop
  104. * @cfg {Object} dragConfig Custom config to pass to the {@link Ext.tree.TreeDragZone} instance
  105. * @cfg {Object} dropConfig Custom config to pass to the {@link Ext.tree.TreeDropZone} instance
  106. * @cfg {String} ddGroup The DD group this TreePanel belongs to
  107. * @cfg {Boolean} ddAppendOnly <tt>true</tt> if the tree should only allow append drops (use for trees which are sorted)
  108. * @cfg {Boolean} ddScroll <tt>true</tt> to enable body scrolling
  109. * @cfg {Boolean} containerScroll <tt>true</tt> to register this container with ScrollManager
  110. * @cfg {Boolean} hlDrop <tt>false</tt> to disable node highlight on drop (defaults to the value of {@link Ext#enableFx})
  111. * @cfg {String} hlColor The color of the node highlight (defaults to <tt>'C3DAF9'</tt>)
  112. * @cfg {Boolean} animate <tt>true</tt> to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx})
  113. * @cfg {Boolean} singleExpand <tt>true</tt> if only 1 node per branch may be expanded
  114. * @cfg {Object} selModel A tree selection model to use with this TreePanel (defaults to an {@link Ext.tree.DefaultSelectionModel})
  115. * @cfg {Boolean} trackMouseOver <tt>false</tt> to disable mouse over highlighting
  116. * @cfg {Ext.tree.TreeLoader} loader A {@link Ext.tree.TreeLoader} for use with this TreePanel
  117. * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to <tt>'/'</tt>)
  118. * @cfg {Boolean} useArrows <tt>true</tt> to use Vista-style arrows in the tree (defaults to <tt>false</tt>)
  119. * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
  120. *
  121. * @constructor
  122. * @param {Object} config
  123. * @xtype treepanel
  124. */
  125. Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
  126. rootVisible : true,
  127. animate : Ext.enableFx,
  128. lines : true,
  129. enableDD : false,
  130. hlDrop : Ext.enableFx,
  131. pathSeparator : '/',
  132. /**
  133. * @cfg {Array} bubbleEvents
  134. * <p>An array of events that, when fired, should be bubbled to any parent container.
  135. * See {@link Ext.util.Observable#enableBubble}.
  136. * Defaults to <tt>[]</tt>.
  137. */
  138. bubbleEvents : [],
  139. initComponent : function(){
  140. Ext.tree.TreePanel.superclass.initComponent.call(this);
  141. if(!this.eventModel){
  142. this.eventModel = new Ext.tree.TreeEventModel(this);
  143. }
  144. // initialize the loader
  145. var l = this.loader;
  146. if(!l){
  147. l = new Ext.tree.TreeLoader({
  148. dataUrl: this.dataUrl,
  149. requestMethod: this.requestMethod
  150. });
  151. }else if(Ext.isObject(l) && !l.load){
  152. l = new Ext.tree.TreeLoader(l);
  153. }
  154. this.loader = l;
  155. this.nodeHash = {};
  156. /**
  157. * The root node of this tree.
  158. * @type Ext.tree.TreeNode
  159. * @property root
  160. */
  161. if(this.root){
  162. var r = this.root;
  163. delete this.root;
  164. this.setRootNode(r);
  165. }
  166. this.addEvents(
  167. /**
  168. * @event append
  169. * Fires when a new child node is appended to a node in this tree.
  170. * @param {Tree} tree The owner tree
  171. * @param {Node} parent The parent node
  172. * @param {Node} node The newly appended node
  173. * @param {Number} index The index of the newly appended node
  174. */
  175. 'append',
  176. /**
  177. * @event remove
  178. * Fires when a child node is removed from a node in this tree.
  179. * @param {Tree} tree The owner tree
  180. * @param {Node} parent The parent node
  181. * @param {Node} node The child node removed
  182. */
  183. 'remove',
  184. /**
  185. * @event movenode
  186. * Fires when a node is moved to a new location in the tree
  187. * @param {Tree} tree The owner tree
  188. * @param {Node} node The node moved
  189. * @param {Node} oldParent The old parent of this node
  190. * @param {Node} newParent The new parent of this node
  191. * @param {Number} index The index it was moved to
  192. */
  193. 'movenode',
  194. /**
  195. * @event insert
  196. * Fires when a new child node is inserted in a node in this tree.
  197. * @param {Tree} tree The owner tree
  198. * @param {Node} parent The parent node
  199. * @param {Node} node The child node inserted
  200. * @param {Node} refNode The child node the node was inserted before
  201. */
  202. 'insert',
  203. /**
  204. * @event beforeappend
  205. * Fires before a new child is appended to a node in this tree, return false to cancel the append.
  206. * @param {Tree} tree The owner tree
  207. * @param {Node} parent The parent node
  208. * @param {Node} node The child node to be appended
  209. */
  210. 'beforeappend',
  211. /**
  212. * @event beforeremove
  213. * Fires before a child is removed from a node in this tree, return false to cancel the remove.
  214. * @param {Tree} tree The owner tree
  215. * @param {Node} parent The parent node
  216. * @param {Node} node The child node to be removed
  217. */
  218. 'beforeremove',
  219. /**
  220. * @event beforemovenode
  221. * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
  222. * @param {Tree} tree The owner tree
  223. * @param {Node} node The node being moved
  224. * @param {Node} oldParent The parent of the node
  225. * @param {Node} newParent The new parent the node is moving to
  226. * @param {Number} index The index it is being moved to
  227. */
  228. 'beforemovenode',
  229. /**
  230. * @event beforeinsert
  231. * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
  232. * @param {Tree} tree The owner tree
  233. * @param {Node} parent The parent node
  234. * @param {Node} node The child node to be inserted
  235. * @param {Node} refNode The child node the node is being inserted before
  236. */
  237. 'beforeinsert',
  238. /**
  239. * @event beforeload
  240. * Fires before a node is loaded, return false to cancel
  241. * @param {Node} node The node being loaded
  242. */
  243. 'beforeload',
  244. /**
  245. * @event load
  246. * Fires when a node is loaded
  247. * @param {Node} node The node that was loaded
  248. */
  249. 'load',
  250. /**
  251. * @event textchange
  252. * Fires when the text for a node is changed
  253. * @param {Node} node The node
  254. * @param {String} text The new text
  255. * @param {String} oldText The old text
  256. */
  257. 'textchange',
  258. /**
  259. * @event beforeexpandnode
  260. * Fires before a node is expanded, return false to cancel.
  261. * @param {Node} node The node
  262. * @param {Boolean} deep
  263. * @param {Boolean} anim
  264. */
  265. 'beforeexpandnode',
  266. /**
  267. * @event beforecollapsenode
  268. * Fires before a node is collapsed, return false to cancel.
  269. * @param {Node} node The node
  270. * @param {Boolean} deep
  271. * @param {Boolean} anim
  272. */
  273. 'beforecollapsenode',
  274. /**
  275. * @event expandnode
  276. * Fires when a node is expanded
  277. * @param {Node} node The node
  278. */
  279. 'expandnode',
  280. /**
  281. * @event disabledchange
  282. * Fires when the disabled status of a node changes
  283. * @param {Node} node The node
  284. * @param {Boolean} disabled
  285. */
  286. 'disabledchange',
  287. /**
  288. * @event collapsenode
  289. * Fires when a node is collapsed
  290. * @param {Node} node The node
  291. */
  292. 'collapsenode',
  293. /**
  294. * @event beforeclick
  295. * Fires before click processing on a node. Return false to cancel the default action.
  296. * @param {Node} node The node
  297. * @param {Ext.EventObject} e The event object
  298. */
  299. 'beforeclick',
  300. /**
  301. * @event click
  302. * Fires when a node is clicked
  303. * @param {Node} node The node
  304. * @param {Ext.EventObject} e The event object
  305. */
  306. 'click',
  307. /**
  308. * @event containerclick
  309. * Fires when the tree container is clicked
  310. * @param {Tree} this
  311. * @param {Ext.EventObject} e The event object
  312. */
  313. 'containerclick',
  314. /**
  315. * @event checkchange
  316. * Fires when a node with a checkbox's checked property changes
  317. * @param {Node} this This node
  318. * @param {Boolean} checked
  319. */
  320. 'checkchange',
  321. /**
  322. * @event beforedblclick
  323. * Fires before double click processing on a node. Return false to cancel the default action.
  324. * @param {Node} node The node
  325. * @param {Ext.EventObject} e The event object
  326. */
  327. 'beforedblclick',
  328. /**
  329. * @event dblclick
  330. * Fires when a node is double clicked
  331. * @param {Node} node The node
  332. * @param {Ext.EventObject} e The event object
  333. */
  334. 'dblclick',
  335. /**
  336. * @event containerdblclick
  337. * Fires when the tree container is double clicked
  338. * @param {Tree} this
  339. * @param {Ext.EventObject} e The event object
  340. */
  341. 'containerdblclick',
  342. /**
  343. * @event contextmenu
  344. * Fires when a node is right clicked. To display a context menu in response to this
  345. * event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add
  346. * a handler for this event:<pre><code>
  347. new Ext.tree.TreePanel({
  348. title: 'My TreePanel',
  349. root: new Ext.tree.AsyncTreeNode({
  350. text: 'The Root',
  351. children: [
  352. { text: 'Child node 1', leaf: true },
  353. { text: 'Child node 2', leaf: true }
  354. ]
  355. }),
  356. contextMenu: new Ext.menu.Menu({
  357. items: [{
  358. id: 'delete-node',
  359. text: 'Delete Node'
  360. }],
  361. listeners: {
  362. itemclick: function(item) {
  363. switch (item.id) {
  364. case 'delete-node':
  365. var n = item.parentMenu.contextNode;
  366. if (n.parentNode) {
  367. n.remove();
  368. }
  369. break;
  370. }
  371. }
  372. }
  373. }),
  374. listeners: {
  375. contextmenu: function(node, e) {
  376. // Register the context node with the menu so that a Menu Item's handler function can access
  377. // it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.
  378. node.select();
  379. var c = node.getOwnerTree().contextMenu;
  380. c.contextNode = node;
  381. c.showAt(e.getXY());
  382. }
  383. }
  384. });
  385. </code></pre>
  386. * @param {Node} node The node
  387. * @param {Ext.EventObject} e The event object
  388. */
  389. 'contextmenu',
  390. /**
  391. * @event containercontextmenu
  392. * Fires when the tree container is right clicked
  393. * @param {Tree} this
  394. * @param {Ext.EventObject} e The event object
  395. */
  396. 'containercontextmenu',
  397. /**
  398. * @event beforechildrenrendered
  399. * Fires right before the child nodes for a node are rendered
  400. * @param {Node} node The node
  401. */
  402. 'beforechildrenrendered',
  403. /**
  404. * @event startdrag
  405. * Fires when a node starts being dragged
  406. * @param {Ext.tree.TreePanel} this
  407. * @param {Ext.tree.TreeNode} node
  408. * @param {event} e The raw browser event
  409. */
  410. 'startdrag',
  411. /**
  412. * @event enddrag
  413. * Fires when a drag operation is complete
  414. * @param {Ext.tree.TreePanel} this
  415. * @param {Ext.tree.TreeNode} node
  416. * @param {event} e The raw browser event
  417. */
  418. 'enddrag',
  419. /**
  420. * @event dragdrop
  421. * Fires when a dragged node is dropped on a valid DD target
  422. * @param {Ext.tree.TreePanel} this
  423. * @param {Ext.tree.TreeNode} node
  424. * @param {DD} dd The dd it was dropped on
  425. * @param {event} e The raw browser event
  426. */
  427. 'dragdrop',
  428. /**
  429. * @event beforenodedrop
  430. * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
  431. * passed to handlers has the following properties:<br />
  432. * <ul style="padding:5px;padding-left:16px;">
  433. * <li>tree - The TreePanel</li>
  434. * <li>target - The node being targeted for the drop</li>
  435. * <li>data - The drag data from the drag source</li>
  436. * <li>point - The point of the drop - append, above or below</li>
  437. * <li>source - The drag source</li>
  438. * <li>rawEvent - Raw mouse event</li>
  439. * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
  440. * to be inserted by setting them on this object.</li>
  441. * <li>cancel - Set this to true to cancel the drop.</li>
  442. * <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true
  443. * will prevent the animated 'repair' from appearing.</li>
  444. * </ul>
  445. * @param {Object} dropEvent
  446. */
  447. 'beforenodedrop',
  448. /**
  449. * @event nodedrop
  450. * Fires after a DD object is dropped on a node in this tree. The dropEvent
  451. * passed to handlers has the following properties:<br />
  452. * <ul style="padding:5px;padding-left:16px;">
  453. * <li>tree - The TreePanel</li>
  454. * <li>target - The node being targeted for the drop</li>
  455. * <li>data - The drag data from the drag source</li>
  456. * <li>point - The point of the drop - append, above or below</li>
  457. * <li>source - The drag source</li>
  458. * <li>rawEvent - Raw mouse event</li>
  459. * <li>dropNode - Dropped node(s).</li>
  460. * </ul>
  461. * @param {Object} dropEvent
  462. */
  463. 'nodedrop',
  464. /**
  465. * @event nodedragover
  466. * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
  467. * passed to handlers has the following properties:<br />
  468. * <ul style="padding:5px;padding-left:16px;">
  469. * <li>tree - The TreePanel</li>
  470. * <li>target - The node being targeted for the drop</li>
  471. * <li>data - The drag data from the drag source</li>
  472. * <li>point - The point of the drop - append, above or below</li>
  473. * <li>source - The drag source</li>
  474. * <li>rawEvent - Raw mouse event</li>
  475. * <li>dropNode - Drop node(s) provided by the source.</li>
  476. * <li>cancel - Set this to true to signal drop not allowed.</li>
  477. * </ul>
  478. * @param {Object} dragOverEvent
  479. */
  480. 'nodedragover'
  481. );
  482. if(this.singleExpand){
  483. this.on('beforeexpandnode', this.restrictExpand, this);
  484. }
  485. },
  486. // private
  487. proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){
  488. if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){
  489. ename = ename+'node';
  490. }
  491. // args inline for performance while bubbling events
  492. return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);
  493. },
  494. /**
  495. * Returns this root node for this tree
  496. * @return {Node}
  497. */
  498. getRootNode : function(){
  499. return this.root;
  500. },
  501. /**
  502. * Sets the root node for this tree. If the TreePanel has already rendered a root node, the
  503. * previous root node (and all of its descendants) are destroyed before the new root node is rendered.
  504. * @param {Node} node
  505. * @return {Node}
  506. */
  507. setRootNode : function(node){
  508. this.destroyRoot();
  509. if(!node.render){ // attributes passed
  510. node = this.loader.createNode(node);
  511. }
  512. this.root = node;
  513. node.ownerTree = this;
  514. node.isRoot = true;
  515. this.registerNode(node);
  516. if(!this.rootVisible){
  517. var uiP = node.attributes.uiProvider;
  518. node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);
  519. }
  520. if(this.innerCt){
  521. this.clearInnerCt();
  522. this.renderRoot();
  523. }
  524. return node;
  525. },
  526. clearInnerCt : function(){
  527. this.innerCt.update('');
  528. },
  529. // private
  530. renderRoot : function(){
  531. this.root.render();
  532. if(!this.rootVisible){
  533. this.root.renderChildren();
  534. }
  535. },
  536. /**
  537. * Gets a node in this tree by its id
  538. * @param {String} id
  539. * @return {Node}
  540. */
  541. getNodeById : function(id){
  542. return this.nodeHash[id];
  543. },
  544. // private
  545. registerNode : function(node){
  546. this.nodeHash[node.id] = node;
  547. },
  548. // private
  549. unregisterNode : function(node){
  550. delete this.nodeHash[node.id];
  551. },
  552. // private
  553. toString : function(){
  554. return '[Tree'+(this.id?' '+this.id:'')+']';
  555. },
  556. // private
  557. restrictExpand : function(node){
  558. var p = node.parentNode;
  559. if(p){
  560. if(p.expandedChild && p.expandedChild.parentNode == p){
  561. p.expandedChild.collapse();
  562. }
  563. p.expandedChild = node;
  564. }
  565. },
  566. /**
  567. * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. 'id')
  568. * @param {String} attribute (optional) Defaults to null (return the actual nodes)
  569. * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
  570. * @return {Array}
  571. */
  572. getChecked : function(a, startNode){
  573. startNode = startNode || this.root;
  574. var r = [];
  575. var f = function(){
  576. if(this.attributes.checked){
  577. r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
  578. }
  579. };
  580. startNode.cascade(f);
  581. return r;
  582. },
  583. /**
  584. * Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.
  585. * @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.
  586. */
  587. getLoader : function(){
  588. return this.loader;
  589. },
  590. /**
  591. * Expand all nodes
  592. */
  593. expandAll : function(){
  594. this.root.expand(true);
  595. },
  596. /**
  597. * Collapse all nodes
  598. */
  599. collapseAll : function(){
  600. this.root.collapse(true);
  601. },
  602. /**
  603. * Returns the selection model used by this TreePanel.
  604. * @return {TreeSelectionModel} The selection model used by this TreePanel
  605. */
  606. getSelectionModel : function(){
  607. if(!this.selModel){
  608. this.selModel = new Ext.tree.DefaultSelectionModel();
  609. }
  610. return this.selModel;
  611. },
  612. /**
  613. * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
  614. * @param {String} path
  615. * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
  616. * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
  617. * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
  618. */
  619. expandPath : function(path, attr, callback){
  620. if(Ext.isEmpty(path)){
  621. if(callback){
  622. callback(false, undefined);
  623. }
  624. return;
  625. }
  626. attr = attr || 'id';
  627. var keys = path.split(this.pathSeparator);
  628. var curNode = this.root;
  629. if(curNode.attributes[attr] != keys[1]){ // invalid root
  630. if(callback){
  631. callback(false, null);
  632. }
  633. return;
  634. }
  635. var index = 1;
  636. var f = function(){
  637. if(++index == keys.length){
  638. if(callback){
  639. callback(true, curNode);
  640. }
  641. return;
  642. }
  643. var c = curNode.findChild(attr, keys[index]);
  644. if(!c){
  645. if(callback){
  646. callback(false, curNode);
  647. }
  648. return;
  649. }
  650. curNode = c;
  651. c.expand(false, false, f);
  652. };
  653. curNode.expand(false, false, f);
  654. },
  655. /**
  656. * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
  657. * @param {String} path
  658. * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
  659. * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
  660. * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
  661. */
  662. selectPath : function(path, attr, callback){
  663. if(Ext.isEmpty(path)){
  664. if(callback){
  665. callback(false, undefined);
  666. }
  667. return;
  668. }
  669. attr = attr || 'id';
  670. var keys = path.split(this.pathSeparator),
  671. v = keys.pop();
  672. if(keys.length > 1){
  673. var f = function(success, node){
  674. if(success && node){
  675. var n = node.findChild(attr, v);
  676. if(n){
  677. n.select();
  678. if(callback){
  679. callback(true, n);
  680. }
  681. }else if(callback){
  682. callback(false, n);
  683. }
  684. }else{
  685. if(callback){
  686. callback(false, n);
  687. }
  688. }
  689. };
  690. this.expandPath(keys.join(this.pathSeparator), attr, f);
  691. }else{
  692. this.root.select();
  693. if(callback){
  694. callback(true, this.root);
  695. }
  696. }
  697. },
  698. /**
  699. * Returns the underlying Element for this tree
  700. * @return {Ext.Element} The Element
  701. */
  702. getTreeEl : function(){
  703. return this.body;
  704. },
  705. // private
  706. onRender : function(ct, position){
  707. Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
  708. this.el.addClass('x-tree');
  709. this.innerCt = this.body.createChild({tag:'ul',
  710. cls:'x-tree-root-ct ' +
  711. (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')});
  712. },
  713. // private
  714. initEvents : function(){
  715. Ext.tree.TreePanel.superclass.initEvents.call(this);
  716. if(this.containerScroll){
  717. Ext.dd.ScrollManager.register(this.body);
  718. }
  719. if((this.enableDD || this.enableDrop) && !this.dropZone){
  720. /**
  721. * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
  722. * @property dropZone
  723. * @type Ext.tree.TreeDropZone
  724. */
  725. this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
  726. ddGroup: this.ddGroup || 'TreeDD', appendOnly: this.ddAppendOnly === true
  727. });
  728. }
  729. if((this.enableDD || this.enableDrag) && !this.dragZone){
  730. /**
  731. * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
  732. * @property dragZone
  733. * @type Ext.tree.TreeDragZone
  734. */
  735. this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
  736. ddGroup: this.ddGroup || 'TreeDD',
  737. scroll: this.ddScroll
  738. });
  739. }
  740. this.getSelectionModel().init(this);
  741. },
  742. // private
  743. afterRender : function(){
  744. Ext.tree.TreePanel.superclass.afterRender.call(this);
  745. this.renderRoot();
  746. },
  747. beforeDestroy : function(){
  748. if(this.rendered){
  749. Ext.dd.ScrollManager.unregister(this.body);
  750. Ext.destroy(this.dropZone, this.dragZone);
  751. }
  752. this.destroyRoot();
  753. Ext.destroy(this.loader);
  754. this.nodeHash = this.root = this.loader = null;
  755. Ext.tree.TreePanel.superclass.beforeDestroy.call(this);
  756. },
  757. /**
  758. * Destroy the root node. Not included by itself because we need to pass the silent parameter.
  759. * @private
  760. */
  761. destroyRoot : function(){
  762. if(this.root && this.root.destroy){
  763. this.root.destroy(true);
  764. }
  765. }
  766. /**
  767. * @cfg {String/Number} activeItem
  768. * @hide
  769. */
  770. /**
  771. * @cfg {Boolean} autoDestroy
  772. * @hide
  773. */
  774. /**
  775. * @cfg {Object/String/Function} autoLoad
  776. * @hide
  777. */
  778. /**
  779. * @cfg {Boolean} autoWidth
  780. * @hide
  781. */
  782. /**
  783. * @cfg {Boolean/Number} bufferResize
  784. * @hide
  785. */
  786. /**
  787. * @cfg {String} defaultType
  788. * @hide
  789. */
  790. /**
  791. * @cfg {Object} defaults
  792. * @hide
  793. */
  794. /**
  795. * @cfg {Boolean} hideBorders
  796. * @hide
  797. */
  798. /**
  799. * @cfg {Mixed} items
  800. * @hide
  801. */
  802. /**
  803. * @cfg {String} layout
  804. * @hide
  805. */
  806. /**
  807. * @cfg {Object} layoutConfig
  808. * @hide
  809. */
  810. /**
  811. * @cfg {Boolean} monitorResize
  812. * @hide
  813. */
  814. /**
  815. * @property items
  816. * @hide
  817. */
  818. /**
  819. * @method cascade
  820. * @hide
  821. */
  822. /**
  823. * @method doLayout
  824. * @hide
  825. */
  826. /**
  827. * @method find
  828. * @hide
  829. */
  830. /**
  831. * @method findBy
  832. * @hide
  833. */
  834. /**
  835. * @method findById
  836. * @hide
  837. */
  838. /**
  839. * @method findByType
  840. * @hide
  841. */
  842. /**
  843. * @method getComponent
  844. * @hide
  845. */
  846. /**
  847. * @method getLayout
  848. * @hide
  849. */
  850. /**
  851. * @method getUpdater
  852. * @hide
  853. */
  854. /**
  855. * @method insert
  856. * @hide
  857. */
  858. /**
  859. * @method load
  860. * @hide
  861. */
  862. /**
  863. * @method remove
  864. * @hide
  865. */
  866. /**
  867. * @event add
  868. * @hide
  869. */
  870. /**
  871. * @method removeAll
  872. * @hide
  873. */
  874. /**
  875. * @event afterLayout
  876. * @hide
  877. */
  878. /**
  879. * @event beforeadd
  880. * @hide
  881. */
  882. /**
  883. * @event beforeremove
  884. * @hide
  885. */
  886. /**
  887. * @event remove
  888. * @hide
  889. */
  890. /**
  891. * @cfg {String} allowDomMove @hide
  892. */
  893. /**
  894. * @cfg {String} autoEl @hide
  895. */
  896. /**
  897. * @cfg {String} applyTo @hide
  898. */
  899. /**
  900. * @cfg {String} contentEl @hide
  901. */
  902. /**
  903. * @cfg {Mixed} data @hide
  904. */
  905. /**
  906. * @cfg {Mixed} tpl @hide
  907. */
  908. /**
  909. * @cfg {String} tplWriteMode @hide
  910. */
  911. /**
  912. * @cfg {String} disabledClass @hide
  913. */
  914. /**
  915. * @cfg {String} elements @hide
  916. */
  917. /**
  918. * @cfg {String} html @hide
  919. */
  920. /**
  921. * @cfg {Boolean} preventBodyReset
  922. * @hide
  923. */
  924. /**
  925. * @property disabled
  926. * @hide
  927. */
  928. /**
  929. * @method applyToMarkup
  930. * @hide
  931. */
  932. /**
  933. * @method enable
  934. * @hide
  935. */
  936. /**
  937. * @method disable
  938. * @hide
  939. */
  940. /**
  941. * @method setDisabled
  942. * @hide
  943. */
  944. });
  945. Ext.tree.TreePanel.nodeTypes = {};
  946. Ext.reg('treepanel', Ext.tree.TreePanel);</pre>
  947. </body>
  948. </html>