Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / widgets / tree / TreeNode.js
index 1c25d9a..27693a6 100644 (file)
@@ -1,5 +1,5 @@
 /*!
 /*!
- * Ext JS Library 3.0.3
+ * Ext JS Library 3.1.0
  * Copyright(c) 2006-2009 Ext JS, LLC
  * licensing@extjs.com
  * http://www.extjs.com/license
  * Copyright(c) 2006-2009 Ext JS, LLC
  * licensing@extjs.com
  * http://www.extjs.com/license
  * @cfg {Boolean} draggable True to make this node draggable (defaults to false)\r
  * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)\r
  * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)\r
  * @cfg {Boolean} draggable True to make this node draggable (defaults to false)\r
  * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)\r
  * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)\r
- * @cfg {Boolean} editable False to not allow this node to be edited by an (@link Ext.tree.TreeEditor} (defaults to true)\r
+ * @cfg {Boolean} editable False to not allow this node to be edited by an {@link Ext.tree.TreeEditor} (defaults to true)\r
  * @constructor\r
  * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node\r
  */\r
 Ext.tree.TreeNode = function(attributes){\r
     attributes = attributes || {};\r
  * @constructor\r
  * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node\r
  */\r
 Ext.tree.TreeNode = function(attributes){\r
     attributes = attributes || {};\r
-    if(typeof attributes == 'string'){\r
+    if(Ext.isString(attributes)){\r
         attributes = {text: attributes};\r
     }\r
     this.childrenRendered = false;\r
         attributes = {text: attributes};\r
     }\r
     this.childrenRendered = false;\r
@@ -186,7 +186,7 @@ Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
 \r
     getLoader : function(){\r
         var owner;\r
 \r
     getLoader : function(){\r
         var owner;\r
-        return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : new Ext.tree.TreeLoader());\r
+        return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : (this.loader = new Ext.tree.TreeLoader()));\r
     },\r
 \r
     // private override\r
     },\r
 \r
     // private override\r
@@ -228,11 +228,11 @@ Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
     },\r
 \r
     // private override\r
     },\r
 \r
     // private override\r
-    removeChild : function(node){\r
+    removeChild : function(node, destroy){\r
         this.ownerTree.getSelectionModel().unselect(node);\r
         Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);\r
         // if it's been rendered remove dom node\r
         this.ownerTree.getSelectionModel().unselect(node);\r
         Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);\r
         // if it's been rendered remove dom node\r
-        if(this.childrenRendered){\r
+        if(node.ui.rendered){\r
             node.ui.remove();\r
         }\r
         if(this.childNodes.length < 1){\r
             node.ui.remove();\r
         }\r
         if(this.childNodes.length < 1){\r
@@ -265,8 +265,7 @@ Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
      */\r
     setText : function(text){\r
         var oldText = this.text;\r
      */\r
     setText : function(text){\r
         var oldText = this.text;\r
-        this.text = text;\r
-        this.attributes.text = text;\r
+        this.text = this.attributes.text = text;\r
         if(this.rendered){ // event without subscribing\r
             this.ui.onTextChange(this, text, oldText);\r
         }\r
         if(this.rendered){ // event without subscribing\r
             this.ui.onTextChange(this, text, oldText);\r
         }\r
@@ -277,14 +276,21 @@ Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
      * Triggers selection of this node\r
      */\r
     select : function(){\r
      * Triggers selection of this node\r
      */\r
     select : function(){\r
-        this.getOwnerTree().getSelectionModel().select(this);\r
+        var t = this.getOwnerTree();\r
+        if(t){\r
+            t.getSelectionModel().select(this);\r
+        }\r
     },\r
 \r
     /**\r
      * Triggers deselection of this node\r
     },\r
 \r
     /**\r
      * Triggers deselection of this node\r
+     * @param {Boolean} silent (optional) True to stop selection change events from firing.\r
      */\r
      */\r
-    unselect : function(){\r
-        this.getOwnerTree().getSelectionModel().unselect(this);\r
+    unselect : function(silent){\r
+        var t = this.getOwnerTree();\r
+        if(t){\r
+            t.getSelectionModel().unselect(this, silent);\r
+        }\r
     },\r
 \r
     /**\r
     },\r
 \r
     /**\r
@@ -292,7 +298,8 @@ Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
      * @return {Boolean}\r
      */\r
     isSelected : function(){\r
      * @return {Boolean}\r
      */\r
     isSelected : function(){\r
-        return this.getOwnerTree().getSelectionModel().isSelected(this);\r
+        var t = this.getOwnerTree();\r
+        return t ? t.getSelectionModel().isSelected(this) : false;\r
     },\r
 \r
     /**\r
     },\r
 \r
     /**\r
@@ -302,7 +309,7 @@ Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
      * @param {Function} callback (optional) A callback to be called when\r
      * expanding this node completes (does not wait for deep expand to complete).\r
      * Called with 1 parameter, this node.\r
      * @param {Function} callback (optional) A callback to be called when\r
      * expanding this node completes (does not wait for deep expand to complete).\r
      * Called with 1 parameter, this node.\r
-     * @param {Object} scope (optional) The scope in which to execute the callback.\r
+     * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.\r
      */\r
     expand : function(deep, anim, callback, scope){\r
         if(!this.expanded){\r
      */\r
     expand : function(deep, anim, callback, scope){\r
         if(!this.expanded){\r
@@ -352,7 +359,7 @@ Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
      * @param {Function} callback (optional) A callback to be called when\r
      * expanding this node completes (does not wait for deep expand to complete).\r
      * Called with 1 parameter, this node.\r
      * @param {Function} callback (optional) A callback to be called when\r
      * expanding this node completes (does not wait for deep expand to complete).\r
      * Called with 1 parameter, this node.\r
-     * @param {Object} scope (optional) The scope in which to execute the callback.\r
+     * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.\r
      */\r
     collapse : function(deep, anim, callback, scope){\r
         if(this.expanded && !this.isHiddenRoot()){\r
      */\r
     collapse : function(deep, anim, callback, scope){\r
         if(this.expanded && !this.isHiddenRoot()){\r
@@ -415,7 +422,7 @@ Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
      * Ensures all parent nodes are expanded, and if necessary, scrolls\r
      * the node into view.\r
      * @param {Function} callback (optional) A function to call when the node has been made visible.\r
      * Ensures all parent nodes are expanded, and if necessary, scrolls\r
      * the node into view.\r
      * @param {Function} callback (optional) A function to call when the node has been made visible.\r
-     * @param {Object} scope (optional) The scope in which to execute the callback.\r
+     * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.\r
      */\r
     ensureVisible : function(callback, scope){\r
         var tree = this.getOwnerTree();\r
      */\r
     ensureVisible : function(callback, scope){\r
         var tree = this.getOwnerTree();\r
@@ -533,15 +540,10 @@ Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
     },\r
 \r
     destroy : function(){\r
     },\r
 \r
     destroy : function(){\r
-        if(this.childNodes){\r
-            for(var i = 0,l = this.childNodes.length; i < l; i++){\r
-                this.childNodes[i].destroy();\r
-            }\r
-            this.childNodes = null;\r
-        }\r
-        if(this.ui.destroy){\r
-            this.ui.destroy();\r
-        }\r
+        this.unselect(true);\r
+        Ext.tree.TreeNode.superclass.destroy.call(this);\r
+        Ext.destroy(this.ui, this.loader);\r
+        this.ui = this.loader = null;\r
     },\r
 \r
     // private\r
     },\r
 \r
     // private\r