Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / widgets / tree / TreePanel.js
index 54000d4..eeff011 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
@@ -118,18 +118,19 @@ new Ext.Viewport({
  */\r
 Ext.tree.TreePanel = Ext.extend(Ext.Panel, {\r
     rootVisible : true,\r
-    animate: Ext.enableFx,\r
+    animate : Ext.enableFx,\r
     lines : true,\r
     enableDD : false,\r
     hlDrop : Ext.enableFx,\r
-    pathSeparator: "/",\r
-    \r
+    pathSeparator : '/',\r
+\r
     /**\r
      * @cfg {Array} bubbleEvents\r
      * <p>An array of events that, when fired, should be bubbled to any parent container.\r
-     * Defaults to <tt>['add', 'remove']</tt>.\r
+     * See {@link Ext.util.Observable#enableBubble}.\r
+     * Defaults to <tt>[]</tt>.\r
      */\r
-    bubbleEvents: [],\r
+    bubbleEvents : [],\r
 \r
     initComponent : function(){\r
         Ext.tree.TreePanel.superclass.initComponent.call(this);\r
@@ -145,7 +146,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
                 dataUrl: this.dataUrl,\r
                 requestMethod: this.requestMethod\r
             });\r
-        }else if(typeof l == 'object' && !l.load){\r
+        }else if(Ext.isObject(l) && !l.load){\r
             l = new Ext.tree.TreeLoader(l);\r
         }\r
         this.loader = l;\r
@@ -174,7 +175,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Node} node The newly appended node\r
             * @param {Number} index The index of the newly appended node\r
             */\r
-           "append",\r
+           'append',\r
            /**\r
             * @event remove\r
             * Fires when a child node is removed from a node in this tree.\r
@@ -182,7 +183,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Node} parent The parent node\r
             * @param {Node} node The child node removed\r
             */\r
-           "remove",\r
+           'remove',\r
            /**\r
             * @event movenode\r
             * Fires when a node is moved to a new location in the tree\r
@@ -192,7 +193,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Node} newParent The new parent of this node\r
             * @param {Number} index The index it was moved to\r
             */\r
-           "movenode",\r
+           'movenode',\r
            /**\r
             * @event insert\r
             * Fires when a new child node is inserted in a node in this tree.\r
@@ -201,7 +202,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Node} node The child node inserted\r
             * @param {Node} refNode The child node the node was inserted before\r
             */\r
-           "insert",\r
+           'insert',\r
            /**\r
             * @event beforeappend\r
             * Fires before a new child is appended to a node in this tree, return false to cancel the append.\r
@@ -209,7 +210,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Node} parent The parent node\r
             * @param {Node} node The child node to be appended\r
             */\r
-           "beforeappend",\r
+           'beforeappend',\r
            /**\r
             * @event beforeremove\r
             * Fires before a child is removed from a node in this tree, return false to cancel the remove.\r
@@ -217,7 +218,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Node} parent The parent node\r
             * @param {Node} node The child node to be removed\r
             */\r
-           "beforeremove",\r
+           'beforeremove',\r
            /**\r
             * @event beforemovenode\r
             * Fires before a node is moved to a new location in the tree. Return false to cancel the move.\r
@@ -227,7 +228,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Node} newParent The new parent the node is moving to\r
             * @param {Number} index The index it is being moved to\r
             */\r
-           "beforemovenode",\r
+           'beforemovenode',\r
            /**\r
             * @event beforeinsert\r
             * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.\r
@@ -236,20 +237,20 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Node} node The child node to be inserted\r
             * @param {Node} refNode The child node the node is being inserted before\r
             */\r
-            "beforeinsert",\r
+            'beforeinsert',\r
 \r
             /**\r
             * @event beforeload\r
             * Fires before a node is loaded, return false to cancel\r
             * @param {Node} node The node being loaded\r
             */\r
-            "beforeload",\r
+            'beforeload',\r
             /**\r
             * @event load\r
             * Fires when a node is loaded\r
             * @param {Node} node The node that was loaded\r
             */\r
-            "load",\r
+            'load',\r
             /**\r
             * @event textchange\r
             * Fires when the text for a node is changed\r
@@ -257,7 +258,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {String} text The new text\r
             * @param {String} oldText The old text\r
             */\r
-            "textchange",\r
+            'textchange',\r
             /**\r
             * @event beforeexpandnode\r
             * Fires before a node is expanded, return false to cancel.\r
@@ -265,7 +266,7 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Boolean} deep\r
             * @param {Boolean} anim\r
             */\r
-            "beforeexpandnode",\r
+            'beforeexpandnode',\r
             /**\r
             * @event beforecollapsenode\r
             * Fires before a node is collapsed, return false to cancel.\r
@@ -273,61 +274,75 @@ Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
             * @param {Boolean} deep\r
             * @param {Boolean} anim\r
             */\r
-            "beforecollapsenode",\r
+            'beforecollapsenode',\r
             /**\r
             * @event expandnode\r
             * Fires when a node is expanded\r
             * @param {Node} node The node\r
             */\r
-            "expandnode",\r
+            'expandnode',\r
             /**\r
             * @event disabledchange\r
             * Fires when the disabled status of a node changes\r
             * @param {Node} node The node\r
             * @param {Boolean} disabled\r
             */\r
-            "disabledchange",\r
+            'disabledchange',\r
             /**\r
             * @event collapsenode\r
             * Fires when a node is collapsed\r
             * @param {Node} node The node\r
             */\r
-            "collapsenode",\r
+            'collapsenode',\r
             /**\r
             * @event beforeclick\r
             * Fires before click processing on a node. Return false to cancel the default action.\r
             * @param {Node} node The node\r
             * @param {Ext.EventObject} e The event object\r
             */\r
-            "beforeclick",\r
+            'beforeclick',\r
             /**\r
             * @event click\r
             * Fires when a node is clicked\r
             * @param {Node} node The node\r
             * @param {Ext.EventObject} e The event object\r
             */\r
-            "click",\r
+            'click',\r
+            /**\r
+            * @event containerclick\r
+            * Fires when the tree container is clicked\r
+            * @param {Tree} this\r
+            * @param {Ext.EventObject} e The event object\r
+            */\r
+            'containerclick',\r
             /**\r
             * @event checkchange\r
             * Fires when a node with a checkbox's checked property changes\r
             * @param {Node} this This node\r
             * @param {Boolean} checked\r
             */\r
-            "checkchange",\r
+            'checkchange',\r
             /**\r
             * @event beforedblclick\r
             * Fires before double click processing on a node. Return false to cancel the default action.\r
             * @param {Node} node The node\r
             * @param {Ext.EventObject} e The event object\r
             */\r
-            "beforedblclick",\r
+            'beforedblclick',\r
             /**\r
             * @event dblclick\r
             * Fires when a node is double clicked\r
             * @param {Node} node The node\r
             * @param {Ext.EventObject} e The event object\r
             */\r
-            "dblclick",\r
+            'dblclick',\r
+            /**\r
+            * @event containerdblclick\r
+            * Fires when the tree container is double clicked\r
+            * @param {Tree} this\r
+            * @param {Ext.EventObject} e The event object\r
+            */\r
+            'containerdblclick',\r
             /**\r
             * @event contextmenu\r
             * Fires when a node is right clicked. To display a context menu in response to this\r
@@ -375,13 +390,20 @@ new Ext.tree.TreePanel({
             * @param {Node} node The node\r
             * @param {Ext.EventObject} e The event object\r
             */\r
-            "contextmenu",\r
+            'contextmenu',\r
+            /**\r
+            * @event containercontextmenu\r
+            * Fires when the tree container is right clicked\r
+            * @param {Tree} this\r
+            * @param {Ext.EventObject} e The event object\r
+            */\r
+            'containercontextmenu',\r
             /**\r
             * @event beforechildrenrendered\r
             * Fires right before the child nodes for a node are rendered\r
             * @param {Node} node The node\r
             */\r
-            "beforechildrenrendered",\r
+            'beforechildrenrendered',\r
            /**\r
              * @event startdrag\r
              * Fires when a node starts being dragged\r
@@ -389,7 +411,7 @@ new Ext.tree.TreePanel({
              * @param {Ext.tree.TreeNode} node\r
              * @param {event} e The raw browser event\r
              */\r
-            "startdrag",\r
+            'startdrag',\r
             /**\r
              * @event enddrag\r
              * Fires when a drag operation is complete\r
@@ -397,7 +419,7 @@ new Ext.tree.TreePanel({
              * @param {Ext.tree.TreeNode} node\r
              * @param {event} e The raw browser event\r
              */\r
-            "enddrag",\r
+            'enddrag',\r
             /**\r
              * @event dragdrop\r
              * Fires when a dragged node is dropped on a valid DD target\r
@@ -406,7 +428,7 @@ new Ext.tree.TreePanel({
              * @param {DD} dd The dd it was dropped on\r
              * @param {event} e The raw browser event\r
              */\r
-            "dragdrop",\r
+            'dragdrop',\r
             /**\r
              * @event beforenodedrop\r
              * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent\r
@@ -422,11 +444,11 @@ new Ext.tree.TreePanel({
              * to be inserted by setting them on this object.</li>\r
              * <li>cancel - Set this to true to cancel the drop.</li>\r
              * <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true\r
-             * will prevent the animated "repair" from appearing.</li>\r
+             * will prevent the animated 'repair' from appearing.</li>\r
              * </ul>\r
              * @param {Object} dropEvent\r
              */\r
-            "beforenodedrop",\r
+            'beforenodedrop',\r
             /**\r
              * @event nodedrop\r
              * Fires after a DD object is dropped on a node in this tree. The dropEvent\r
@@ -442,7 +464,7 @@ new Ext.tree.TreePanel({
              * </ul>\r
              * @param {Object} dropEvent\r
              */\r
-            "nodedrop",\r
+            'nodedrop',\r
              /**\r
              * @event nodedragover\r
              * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent\r
@@ -459,10 +481,10 @@ new Ext.tree.TreePanel({
              * </ul>\r
              * @param {Object} dragOverEvent\r
              */\r
-            "nodedragover"\r
+            'nodedragover'\r
         );\r
         if(this.singleExpand){\r
-            this.on("beforeexpandnode", this.restrictExpand, this);\r
+            this.on('beforeexpandnode', this.restrictExpand, this);\r
         }\r
     },\r
 \r
@@ -531,7 +553,7 @@ new Ext.tree.TreePanel({
 \r
     // private\r
     toString : function(){\r
-        return "[Tree"+(this.id?" "+this.id:"")+"]";\r
+        return '[Tree'+(this.id?' '+this.id:'')+']';\r
     },\r
 \r
     // private\r
@@ -546,7 +568,7 @@ new Ext.tree.TreePanel({
     },\r
 \r
     /**\r
-     * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")\r
+     * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. 'id')\r
      * @param {String} attribute (optional) Defaults to null (return the actual nodes)\r
      * @param {TreeNode} startNode (optional) The node to start from, defaults to the root\r
      * @return {Array}\r
@@ -563,14 +585,6 @@ new Ext.tree.TreePanel({
         return r;\r
     },\r
 \r
-    /**\r
-     * Returns the container element for this TreePanel.\r
-     * @return {Element} The container element for this TreePanel.\r
-     */\r
-    getEl : function(){\r
-        return this.el;\r
-    },\r
-\r
     /**\r
      * Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.\r
      * @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.\r
@@ -612,7 +626,7 @@ new Ext.tree.TreePanel({
      * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.\r
      */\r
     expandPath : function(path, attr, callback){\r
-        attr = attr || "id";\r
+        attr = attr || 'id';\r
         var keys = path.split(this.pathSeparator);\r
         var curNode = this.root;\r
         if(curNode.attributes[attr] != keys[1]){ // invalid root\r
@@ -650,7 +664,7 @@ new Ext.tree.TreePanel({
      * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.\r
      */\r
     selectPath : function(path, attr, callback){\r
-        attr = attr || "id";\r
+        attr = attr || 'id';\r
         var keys = path.split(this.pathSeparator),\r
             v = keys.pop();\r
         if(keys.length > 1){\r
@@ -692,9 +706,9 @@ new Ext.tree.TreePanel({
     onRender : function(ct, position){\r
         Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);\r
         this.el.addClass('x-tree');\r
-        this.innerCt = this.body.createChild({tag:"ul",\r
-               cls:"x-tree-root-ct " +\r
-               (this.useArrows ? 'x-tree-arrows' : this.lines ? "x-tree-lines" : "x-tree-no-lines")});\r
+        this.innerCt = this.body.createChild({tag:'ul',\r
+               cls:'x-tree-root-ct ' +\r
+               (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')});\r
     },\r
 \r
     // private\r
@@ -711,7 +725,7 @@ new Ext.tree.TreePanel({
             * @type Ext.tree.TreeDropZone\r
             */\r
              this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {\r
-               ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true\r
+               ddGroup: this.ddGroup || 'TreeDD', appendOnly: this.ddAppendOnly === true\r
            });\r
         }\r
         if((this.enableDD || this.enableDrag) && !this.dragZone){\r
@@ -721,7 +735,7 @@ new Ext.tree.TreePanel({
             * @type Ext.tree.TreeDragZone\r
             */\r
             this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {\r
-               ddGroup: this.ddGroup || "TreeDD",\r
+               ddGroup: this.ddGroup || 'TreeDD',\r
                scroll: this.ddScroll\r
            });\r
         }\r
@@ -737,20 +751,14 @@ new Ext.tree.TreePanel({
         }\r
     },\r
 \r
-    onDestroy : function(){\r
+    beforeDestroy : function(){\r
         if(this.rendered){\r
-            this.body.removeAllListeners();\r
             Ext.dd.ScrollManager.unregister(this.body);\r
-            if(this.dropZone){\r
-                this.dropZone.unreg();\r
-            }\r
-            if(this.dragZone){\r
-               this.dragZone.unreg();\r
-            }\r
+            Ext.destroy(this.dropZone, this.dragZone);\r
         }\r
-        this.root.destroy();\r
-        this.nodeHash = null;\r
-        Ext.tree.TreePanel.superclass.onDestroy.call(this);\r
+        Ext.destroy(this.root, this.loader);\r
+        this.nodeHash = this.root = this.loader = null;\r
+        Ext.tree.TreePanel.superclass.beforeDestroy.call(this);\r
     }\r
 \r
     /**\r