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.

127 lines
4.6 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-tree-AsyncTreeNode-method-constructor'><span id='Ext-tree-AsyncTreeNode-cfg-loader'><span id='Ext-tree-AsyncTreeNode'>/**
  19. </span></span></span> * @class Ext.tree.AsyncTreeNode
  20. * @extends Ext.tree.TreeNode
  21. * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
  22. * @constructor
  23. * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
  24. */
  25. Ext.tree.AsyncTreeNode = function(config){
  26. this.loaded = config &amp;&amp; config.loaded === true;
  27. this.loading = false;
  28. Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
  29. <span id='Ext-tree-AsyncTreeNode-event-beforeload'> /**
  30. </span> * @event beforeload
  31. * Fires before this node is loaded, return false to cancel
  32. * @param {Node} this This node
  33. */
  34. this.addEvents('beforeload', 'load');
  35. <span id='Ext-tree-AsyncTreeNode-event-load'> /**
  36. </span> * @event load
  37. * Fires when this node is loaded
  38. * @param {Node} this This node
  39. */
  40. <span id='Ext-tree-AsyncTreeNode-property-loader'> /**
  41. </span> * The loader used by this node (defaults to using the tree's defined loader)
  42. * @type TreeLoader
  43. * @property loader
  44. */
  45. };
  46. Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
  47. expand : function(deep, anim, callback, scope){
  48. if(this.loading){ // if an async load is already running, waiting til it's done
  49. var timer;
  50. var f = function(){
  51. if(!this.loading){ // done loading
  52. clearInterval(timer);
  53. this.expand(deep, anim, callback, scope);
  54. }
  55. }.createDelegate(this);
  56. timer = setInterval(f, 200);
  57. return;
  58. }
  59. if(!this.loaded){
  60. if(this.fireEvent(&quot;beforeload&quot;, this) === false){
  61. return;
  62. }
  63. this.loading = true;
  64. this.ui.beforeLoad(this);
  65. var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
  66. if(loader){
  67. loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
  68. return;
  69. }
  70. }
  71. Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
  72. },
  73. <span id='Ext-tree-AsyncTreeNode-method-isLoading'> /**
  74. </span> * Returns true if this node is currently loading
  75. * @return {Boolean}
  76. */
  77. isLoading : function(){
  78. return this.loading;
  79. },
  80. loadComplete : function(deep, anim, callback, scope){
  81. this.loading = false;
  82. this.loaded = true;
  83. this.ui.afterLoad(this);
  84. this.fireEvent(&quot;load&quot;, this);
  85. this.expand(deep, anim, callback, scope);
  86. },
  87. <span id='Ext-tree-AsyncTreeNode-method-isLoaded'> /**
  88. </span> * Returns true if this node has been loaded
  89. * @return {Boolean}
  90. */
  91. isLoaded : function(){
  92. return this.loaded;
  93. },
  94. hasChildNodes : function(){
  95. if(!this.isLeaf() &amp;&amp; !this.loaded){
  96. return true;
  97. }else{
  98. return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
  99. }
  100. },
  101. <span id='Ext-tree-AsyncTreeNode-method-reload'> /**
  102. </span> * Trigger a reload for this node
  103. * @param {Function} callback
  104. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the callback is executed. Defaults to this Node.
  105. */
  106. reload : function(callback, scope){
  107. this.collapse(false, false);
  108. while(this.firstChild){
  109. this.removeChild(this.firstChild).destroy();
  110. }
  111. this.childrenRendered = false;
  112. this.loaded = false;
  113. if(this.isHiddenRoot()){
  114. this.expanded = false;
  115. }
  116. this.expand(false, false, callback, scope);
  117. }
  118. });
  119. Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;</pre>
  120. </body>
  121. </html>