NodeInterface.html 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  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-data-NodeInterface'>/**
  19. </span> * This class is used as a set of methods that are applied to the prototype of a
  20. * Model to decorate it with a Node API. This means that models used in conjunction with a tree
  21. * will have all of the tree related methods available on the model. In general this class will
  22. * not be used directly by the developer. This class also creates extra fields on the model if
  23. * they do not exist, to help maintain the tree state and UI. These fields are documented as
  24. * config options.
  25. */
  26. Ext.define('Ext.data.NodeInterface', {
  27. requires: ['Ext.data.Field'],
  28. <span id='Ext-data-NodeInterface-cfg-parentId'> /**
  29. </span> * @cfg {String} parentId
  30. * ID of parent node.
  31. */
  32. <span id='Ext-data-NodeInterface-cfg-index'> /**
  33. </span> * @cfg {Number} index
  34. * The position of the node inside its parent. When parent has 4 children and the node is third amongst them,
  35. * index will be 2.
  36. */
  37. <span id='Ext-data-NodeInterface-cfg-depth'> /**
  38. </span> * @cfg {Number} depth
  39. * The number of parents this node has. A root node has depth 0, a child of it depth 1, and so on...
  40. */
  41. <span id='Ext-data-NodeInterface-cfg-expanded'> /**
  42. </span> * @cfg {Boolean} [expanded=false]
  43. * True if the node is expanded.
  44. */
  45. <span id='Ext-data-NodeInterface-cfg-expandable'> /**
  46. </span> * @cfg {Boolean} [expandable=false]
  47. * Set to true to allow for expanding/collapsing of this node.
  48. */
  49. <span id='Ext-data-NodeInterface-cfg-checked'> /**
  50. </span> * @cfg {Boolean} [checked=null]
  51. * Set to true or false to show a checkbox alongside this node.
  52. */
  53. <span id='Ext-data-NodeInterface-cfg-leaf'> /**
  54. </span> * @cfg {Boolean} [leaf=false]
  55. * Set to true to indicate that this child can have no children. The expand icon/arrow will then not be
  56. * rendered for this node.
  57. */
  58. <span id='Ext-data-NodeInterface-cfg-cls'> /**
  59. </span> * @cfg {String} cls
  60. * CSS class to apply for this node.
  61. */
  62. <span id='Ext-data-NodeInterface-cfg-iconCls'> /**
  63. </span> * @cfg {String} iconCls
  64. * CSS class to apply for this node's icon.
  65. */
  66. <span id='Ext-data-NodeInterface-cfg-icon'> /**
  67. </span> * @cfg {String} icon
  68. * URL for this node's icon.
  69. */
  70. <span id='Ext-data-NodeInterface-cfg-root'> /**
  71. </span> * @cfg {Boolean} root
  72. * True if this is the root node.
  73. */
  74. <span id='Ext-data-NodeInterface-cfg-isLast'> /**
  75. </span> * @cfg {Boolean} isLast
  76. * True if this is the last node.
  77. */
  78. <span id='Ext-data-NodeInterface-cfg-isFirst'> /**
  79. </span> * @cfg {Boolean} isFirst
  80. * True if this is the first node.
  81. */
  82. <span id='Ext-data-NodeInterface-cfg-allowDrop'> /**
  83. </span> * @cfg {Boolean} [allowDrop=true]
  84. * Set to false to deny dropping on this node.
  85. */
  86. <span id='Ext-data-NodeInterface-cfg-allowDrag'> /**
  87. </span> * @cfg {Boolean} [allowDrag=true]
  88. * Set to false to deny dragging of this node.
  89. */
  90. <span id='Ext-data-NodeInterface-cfg-loaded'> /**
  91. </span> * @cfg {Boolean} [loaded=false]
  92. * True if the node has finished loading.
  93. */
  94. <span id='Ext-data-NodeInterface-cfg-loading'> /**
  95. </span> * @cfg {Boolean} [loading=false]
  96. * True if the node is currently loading.
  97. */
  98. <span id='Ext-data-NodeInterface-cfg-href'> /**
  99. </span> * @cfg {String} href
  100. * An URL for a link that's created when this config is specified.
  101. */
  102. <span id='Ext-data-NodeInterface-cfg-hrefTarget'> /**
  103. </span> * @cfg {String} hrefTarget
  104. * Target for link. Only applicable when {@link #href} also specified.
  105. */
  106. <span id='Ext-data-NodeInterface-cfg-qtip'> /**
  107. </span> * @cfg {String} qtip
  108. * Tooltip text to show on this node.
  109. */
  110. <span id='Ext-data-NodeInterface-cfg-qtitle'> /**
  111. </span> * @cfg {String} qtitle
  112. * Tooltip title.
  113. */
  114. <span id='Ext-data-NodeInterface-cfg-text'> /**
  115. </span> * @cfg {String} text
  116. * The text for to show on node label.
  117. */
  118. <span id='Ext-data-NodeInterface-cfg-children'> /**
  119. </span> * @cfg {Ext.data.NodeInterface[]} children
  120. * Array of child nodes.
  121. */
  122. <span id='Ext-data-NodeInterface-property-nextSibling'> /**
  123. </span> * @property nextSibling
  124. * A reference to this node's next sibling node. `null` if this node does not have a next sibling.
  125. */
  126. <span id='Ext-data-NodeInterface-property-previousSibling'> /**
  127. </span> * @property previousSibling
  128. * A reference to this node's previous sibling node. `null` if this node does not have a previous sibling.
  129. */
  130. <span id='Ext-data-NodeInterface-property-parentNode'> /**
  131. </span> * @property parentNode
  132. * A reference to this node's parent node. `null` if this node is the root node.
  133. */
  134. <span id='Ext-data-NodeInterface-property-lastChild'> /**
  135. </span> * @property lastChild
  136. * A reference to this node's last child node. `null` if this node has no children.
  137. */
  138. <span id='Ext-data-NodeInterface-property-firstChild'> /**
  139. </span> * @property firstChild
  140. * A reference to this node's first child node. `null` if this node has no children.
  141. */
  142. <span id='Ext-data-NodeInterface-property-childNodes'> /**
  143. </span> * @property childNodes
  144. * An array of this nodes children. Array will be empty if this node has no chidren.
  145. */
  146. statics: {
  147. <span id='Ext-data-NodeInterface-static-method-decorate'> /**
  148. </span> * This method allows you to decorate a Model's class to implement the NodeInterface.
  149. * This adds a set of methods, new events, new properties and new fields on every Record.
  150. * @param {Ext.Class/Ext.data.Model} modelClass The Model class or an instance of the Model class you want to
  151. * decorate the prototype of.
  152. * @static
  153. */
  154. decorate: function(modelClass) {
  155. var idName, idType;
  156. // get the reference to the model class, in case the argument was a string or a record
  157. if (typeof modelClass == 'string') {
  158. modelClass = Ext.ModelManager.getModel(modelClass);
  159. } else if (modelClass.isModel) {
  160. modelClass = Ext.ModelManager.getModel(modelClass.modelName);
  161. }
  162. // avoid unnecessary work in case the model was already decorated
  163. if (modelClass.prototype.isNode) {
  164. return;
  165. }
  166. idName = modelClass.prototype.idProperty;
  167. idField = modelClass.prototype.fields.get(idName);
  168. idType = modelClass.prototype.fields.get(idName).type.type;
  169. modelClass.override(this.getPrototypeBody());
  170. this.applyFields(modelClass, [
  171. {name: 'parentId', type: idType, defaultValue: null, useNull: idField.useNull},
  172. {name: 'index', type: 'int', defaultValue: null, persist: false},
  173. {name: 'depth', type: 'int', defaultValue: 0, persist: false},
  174. {name: 'expanded', type: 'bool', defaultValue: false, persist: false},
  175. {name: 'expandable', type: 'bool', defaultValue: true, persist: false},
  176. {name: 'checked', type: 'auto', defaultValue: null, persist: false},
  177. {name: 'leaf', type: 'bool', defaultValue: false},
  178. {name: 'cls', type: 'string', defaultValue: null, persist: false},
  179. {name: 'iconCls', type: 'string', defaultValue: null, persist: false},
  180. {name: 'icon', type: 'string', defaultValue: null, persist: false},
  181. {name: 'root', type: 'boolean', defaultValue: false, persist: false},
  182. {name: 'isLast', type: 'boolean', defaultValue: false, persist: false},
  183. {name: 'isFirst', type: 'boolean', defaultValue: false, persist: false},
  184. {name: 'allowDrop', type: 'boolean', defaultValue: true, persist: false},
  185. {name: 'allowDrag', type: 'boolean', defaultValue: true, persist: false},
  186. {name: 'loaded', type: 'boolean', defaultValue: false, persist: false},
  187. {name: 'loading', type: 'boolean', defaultValue: false, persist: false},
  188. {name: 'href', type: 'string', defaultValue: null, persist: false},
  189. {name: 'hrefTarget', type: 'string', defaultValue: null, persist: false},
  190. {name: 'qtip', type: 'string', defaultValue: null, persist: false},
  191. {name: 'qtitle', type: 'string', defaultValue: null, persist: false},
  192. {name: 'children', type: 'auto', defaultValue: null, persist: false}
  193. ]);
  194. },
  195. applyFields: function(modelClass, addFields) {
  196. var modelPrototype = modelClass.prototype,
  197. fields = modelPrototype.fields,
  198. keys = fields.keys,
  199. ln = addFields.length,
  200. addField, i;
  201. for (i = 0; i &lt; ln; i++) {
  202. addField = addFields[i];
  203. if (!Ext.Array.contains(keys, addField.name)) {
  204. fields.add(new Ext.data.Field(addField));
  205. }
  206. }
  207. },
  208. getPrototypeBody: function() {
  209. return {
  210. <span id='Ext-data-NodeInterface-property-isNode'> /**
  211. </span> * @property {Boolean} isNode
  212. * `true` in this class to identify an object as an instantiated Node, or subclass thereof.
  213. */
  214. isNode: true,
  215. constructor: function() {
  216. var me = this;
  217. this.callParent(arguments);
  218. Ext.applyIf(me, {
  219. firstChild: null,
  220. lastChild: null,
  221. parentNode: null,
  222. previousSibling: null,
  223. nextSibling: null,
  224. childNodes: []
  225. });
  226. me.enableBubble([
  227. <span id='Ext-data-NodeInterface-event-append'> /**
  228. </span> * @event append
  229. * Fires when a new child node is appended
  230. * @param {Ext.data.NodeInterface} this This node
  231. * @param {Ext.data.NodeInterface} node The newly appended node
  232. * @param {Number} index The index of the newly appended node
  233. */
  234. &quot;append&quot;,
  235. <span id='Ext-data-NodeInterface-event-remove'> /**
  236. </span> * @event remove
  237. * Fires when a child node is removed
  238. * @param {Ext.data.NodeInterface} this This node
  239. * @param {Ext.data.NodeInterface} node The removed node
  240. * @param {Boolean} isMove `true` if the child node is being removed so it can be moved to another position in the tree.
  241. * (a side effect of calling {@link Ext.data.NodeInterface#appendChild appendChild} or
  242. * {@link Ext.data.NodeInterface#insertBefore insertBefore} with a node that already has a parentNode)
  243. */
  244. &quot;remove&quot;,
  245. <span id='Ext-data-NodeInterface-event-move'> /**
  246. </span> * @event move
  247. * Fires when this node is moved to a new location in the tree
  248. * @param {Ext.data.NodeInterface} this This node
  249. * @param {Ext.data.NodeInterface} oldParent The old parent of this node
  250. * @param {Ext.data.NodeInterface} newParent The new parent of this node
  251. * @param {Number} index The index it was moved to
  252. */
  253. &quot;move&quot;,
  254. <span id='Ext-data-NodeInterface-event-insert'> /**
  255. </span> * @event insert
  256. * Fires when a new child node is inserted.
  257. * @param {Ext.data.NodeInterface} this This node
  258. * @param {Ext.data.NodeInterface} node The child node inserted
  259. * @param {Ext.data.NodeInterface} refNode The child node the node was inserted before
  260. */
  261. &quot;insert&quot;,
  262. <span id='Ext-data-NodeInterface-event-beforeappend'> /**
  263. </span> * @event beforeappend
  264. * Fires before a new child is appended, return false to cancel the append.
  265. * @param {Ext.data.NodeInterface} this This node
  266. * @param {Ext.data.NodeInterface} node The child node to be appended
  267. */
  268. &quot;beforeappend&quot;,
  269. <span id='Ext-data-NodeInterface-event-beforeremove'> /**
  270. </span> * @event beforeremove
  271. * Fires before a child is removed, return false to cancel the remove.
  272. * @param {Ext.data.NodeInterface} this This node
  273. * @param {Ext.data.NodeInterface} node The child node to be removed
  274. * @param {Boolean} isMove `true` if the child node is being removed so it can be moved to another position in the tree.
  275. * (a side effect of calling {@link Ext.data.NodeInterface#appendChild appendChild} or
  276. * {@link Ext.data.NodeInterface#insertBefore insertBefore} with a node that already has a parentNode)
  277. */
  278. &quot;beforeremove&quot;,
  279. <span id='Ext-data-NodeInterface-event-beforemove'> /**
  280. </span> * @event beforemove
  281. * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
  282. * @param {Ext.data.NodeInterface} this This node
  283. * @param {Ext.data.NodeInterface} oldParent The parent of this node
  284. * @param {Ext.data.NodeInterface} newParent The new parent this node is moving to
  285. * @param {Number} index The index it is being moved to
  286. */
  287. &quot;beforemove&quot;,
  288. <span id='Ext-data-NodeInterface-event-beforeinsert'> /**
  289. </span> * @event beforeinsert
  290. * Fires before a new child is inserted, return false to cancel the insert.
  291. * @param {Ext.data.NodeInterface} this This node
  292. * @param {Ext.data.NodeInterface} node The child node to be inserted
  293. * @param {Ext.data.NodeInterface} refNode The child node the node is being inserted before
  294. */
  295. &quot;beforeinsert&quot;,
  296. <span id='Ext-data-NodeInterface-event-expand'> /**
  297. </span> * @event expand
  298. * Fires when this node is expanded.
  299. * @param {Ext.data.NodeInterface} this The expanding node
  300. */
  301. &quot;expand&quot;,
  302. <span id='Ext-data-NodeInterface-event-collapse'> /**
  303. </span> * @event collapse
  304. * Fires when this node is collapsed.
  305. * @param {Ext.data.NodeInterface} this The collapsing node
  306. */
  307. &quot;collapse&quot;,
  308. <span id='Ext-data-NodeInterface-event-beforeexpand'> /**
  309. </span> * @event beforeexpand
  310. * Fires before this node is expanded.
  311. * @param {Ext.data.NodeInterface} this The expanding node
  312. */
  313. &quot;beforeexpand&quot;,
  314. <span id='Ext-data-NodeInterface-event-beforecollapse'> /**
  315. </span> * @event beforecollapse
  316. * Fires before this node is collapsed.
  317. * @param {Ext.data.NodeInterface} this The collapsing node
  318. */
  319. &quot;beforecollapse&quot;,
  320. <span id='Ext-data-NodeInterface-event-sort'> /**
  321. </span> * @event sort
  322. * Fires when this node's childNodes are sorted.
  323. * @param {Ext.data.NodeInterface} this This node.
  324. * @param {Ext.data.NodeInterface[]} childNodes The childNodes of this node.
  325. */
  326. &quot;sort&quot;
  327. ]);
  328. return me;
  329. },
  330. <span id='Ext-data-NodeInterface-method-createNode'> /**
  331. </span> * Ensures that the passed object is an instance of a Record with the NodeInterface applied
  332. * @return {Ext.data.NodeInterface}
  333. */
  334. createNode: function(node) {
  335. if (Ext.isObject(node) &amp;&amp; !node.isModel) {
  336. node = Ext.ModelManager.create(node, this.modelName);
  337. }
  338. // The node may already decorated, but may not have been
  339. // so when the model constructor was called. If not,
  340. // setup defaults here
  341. if (!node.childNodes) {
  342. Ext.applyIf(node, {
  343. firstChild: null,
  344. lastChild: null,
  345. parentNode: null,
  346. previousSibling: null,
  347. nextSibling: null,
  348. childNodes: []
  349. });
  350. }
  351. return node;
  352. },
  353. <span id='Ext-data-NodeInterface-method-isLeaf'> /**
  354. </span> * Returns true if this node is a leaf
  355. * @return {Boolean}
  356. */
  357. isLeaf : function() {
  358. return this.get('leaf') === true;
  359. },
  360. <span id='Ext-data-NodeInterface-method-setFirstChild'> /**
  361. </span> * Sets the first child of this node
  362. * @private
  363. * @param {Ext.data.NodeInterface} node
  364. */
  365. setFirstChild : function(node) {
  366. this.firstChild = node;
  367. },
  368. <span id='Ext-data-NodeInterface-method-setLastChild'> /**
  369. </span> * Sets the last child of this node
  370. * @private
  371. * @param {Ext.data.NodeInterface} node
  372. */
  373. setLastChild : function(node) {
  374. this.lastChild = node;
  375. },
  376. <span id='Ext-data-NodeInterface-method-updateInfo'> /**
  377. </span> * Updates general data of this node like isFirst, isLast, depth. This
  378. * method is internally called after a node is moved. This shouldn't
  379. * have to be called by the developer unless they are creating custom
  380. * Tree plugins.
  381. * @return {Boolean}
  382. */
  383. updateInfo: function(commit) {
  384. var me = this,
  385. isRoot = me.isRoot(),
  386. parentNode = me.parentNode,
  387. isFirst = (!parentNode || isRoot ? true : parentNode.firstChild === me),
  388. isLast = (!parentNode || isRoot ? true : parentNode.lastChild === me),
  389. depth = 0,
  390. parent = me,
  391. children = me.childNodes,
  392. len = children.length,
  393. i = 0,
  394. phantom = me.phantom;
  395. while (parent.parentNode) {
  396. ++depth;
  397. parent = parent.parentNode;
  398. }
  399. me.beginEdit();
  400. me.set({
  401. isFirst: isFirst,
  402. isLast: isLast,
  403. depth: depth,
  404. index: parentNode ? parentNode.indexOf(me) : 0,
  405. parentId: parentNode ? parentNode.getId() : null
  406. });
  407. me.endEdit(true);
  408. if (commit) {
  409. me.commit();
  410. me.phantom = phantom;
  411. }
  412. for (i = 0; i &lt; len; i++) {
  413. children[i].updateInfo(commit);
  414. }
  415. },
  416. <span id='Ext-data-NodeInterface-method-isLast'> /**
  417. </span> * Returns true if this node is the last child of its parent
  418. * @return {Boolean}
  419. */
  420. isLast : function() {
  421. return this.get('isLast');
  422. },
  423. <span id='Ext-data-NodeInterface-method-isFirst'> /**
  424. </span> * Returns true if this node is the first child of its parent
  425. * @return {Boolean}
  426. */
  427. isFirst : function() {
  428. return this.get('isFirst');
  429. },
  430. <span id='Ext-data-NodeInterface-method-hasChildNodes'> /**
  431. </span> * Returns true if this node has one or more child nodes, else false.
  432. * @return {Boolean}
  433. */
  434. hasChildNodes : function() {
  435. return !this.isLeaf() &amp;&amp; this.childNodes.length &gt; 0;
  436. },
  437. <span id='Ext-data-NodeInterface-method-isExpandable'> /**
  438. </span> * Returns true if this node has one or more child nodes, or if the &lt;tt&gt;expandable&lt;/tt&gt;
  439. * node attribute is explicitly specified as true, otherwise returns false.
  440. * @return {Boolean}
  441. */
  442. isExpandable : function() {
  443. var me = this;
  444. if (me.get('expandable')) {
  445. return !(me.isLeaf() || (me.isLoaded() &amp;&amp; !me.hasChildNodes()));
  446. }
  447. return false;
  448. },
  449. triggerUIUpdate: function(){
  450. // This isn't ideal, however none of the underlying fields have changed
  451. // but we still need to update the UI
  452. this.afterEdit([]);
  453. },
  454. <span id='Ext-data-NodeInterface-method-appendChild'> /**
  455. </span> * Inserts node(s) as the last child node of this node.
  456. *
  457. * If the node was previously a child node of another parent node, it will be removed from that node first.
  458. *
  459. * @param {Ext.data.NodeInterface/Ext.data.NodeInterface[]} node The node or Array of nodes to append
  460. * @return {Ext.data.NodeInterface} The appended node if single append, or null if an array was passed
  461. */
  462. appendChild : function(node, suppressEvents, commit) {
  463. var me = this,
  464. i, ln,
  465. index,
  466. oldParent,
  467. ps;
  468. // if passed an array do them one by one
  469. if (Ext.isArray(node)) {
  470. // suspend auto syncing while we append all the nodes
  471. me.callStore('suspendAutoSync');
  472. for (i = 0, ln = node.length - 1; i &lt; ln; i++) {
  473. me.appendChild(node[i]);
  474. }
  475. // resume auto syncing before we append the last node
  476. me.callStore('resumeAutoSync');
  477. me.appendChild(node[ln]);
  478. } else {
  479. // Make sure it is a record
  480. node = me.createNode(node);
  481. if (suppressEvents !== true &amp;&amp; (!me.hasListeners.beforeappend || me.fireEvent(&quot;beforeappend&quot;, me, node) === false)) {
  482. return false;
  483. }
  484. index = me.childNodes.length;
  485. oldParent = node.parentNode;
  486. // it's a move, make sure we move it cleanly
  487. if (oldParent) {
  488. if (suppressEvents !== true &amp;&amp; (!me.hasListeners.beforeremove || node.fireEvent(&quot;beforemove&quot;, node, oldParent, me, index) === false)) {
  489. return false;
  490. }
  491. oldParent.removeChild(node, false, false, true);
  492. }
  493. index = me.childNodes.length;
  494. if (index === 0) {
  495. me.setFirstChild(node);
  496. }
  497. me.childNodes.push(node);
  498. node.parentNode = me;
  499. node.nextSibling = null;
  500. me.setLastChild(node);
  501. ps = me.childNodes[index - 1];
  502. if (ps) {
  503. node.previousSibling = ps;
  504. ps.nextSibling = node;
  505. ps.updateInfo(commit);
  506. } else {
  507. node.previousSibling = null;
  508. }
  509. node.updateInfo(commit);
  510. // As soon as we append a child to this node, we are loaded
  511. if (!me.isLoaded()) {
  512. me.set('loaded', true);
  513. } else if (me.childNodes.length === 1) {
  514. me.triggerUIUpdate();
  515. }
  516. if(!node.isLeaf() &amp;&amp; node.phantom) {
  517. node.set('loaded', true);
  518. }
  519. if (suppressEvents !== true) {
  520. me.fireEvent(&quot;append&quot;, me, node, index);
  521. if (oldParent) {
  522. node.fireEvent(&quot;move&quot;, node, oldParent, me, index);
  523. }
  524. }
  525. return node;
  526. }
  527. },
  528. <span id='Ext-data-NodeInterface-method-getBubbleTarget'> /**
  529. </span> * Returns the bubble target for this node
  530. * @private
  531. * @return {Object} The bubble target
  532. */
  533. getBubbleTarget: function() {
  534. return this.parentNode;
  535. },
  536. <span id='Ext-data-NodeInterface-method-removeChild'> /**
  537. </span> * Removes a child node from this node.
  538. * @param {Ext.data.NodeInterface} node The node to remove
  539. * @param {Boolean} [destroy=false] True to destroy the node upon removal.
  540. * @return {Ext.data.NodeInterface} The removed node
  541. */
  542. removeChild : function(node, destroy, suppressEvents, isMove) {
  543. var me = this,
  544. index = me.indexOf(node),
  545. i, childCount;
  546. if (index == -1 || (suppressEvents !== true &amp;&amp; (!me.hasListeners.beforeremove || me.fireEvent(&quot;beforeremove&quot;, me, node, !!isMove) === false))) {
  547. return false;
  548. }
  549. // remove it from childNodes collection
  550. Ext.Array.erase(me.childNodes, index, 1);
  551. // update child refs
  552. if (me.firstChild == node) {
  553. me.setFirstChild(node.nextSibling);
  554. }
  555. if (me.lastChild == node) {
  556. me.setLastChild(node.previousSibling);
  557. }
  558. // update siblings
  559. if (node.previousSibling) {
  560. node.previousSibling.nextSibling = node.nextSibling;
  561. }
  562. if (node.nextSibling) {
  563. node.nextSibling.previousSibling = node.previousSibling;
  564. }
  565. // update the info for all siblings starting at the index before the node's old index (or 0 if the removed node was the firstChild)
  566. for(i = index &gt; 0 ? index - 1 : 0, childCount = me.childNodes.length; i &lt; childCount; i++) {
  567. me.childNodes[i].updateInfo();
  568. }
  569. // If this node suddenly doesnt have childnodes anymore, update myself
  570. if (!me.childNodes.length) {
  571. me.triggerUIUpdate();
  572. }
  573. if (suppressEvents !== true) {
  574. if (me.hasListeners.remove) {
  575. me.fireEvent(&quot;remove&quot;, me, node, !!isMove);
  576. }
  577. }
  578. if (destroy) {
  579. node.destroy(true);
  580. } else {
  581. node.clear();
  582. }
  583. return node;
  584. },
  585. <span id='Ext-data-NodeInterface-method-copy'> /**
  586. </span> * Creates a copy (clone) of this Node.
  587. * @param {String} [id] A new id, defaults to this Node's id.
  588. * @param {Boolean} [deep=false] True to recursively copy all child Nodes into the new Node.
  589. * False to copy without child Nodes.
  590. * @return {Ext.data.NodeInterface} A copy of this Node.
  591. */
  592. copy: function(newId, deep) {
  593. var me = this,
  594. result = me.callOverridden(arguments),
  595. len = me.childNodes ? me.childNodes.length : 0,
  596. i;
  597. // Move child nodes across to the copy if required
  598. if (deep) {
  599. for (i = 0; i &lt; len; i++) {
  600. result.appendChild(me.childNodes[i].copy(true));
  601. }
  602. }
  603. return result;
  604. },
  605. <span id='Ext-data-NodeInterface-method-clear'> /**
  606. </span> * Clears the node.
  607. * @private
  608. * @param {Boolean} [destroy=false] True to destroy the node.
  609. */
  610. clear : function(destroy) {
  611. var me = this;
  612. // clear any references from the node
  613. me.parentNode = me.previousSibling = me.nextSibling = null;
  614. if (destroy) {
  615. me.firstChild = me.lastChild = null;
  616. }
  617. },
  618. <span id='Ext-data-NodeInterface-method-destroy'> /**
  619. </span> * Destroys the node.
  620. */
  621. destroy : function(silent) {
  622. /*
  623. * Silent is to be used in a number of cases
  624. * 1) When setRoot is called.
  625. * 2) When destroy on the tree is called
  626. * 3) For destroying child nodes on a node
  627. */
  628. var me = this,
  629. options = me.destroyOptions,
  630. nodes = me.childNodes,
  631. nLen = nodes.length,
  632. n;
  633. if (silent === true) {
  634. me.clear(true);
  635. for (n = 0; n &lt; nLen; n++) {
  636. nodes[n].destroy(true);
  637. }
  638. me.childNodes = null;
  639. delete me.destroyOptions;
  640. me.callOverridden([options]);
  641. } else {
  642. me.destroyOptions = silent;
  643. // overridden method will be called, since remove will end up calling destroy(true);
  644. me.remove(true);
  645. }
  646. },
  647. <span id='Ext-data-NodeInterface-method-insertBefore'> /**
  648. </span> * Inserts the first node before the second node in this nodes childNodes collection.
  649. * @param {Ext.data.NodeInterface} node The node to insert
  650. * @param {Ext.data.NodeInterface} refNode The node to insert before (if null the node is appended)
  651. * @return {Ext.data.NodeInterface} The inserted node
  652. */
  653. insertBefore : function(node, refNode, suppressEvents) {
  654. var me = this,
  655. index = me.indexOf(refNode),
  656. oldParent = node.parentNode,
  657. refIndex = index,
  658. childCount, ps, i;
  659. if (!refNode) { // like standard Dom, refNode can be null for append
  660. return me.appendChild(node);
  661. }
  662. // nothing to do
  663. if (node == refNode) {
  664. return false;
  665. }
  666. // Make sure it is a record with the NodeInterface
  667. node = me.createNode(node);
  668. if (suppressEvents !== true &amp;&amp; (!me.hasListeners.beforeinsert || me.fireEvent(&quot;beforeinsert&quot;, me, node, refNode) === false)) {
  669. return false;
  670. }
  671. // when moving internally, indexes will change after remove
  672. if (oldParent == me &amp;&amp; me.indexOf(node) &lt; index) {
  673. refIndex--;
  674. }
  675. // it's a move, make sure we move it cleanly
  676. if (oldParent) {
  677. if (suppressEvents !== true &amp;&amp; (!me.hasListeners.beforeremove || node.fireEvent(&quot;beforemove&quot;, node, oldParent, me, index, refNode) === false)) {
  678. return false;
  679. }
  680. oldParent.removeChild(node, false, false, true);
  681. }
  682. if (refIndex === 0) {
  683. me.setFirstChild(node);
  684. }
  685. Ext.Array.splice(me.childNodes, refIndex, 0, node);
  686. node.parentNode = me;
  687. node.nextSibling = refNode;
  688. refNode.previousSibling = node;
  689. ps = me.childNodes[refIndex - 1];
  690. if (ps) {
  691. node.previousSibling = ps;
  692. ps.nextSibling = node;
  693. } else {
  694. node.previousSibling = null;
  695. }
  696. // update the info for all siblings starting at the index before the node's insertion point (or 0 if the inserted node is the firstChild)
  697. for(i = refIndex &gt; 0 ? refIndex - 1 : 0, childCount = me.childNodes.length; i &lt; childCount; i++) {
  698. me.childNodes[i].updateInfo();
  699. }
  700. if (!me.isLoaded()) {
  701. me.set('loaded', true);
  702. }
  703. // If this node didnt have any childnodes before, update myself
  704. else if (me.childNodes.length === 1) {
  705. me.triggerUIUpdate();
  706. }
  707. if(!node.isLeaf() &amp;&amp; node.phantom) {
  708. node.set('loaded', true);
  709. }
  710. if (suppressEvents !== true) {
  711. if (me.hasListeners.insert) {
  712. me.fireEvent(&quot;insert&quot;, me, node, refNode);
  713. }
  714. if (oldParent &amp;&amp; me.hasListeners.move) {
  715. node.fireEvent(&quot;move&quot;, node, oldParent, me, refIndex, refNode);
  716. }
  717. }
  718. return node;
  719. },
  720. <span id='Ext-data-NodeInterface-method-insertChild'> /**
  721. </span> * Inserts a node into this node.
  722. * @param {Number} index The zero-based index to insert the node at
  723. * @param {Ext.data.NodeInterface} node The node to insert
  724. * @return {Ext.data.NodeInterface} The node you just inserted
  725. */
  726. insertChild: function(index, node) {
  727. var sibling = this.childNodes[index];
  728. if (sibling) {
  729. return this.insertBefore(node, sibling);
  730. }
  731. else {
  732. return this.appendChild(node);
  733. }
  734. },
  735. <span id='Ext-data-NodeInterface-method-remove'> /**
  736. </span> * Removes this node from its parent
  737. * @param {Boolean} [destroy=false] True to destroy the node upon removal.
  738. * @return {Ext.data.NodeInterface} this
  739. */
  740. remove : function(destroy, suppressEvents) {
  741. var parentNode = this.parentNode;
  742. if (parentNode) {
  743. parentNode.removeChild(this, destroy, suppressEvents);
  744. }
  745. return this;
  746. },
  747. <span id='Ext-data-NodeInterface-method-removeAll'> /**
  748. </span> * Removes all child nodes from this node.
  749. * @param {Boolean} [destroy=false] &lt;True to destroy the node upon removal.
  750. * @return {Ext.data.NodeInterface} this
  751. */
  752. removeAll : function(destroy, suppressEvents) {
  753. var cn = this.childNodes,
  754. n;
  755. while ((n = cn[0])) {
  756. this.removeChild(n, destroy, suppressEvents);
  757. }
  758. return this;
  759. },
  760. <span id='Ext-data-NodeInterface-method-getChildAt'> /**
  761. </span> * Returns the child node at the specified index.
  762. * @param {Number} index
  763. * @return {Ext.data.NodeInterface}
  764. */
  765. getChildAt : function(index) {
  766. return this.childNodes[index];
  767. },
  768. <span id='Ext-data-NodeInterface-method-replaceChild'> /**
  769. </span> * Replaces one child node in this node with another.
  770. * @param {Ext.data.NodeInterface} newChild The replacement node
  771. * @param {Ext.data.NodeInterface} oldChild The node to replace
  772. * @return {Ext.data.NodeInterface} The replaced node
  773. */
  774. replaceChild : function(newChild, oldChild, suppressEvents) {
  775. var s = oldChild ? oldChild.nextSibling : null;
  776. this.removeChild(oldChild, false, suppressEvents);
  777. this.insertBefore(newChild, s, suppressEvents);
  778. return oldChild;
  779. },
  780. <span id='Ext-data-NodeInterface-method-indexOf'> /**
  781. </span> * Returns the index of a child node
  782. * @param {Ext.data.NodeInterface} node
  783. * @return {Number} The index of the node or -1 if it was not found
  784. */
  785. indexOf : function(child) {
  786. return Ext.Array.indexOf(this.childNodes, child);
  787. },
  788. <span id='Ext-data-NodeInterface-method-indexOfId'> /**
  789. </span> * Returns the index of a child node that matches the id
  790. * @param {String} id The id of the node to find
  791. * @return {Number} The index of the node or -1 if it was not found
  792. */
  793. indexOfId: function(id) {
  794. var childNodes = this.childNodes,
  795. len = childNodes.length,
  796. i = 0;
  797. for (; i &lt; len; ++i) {
  798. if (childNodes[i].getId() === id) {
  799. return i;
  800. }
  801. }
  802. return -1;
  803. },
  804. <span id='Ext-data-NodeInterface-method-getPath'> /**
  805. </span> * Gets the hierarchical path from the root of the current node.
  806. * @param {String} [field] The field to construct the path from. Defaults to the model idProperty.
  807. * @param {String} [separator=&quot;/&quot;] A separator to use.
  808. * @return {String} The node path
  809. */
  810. getPath: function(field, separator) {
  811. field = field || this.idProperty;
  812. separator = separator || '/';
  813. var path = [this.get(field)],
  814. parent = this.parentNode;
  815. while (parent) {
  816. path.unshift(parent.get(field));
  817. parent = parent.parentNode;
  818. }
  819. return separator + path.join(separator);
  820. },
  821. <span id='Ext-data-NodeInterface-method-getDepth'> /**
  822. </span> * Returns depth of this node (the root node has a depth of 0)
  823. * @return {Number}
  824. */
  825. getDepth : function() {
  826. return this.get('depth');
  827. },
  828. <span id='Ext-data-NodeInterface-method-bubble'> /**
  829. </span> * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function
  830. * will be the args provided or the current node. If the function returns false at any point,
  831. * the bubble is stopped.
  832. * @param {Function} fn The function to call
  833. * @param {Object} [scope] The scope (this reference) in which the function is executed. Defaults to the current Node.
  834. * @param {Array} [args] The args to call the function with. Defaults to passing the current Node.
  835. */
  836. bubble : function(fn, scope, args) {
  837. var p = this;
  838. while (p) {
  839. if (fn.apply(scope || p, args || [p]) === false) {
  840. break;
  841. }
  842. p = p.parentNode;
  843. }
  844. },
  845. //&lt;deprecated since=0.99&gt;
  846. cascade: function() {
  847. if (Ext.isDefined(Ext.global.console)) {
  848. Ext.global.console.warn('Ext.data.Node: cascade has been deprecated. Please use cascadeBy instead.');
  849. }
  850. return this.cascadeBy.apply(this, arguments);
  851. },
  852. //&lt;/deprecated&gt;
  853. <span id='Ext-data-NodeInterface-method-cascadeBy'> /**
  854. </span> * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function
  855. * will be the args provided or the current node. If the function returns false at any point,
  856. * the cascade is stopped on that branch.
  857. * @param {Function} fn The function to call
  858. * @param {Object} [scope] The scope (this reference) in which the function is executed. Defaults to the current Node.
  859. * @param {Array} [args] The args to call the function with. Defaults to passing the current Node.
  860. */
  861. cascadeBy : function(fn, scope, args) {
  862. if (fn.apply(scope || this, args || [this]) !== false) {
  863. var childNodes = this.childNodes,
  864. length = childNodes.length,
  865. i;
  866. for (i = 0; i &lt; length; i++) {
  867. childNodes[i].cascadeBy(fn, scope, args);
  868. }
  869. }
  870. },
  871. <span id='Ext-data-NodeInterface-method-eachChild'> /**
  872. </span> * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function
  873. * will be the args provided or the current node. If the function returns false at any point,
  874. * the iteration stops.
  875. * @param {Function} fn The function to call
  876. * @param {Object} [scope] The scope (this reference) in which the function is executed. Defaults to the current Node in iteration.
  877. * @param {Array} [args] The args to call the function with. Defaults to passing the current Node.
  878. */
  879. eachChild : function(fn, scope, args) {
  880. var childNodes = this.childNodes,
  881. length = childNodes.length,
  882. i;
  883. for (i = 0; i &lt; length; i++) {
  884. if (fn.apply(scope || this, args || [childNodes[i]]) === false) {
  885. break;
  886. }
  887. }
  888. },
  889. <span id='Ext-data-NodeInterface-method-findChild'> /**
  890. </span> * Finds the first child that has the attribute with the specified value.
  891. * @param {String} attribute The attribute name
  892. * @param {Object} value The value to search for
  893. * @param {Boolean} [deep=false] True to search through nodes deeper than the immediate children
  894. * @return {Ext.data.NodeInterface} The found child or null if none was found
  895. */
  896. findChild : function(attribute, value, deep) {
  897. return this.findChildBy(function() {
  898. return this.get(attribute) == value;
  899. }, null, deep);
  900. },
  901. <span id='Ext-data-NodeInterface-method-findChildBy'> /**
  902. </span> * Finds the first child by a custom function. The child matches if the function passed returns true.
  903. * @param {Function} fn A function which must return true if the passed Node is the required Node.
  904. * @param {Object} [scope] The scope (this reference) in which the function is executed. Defaults to the Node being tested.
  905. * @param {Boolean} [deep=false] True to search through nodes deeper than the immediate children
  906. * @return {Ext.data.NodeInterface} The found child or null if none was found
  907. */
  908. findChildBy : function(fn, scope, deep) {
  909. var cs = this.childNodes,
  910. len = cs.length,
  911. i = 0, n, res;
  912. for (; i &lt; len; i++) {
  913. n = cs[i];
  914. if (fn.call(scope || n, n) === true) {
  915. return n;
  916. }
  917. else if (deep) {
  918. res = n.findChildBy(fn, scope, deep);
  919. if (res !== null) {
  920. return res;
  921. }
  922. }
  923. }
  924. return null;
  925. },
  926. <span id='Ext-data-NodeInterface-method-contains'> /**
  927. </span> * Returns true if this node is an ancestor (at any point) of the passed node.
  928. * @param {Ext.data.NodeInterface} node
  929. * @return {Boolean}
  930. */
  931. contains : function(node) {
  932. return node.isAncestor(this);
  933. },
  934. <span id='Ext-data-NodeInterface-method-isAncestor'> /**
  935. </span> * Returns true if the passed node is an ancestor (at any point) of this node.
  936. * @param {Ext.data.NodeInterface} node
  937. * @return {Boolean}
  938. */
  939. isAncestor : function(node) {
  940. var p = this.parentNode;
  941. while (p) {
  942. if (p == node) {
  943. return true;
  944. }
  945. p = p.parentNode;
  946. }
  947. return false;
  948. },
  949. <span id='Ext-data-NodeInterface-method-sort'> /**
  950. </span> * Sorts this nodes children using the supplied sort function.
  951. * @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.
  952. * @param {Boolean} [recursive=false] True to apply this sort recursively
  953. * @param {Boolean} [suppressEvent=false] True to not fire a sort event.
  954. */
  955. sort : function(sortFn, recursive, suppressEvent) {
  956. var cs = this.childNodes,
  957. ln = cs.length,
  958. i, n;
  959. if (ln &gt; 0) {
  960. Ext.Array.sort(cs, sortFn);
  961. for (i = 0; i &lt; ln; i++) {
  962. n = cs[i];
  963. n.previousSibling = cs[i-1];
  964. n.nextSibling = cs[i+1];
  965. if (i === 0) {
  966. this.setFirstChild(n);
  967. }
  968. if (i == ln - 1) {
  969. this.setLastChild(n);
  970. }
  971. n.updateInfo();
  972. if (recursive &amp;&amp; !n.isLeaf()) {
  973. n.sort(sortFn, true, true);
  974. }
  975. }
  976. if (suppressEvent !== true) {
  977. this.fireEvent('sort', this, cs);
  978. }
  979. }
  980. },
  981. <span id='Ext-data-NodeInterface-method-isExpanded'> /**
  982. </span> * Returns true if this node is expaned
  983. * @return {Boolean}
  984. */
  985. isExpanded: function() {
  986. return this.get('expanded');
  987. },
  988. <span id='Ext-data-NodeInterface-method-isLoaded'> /**
  989. </span> * Returns true if this node is loaded
  990. * @return {Boolean}
  991. */
  992. isLoaded: function() {
  993. return this.get('loaded');
  994. },
  995. <span id='Ext-data-NodeInterface-method-isLoading'> /**
  996. </span> * Returns true if this node is loading
  997. * @return {Boolean}
  998. */
  999. isLoading: function() {
  1000. return this.get('loading');
  1001. },
  1002. <span id='Ext-data-NodeInterface-method-isRoot'> /**
  1003. </span> * Returns true if this node is the root node
  1004. * @return {Boolean}
  1005. */
  1006. isRoot: function() {
  1007. return !this.parentNode;
  1008. },
  1009. <span id='Ext-data-NodeInterface-method-isVisible'> /**
  1010. </span> * Returns true if this node is visible
  1011. * @return {Boolean}
  1012. */
  1013. isVisible: function() {
  1014. var parent = this.parentNode;
  1015. while (parent) {
  1016. if (!parent.isExpanded()) {
  1017. return false;
  1018. }
  1019. parent = parent.parentNode;
  1020. }
  1021. return true;
  1022. },
  1023. <span id='Ext-data-NodeInterface-method-expand'> /**
  1024. </span> * Expand this node.
  1025. * @param {Boolean} [recursive=false] True to recursively expand all the children
  1026. * @param {Function} [callback] The function to execute once the expand completes
  1027. * @param {Object} [scope] The scope to run the callback in
  1028. */
  1029. expand: function(recursive, callback, scope) {
  1030. var me = this;
  1031. // all paths must call the callback (eventually) or things like
  1032. // selectPath fail
  1033. // First we start by checking if this node is a parent
  1034. if (!me.isLeaf()) {
  1035. // If it's loaded, wait until it loads before proceeding
  1036. if (me.isLoading()) {
  1037. me.on('expand', function(){
  1038. me.expand(recursive, callback, scope);
  1039. }, me, {single: true});
  1040. } else {
  1041. // Now we check if this record is already expanding or expanded
  1042. if (!me.isExpanded()) {
  1043. // The TreeStore actually listens for the beforeexpand method and checks
  1044. // whether we have to asynchronously load the children from the server
  1045. // first. Thats why we pass a callback function to the event that the
  1046. // store can call once it has loaded and parsed all the children.
  1047. me.fireEvent('beforeexpand', me, function() {
  1048. me.set('expanded', true);
  1049. if (me.hasListeners.expand) {
  1050. me.fireEvent('expand', me, me.childNodes, false);
  1051. }
  1052. // Call the expandChildren method if recursive was set to true
  1053. if (recursive) {
  1054. me.expandChildren(true, callback, scope);
  1055. } else {
  1056. Ext.callback(callback, scope || me, [me.childNodes]);
  1057. }
  1058. }, me);
  1059. } else if (recursive) {
  1060. // If it is is already expanded but we want to recursively expand then call expandChildren
  1061. me.expandChildren(true, callback, scope);
  1062. } else {
  1063. Ext.callback(callback, scope || me, [me.childNodes]);
  1064. }
  1065. }
  1066. } else {
  1067. // If it's not then we fire the callback right away
  1068. Ext.callback(callback, scope || me); // leaf = no childNodes
  1069. }
  1070. },
  1071. <span id='Ext-data-NodeInterface-method-expandChildren'> /**
  1072. </span> * Expand all the children of this node.
  1073. * @param {Boolean} [recursive=false] True to recursively expand all the children
  1074. * @param {Function} [callback] The function to execute once all the children are expanded
  1075. * @param {Object} [scope] The scope to run the callback in
  1076. */
  1077. expandChildren: function(recursive, callback, scope) {
  1078. var me = this,
  1079. i = 0,
  1080. nodes = me.childNodes,
  1081. ln = nodes.length,
  1082. node,
  1083. expanding = 0;
  1084. for (; i &lt; ln; ++i) {
  1085. node = nodes[i];
  1086. if (!node.isLeaf()) {
  1087. expanding++;
  1088. nodes[i].expand(recursive, function () {
  1089. expanding--;
  1090. if (callback &amp;&amp; !expanding) {
  1091. Ext.callback(callback, scope || me, [me.childNodes]);
  1092. }
  1093. });
  1094. }
  1095. }
  1096. if (!expanding &amp;&amp; callback) {
  1097. Ext.callback(callback, scope || me, [me.childNodes]); }
  1098. },
  1099. <span id='Ext-data-NodeInterface-method-collapse'> /**
  1100. </span> * Collapse this node.
  1101. * @param {Boolean} [recursive=false] True to recursively collapse all the children
  1102. * @param {Function} [callback] The function to execute once the collapse completes
  1103. * @param {Object} [scope] The scope to run the callback in
  1104. */
  1105. collapse: function(recursive, callback, scope) {
  1106. var me = this;
  1107. // First we start by checking if this node is a parent
  1108. if (!me.isLeaf()) {
  1109. // Now we check if this record is already collapsing or collapsed
  1110. if (!me.collapsing &amp;&amp; me.isExpanded()) {
  1111. me.fireEvent('beforecollapse', me, function() {
  1112. me.set('expanded', false);
  1113. if (me.hasListeners.collapse) {
  1114. me.fireEvent('collapse', me, me.childNodes, false);
  1115. }
  1116. // Call the collapseChildren method if recursive was set to true
  1117. if (recursive) {
  1118. me.collapseChildren(true, callback, scope);
  1119. }
  1120. else {
  1121. Ext.callback(callback, scope || me, [me.childNodes]);
  1122. }
  1123. }, me);
  1124. }
  1125. // If it is is already collapsed but we want to recursively collapse then call collapseChildren
  1126. else if (recursive) {
  1127. me.collapseChildren(true, callback, scope);
  1128. } else {
  1129. Ext.callback(callback, scope || me, [me.childNodes]);
  1130. }
  1131. }
  1132. // If it's not then we fire the callback right away
  1133. else {
  1134. Ext.callback(callback, scope || me, [me.childNodes]);
  1135. }
  1136. },
  1137. <span id='Ext-data-NodeInterface-method-collapseChildren'> /**
  1138. </span> * Collapse all the children of this node.
  1139. * @param {Function} [recursive=false] True to recursively collapse all the children
  1140. * @param {Function} [callback] The function to execute once all the children are collapsed
  1141. * @param {Object} [scope] The scope to run the callback in
  1142. */
  1143. collapseChildren: function(recursive, callback, scope) {
  1144. var me = this,
  1145. i = 0,
  1146. nodes = me.childNodes,
  1147. ln = nodes.length,
  1148. node,
  1149. collapsing = 0;
  1150. for (; i &lt; ln; ++i) {
  1151. node = nodes[i];
  1152. if (!node.isLeaf()) {
  1153. collapsing++;
  1154. nodes[i].collapse(recursive, function () {
  1155. collapsing--;
  1156. if (callback &amp;&amp; !collapsing) {
  1157. Ext.callback(callback, scope || me, [me.childNodes]);
  1158. }
  1159. });
  1160. }
  1161. }
  1162. if (!collapsing &amp;&amp; callback) {
  1163. Ext.callback(callback, scope || me, [me.childNodes]);
  1164. }
  1165. }
  1166. };
  1167. }
  1168. }
  1169. });
  1170. </pre>
  1171. </body>
  1172. </html>