-/**\r
- * @class Ext.tree.TreePanel\r
- * @extends Ext.Panel\r
- * <p>The TreePanel provides tree-structured UI representation of tree-structured data.</p>\r
- * <p>{@link Ext.tree.TreeNode TreeNode}s added to the TreePanel may each contain metadata\r
- * used by your application in their {@link Ext.tree.TreeNode#attributes attributes} property.</p>\r
- * <p><b>A TreePanel must have a {@link #root} node before it is rendered.</b> This may either be\r
- * specified using the {@link #root} config option, or using the {@link #setRootNode} method.\r
- * <p>An example of tree rendered to an existing div:</p><pre><code>\r
-var tree = new Ext.tree.TreePanel({\r
- renderTo: 'tree-div',\r
- useArrows: true,\r
- autoScroll: true,\r
- animate: true,\r
- enableDD: true,\r
- containerScroll: true,\r
- border: false,\r
- // auto create TreeLoader\r
- dataUrl: 'get-nodes.php',\r
-\r
- root: {\r
- nodeType: 'async',\r
- text: 'Ext JS',\r
- draggable: false,\r
- id: 'source'\r
- }\r
-});\r
-\r
-tree.getRootNode().expand();\r
- * </code></pre>\r
- * <p>The example above would work with a data packet similar to this:</p><pre><code>\r
-[{\r
- "text": "adapter",\r
- "id": "source\/adapter",\r
- "cls": "folder"\r
-}, {\r
- "text": "dd",\r
- "id": "source\/dd",\r
- "cls": "folder"\r
-}, {\r
- "text": "debug.js",\r
- "id": "source\/debug.js",\r
- "leaf": true,\r
- "cls": "file"\r
-}]\r
- * </code></pre>\r
- * <p>An example of tree within a Viewport:</p><pre><code>\r
-new Ext.Viewport({\r
- layout: 'border',\r
- items: [{\r
- region: 'west',\r
- collapsible: true,\r
- title: 'Navigation',\r
- xtype: 'treepanel',\r
- width: 200,\r
- autoScroll: true,\r
- split: true,\r
- loader: new Ext.tree.TreeLoader(),\r
- root: new Ext.tree.AsyncTreeNode({\r
- expanded: true,\r
- children: [{\r
- text: 'Menu Option 1',\r
- leaf: true\r
- }, {\r
- text: 'Menu Option 2',\r
- leaf: true\r
- }, {\r
- text: 'Menu Option 3',\r
- leaf: true\r
- }]\r
- }),\r
- rootVisible: false,\r
- listeners: {\r
- click: function(n) {\r
- Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');\r
- }\r
- }\r
- }, {\r
- region: 'center',\r
- xtype: 'tabpanel',\r
- // remaining code not shown ...\r
- }]\r
-});\r
-</code></pre>\r
- *\r
- * @cfg {Ext.tree.TreeNode} root The root node for the tree.\r
- * @cfg {Boolean} rootVisible <tt>false</tt> to hide the root node (defaults to <tt>true</tt>)\r
- * @cfg {Boolean} lines <tt>false</tt> to disable tree lines (defaults to <tt>true</tt>)\r
- * @cfg {Boolean} enableDD <tt>true</tt> to enable drag and drop\r
- * @cfg {Boolean} enableDrag <tt>true</tt> to enable just drag\r
- * @cfg {Boolean} enableDrop <tt>true</tt> to enable just drop\r
- * @cfg {Object} dragConfig Custom config to pass to the {@link Ext.tree.TreeDragZone} instance\r
- * @cfg {Object} dropConfig Custom config to pass to the {@link Ext.tree.TreeDropZone} instance\r
- * @cfg {String} ddGroup The DD group this TreePanel belongs to\r
- * @cfg {Boolean} ddAppendOnly <tt>true</tt> if the tree should only allow append drops (use for trees which are sorted)\r
- * @cfg {Boolean} ddScroll <tt>true</tt> to enable body scrolling\r
- * @cfg {Boolean} containerScroll <tt>true</tt> to register this container with ScrollManager\r
- * @cfg {Boolean} hlDrop <tt>false</tt> to disable node highlight on drop (defaults to the value of {@link Ext#enableFx})\r
- * @cfg {String} hlColor The color of the node highlight (defaults to <tt>'C3DAF9'</tt>)\r
- * @cfg {Boolean} animate <tt>true</tt> to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx})\r
- * @cfg {Boolean} singleExpand <tt>true</tt> if only 1 node per branch may be expanded\r
- * @cfg {Object} selModel A tree selection model to use with this TreePanel (defaults to an {@link Ext.tree.DefaultSelectionModel})\r
- * @cfg {Boolean} trackMouseOver <tt>false</tt> to disable mouse over highlighting\r
- * @cfg {Ext.tree.TreeLoader} loader A {@link Ext.tree.TreeLoader} for use with this TreePanel\r
- * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to <tt>'/'</tt>)\r
- * @cfg {Boolean} useArrows <tt>true</tt> to use Vista-style arrows in the tree (defaults to <tt>false</tt>)\r
- * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).\r
- *\r
- * @constructor\r
- * @param {Object} config\r
- * @xtype treepanel\r
- */\r
-Ext.tree.TreePanel = Ext.extend(Ext.Panel, {\r
- rootVisible : true,\r
- animate: Ext.enableFx,\r
- lines : true,\r
- enableDD : false,\r
- hlDrop : Ext.enableFx,\r
- pathSeparator: "/",\r
-\r
- initComponent : function(){\r
- Ext.tree.TreePanel.superclass.initComponent.call(this);\r
-\r
- if(!this.eventModel){\r
- this.eventModel = new Ext.tree.TreeEventModel(this);\r
- }\r
-\r
- // initialize the loader\r
- var l = this.loader;\r
- if(!l){\r
- l = new Ext.tree.TreeLoader({\r
- dataUrl: this.dataUrl,\r
- requestMethod: this.requestMethod\r
- });\r
- }else if(typeof l == 'object' && !l.load){\r
- l = new Ext.tree.TreeLoader(l);\r
- }\r
- this.loader = l;\r
-\r
- this.nodeHash = {};\r
-\r
- /**\r
- * The root node of this tree.\r
- * @type Ext.tree.TreeNode\r
- * @property root\r
- */\r
- if(this.root){\r
- var r = this.root;\r
- delete this.root;\r
- this.setRootNode(r);\r
- }\r
-\r
-\r
- this.addEvents(\r
-\r
- /**\r
- * @event append\r
- * Fires when a new child node is appended to a node in this tree.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The newly appended node\r
- * @param {Number} index The index of the newly appended node\r
- */\r
- "append",\r
- /**\r
- * @event remove\r
- * Fires when a child node is removed from a node in this tree.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The child node removed\r
- */\r
- "remove",\r
- /**\r
- * @event movenode\r
- * Fires when a node is moved to a new location in the tree\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} node The node moved\r
- * @param {Node} oldParent The old parent of this node\r
- * @param {Node} newParent The new parent of this node\r
- * @param {Number} index The index it was moved to\r
- */\r
- "movenode",\r
- /**\r
- * @event insert\r
- * Fires when a new child node is inserted in a node in this tree.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The child node inserted\r
- * @param {Node} refNode The child node the node was inserted before\r
- */\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
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The child node to be appended\r
- */\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
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The child node to be removed\r
- */\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
- * @param {Tree} tree The owner tree\r
- * @param {Node} node The node being moved\r
- * @param {Node} oldParent The parent of the node\r
- * @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
- /**\r
- * @event beforeinsert\r
- * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @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
-\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
- /**\r
- * @event load\r
- * Fires when a node is loaded\r
- * @param {Node} node The node that was loaded\r
- */\r
- "load",\r
- /**\r
- * @event textchange\r
- * Fires when the text for a node is changed\r
- * @param {Node} node The node\r
- * @param {String} text The new text\r
- * @param {String} oldText The old text\r
- */\r
- "textchange",\r
- /**\r
- * @event beforeexpandnode\r
- * Fires before a node is expanded, return false to cancel.\r
- * @param {Node} node The node\r
- * @param {Boolean} deep\r
- * @param {Boolean} anim\r
- */\r
- "beforeexpandnode",\r
- /**\r
- * @event beforecollapsenode\r
- * Fires before a node is collapsed, return false to cancel.\r
- * @param {Node} node The node\r
- * @param {Boolean} deep\r
- * @param {Boolean} anim\r
- */\r
- "beforecollapsenode",\r
- /**\r
- * @event expandnode\r
- * Fires when a node is expanded\r
- * @param {Node} node The node\r
- */\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
- /**\r
- * @event collapsenode\r
- * Fires when a node is collapsed\r
- * @param {Node} node The node\r
- */\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
- /**\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
- /**\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
- /**\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
- /**\r
- * @event contextmenu\r
- * Fires when a node is right clicked. To display a context menu in response to this\r
- * event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add\r
- * a handler for this event:<pre><code>\r
-new Ext.tree.TreePanel({\r
- title: 'My TreePanel',\r
- root: new Ext.tree.AsyncTreeNode({\r
- text: 'The Root',\r
- children: [\r
- { text: 'Child node 1', leaf: true },\r
- { text: 'Child node 2', leaf: true }\r
- ]\r
- }),\r
- contextMenu: new Ext.menu.Menu({\r
- items: [{\r
- id: 'delete-node',\r
- text: 'Delete Node'\r
- }],\r
- listeners: {\r
- itemclick: function(item) {\r
- switch (item.id) {\r
- case 'delete-node':\r
- var n = item.parentMenu.contextNode;\r
- if (n.parentNode) {\r
- n.remove();\r
- }\r
- break;\r
- }\r
- }\r
- }\r
- }),\r
- listeners: {\r
- contextmenu: function(node, e) {\r
-// Register the context node with the menu so that a Menu Item's handler function can access\r
-// it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.\r
- node.select();\r
- var c = node.getOwnerTree().contextMenu;\r
- c.contextNode = node;\r
- c.showAt(e.getXY());\r
- }\r
- }\r
-});\r
-</code></pre>\r
- * @param {Node} node The node\r
- * @param {Ext.EventObject} e The event object\r
- */\r
- "contextmenu",\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
- /**\r
- * @event startdrag\r
- * Fires when a node starts being dragged\r
- * @param {Ext.tree.TreePanel} this\r
- * @param {Ext.tree.TreeNode} node\r
- * @param {event} e The raw browser event\r
- */\r
- "startdrag",\r
- /**\r
- * @event enddrag\r
- * Fires when a drag operation is complete\r
- * @param {Ext.tree.TreePanel} this\r
- * @param {Ext.tree.TreeNode} node\r
- * @param {event} e The raw browser event\r
- */\r
- "enddrag",\r
- /**\r
- * @event dragdrop\r
- * Fires when a dragged node is dropped on a valid DD target\r
- * @param {Ext.tree.TreePanel} this\r
- * @param {Ext.tree.TreeNode} node\r
- * @param {DD} dd The dd it was dropped on\r
- * @param {event} e The raw browser event\r
- */\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
- * passed to handlers has the following properties:<br />\r
- * <ul style="padding:5px;padding-left:16px;">\r
- * <li>tree - The TreePanel</li>\r
- * <li>target - The node being targeted for the drop</li>\r
- * <li>data - The drag data from the drag source</li>\r
- * <li>point - The point of the drop - append, above or below</li>\r
- * <li>source - The drag source</li>\r
- * <li>rawEvent - Raw mouse event</li>\r
- * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)\r
- * 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
- * </ul>\r
- * @param {Object} dropEvent\r
- */\r
- "beforenodedrop",\r
- /**\r
- * @event nodedrop\r
- * Fires after a DD object is dropped on a node in this tree. The dropEvent\r
- * passed to handlers has the following properties:<br />\r
- * <ul style="padding:5px;padding-left:16px;">\r
- * <li>tree - The TreePanel</li>\r
- * <li>target - The node being targeted for the drop</li>\r
- * <li>data - The drag data from the drag source</li>\r
- * <li>point - The point of the drop - append, above or below</li>\r
- * <li>source - The drag source</li>\r
- * <li>rawEvent - Raw mouse event</li>\r
- * <li>dropNode - Dropped node(s).</li>\r
- * </ul>\r
- * @param {Object} dropEvent\r
- */\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
- * passed to handlers has the following properties:<br />\r
- * <ul style="padding:5px;padding-left:16px;">\r
- * <li>tree - The TreePanel</li>\r
- * <li>target - The node being targeted for the drop</li>\r
- * <li>data - The drag data from the drag source</li>\r
- * <li>point - The point of the drop - append, above or below</li>\r
- * <li>source - The drag source</li>\r
- * <li>rawEvent - Raw mouse event</li>\r
- * <li>dropNode - Drop node(s) provided by the source.</li>\r
- * <li>cancel - Set this to true to signal drop not allowed.</li>\r
- * </ul>\r
- * @param {Object} dragOverEvent\r
- */\r
- "nodedragover"\r
- );\r
- if(this.singleExpand){\r
- this.on("beforeexpandnode", this.restrictExpand, this);\r
- }\r
- },\r
-\r
- // private\r
- proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){\r
- if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){\r
- ename = ename+'node';\r
- }\r
- // args inline for performance while bubbling events\r
- return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);\r
- },\r
-\r
-\r
- /**\r
- * Returns this root node for this tree\r
- * @return {Node}\r
- */\r
- getRootNode : function(){\r
- return this.root;\r
- },\r
-\r
- /**\r
- * Sets the root node for this tree. If the TreePanel has already rendered a root node, the\r
- * previous root node (and all of its descendants) are destroyed before the new root node is rendered.\r
- * @param {Node} node\r
- * @return {Node}\r
- */\r
- setRootNode : function(node){\r
- Ext.destroy(this.root);\r
- if(!node.render){ // attributes passed\r
- node = this.loader.createNode(node);\r
- }\r
- this.root = node;\r
- node.ownerTree = this;\r
- node.isRoot = true;\r
- this.registerNode(node);\r
- if(!this.rootVisible){\r
- var uiP = node.attributes.uiProvider;\r
- node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);\r
- }\r
- if (this.innerCt) {\r
- this.innerCt.update('');\r
- this.afterRender();\r
- }\r
- return node;\r
- },\r
-\r
- /**\r
- * Gets a node in this tree by its id\r
- * @param {String} id\r
- * @return {Node}\r
- */\r
- getNodeById : function(id){\r
- return this.nodeHash[id];\r
- },\r
-\r
- // private\r
- registerNode : function(node){\r
- this.nodeHash[node.id] = node;\r
- },\r
-\r
- // private\r
- unregisterNode : function(node){\r
- delete this.nodeHash[node.id];\r
- },\r
-\r
- // private\r
- toString : function(){\r
- return "[Tree"+(this.id?" "+this.id:"")+"]";\r
- },\r
-\r
- // private\r
- restrictExpand : function(node){\r
- var p = node.parentNode;\r
- if(p){\r
- if(p.expandedChild && p.expandedChild.parentNode == p){\r
- p.expandedChild.collapse();\r
- }\r
- p.expandedChild = node;\r
- }\r
- },\r
-\r
- /**\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
- */\r
- getChecked : function(a, startNode){\r
- startNode = startNode || this.root;\r
- var r = [];\r
- var f = function(){\r
- if(this.attributes.checked){\r
- r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));\r
- }\r
- };\r
- startNode.cascade(f);\r
- 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
- */\r
- getLoader : function(){\r
- return this.loader;\r
- },\r
-\r
- /**\r
- * Expand all nodes\r
- */\r
- expandAll : function(){\r
- this.root.expand(true);\r
- },\r
-\r
- /**\r
- * Collapse all nodes\r
- */\r
- collapseAll : function(){\r
- this.root.collapse(true);\r
- },\r
-\r
- /**\r
- * Returns the selection model used by this TreePanel.\r
- * @return {TreeSelectionModel} The selection model used by this TreePanel\r
- */\r
- getSelectionModel : function(){\r
- if(!this.selModel){\r
- this.selModel = new Ext.tree.DefaultSelectionModel();\r
- }\r
- return this.selModel;\r
- },\r
-\r
- /**\r
- * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}\r
- * @param {String} path\r
- * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)\r
- * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with\r
- * (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
- var keys = path.split(this.pathSeparator);\r
- var curNode = this.root;\r
- if(curNode.attributes[attr] != keys[1]){ // invalid root\r
- if(callback){\r
- callback(false, null);\r
- }\r
- return;\r
- }\r
- var index = 1;\r
- var f = function(){\r
- if(++index == keys.length){\r
- if(callback){\r
- callback(true, curNode);\r
- }\r
- return;\r
- }\r
- var c = curNode.findChild(attr, keys[index]);\r
- if(!c){\r
- if(callback){\r
- callback(false, curNode);\r
- }\r
- return;\r
- }\r
- curNode = c;\r
- c.expand(false, false, f);\r
- };\r
- curNode.expand(false, false, f);\r
- },\r
-\r
- /**\r
- * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}\r
- * @param {String} path\r
- * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)\r
- * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with\r
- * (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
- var keys = path.split(this.pathSeparator);\r
- var v = keys.pop();\r
- if(keys.length > 0){\r
- var f = function(success, node){\r
- if(success && node){\r
- var n = node.findChild(attr, v);\r
- if(n){\r
- n.select();\r
- if(callback){\r
- callback(true, n);\r
- }\r
- }else if(callback){\r
- callback(false, n);\r
- }\r
- }else{\r
- if(callback){\r
- callback(false, n);\r
- }\r
- }\r
- };\r
- this.expandPath(keys.join(this.pathSeparator), attr, f);\r
- }else{\r
- this.root.select();\r
- if(callback){\r
- callback(true, this.root);\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Returns the underlying Element for this tree\r
- * @return {Ext.Element} The Element\r
- */\r
- getTreeEl : function(){\r
- return this.body;\r
- },\r
-\r
- // private\r
- 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
- },\r
-\r
- // private\r
- initEvents : function(){\r
- Ext.tree.TreePanel.superclass.initEvents.call(this);\r
-\r
- if(this.containerScroll){\r
- Ext.dd.ScrollManager.register(this.body);\r
- }\r
- if((this.enableDD || this.enableDrop) && !this.dropZone){\r
- /**\r
- * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})\r
- * @property dropZone\r
- * @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
- });\r
- }\r
- if((this.enableDD || this.enableDrag) && !this.dragZone){\r
- /**\r
- * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})\r
- * @property dragZone\r
- * @type Ext.tree.TreeDragZone\r
- */\r
- this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {\r
- ddGroup: this.ddGroup || "TreeDD",\r
- scroll: this.ddScroll\r
- });\r
- }\r
- this.getSelectionModel().init(this);\r
- },\r
-\r
- // private\r
- afterRender : function(){\r
- Ext.tree.TreePanel.superclass.afterRender.call(this);\r
- this.root.render();\r
- if(!this.rootVisible){\r
- this.root.renderChildren();\r
- }\r
- },\r
-\r
- onDestroy : 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
- }\r
- this.root.destroy();\r
- this.nodeHash = null;\r
- Ext.tree.TreePanel.superclass.onDestroy.call(this);\r
- }\r
-\r
- /**\r
- * @cfg {String/Number} activeItem\r
- * @hide\r
- */\r
- /**\r
- * @cfg {Boolean} autoDestroy\r
- * @hide\r
- */\r
- /**\r
- * @cfg {Object/String/Function} autoLoad\r
- * @hide\r
- */\r
- /**\r
- * @cfg {Boolean} autoWidth\r
- * @hide\r
- */\r
- /**\r
- * @cfg {Boolean/Number} bufferResize\r
- * @hide\r
- */\r
- /**\r
- * @cfg {String} defaultType\r
- * @hide\r
- */\r
- /**\r
- * @cfg {Object} defaults\r
- * @hide\r
- */\r
- /**\r
- * @cfg {Boolean} hideBorders\r
- * @hide\r
- */\r
- /**\r
- * @cfg {Mixed} items\r
- * @hide\r
- */\r
- /**\r
- * @cfg {String} layout\r
- * @hide\r
- */\r
- /**\r
- * @cfg {Object} layoutConfig\r
- * @hide\r
- */\r
- /**\r
- * @cfg {Boolean} monitorResize\r
- * @hide\r
- */\r
- /**\r
- * @property items\r
- * @hide\r
- */\r
- /**\r
- * @method cascade\r
- * @hide\r
- */\r
- /**\r
- * @method doLayout\r
- * @hide\r
- */\r
- /**\r
- * @method find\r
- * @hide\r
- */\r
- /**\r
- * @method findBy\r
- * @hide\r
- */\r
- /**\r
- * @method findById\r
- * @hide\r
- */\r
- /**\r
- * @method findByType\r
- * @hide\r
- */\r
- /**\r
- * @method getComponent\r
- * @hide\r
- */\r
- /**\r
- * @method getLayout\r
- * @hide\r
- */\r
- /**\r
- * @method getUpdater\r
- * @hide\r
- */\r
- /**\r
- * @method insert\r
- * @hide\r
- */\r
- /**\r
- * @method load\r
- * @hide\r
- */\r
- /**\r
- * @method remove\r
- * @hide\r
- */\r
- /**\r
- * @event add\r
- * @hide\r
- */\r
- /**\r
- * @method removeAll\r
- * @hide\r
- */\r
- /**\r
- * @event afterLayout\r
- * @hide\r
- */\r
- /**\r
- * @event beforeadd\r
- * @hide\r
- */\r
- /**\r
- * @event beforeremove\r
- * @hide\r
- */\r
- /**\r
- * @event remove\r
- * @hide\r
- */\r
-\r
-\r
-\r
- /**\r
- * @cfg {String} allowDomMove @hide\r
- */\r
- /**\r
- * @cfg {String} autoEl @hide\r
- */\r
- /**\r
- * @cfg {String} applyTo @hide\r
- */\r
- /**\r
- * @cfg {String} contentEl @hide\r
- */\r
- /**\r
- * @cfg {String} disabledClass @hide\r
- */\r
- /**\r
- * @cfg {String} elements @hide\r
- */\r
- /**\r
- * @cfg {String} html @hide\r
- */\r
- /**\r
- * @cfg {Boolean} preventBodyReset\r
- * @hide\r
- */\r
- /**\r
- * @property disabled\r
- * @hide\r
- */\r
- /**\r
- * @method applyToMarkup\r
- * @hide\r
- */\r
- /**\r
- * @method enable\r
- * @hide\r
- */\r
- /**\r
- * @method disable\r
- * @hide\r
- */\r
- /**\r
- * @method setDisabled\r
- * @hide\r
- */\r
-});\r
-\r
-Ext.tree.TreePanel.nodeTypes = {};\r
-\r
-Ext.reg('treepanel', Ext.tree.TreePanel);Ext.tree.TreeEventModel = function(tree){\r
- this.tree = tree;\r
- this.tree.on('render', this.initEvents, this);\r
-}\r
-\r
-Ext.tree.TreeEventModel.prototype = {\r
- initEvents : function(){\r
- var el = this.tree.getTreeEl();\r
- el.on('click', this.delegateClick, this);\r
- if(this.tree.trackMouseOver !== false){\r
- this.tree.innerCt.on('mouseover', this.delegateOver, this);\r
- this.tree.innerCt.on('mouseout', this.delegateOut, this);\r
- }\r
- el.on('dblclick', this.delegateDblClick, this);\r
- el.on('contextmenu', this.delegateContextMenu, this);\r
- },\r
-\r
- getNode : function(e){\r
- var t;\r
- if(t = e.getTarget('.x-tree-node-el', 10)){\r
- var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');\r
- if(id){\r
- return this.tree.getNodeById(id);\r
- }\r
- }\r
- return null;\r
- },\r
-\r
- getNodeTarget : function(e){\r
- var t = e.getTarget('.x-tree-node-icon', 1);\r
- if(!t){\r
- t = e.getTarget('.x-tree-node-el', 6);\r
- }\r
- return t;\r
- },\r
-\r
- delegateOut : function(e, t){\r
- if(!this.beforeEvent(e)){\r
- return;\r
- }\r
- if(e.getTarget('.x-tree-ec-icon', 1)){\r
- var n = this.getNode(e);\r
- this.onIconOut(e, n);\r
- if(n == this.lastEcOver){\r
- delete this.lastEcOver;\r
- }\r
- }\r
- if((t = this.getNodeTarget(e)) && !e.within(t, true)){\r
- this.onNodeOut(e, this.getNode(e));\r
- }\r
- },\r
-\r
- delegateOver : function(e, t){\r
- if(!this.beforeEvent(e)){\r
- return;\r
- }\r
- if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF\r
- Ext.getBody().on('mouseover', this.trackExit, this);\r
- this.trackingDoc = true;\r
- }\r
- if(this.lastEcOver){ // prevent hung highlight\r
- this.onIconOut(e, this.lastEcOver);\r
- delete this.lastEcOver;\r
- }\r
- if(e.getTarget('.x-tree-ec-icon', 1)){\r
- this.lastEcOver = this.getNode(e);\r
- this.onIconOver(e, this.lastEcOver);\r
- }\r
- if(t = this.getNodeTarget(e)){\r
- this.onNodeOver(e, this.getNode(e));\r
- }\r
- },\r
-\r
- trackExit : function(e){\r
- if(this.lastOverNode && !e.within(this.lastOverNode.ui.getEl())){\r
- this.onNodeOut(e, this.lastOverNode);\r
- delete this.lastOverNode;\r
- Ext.getBody().un('mouseover', this.trackExit, this);\r
- this.trackingDoc = false;\r
- }\r
- },\r
-\r
- delegateClick : function(e, t){\r
- if(!this.beforeEvent(e)){\r
- return;\r
- }\r
-\r
- if(e.getTarget('input[type=checkbox]', 1)){\r
- this.onCheckboxClick(e, this.getNode(e));\r
- }\r
- else if(e.getTarget('.x-tree-ec-icon', 1)){\r
- this.onIconClick(e, this.getNode(e));\r
- }\r
- else if(this.getNodeTarget(e)){\r
- this.onNodeClick(e, this.getNode(e));\r
- }\r
- },\r
-\r
- delegateDblClick : function(e, t){\r
- if(this.beforeEvent(e) && this.getNodeTarget(e)){\r
- this.onNodeDblClick(e, this.getNode(e));\r
- }\r
- },\r
-\r
- delegateContextMenu : function(e, t){\r
- if(this.beforeEvent(e) && this.getNodeTarget(e)){\r
- this.onNodeContextMenu(e, this.getNode(e));\r
- }\r
- },\r
-\r
- onNodeClick : function(e, node){\r
- node.ui.onClick(e);\r
- },\r
-\r
- onNodeOver : function(e, node){\r
- this.lastOverNode = node;\r
- node.ui.onOver(e);\r
- },\r
-\r
- onNodeOut : function(e, node){\r
- node.ui.onOut(e);\r
- },\r
-\r
- onIconOver : function(e, node){\r
- node.ui.addClass('x-tree-ec-over');\r
- },\r
-\r
- onIconOut : function(e, node){\r
- node.ui.removeClass('x-tree-ec-over');\r
- },\r
-\r
- onIconClick : function(e, node){\r
- node.ui.ecClick(e);\r
- },\r
-\r
- onCheckboxClick : function(e, node){\r
- node.ui.onCheckChange(e);\r
- },\r
-\r
- onNodeDblClick : function(e, node){\r
- node.ui.onDblClick(e);\r
- },\r
-\r
- onNodeContextMenu : function(e, node){\r
- node.ui.onContextMenu(e);\r
- },\r
-\r
- beforeEvent : function(e){\r
- if(this.disabled){\r
- e.stopEvent();\r
- return false;\r
- }\r
- return true;\r
- },\r
-\r
- disable: function(){\r
- this.disabled = true;\r
- },\r
-\r
- enable: function(){\r
- this.disabled = false;\r
- }\r
-};/**\r
- * @class Ext.tree.DefaultSelectionModel\r
- * @extends Ext.util.Observable\r
- * The default single selection for a TreePanel.\r
- */\r
-Ext.tree.DefaultSelectionModel = function(config){\r
- this.selNode = null;\r
- \r
- this.addEvents(\r
- /**\r
- * @event selectionchange\r
- * Fires when the selected node changes\r
- * @param {DefaultSelectionModel} this\r
- * @param {TreeNode} node the new selection\r
- */\r
- "selectionchange",\r
-\r
- /**\r
- * @event beforeselect\r
- * Fires before the selected node changes, return false to cancel the change\r
- * @param {DefaultSelectionModel} this\r
- * @param {TreeNode} node the new selection\r
- * @param {TreeNode} node the old selection\r
- */\r
- "beforeselect"\r
- );\r
-\r
- Ext.apply(this, config);\r
- Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);\r
-};\r
-\r
-Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {\r
- init : function(tree){\r
- this.tree = tree;\r
- tree.getTreeEl().on("keydown", this.onKeyDown, this);\r
- tree.on("click", this.onNodeClick, this);\r
- },\r
- \r
- onNodeClick : function(node, e){\r
- this.select(node);\r
- },\r
- \r
- /**\r
- * Select a node.\r
- * @param {TreeNode} node The node to select\r
- * @return {TreeNode} The selected node\r
- */\r
- select : function(node){\r
- var last = this.selNode;\r
- if(node == last){\r
- node.ui.onSelectedChange(true);\r
- }else if(this.fireEvent('beforeselect', this, node, last) !== false){\r
- if(last){\r
- last.ui.onSelectedChange(false);\r
- }\r
- this.selNode = node;\r
- node.ui.onSelectedChange(true);\r
- this.fireEvent("selectionchange", this, node, last);\r
- }\r
- return node;\r
- },\r
- \r
- /**\r
- * Deselect a node.\r
- * @param {TreeNode} node The node to unselect\r
- */\r
- unselect : function(node){\r
- if(this.selNode == node){\r
- this.clearSelections();\r
- } \r
- },\r
- \r
- /**\r
- * Clear all selections\r
- */\r
- clearSelections : function(){\r
- var n = this.selNode;\r
- if(n){\r
- n.ui.onSelectedChange(false);\r
- this.selNode = null;\r
- this.fireEvent("selectionchange", this, null);\r
- }\r
- return n;\r
- },\r
- \r
- /**\r
- * Get the selected node\r
- * @return {TreeNode} The selected node\r
- */\r
- getSelectedNode : function(){\r
- return this.selNode; \r
- },\r
- \r
- /**\r
- * Returns true if the node is selected\r
- * @param {TreeNode} node The node to check\r
- * @return {Boolean}\r
- */\r
- isSelected : function(node){\r
- return this.selNode == node; \r
- },\r
-\r
- /**\r
- * Selects the node above the selected node in the tree, intelligently walking the nodes\r
- * @return TreeNode The new selection\r
- */\r
- selectPrevious : function(){\r
- var s = this.selNode || this.lastSelNode;\r
- if(!s){\r
- return null;\r
- }\r
- var ps = s.previousSibling;\r
- if(ps){\r
- if(!ps.isExpanded() || ps.childNodes.length < 1){\r
- return this.select(ps);\r
- } else{\r
- var lc = ps.lastChild;\r
- while(lc && lc.isExpanded() && lc.childNodes.length > 0){\r
- lc = lc.lastChild;\r
- }\r
- return this.select(lc);\r
- }\r
- } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){\r
- return this.select(s.parentNode);\r
- }\r
- return null;\r
- },\r
-\r
- /**\r
- * Selects the node above the selected node in the tree, intelligently walking the nodes\r
- * @return TreeNode The new selection\r
- */\r
- selectNext : function(){\r
- var s = this.selNode || this.lastSelNode;\r
- if(!s){\r
- return null;\r
- }\r
- if(s.firstChild && s.isExpanded()){\r
- return this.select(s.firstChild);\r
- }else if(s.nextSibling){\r
- return this.select(s.nextSibling);\r
- }else if(s.parentNode){\r
- var newS = null;\r
- s.parentNode.bubble(function(){\r
- if(this.nextSibling){\r
- newS = this.getOwnerTree().selModel.select(this.nextSibling);\r
- return false;\r
- }\r
- });\r
- return newS;\r
- }\r
- return null;\r
- },\r
-\r
- onKeyDown : function(e){\r
- var s = this.selNode || this.lastSelNode;\r
- // undesirable, but required\r
- var sm = this;\r
- if(!s){\r
- return;\r
- }\r
- var k = e.getKey();\r
- switch(k){\r
- case e.DOWN:\r
- e.stopEvent();\r
- this.selectNext();\r
- break;\r
- case e.UP:\r
- e.stopEvent();\r
- this.selectPrevious();\r
- break;\r
- case e.RIGHT:\r
- e.preventDefault();\r
- if(s.hasChildNodes()){\r
- if(!s.isExpanded()){\r
- s.expand();\r
- }else if(s.firstChild){\r
- this.select(s.firstChild, e);\r
- }\r
- }\r
- break;\r
- case e.LEFT:\r
- e.preventDefault();\r
- if(s.hasChildNodes() && s.isExpanded()){\r
- s.collapse();\r
- }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){\r
- this.select(s.parentNode, e);\r
- }\r
- break;\r
- };\r
- }\r
-});\r
-\r
-/**\r
- * @class Ext.tree.MultiSelectionModel\r
- * @extends Ext.util.Observable\r
- * Multi selection for a TreePanel.\r
- */\r
-Ext.tree.MultiSelectionModel = function(config){\r
- this.selNodes = [];\r
- this.selMap = {};\r
- this.addEvents(\r
- /**\r
- * @event selectionchange\r
- * Fires when the selected nodes change\r
- * @param {MultiSelectionModel} this\r
- * @param {Array} nodes Array of the selected nodes\r
- */\r
- "selectionchange"\r
- );\r
- Ext.apply(this, config);\r
- Ext.tree.MultiSelectionModel.superclass.constructor.call(this);\r
-};\r
-\r
-Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {\r
- init : function(tree){\r
- this.tree = tree;\r
- tree.getTreeEl().on("keydown", this.onKeyDown, this);\r
- tree.on("click", this.onNodeClick, this);\r
- },\r
- \r
- onNodeClick : function(node, e){\r
- if(e.ctrlKey && this.isSelected(node)){\r
- this.unselect(node);\r
- }else{\r
- this.select(node, e, e.ctrlKey);\r
- }\r
- },\r
- \r
- /**\r
- * Select a node.\r
- * @param {TreeNode} node The node to select\r
- * @param {EventObject} e (optional) An event associated with the selection\r
- * @param {Boolean} keepExisting True to retain existing selections\r
- * @return {TreeNode} The selected node\r
- */\r
- select : function(node, e, keepExisting){\r
- if(keepExisting !== true){\r
- this.clearSelections(true);\r
- }\r
- if(this.isSelected(node)){\r
- this.lastSelNode = node;\r
- return node;\r
- }\r
- this.selNodes.push(node);\r
- this.selMap[node.id] = node;\r
- this.lastSelNode = node;\r
- node.ui.onSelectedChange(true);\r
- this.fireEvent("selectionchange", this, this.selNodes);\r
- return node;\r
- },\r
- \r
- /**\r
- * Deselect a node.\r
- * @param {TreeNode} node The node to unselect\r
- */\r
- unselect : function(node){\r
- if(this.selMap[node.id]){\r
- node.ui.onSelectedChange(false);\r
- var sn = this.selNodes;\r
- var index = sn.indexOf(node);\r
- if(index != -1){\r
- this.selNodes.splice(index, 1);\r
- }\r
- delete this.selMap[node.id];\r
- this.fireEvent("selectionchange", this, this.selNodes);\r
- }\r
- },\r
- \r
- /**\r
- * Clear all selections\r
- */\r
- clearSelections : function(suppressEvent){\r
- var sn = this.selNodes;\r
- if(sn.length > 0){\r
- for(var i = 0, len = sn.length; i < len; i++){\r
- sn[i].ui.onSelectedChange(false);\r
- }\r
- this.selNodes = [];\r
- this.selMap = {};\r
- if(suppressEvent !== true){\r
- this.fireEvent("selectionchange", this, this.selNodes);\r
- }\r
- }\r
- },\r
- \r
- /**\r
- * Returns true if the node is selected\r
- * @param {TreeNode} node The node to check\r
- * @return {Boolean}\r
- */\r
- isSelected : function(node){\r
- return this.selMap[node.id] ? true : false; \r
- },\r
- \r
- /**\r
- * Returns an array of the selected nodes\r
- * @return {Array}\r
- */\r
- getSelectedNodes : function(){\r
- return this.selNodes; \r
- },\r
-\r
- onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,\r
-\r
- selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,\r
-\r
- selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious\r
-});/**\r
- * @class Ext.data.Tree\r
- * @extends Ext.util.Observable\r
- * Represents a tree data structure and bubbles all the events for its nodes. The nodes\r
- * in the tree have most standard DOM functionality.\r
- * @constructor\r
- * @param {Node} root (optional) The root node\r
- */\r
-Ext.data.Tree = function(root){\r
- this.nodeHash = {};\r
- /**\r
- * The root node for this tree\r
- * @type Node\r
- */\r
- this.root = null;\r
- if(root){\r
- this.setRootNode(root);\r
- }\r
- this.addEvents(\r
- /**\r
- * @event append\r
- * Fires when a new child node is appended to a node in this tree.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The newly appended node\r
- * @param {Number} index The index of the newly appended node\r
- */\r
- "append",\r
- /**\r
- * @event remove\r
- * Fires when a child node is removed from a node in this tree.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The child node removed\r
- */\r
- "remove",\r
- /**\r
- * @event move\r
- * Fires when a node is moved to a new location in the tree\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} node The node moved\r
- * @param {Node} oldParent The old parent of this node\r
- * @param {Node} newParent The new parent of this node\r
- * @param {Number} index The index it was moved to\r
- */\r
- "move",\r
- /**\r
- * @event insert\r
- * Fires when a new child node is inserted in a node in this tree.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The child node inserted\r
- * @param {Node} refNode The child node the node was inserted before\r
- */\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
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The child node to be appended\r
- */\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
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @param {Node} node The child node to be removed\r
- */\r
- "beforeremove",\r
- /**\r
- * @event beforemove\r
- * Fires before a node is moved to a new location in the tree. Return false to cancel the move.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} node The node being moved\r
- * @param {Node} oldParent The parent of the node\r
- * @param {Node} newParent The new parent the node is moving to\r
- * @param {Number} index The index it is being moved to\r
- */\r
- "beforemove",\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
- * @param {Tree} tree The owner tree\r
- * @param {Node} parent The parent node\r
- * @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
- );\r
-\r
- Ext.data.Tree.superclass.constructor.call(this);\r
-};\r
-\r
-Ext.extend(Ext.data.Tree, Ext.util.Observable, {\r
- /**\r
- * @cfg {String} pathSeparator\r
- * The token used to separate paths in node ids (defaults to '/').\r
- */\r
- pathSeparator: "/",\r
-\r
- // private\r
- proxyNodeEvent : function(){\r
- return this.fireEvent.apply(this, arguments);\r
- },\r
-\r
- /**\r
- * Returns the root node for this tree.\r
- * @return {Node}\r
- */\r
- getRootNode : function(){\r
- return this.root;\r
- },\r
-\r
- /**\r
- * Sets the root node for this tree.\r
- * @param {Node} node\r
- * @return {Node}\r
- */\r
- setRootNode : function(node){\r
- this.root = node;\r
- node.ownerTree = this;\r
- node.isRoot = true;\r
- this.registerNode(node);\r
- return node;\r
- },\r
-\r
- /**\r
- * Gets a node in this tree by its id.\r
- * @param {String} id\r
- * @return {Node}\r
- */\r
- getNodeById : function(id){\r
- return this.nodeHash[id];\r
- },\r
-\r
- // private\r
- registerNode : function(node){\r
- this.nodeHash[node.id] = node;\r
- },\r
-\r
- // private\r
- unregisterNode : function(node){\r
- delete this.nodeHash[node.id];\r
- },\r
-\r
- toString : function(){\r
- return "[Tree"+(this.id?" "+this.id:"")+"]";\r
- }\r
-});\r
-\r
-/**\r
- * @class Ext.data.Node\r
- * @extends Ext.util.Observable\r
- * @cfg {Boolean} leaf true if this node is a leaf and does not have children\r
- * @cfg {String} id The id for this node. If one is not specified, one is generated.\r
- * @constructor\r
- * @param {Object} attributes The attributes/config for the node\r
- */\r
-Ext.data.Node = function(attributes){\r
- /**\r
- * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.\r
- * @type {Object}\r
- */\r
- this.attributes = attributes || {};\r
- this.leaf = this.attributes.leaf;\r
- /**\r
- * The node id. @type String\r
- */\r
- this.id = this.attributes.id;\r
- if(!this.id){\r
- this.id = Ext.id(null, "xnode-");\r
- this.attributes.id = this.id;\r
- }\r
- /**\r
- * All child nodes of this node. @type Array\r
- */\r
- this.childNodes = [];\r
- if(!this.childNodes.indexOf){ // indexOf is a must\r
- this.childNodes.indexOf = function(o){\r
- for(var i = 0, len = this.length; i < len; i++){\r
- if(this[i] == o){\r
- return i;\r
- }\r
- }\r
- return -1;\r
- };\r
- }\r
- /**\r
- * The parent node for this node. @type Node\r
- */\r
- this.parentNode = null;\r
- /**\r
- * The first direct child node of this node, or null if this node has no child nodes. @type Node\r
- */\r
- this.firstChild = null;\r
- /**\r
- * The last direct child node of this node, or null if this node has no child nodes. @type Node\r
- */\r
- this.lastChild = null;\r
- /**\r
- * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node\r
- */\r
- this.previousSibling = null;\r
- /**\r
- * The node immediately following this node in the tree, or null if there is no sibling node. @type Node\r
- */\r
- this.nextSibling = null;\r
-\r
- this.addEvents({\r
- /**\r
- * @event append\r
- * Fires when a new child node is appended\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} this This node\r
- * @param {Node} node The newly appended node\r
- * @param {Number} index The index of the newly appended node\r
- */\r
- "append" : true,\r
- /**\r
- * @event remove\r
- * Fires when a child node is removed\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} this This node\r
- * @param {Node} node The removed node\r
- */\r
- "remove" : true,\r
- /**\r
- * @event move\r
- * Fires when this node is moved to a new location in the tree\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} this This node\r
- * @param {Node} oldParent The old parent of this node\r
- * @param {Node} newParent The new parent of this node\r
- * @param {Number} index The index it was moved to\r
- */\r
- "move" : true,\r
- /**\r
- * @event insert\r
- * Fires when a new child node is inserted.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} this This node\r
- * @param {Node} node The child node inserted\r
- * @param {Node} refNode The child node the node was inserted before\r
- */\r
- "insert" : true,\r
- /**\r
- * @event beforeappend\r
- * Fires before a new child is appended, return false to cancel the append.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} this This node\r
- * @param {Node} node The child node to be appended\r
- */\r
- "beforeappend" : true,\r
- /**\r
- * @event beforeremove\r
- * Fires before a child is removed, return false to cancel the remove.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} this This node\r
- * @param {Node} node The child node to be removed\r
- */\r
- "beforeremove" : true,\r
- /**\r
- * @event beforemove\r
- * Fires before this node is moved to a new location in the tree. Return false to cancel the move.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} this This node\r
- * @param {Node} oldParent The parent of this node\r
- * @param {Node} newParent The new parent this node is moving to\r
- * @param {Number} index The index it is being moved to\r
- */\r
- "beforemove" : true,\r
- /**\r
- * @event beforeinsert\r
- * Fires before a new child is inserted, return false to cancel the insert.\r
- * @param {Tree} tree The owner tree\r
- * @param {Node} this This node\r
- * @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" : true\r
- });\r
- this.listeners = this.attributes.listeners;\r
- Ext.data.Node.superclass.constructor.call(this);\r
-};\r
-\r
-Ext.extend(Ext.data.Node, Ext.util.Observable, {\r
- // private\r
- fireEvent : function(evtName){\r
- // first do standard event for this node\r
- if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){\r
- return false;\r
- }\r
- // then bubble it up to the tree if the event wasn't cancelled\r
- var ot = this.getOwnerTree();\r
- if(ot){\r
- if(ot.proxyNodeEvent.apply(ot, arguments) === false){\r
- return false;\r
- }\r
- }\r
- return true;\r
- },\r
-\r
- /**\r
- * Returns true if this node is a leaf\r
- * @return {Boolean}\r
- */\r
- isLeaf : function(){\r
- return this.leaf === true;\r
- },\r
-\r
- // private\r
- setFirstChild : function(node){\r
- this.firstChild = node;\r
- },\r
-\r
- //private\r
- setLastChild : function(node){\r
- this.lastChild = node;\r
- },\r
-\r
-\r
- /**\r
- * Returns true if this node is the last child of its parent\r
- * @return {Boolean}\r
- */\r
- isLast : function(){\r
- return (!this.parentNode ? true : this.parentNode.lastChild == this);\r
- },\r
-\r
- /**\r
- * Returns true if this node is the first child of its parent\r
- * @return {Boolean}\r
- */\r
- isFirst : function(){\r
- return (!this.parentNode ? true : this.parentNode.firstChild == this);\r
- },\r
-\r
- /**\r
- * Returns true if this node has one or more child nodes, else false.\r
- * @return {Boolean}\r
- */\r
- hasChildNodes : function(){\r
- return !this.isLeaf() && this.childNodes.length > 0;\r
- },\r
- \r
- /**\r
- * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>\r
- * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.\r
- * @return {Boolean}\r
- */\r
- isExpandable : function(){\r
- return this.attributes.expandable || this.hasChildNodes();\r
- },\r
-\r
- /**\r
- * Insert node(s) as the last child node of this node.\r
- * @param {Node/Array} node The node or Array of nodes to append\r
- * @return {Node} The appended node if single append, or null if an array was passed\r
- */\r
- appendChild : function(node){\r
- var multi = false;\r
- if(Ext.isArray(node)){\r
- multi = node;\r
- }else if(arguments.length > 1){\r
- multi = arguments;\r
- }\r
- // if passed an array or multiple args do them one by one\r
- if(multi){\r
- for(var i = 0, len = multi.length; i < len; i++) {\r
- this.appendChild(multi[i]);\r
- }\r
- }else{\r
- if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){\r
- return false;\r
- }\r
- var index = this.childNodes.length;\r
- var oldParent = node.parentNode;\r
- // it's a move, make sure we move it cleanly\r
- if(oldParent){\r
- if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){\r
- return false;\r
- }\r
- oldParent.removeChild(node);\r
- }\r
- index = this.childNodes.length;\r
- if(index === 0){\r
- this.setFirstChild(node);\r
- }\r
- this.childNodes.push(node);\r
- node.parentNode = this;\r
- var ps = this.childNodes[index-1];\r
- if(ps){\r
- node.previousSibling = ps;\r
- ps.nextSibling = node;\r
- }else{\r
- node.previousSibling = null;\r
- }\r
- node.nextSibling = null;\r
- this.setLastChild(node);\r
- node.setOwnerTree(this.getOwnerTree());\r
- this.fireEvent("append", this.ownerTree, this, node, index);\r
- if(oldParent){\r
- node.fireEvent("move", this.ownerTree, node, oldParent, this, index);\r
- }\r
- return node;\r
- }\r
- },\r
-\r
- /**\r
- * Removes a child node from this node.\r
- * @param {Node} node The node to remove\r
- * @return {Node} The removed node\r
- */\r
- removeChild : function(node){\r
- var index = this.childNodes.indexOf(node);\r
- if(index == -1){\r
- return false;\r
- }\r
- if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){\r
- return false;\r
- }\r
-\r
- // remove it from childNodes collection\r
- this.childNodes.splice(index, 1);\r
-\r
- // update siblings\r
- if(node.previousSibling){\r
- node.previousSibling.nextSibling = node.nextSibling;\r
- }\r
- if(node.nextSibling){\r
- node.nextSibling.previousSibling = node.previousSibling;\r
- }\r
-\r
- // update child refs\r
- if(this.firstChild == node){\r
- this.setFirstChild(node.nextSibling);\r
- }\r
- if(this.lastChild == node){\r
- this.setLastChild(node.previousSibling);\r
- }\r
-\r
- node.setOwnerTree(null);\r
- // clear any references from the node\r
- node.parentNode = null;\r
- node.previousSibling = null;\r
- node.nextSibling = null;\r
- this.fireEvent("remove", this.ownerTree, this, node);\r
- return node;\r
- },\r
-\r
- /**\r
- * Inserts the first node before the second node in this nodes childNodes collection.\r
- * @param {Node} node The node to insert\r
- * @param {Node} refNode The node to insert before (if null the node is appended)\r
- * @return {Node} The inserted node\r
- */\r
- insertBefore : function(node, refNode){\r
- if(!refNode){ // like standard Dom, refNode can be null for append\r
- return this.appendChild(node);\r
- }\r
- // nothing to do\r
- if(node == refNode){\r
- return false;\r
- }\r
-\r
- if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){\r
- return false;\r
- }\r
- var index = this.childNodes.indexOf(refNode);\r
- var oldParent = node.parentNode;\r
- var refIndex = index;\r
-\r
- // when moving internally, indexes will change after remove\r
- if(oldParent == this && this.childNodes.indexOf(node) < index){\r
- refIndex--;\r
- }\r
-\r
- // it's a move, make sure we move it cleanly\r
- if(oldParent){\r
- if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){\r
- return false;\r
- }\r
- oldParent.removeChild(node);\r
- }\r
- if(refIndex === 0){\r
- this.setFirstChild(node);\r
- }\r
- this.childNodes.splice(refIndex, 0, node);\r
- node.parentNode = this;\r
- var ps = this.childNodes[refIndex-1];\r
- if(ps){\r
- node.previousSibling = ps;\r
- ps.nextSibling = node;\r
- }else{\r
- node.previousSibling = null;\r
- }\r
- node.nextSibling = refNode;\r
- refNode.previousSibling = node;\r
- node.setOwnerTree(this.getOwnerTree());\r
- this.fireEvent("insert", this.ownerTree, this, node, refNode);\r
- if(oldParent){\r
- node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);\r
- }\r
- return node;\r
- },\r
-\r
- /**\r
- * Removes this node from its parent\r
- * @return {Node} this\r
- */\r
- remove : function(){\r
- this.parentNode.removeChild(this);\r
- return this;\r
- },\r
-\r
- /**\r
- * Returns the child node at the specified index.\r
- * @param {Number} index\r
- * @return {Node}\r
- */\r
- item : function(index){\r
- return this.childNodes[index];\r
- },\r
-\r
- /**\r
- * Replaces one child node in this node with another.\r
- * @param {Node} newChild The replacement node\r
- * @param {Node} oldChild The node to replace\r
- * @return {Node} The replaced node\r
- */\r
- replaceChild : function(newChild, oldChild){\r
- var s = oldChild ? oldChild.nextSibling : null;\r
- this.removeChild(oldChild);\r
- this.insertBefore(newChild, s);\r
- return oldChild;\r
- },\r
-\r
- /**\r
- * Returns the index of a child node\r
- * @param {Node} node\r
- * @return {Number} The index of the node or -1 if it was not found\r
- */\r
- indexOf : function(child){\r
- return this.childNodes.indexOf(child);\r
- },\r
-\r
- /**\r
- * Returns the tree this node is in.\r
- * @return {Tree}\r
- */\r
- getOwnerTree : function(){\r
- // if it doesn't have one, look for one\r
- if(!this.ownerTree){\r
- var p = this;\r
- while(p){\r
- if(p.ownerTree){\r
- this.ownerTree = p.ownerTree;\r
- break;\r
- }\r
- p = p.parentNode;\r
- }\r
- }\r
- return this.ownerTree;\r
- },\r
-\r
- /**\r
- * Returns depth of this node (the root node has a depth of 0)\r
- * @return {Number}\r
- */\r
- getDepth : function(){\r
- var depth = 0;\r
- var p = this;\r
- while(p.parentNode){\r
- ++depth;\r
- p = p.parentNode;\r
- }\r
- return depth;\r
- },\r
-\r
- // private\r
- setOwnerTree : function(tree){\r
- // if it is a move, we need to update everyone\r
- if(tree != this.ownerTree){\r
- if(this.ownerTree){\r
- this.ownerTree.unregisterNode(this);\r
- }\r
- this.ownerTree = tree;\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++) {\r
- cs[i].setOwnerTree(tree);\r
- }\r
- if(tree){\r
- tree.registerNode(this);\r
- }\r
- }\r
- },\r
- \r
- /**\r
- * Changes the id of this node.\r
- * @param {String} id The new id for the node.\r
- */\r
- setId: function(id){\r
- if(id !== this.id){\r
- var t = this.ownerTree;\r
- if(t){\r
- t.unregisterNode(this);\r
- }\r
- this.id = id;\r
- if(t){\r
- t.registerNode(this);\r
- }\r
- this.onIdChange(id);\r
- }\r
- },\r
- \r
- // private\r
- onIdChange: Ext.emptyFn,\r
-\r
- /**\r
- * Returns the path for this node. The path can be used to expand or select this node programmatically.\r
- * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)\r
- * @return {String} The path\r
- */\r
- getPath : function(attr){\r
- attr = attr || "id";\r
- var p = this.parentNode;\r
- var b = [this.attributes[attr]];\r
- while(p){\r
- b.unshift(p.attributes[attr]);\r
- p = p.parentNode;\r
- }\r
- var sep = this.getOwnerTree().pathSeparator;\r
- return sep + b.join(sep);\r
- },\r
-\r
- /**\r
- * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of\r
- * function call will be the scope provided or the current node. The arguments to the function\r
- * will be the args provided or the current node. If the function returns false at any point,\r
- * the bubble is stopped.\r
- * @param {Function} fn The function to call\r
- * @param {Object} scope (optional) The scope of the function (defaults to current node)\r
- * @param {Array} args (optional) The args to call the function with (default to passing the current node)\r
- */\r
- bubble : function(fn, scope, args){\r
- var p = this;\r
- while(p){\r
- if(fn.apply(scope || p, args || [p]) === false){\r
- break;\r
- }\r
- p = p.parentNode;\r
- }\r
- },\r
-\r
- /**\r
- * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of\r
- * function call will be the scope provided or the current node. The arguments to the function\r
- * will be the args provided or the current node. If the function returns false at any point,\r
- * the cascade is stopped on that branch.\r
- * @param {Function} fn The function to call\r
- * @param {Object} scope (optional) The scope of the function (defaults to current node)\r
- * @param {Array} args (optional) The args to call the function with (default to passing the current node)\r
- */\r
- cascade : function(fn, scope, args){\r
- if(fn.apply(scope || this, args || [this]) !== false){\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++) {\r
- cs[i].cascade(fn, scope, args);\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of\r
- * function call will be the scope provided or the current node. The arguments to the function\r
- * will be the args provided or the current node. If the function returns false at any point,\r
- * the iteration stops.\r
- * @param {Function} fn The function to call\r
- * @param {Object} scope (optional) The scope of the function (defaults to current node)\r
- * @param {Array} args (optional) The args to call the function with (default to passing the current node)\r
- */\r
- eachChild : function(fn, scope, args){\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++) {\r
- if(fn.apply(scope || this, args || [cs[i]]) === false){\r
- break;\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Finds the first child that has the attribute with the specified value.\r
- * @param {String} attribute The attribute name\r
- * @param {Mixed} value The value to search for\r
- * @return {Node} The found child or null if none was found\r
- */\r
- findChild : function(attribute, value){\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++) {\r
- if(cs[i].attributes[attribute] == value){\r
- return cs[i];\r
- }\r
- }\r
- return null;\r
- },\r
-\r
- /**\r
- * Finds the first child by a custom function. The child matches if the function passed\r
- * returns true.\r
- * @param {Function} fn\r
- * @param {Object} scope (optional)\r
- * @return {Node} The found child or null if none was found\r
- */\r
- findChildBy : function(fn, scope){\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++) {\r
- if(fn.call(scope||cs[i], cs[i]) === true){\r
- return cs[i];\r
- }\r
- }\r
- return null;\r
- },\r
-\r
- /**\r
- * Sorts this nodes children using the supplied sort function\r
- * @param {Function} fn\r
- * @param {Object} scope (optional)\r
- */\r
- sort : function(fn, scope){\r
- var cs = this.childNodes;\r
- var len = cs.length;\r
- if(len > 0){\r
- var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;\r
- cs.sort(sortFn);\r
- for(var i = 0; i < len; i++){\r
- var n = cs[i];\r
- n.previousSibling = cs[i-1];\r
- n.nextSibling = cs[i+1];\r
- if(i === 0){\r
- this.setFirstChild(n);\r
- }\r
- if(i == len-1){\r
- this.setLastChild(n);\r
- }\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Returns true if this node is an ancestor (at any point) of the passed node.\r
- * @param {Node} node\r
- * @return {Boolean}\r
- */\r
- contains : function(node){\r
- return node.isAncestor(this);\r
- },\r
-\r
- /**\r
- * Returns true if the passed node is an ancestor (at any point) of this node.\r
- * @param {Node} node\r
- * @return {Boolean}\r
- */\r
- isAncestor : function(node){\r
- var p = this.parentNode;\r
- while(p){\r
- if(p == node){\r
- return true;\r
- }\r
- p = p.parentNode;\r
- }\r
- return false;\r
- },\r
-\r
- toString : function(){\r
- return "[Node"+(this.id?" "+this.id:"")+"]";\r
- }\r
-});/**\r
- * @class Ext.tree.TreeNode\r
- * @extends Ext.data.Node\r
- * @cfg {String} text The text for this node\r
- * @cfg {Boolean} expanded true to start the node expanded\r
- * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)\r
- * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)\r
- * @cfg {Boolean} disabled true to start the node disabled\r
- * @cfg {String} icon The path to an icon for the node. The preferred way to do this\r
- * is to use the cls or iconCls attributes and add the icon via a CSS background image.\r
- * @cfg {String} cls A css class to be added to the node\r
- * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images\r
- * @cfg {String} href URL of the link used for the node (defaults to #)\r
- * @cfg {String} hrefTarget target frame for the link\r
- * @cfg {Boolean} hidden True to render hidden. (Defaults to false).\r
- * @cfg {String} qtip An Ext QuickTip for the node\r
- * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty\r
- * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)\r
- * @cfg {Boolean} singleClickExpand True for single click expand on this node\r
- * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)\r
- * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox\r
- * (defaults to undefined with no checkbox rendered)\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
- * @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
- attributes = {text: attributes};\r
- }\r
- this.childrenRendered = false;\r
- this.rendered = false;\r
- Ext.tree.TreeNode.superclass.constructor.call(this, attributes);\r
- this.expanded = attributes.expanded === true;\r
- this.isTarget = attributes.isTarget !== false;\r
- this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;\r
- this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;\r
-\r
- /**\r
- * Read-only. The text for this node. To change it use setText().\r
- * @type String\r
- */\r
- this.text = attributes.text;\r
- /**\r
- * True if this node is disabled.\r
- * @type Boolean\r
- */\r
- this.disabled = attributes.disabled === true;\r
- /**\r
- * True if this node is hidden.\r
- * @type Boolean\r
- */\r
- this.hidden = attributes.hidden === true;\r
-\r
- this.addEvents(\r
- /**\r
- * @event textchange\r
- * Fires when the text for this node is changed\r
- * @param {Node} this This node\r
- * @param {String} text The new text\r
- * @param {String} oldText The old text\r
- */\r
- "textchange",\r
- /**\r
- * @event beforeexpand\r
- * Fires before this node is expanded, return false to cancel.\r
- * @param {Node} this This node\r
- * @param {Boolean} deep\r
- * @param {Boolean} anim\r
- */\r
- "beforeexpand",\r
- /**\r
- * @event beforecollapse\r
- * Fires before this node is collapsed, return false to cancel.\r
- * @param {Node} this This node\r
- * @param {Boolean} deep\r
- * @param {Boolean} anim\r
- */\r
- "beforecollapse",\r
- /**\r
- * @event expand\r
- * Fires when this node is expanded\r
- * @param {Node} this This node\r
- */\r
- "expand",\r
- /**\r
- * @event disabledchange\r
- * Fires when the disabled status of this node changes\r
- * @param {Node} this This node\r
- * @param {Boolean} disabled\r
- */\r
- "disabledchange",\r
- /**\r
- * @event collapse\r
- * Fires when this node is collapsed\r
- * @param {Node} this This node\r
- */\r
- "collapse",\r
- /**\r
- * @event beforeclick\r
- * Fires before click processing. Return false to cancel the default action.\r
- * @param {Node} this This node\r
- * @param {Ext.EventObject} e The event object\r
- */\r
- "beforeclick",\r
- /**\r
- * @event click\r
- * Fires when this node is clicked\r
- * @param {Node} this This node\r
- * @param {Ext.EventObject} e The event object\r
- */\r
- "click",\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
- /**\r
- * @event dblclick\r
- * Fires when this node is double clicked\r
- * @param {Node} this This node\r
- * @param {Ext.EventObject} e The event object\r
- */\r
- "dblclick",\r
- /**\r
- * @event contextmenu\r
- * Fires when this node is right clicked\r
- * @param {Node} this This node\r
- * @param {Ext.EventObject} e The event object\r
- */\r
- "contextmenu",\r
- /**\r
- * @event beforechildrenrendered\r
- * Fires right before the child nodes for this node are rendered\r
- * @param {Node} this This node\r
- */\r
- "beforechildrenrendered"\r
- );\r
-\r
- var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;\r
-\r
- /**\r
- * Read-only. The UI for this node\r
- * @type TreeNodeUI\r
- */\r
- this.ui = new uiClass(this);\r
-};\r
-Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {\r
- preventHScroll: true,\r
- /**\r
- * Returns true if this node is expanded\r
- * @return {Boolean}\r
- */\r
- isExpanded : function(){\r
- return this.expanded;\r
- },\r
-\r
-/**\r
- * Returns the UI object for this node.\r
- * @return {TreeNodeUI} The object which is providing the user interface for this tree\r
- * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance\r
- * of {@link Ext.tree.TreeNodeUI}\r
- */\r
- getUI : function(){\r
- return this.ui;\r
- },\r
-\r
- getLoader : function(){\r
- var owner;\r
- return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : new Ext.tree.TreeLoader());\r
- },\r
-\r
- // private override\r
- setFirstChild : function(node){\r
- var of = this.firstChild;\r
- Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);\r
- if(this.childrenRendered && of && node != of){\r
- of.renderIndent(true, true);\r
- }\r
- if(this.rendered){\r
- this.renderIndent(true, true);\r
- }\r
- },\r
-\r
- // private override\r
- setLastChild : function(node){\r
- var ol = this.lastChild;\r
- Ext.tree.TreeNode.superclass.setLastChild.call(this, node);\r
- if(this.childrenRendered && ol && node != ol){\r
- ol.renderIndent(true, true);\r
- }\r
- if(this.rendered){\r
- this.renderIndent(true, true);\r
- }\r
- },\r
-\r
- // these methods are overridden to provide lazy rendering support\r
- // private override\r
- appendChild : function(n){\r
- if(!n.render && !Ext.isArray(n)){\r
- n = this.getLoader().createNode(n);\r
- }\r
- var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);\r
- if(node && this.childrenRendered){\r
- node.render();\r
- }\r
- this.ui.updateExpandIcon();\r
- return node;\r
- },\r
-\r
- // private override\r
- removeChild : function(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
- node.ui.remove();\r
- }\r
- if(this.childNodes.length < 1){\r
- this.collapse(false, false);\r
- }else{\r
- this.ui.updateExpandIcon();\r
- }\r
- if(!this.firstChild && !this.isHiddenRoot()) {\r
- this.childrenRendered = false;\r
- }\r
- return node;\r
- },\r
-\r
- // private override\r
- insertBefore : function(node, refNode){\r
- if(!node.render){ \r
- node = this.getLoader().createNode(node);\r
- }\r
- var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);\r
- if(newNode && refNode && this.childrenRendered){\r
- node.render();\r
- }\r
- this.ui.updateExpandIcon();\r
- return newNode;\r
- },\r
-\r
- /**\r
- * Sets the text for this node\r
- * @param {String} text\r
- */\r
- setText : function(text){\r
- var oldText = this.text;\r
- this.text = text;\r
- this.attributes.text = text;\r
- if(this.rendered){ // event without subscribing\r
- this.ui.onTextChange(this, text, oldText);\r
- }\r
- this.fireEvent("textchange", this, text, oldText);\r
- },\r
-\r
- /**\r
- * Triggers selection of this node\r
- */\r
- select : function(){\r
- this.getOwnerTree().getSelectionModel().select(this);\r
- },\r
-\r
- /**\r
- * Triggers deselection of this node\r
- */\r
- unselect : function(){\r
- this.getOwnerTree().getSelectionModel().unselect(this);\r
- },\r
-\r
- /**\r
- * Returns true if this node is selected\r
- * @return {Boolean}\r
- */\r
- isSelected : function(){\r
- return this.getOwnerTree().getSelectionModel().isSelected(this);\r
- },\r
-\r
- /**\r
- * Expand this node.\r
- * @param {Boolean} deep (optional) True to expand all children as well\r
- * @param {Boolean} anim (optional) false to cancel the default animation\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
- */\r
- expand : function(deep, anim, callback, scope){\r
- if(!this.expanded){\r
- if(this.fireEvent("beforeexpand", this, deep, anim) === false){\r
- return;\r
- }\r
- if(!this.childrenRendered){\r
- this.renderChildren();\r
- }\r
- this.expanded = true;\r
- if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){\r
- this.ui.animExpand(function(){\r
- this.fireEvent("expand", this);\r
- this.runCallback(callback, scope || this, [this]);\r
- if(deep === true){\r
- this.expandChildNodes(true);\r
- }\r
- }.createDelegate(this));\r
- return;\r
- }else{\r
- this.ui.expand();\r
- this.fireEvent("expand", this);\r
- this.runCallback(callback, scope || this, [this]);\r
- }\r
- }else{\r
- this.runCallback(callback, scope || this, [this]);\r
- }\r
- if(deep === true){\r
- this.expandChildNodes(true);\r
- }\r
- },\r
- \r
- runCallback: function(cb, scope, args){\r
- if(Ext.isFunction(cb)){\r
- cb.apply(scope, args);\r
- }\r
- },\r
-\r
- isHiddenRoot : function(){\r
- return this.isRoot && !this.getOwnerTree().rootVisible;\r
- },\r
-\r
- /**\r
- * Collapse this node.\r
- * @param {Boolean} deep (optional) True to collapse all children as well\r
- * @param {Boolean} anim (optional) false to cancel the default animation\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
- */\r
- collapse : function(deep, anim, callback, scope){\r
- if(this.expanded && !this.isHiddenRoot()){\r
- if(this.fireEvent("beforecollapse", this, deep, anim) === false){\r
- return;\r
- }\r
- this.expanded = false;\r
- if((this.getOwnerTree().animate && anim !== false) || anim){\r
- this.ui.animCollapse(function(){\r
- this.fireEvent("collapse", this);\r
- this.runCallback(callback, scope || this, [this]);\r
- if(deep === true){\r
- this.collapseChildNodes(true);\r
- }\r
- }.createDelegate(this));\r
- return;\r
- }else{\r
- this.ui.collapse();\r
- this.fireEvent("collapse", this);\r
- this.runCallback(callback, scope || this, [this]);\r
- }\r
- }else if(!this.expanded){\r
- this.runCallback(callback, scope || this, [this]);\r
- }\r
- if(deep === true){\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++) {\r
- cs[i].collapse(true, false);\r
- }\r
- }\r
- },\r
-\r
- // private\r
- delayedExpand : function(delay){\r
- if(!this.expandProcId){\r
- this.expandProcId = this.expand.defer(delay, this);\r
- }\r
- },\r
-\r
- // private\r
- cancelExpand : function(){\r
- if(this.expandProcId){\r
- clearTimeout(this.expandProcId);\r
- }\r
- this.expandProcId = false;\r
- },\r
-\r
- /**\r
- * Toggles expanded/collapsed state of the node\r
- */\r
- toggle : function(){\r
- if(this.expanded){\r
- this.collapse();\r
- }else{\r
- this.expand();\r
- }\r
- },\r
-\r
- /**\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
- */\r
- ensureVisible : function(callback, scope){\r
- var tree = this.getOwnerTree();\r
- tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){\r
- var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime\r
- tree.getTreeEl().scrollChildIntoView(node.ui.anchor);\r
- this.runCallback(callback, scope || this, [this]);\r
- }.createDelegate(this));\r
- },\r
-\r
- /**\r
- * Expand all child nodes\r
- * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes\r
- */\r
- expandChildNodes : function(deep){\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++) {\r
- cs[i].expand(deep);\r
- }\r
- },\r
-\r
- /**\r
- * Collapse all child nodes\r
- * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes\r
- */\r
- collapseChildNodes : function(deep){\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++) {\r
- cs[i].collapse(deep);\r
- }\r
- },\r
-\r
- /**\r
- * Disables this node\r
- */\r
- disable : function(){\r
- this.disabled = true;\r
- this.unselect();\r
- if(this.rendered && this.ui.onDisableChange){ // event without subscribing\r
- this.ui.onDisableChange(this, true);\r
- }\r
- this.fireEvent("disabledchange", this, true);\r
- },\r
-\r
- /**\r
- * Enables this node\r
- */\r
- enable : function(){\r
- this.disabled = false;\r
- if(this.rendered && this.ui.onDisableChange){ // event without subscribing\r
- this.ui.onDisableChange(this, false);\r
- }\r
- this.fireEvent("disabledchange", this, false);\r
- },\r
-\r
- // private\r
- renderChildren : function(suppressEvent){\r
- if(suppressEvent !== false){\r
- this.fireEvent("beforechildrenrendered", this);\r
- }\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++){\r
- cs[i].render(true);\r
- }\r
- this.childrenRendered = true;\r
- },\r
-\r
- // private\r
- sort : function(fn, scope){\r
- Ext.tree.TreeNode.superclass.sort.apply(this, arguments);\r
- if(this.childrenRendered){\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++){\r
- cs[i].render(true);\r
- }\r
- }\r
- },\r
-\r
- // private\r
- render : function(bulkRender){\r
- this.ui.render(bulkRender);\r
- if(!this.rendered){\r
- // make sure it is registered\r
- this.getOwnerTree().registerNode(this);\r
- this.rendered = true;\r
- if(this.expanded){\r
- this.expanded = false;\r
- this.expand(false, false);\r
- }\r
- }\r
- },\r
-\r
- // private\r
- renderIndent : function(deep, refresh){\r
- if(refresh){\r
- this.ui.childIndent = null;\r
- }\r
- this.ui.renderIndent();\r
- if(deep === true && this.childrenRendered){\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++){\r
- cs[i].renderIndent(true, refresh);\r
- }\r
- }\r
- },\r
-\r
- beginUpdate : function(){\r
- this.childrenRendered = false;\r
- },\r
-\r
- endUpdate : function(){\r
- if(this.expanded && this.rendered){\r
- this.renderChildren();\r
- }\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
- },\r
- \r
- // private\r
- onIdChange: function(id){\r
- this.ui.onIdChange(id);\r
- }\r
-});\r
-\r
-Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;/**\r
- * @class Ext.tree.AsyncTreeNode\r
- * @extends Ext.tree.TreeNode\r
- * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)\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.AsyncTreeNode = function(config){\r
- this.loaded = config && config.loaded === true;\r
- this.loading = false;\r
- Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);\r
- /**\r
- * @event beforeload\r
- * Fires before this node is loaded, return false to cancel\r
- * @param {Node} this This node\r
- */\r
- this.addEvents('beforeload', 'load');\r
- /**\r
- * @event load\r
- * Fires when this node is loaded\r
- * @param {Node} this This node\r
- */\r
- /**\r
- * The loader used by this node (defaults to using the tree's defined loader)\r
- * @type TreeLoader\r
- * @property loader\r
- */\r
-};\r
-Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {\r
- expand : function(deep, anim, callback, scope){\r
- if(this.loading){ // if an async load is already running, waiting til it's done\r
- var timer;\r
- var f = function(){\r
- if(!this.loading){ // done loading\r
- clearInterval(timer);\r
- this.expand(deep, anim, callback, scope);\r
- }\r
- }.createDelegate(this);\r
- timer = setInterval(f, 200);\r
- return;\r
- }\r
- if(!this.loaded){\r
- if(this.fireEvent("beforeload", this) === false){\r
- return;\r
- }\r
- this.loading = true;\r
- this.ui.beforeLoad(this);\r
- var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();\r
- if(loader){\r
- loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);\r
- return;\r
- }\r
- }\r
- Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);\r
- },\r
- \r
- /**\r
- * Returns true if this node is currently loading\r
- * @return {Boolean}\r
- */\r
- isLoading : function(){\r
- return this.loading; \r
- },\r
- \r
- loadComplete : function(deep, anim, callback, scope){\r
- this.loading = false;\r
- this.loaded = true;\r
- this.ui.afterLoad(this);\r
- this.fireEvent("load", this);\r
- this.expand(deep, anim, callback, scope);\r
- },\r
- \r
- /**\r
- * Returns true if this node has been loaded\r
- * @return {Boolean}\r
- */\r
- isLoaded : function(){\r
- return this.loaded;\r
- },\r
- \r
- hasChildNodes : function(){\r
- if(!this.isLeaf() && !this.loaded){\r
- return true;\r
- }else{\r
- return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);\r
- }\r
- },\r
-\r
- /**\r
- * Trigger a reload for this node\r
- * @param {Function} callback\r
- * @param {Object} scope (optional) The scope in which to execute the callback.\r
- */\r
- reload : function(callback, scope){\r
- this.collapse(false, false);\r
- while(this.firstChild){\r
- this.removeChild(this.firstChild).destroy();\r
- }\r
- this.childrenRendered = false;\r
- this.loaded = false;\r
- if(this.isHiddenRoot()){\r
- this.expanded = false;\r
- }\r
- this.expand(false, false, callback, scope);\r
- }\r
-});\r
-\r
-Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;/**\r
- * @class Ext.tree.TreeNodeUI\r
- * This class provides the default UI implementation for Ext TreeNodes.\r
- * The TreeNode UI implementation is separate from the\r
- * tree implementation, and allows customizing of the appearance of\r
- * tree nodes.<br>\r
- * <p>\r
- * If you are customizing the Tree's user interface, you\r
- * may need to extend this class, but you should never need to instantiate this class.<br>\r
- * <p>\r
- * This class provides access to the user interface components of an Ext TreeNode, through\r
- * {@link Ext.tree.TreeNode#getUI}\r
- */\r
-Ext.tree.TreeNodeUI = function(node){\r
- this.node = node;\r
- this.rendered = false;\r
- this.animating = false;\r
- this.wasLeaf = true;\r
- this.ecc = 'x-tree-ec-icon x-tree-elbow';\r
- this.emptyIcon = Ext.BLANK_IMAGE_URL;\r
-};\r
-\r
-Ext.tree.TreeNodeUI.prototype = {\r
- // private\r
- removeChild : function(node){\r
- if(this.rendered){\r
- this.ctNode.removeChild(node.ui.getEl());\r
- } \r
- },\r
-\r
- // private\r
- beforeLoad : function(){\r
- this.addClass("x-tree-node-loading");\r
- },\r
-\r
- // private\r
- afterLoad : function(){\r
- this.removeClass("x-tree-node-loading");\r
- },\r
-\r
- // private\r
- onTextChange : function(node, text, oldText){\r
- if(this.rendered){\r
- this.textNode.innerHTML = text;\r
- }\r
- },\r
-\r
- // private\r
- onDisableChange : function(node, state){\r
- this.disabled = state;\r
- if (this.checkbox) {\r
- this.checkbox.disabled = state;\r
- } \r
- if(state){\r
- this.addClass("x-tree-node-disabled");\r
- }else{\r
- this.removeClass("x-tree-node-disabled");\r
- } \r
- },\r
-\r
- // private\r
- onSelectedChange : function(state){\r
- if(state){\r
- this.focus();\r
- this.addClass("x-tree-selected");\r
- }else{\r
- //this.blur();\r
- this.removeClass("x-tree-selected");\r
- }\r
- },\r
-\r
- // private\r
- onMove : function(tree, node, oldParent, newParent, index, refNode){\r
- this.childIndent = null;\r
- if(this.rendered){\r
- var targetNode = newParent.ui.getContainer();\r
- if(!targetNode){//target not rendered\r
- this.holder = document.createElement("div");\r
- this.holder.appendChild(this.wrap);\r
- return;\r
- }\r
- var insertBefore = refNode ? refNode.ui.getEl() : null;\r
- if(insertBefore){\r
- targetNode.insertBefore(this.wrap, insertBefore);\r
- }else{\r
- targetNode.appendChild(this.wrap);\r
- }\r
- this.node.renderIndent(true, oldParent != newParent);\r
- }\r
- },\r
-\r
-/**\r
- * Adds one or more CSS classes to the node's UI element.\r
- * Duplicate classes are automatically filtered out.\r
- * @param {String/Array} className The CSS class to add, or an array of classes\r
- */\r
- addClass : function(cls){\r
- if(this.elNode){\r
- Ext.fly(this.elNode).addClass(cls);\r
- }\r
- },\r
-\r
-/**\r
- * Removes one or more CSS classes from the node's UI element.\r
- * @param {String/Array} className The CSS class to remove, or an array of classes\r
- */\r
- removeClass : function(cls){\r
- if(this.elNode){\r
- Ext.fly(this.elNode).removeClass(cls); \r
- }\r
- },\r
-\r
- // private\r
- remove : function(){\r
- if(this.rendered){\r
- this.holder = document.createElement("div");\r
- this.holder.appendChild(this.wrap);\r
- } \r
- },\r
-\r
- // private\r
- fireEvent : function(){\r
- return this.node.fireEvent.apply(this.node, arguments); \r
- },\r
-\r
- // private\r
- initEvents : function(){\r
- this.node.on("move", this.onMove, this);\r
-\r
- if(this.node.disabled){\r
- this.addClass("x-tree-node-disabled");\r
- if (this.checkbox) {\r
- this.checkbox.disabled = true;\r
- } \r
- }\r
- if(this.node.hidden){\r
- this.hide();\r
- }\r
- var ot = this.node.getOwnerTree();\r
- var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;\r
- if(dd && (!this.node.isRoot || ot.rootVisible)){\r
- Ext.dd.Registry.register(this.elNode, {\r
- node: this.node,\r
- handles: this.getDDHandles(),\r
- isHandle: false\r
- });\r
- }\r
- },\r
-\r
- // private\r
- getDDHandles : function(){\r
- return [this.iconNode, this.textNode, this.elNode];\r
- },\r
-\r
-/**\r
- * Hides this node.\r
- */\r
- hide : function(){\r
- this.node.hidden = true;\r
- if(this.wrap){\r
- this.wrap.style.display = "none";\r
- }\r
- },\r
-\r
-/**\r
- * Shows this node.\r
- */\r
- show : function(){\r
- this.node.hidden = false;\r
- if(this.wrap){\r
- this.wrap.style.display = "";\r
- } \r
- },\r
-\r
- // private\r
- onContextMenu : function(e){\r
- if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {\r
- e.preventDefault();\r
- this.focus();\r
- this.fireEvent("contextmenu", this.node, e);\r
- }\r
- },\r
-\r
- // private\r
- onClick : function(e){\r
- if(this.dropping){\r
- e.stopEvent();\r
- return;\r
- }\r
- if(this.fireEvent("beforeclick", this.node, e) !== false){\r
- var a = e.getTarget('a');\r
- if(!this.disabled && this.node.attributes.href && a){\r
- this.fireEvent("click", this.node, e);\r
- return;\r
- }else if(a && e.ctrlKey){\r
- e.stopEvent();\r
- }\r
- e.preventDefault();\r
- if(this.disabled){\r
- return;\r
- }\r
-\r
- if(this.node.attributes.singleClickExpand && !this.animating && this.node.isExpandable()){\r
- this.node.toggle();\r
- }\r
-\r
- this.fireEvent("click", this.node, e);\r
- }else{\r
- e.stopEvent();\r
- }\r
- },\r
-\r
- // private\r
- onDblClick : function(e){\r
- e.preventDefault();\r
- if(this.disabled){\r
- return;\r
- }\r
- if(this.checkbox){\r
- this.toggleCheck();\r
- }\r
- if(!this.animating && this.node.isExpandable()){\r
- this.node.toggle();\r
- }\r
- this.fireEvent("dblclick", this.node, e);\r
- },\r
-\r
- onOver : function(e){\r
- this.addClass('x-tree-node-over');\r
- },\r
-\r
- onOut : function(e){\r
- this.removeClass('x-tree-node-over');\r
- },\r
-\r
- // private\r
- onCheckChange : function(){\r
- var checked = this.checkbox.checked;\r
- // fix for IE6\r
- this.checkbox.defaultChecked = checked; \r
- this.node.attributes.checked = checked;\r
- this.fireEvent('checkchange', this.node, checked);\r
- },\r
-\r
- // private\r
- ecClick : function(e){\r
- if(!this.animating && this.node.isExpandable()){\r
- this.node.toggle();\r
- }\r
- },\r
-\r
- // private\r
- startDrop : function(){\r
- this.dropping = true;\r
- },\r
- \r
- // delayed drop so the click event doesn't get fired on a drop\r
- endDrop : function(){ \r
- setTimeout(function(){\r
- this.dropping = false;\r
- }.createDelegate(this), 50); \r
- },\r
-\r
- // private\r
- expand : function(){\r
- this.updateExpandIcon();\r
- this.ctNode.style.display = "";\r
- },\r
-\r
- // private\r
- focus : function(){\r
- if(!this.node.preventHScroll){\r
- try{this.anchor.focus();\r
- }catch(e){}\r
- }else{\r
- try{\r
- var noscroll = this.node.getOwnerTree().getTreeEl().dom;\r
- var l = noscroll.scrollLeft;\r
- this.anchor.focus();\r
- noscroll.scrollLeft = l;\r
- }catch(e){}\r
- }\r
- },\r
-\r
-/**\r
- * Sets the checked status of the tree node to the passed value, or, if no value was passed,\r
- * toggles the checked status. If the node was rendered with no checkbox, this has no effect.\r
- * @param {Boolean} (optional) The new checked status.\r
- */\r
- toggleCheck : function(value){\r
- var cb = this.checkbox;\r
- if(cb){\r
- cb.checked = (value === undefined ? !cb.checked : value);\r
- this.onCheckChange();\r
- }\r
- },\r
-\r
- // private\r
- blur : function(){\r
- try{\r
- this.anchor.blur();\r
- }catch(e){} \r
- },\r
-\r
- // private\r
- animExpand : function(callback){\r
- var ct = Ext.get(this.ctNode);\r
- ct.stopFx();\r
- if(!this.node.isExpandable()){\r
- this.updateExpandIcon();\r
- this.ctNode.style.display = "";\r
- Ext.callback(callback);\r
- return;\r
- }\r
- this.animating = true;\r
- this.updateExpandIcon();\r
- \r
- ct.slideIn('t', {\r
- callback : function(){\r
- this.animating = false;\r
- Ext.callback(callback);\r
- },\r
- scope: this,\r
- duration: this.node.ownerTree.duration || .25\r
- });\r
- },\r
-\r
- // private\r
- highlight : function(){\r
- var tree = this.node.getOwnerTree();\r
- Ext.fly(this.wrap).highlight(\r
- tree.hlColor || "C3DAF9",\r
- {endColor: tree.hlBaseColor}\r
- );\r
- },\r
-\r
- // private\r
- collapse : function(){\r
- this.updateExpandIcon();\r
- this.ctNode.style.display = "none";\r
- },\r
-\r
- // private\r
- animCollapse : function(callback){\r
- var ct = Ext.get(this.ctNode);\r
- ct.enableDisplayMode('block');\r
- ct.stopFx();\r
-\r
- this.animating = true;\r
- this.updateExpandIcon();\r
-\r
- ct.slideOut('t', {\r
- callback : function(){\r
- this.animating = false;\r
- Ext.callback(callback);\r
- },\r
- scope: this,\r
- duration: this.node.ownerTree.duration || .25\r
- });\r
- },\r
-\r
- // private\r
- getContainer : function(){\r
- return this.ctNode; \r
- },\r
-\r
- // private\r
- getEl : function(){\r
- return this.wrap; \r
- },\r
-\r
- // private\r
- appendDDGhost : function(ghostNode){\r
- ghostNode.appendChild(this.elNode.cloneNode(true));\r
- },\r
-\r
- // private\r
- getDDRepairXY : function(){\r
- return Ext.lib.Dom.getXY(this.iconNode);\r
- },\r
-\r
- // private\r
- onRender : function(){\r
- this.render(); \r
- },\r
-\r
- // private\r
- render : function(bulkRender){\r
- var n = this.node, a = n.attributes;\r
- var targetNode = n.parentNode ? \r
- n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;\r
- \r
- if(!this.rendered){\r
- this.rendered = true;\r
-\r
- this.renderElements(n, a, targetNode, bulkRender);\r
-\r
- if(a.qtip){\r
- if(this.textNode.setAttributeNS){\r
- this.textNode.setAttributeNS("ext", "qtip", a.qtip);\r
- if(a.qtipTitle){\r
- this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);\r
- }\r
- }else{\r
- this.textNode.setAttribute("ext:qtip", a.qtip);\r
- if(a.qtipTitle){\r
- this.textNode.setAttribute("ext:qtitle", a.qtipTitle);\r
- }\r
- } \r
- }else if(a.qtipCfg){\r
- a.qtipCfg.target = Ext.id(this.textNode);\r
- Ext.QuickTips.register(a.qtipCfg);\r
- }\r
- this.initEvents();\r
- if(!this.node.expanded){\r
- this.updateExpandIcon(true);\r
- }\r
- }else{\r
- if(bulkRender === true) {\r
- targetNode.appendChild(this.wrap);\r
- }\r
- }\r
- },\r
-\r
- // private\r
- renderElements : function(n, a, targetNode, bulkRender){\r
- // add some indent caching, this helps performance when rendering a large tree\r
- this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';\r
-\r
- var cb = typeof a.checked == 'boolean';\r
-\r
- var href = a.href ? a.href : Ext.isGecko ? "" : "#";\r
- var buf = ['<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf x-unselectable ', a.cls,'" unselectable="on">',\r
- '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",\r
- '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',\r
- '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',\r
- cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',\r
- '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ',\r
- a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",\r
- '<ul class="x-tree-node-ct" style="display:none;"></ul>',\r
- "</li>"].join('');\r
-\r
- var nel;\r
- if(bulkRender !== true && n.nextSibling && (nel = n.nextSibling.ui.getEl())){\r
- this.wrap = Ext.DomHelper.insertHtml("beforeBegin", nel, buf);\r
- }else{\r
- this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf);\r
- }\r
- \r
- this.elNode = this.wrap.childNodes[0];\r
- this.ctNode = this.wrap.childNodes[1];\r
- var cs = this.elNode.childNodes;\r
- this.indentNode = cs[0];\r
- this.ecNode = cs[1];\r
- this.iconNode = cs[2];\r
- var index = 3;\r
- if(cb){\r
- this.checkbox = cs[3];\r
- // fix for IE6\r
- this.checkbox.defaultChecked = this.checkbox.checked; \r
- index++;\r
- }\r
- this.anchor = cs[index];\r
- this.textNode = cs[index].firstChild;\r
- },\r
-\r
-/**\r
- * Returns the <a> element that provides focus for the node's UI.\r
- * @return {HtmlElement} The DOM anchor element.\r
- */\r
- getAnchor : function(){\r
- return this.anchor;\r
- },\r
- \r
-/**\r
- * Returns the text node.\r
- * @return {HtmlNode} The DOM text node.\r
- */\r
- getTextEl : function(){\r
- return this.textNode;\r
- },\r
- \r
-/**\r
- * Returns the icon <img> element.\r
- * @return {HtmlElement} The DOM image element.\r
- */\r
- getIconEl : function(){\r
- return this.iconNode;\r
- },\r
-\r
-/**\r
- * Returns the checked status of the node. If the node was rendered with no\r
- * checkbox, it returns false.\r
- * @return {Boolean} The checked flag.\r
- */\r
- isChecked : function(){\r
- return this.checkbox ? this.checkbox.checked : false; \r
- },\r
-\r
- // private\r
- updateExpandIcon : function(){\r
- if(this.rendered){\r
- var n = this.node, c1, c2;\r
- var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";\r
- var hasChild = n.hasChildNodes();\r
- if(hasChild || n.attributes.expandable){\r
- if(n.expanded){\r
- cls += "-minus";\r
- c1 = "x-tree-node-collapsed";\r
- c2 = "x-tree-node-expanded";\r
- }else{\r
- cls += "-plus";\r
- c1 = "x-tree-node-expanded";\r
- c2 = "x-tree-node-collapsed";\r
- }\r
- if(this.wasLeaf){\r
- this.removeClass("x-tree-node-leaf");\r
- this.wasLeaf = false;\r
- }\r
- if(this.c1 != c1 || this.c2 != c2){\r
- Ext.fly(this.elNode).replaceClass(c1, c2);\r
- this.c1 = c1; this.c2 = c2;\r
- }\r
- }else{\r
- if(!this.wasLeaf){\r
- Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");\r
- delete this.c1;\r
- delete this.c2;\r
- this.wasLeaf = true;\r
- }\r
- }\r
- var ecc = "x-tree-ec-icon "+cls;\r
- if(this.ecc != ecc){\r
- this.ecNode.className = ecc;\r
- this.ecc = ecc;\r
- }\r
- }\r
- },\r
- \r
- // private\r
- onIdChange: function(id){\r
- if(this.rendered){\r
- this.elNode.setAttribute('ext:tree-node-id', id);\r
- }\r
- },\r
-\r
- // private\r
- getChildIndent : function(){\r
- if(!this.childIndent){\r
- var buf = [];\r
- var p = this.node;\r
- while(p){\r
- if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){\r
- if(!p.isLast()) {\r
- buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');\r
- } else {\r
- buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');\r
- }\r
- }\r
- p = p.parentNode;\r
- }\r
- this.childIndent = buf.join("");\r
- }\r
- return this.childIndent;\r
- },\r
-\r
- // private\r
- renderIndent : function(){\r
- if(this.rendered){\r
- var indent = "";\r
- var p = this.node.parentNode;\r
- if(p){\r
- indent = p.ui.getChildIndent();\r
- }\r
- if(this.indentMarkup != indent){ // don't rerender if not required\r
- this.indentNode.innerHTML = indent;\r
- this.indentMarkup = indent;\r
- }\r
- this.updateExpandIcon();\r
- }\r
- },\r
-\r
- destroy : function(){\r
- if(this.elNode){\r
- Ext.dd.Registry.unregister(this.elNode.id);\r
- }\r
- delete this.elNode;\r
- delete this.ctNode;\r
- delete this.indentNode;\r
- delete this.ecNode;\r
- delete this.iconNode;\r
- delete this.checkbox;\r
- delete this.anchor;\r
- delete this.textNode;\r
- \r
- if (this.holder){\r
- delete this.wrap;\r
- Ext.removeNode(this.holder);\r
- delete this.holder;\r
- }else{\r
- Ext.removeNode(this.wrap);\r
- delete this.wrap;\r
- }\r
- }\r
-};\r
-\r
-/**\r
- * @class Ext.tree.RootTreeNodeUI\r
- * This class provides the default UI implementation for <b>root</b> Ext TreeNodes.\r
- * The RootTreeNode UI implementation allows customizing the appearance of the root tree node.<br>\r
- * <p>\r
- * If you are customizing the Tree's user interface, you\r
- * may need to extend this class, but you should never need to instantiate this class.<br>\r
- */\r
-Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {\r
- // private\r
- render : function(){\r
- if(!this.rendered){\r
- var targetNode = this.node.ownerTree.innerCt.dom;\r
- this.node.expanded = true;\r
- targetNode.innerHTML = '<div class="x-tree-root-node"></div>';\r
- this.wrap = this.ctNode = targetNode.firstChild;\r
- }\r
- },\r
- collapse : Ext.emptyFn,\r
- expand : Ext.emptyFn\r
-});/**\r
- * @class Ext.tree.TreeLoader\r
- * @extends Ext.util.Observable\r
- * A TreeLoader provides for lazy loading of an {@link Ext.tree.TreeNode}'s child\r
- * nodes from a specified URL. The response must be a JavaScript Array definition\r
- * whose elements are node definition objects. e.g.:\r
- * <pre><code>\r
- [{\r
- id: 1,\r
- text: 'A leaf Node',\r
- leaf: true\r
- },{\r
- id: 2,\r
- text: 'A folder Node',\r
- children: [{\r
- id: 3,\r
- text: 'A child Node',\r
- leaf: true\r
- }]\r
- }]\r
-</code></pre>\r
- * <br><br>\r
- * A server request is sent, and child nodes are loaded only when a node is expanded.\r
- * The loading node's id is passed to the server under the parameter name "node" to\r
- * enable the server to produce the correct child nodes.\r
- * <br><br>\r
- * To pass extra parameters, an event handler may be attached to the "beforeload"\r
- * event, and the parameters specified in the TreeLoader's baseParams property:\r
- * <pre><code>\r
- myTreeLoader.on("beforeload", function(treeLoader, node) {\r
- this.baseParams.category = node.attributes.category;\r
- }, this);\r
-</code></pre>\r
- * This would pass an HTTP parameter called "category" to the server containing\r
- * the value of the Node's "category" attribute.\r
- * @constructor\r
- * Creates a new Treeloader.\r
- * @param {Object} config A config object containing config properties.\r
- */\r
-Ext.tree.TreeLoader = function(config){\r
- this.baseParams = {};\r
- Ext.apply(this, config);\r
-\r
- this.addEvents(\r
- /**\r
- * @event beforeload\r
- * Fires before a network request is made to retrieve the Json text which specifies a node's children.\r
- * @param {Object} This TreeLoader object.\r
- * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.\r
- * @param {Object} callback The callback function specified in the {@link #load} call.\r
- */\r
- "beforeload",\r
- /**\r
- * @event load\r
- * Fires when the node has been successfuly loaded.\r
- * @param {Object} This TreeLoader object.\r
- * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.\r
- * @param {Object} response The response object containing the data from the server.\r
- */\r
- "load",\r
- /**\r
- * @event loadexception\r
- * Fires if the network request failed.\r
- * @param {Object} This TreeLoader object.\r
- * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.\r
- * @param {Object} response The response object containing the data from the server.\r
- */\r
- "loadexception"\r
- );\r
- Ext.tree.TreeLoader.superclass.constructor.call(this);\r
- if(typeof this.paramOrder == 'string'){\r
- this.paramOrder = this.paramOrder.split(/[\s,|]/);\r
- }\r
-};\r
-\r
-Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, {\r
- /**\r
- * @cfg {String} dataUrl The URL from which to request a Json string which\r
- * specifies an array of node definition objects representing the child nodes\r
- * to be loaded.\r
- */\r
- /**\r
- * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).\r
- */\r
- /**\r
- * @cfg {String} url Equivalent to {@link #dataUrl}.\r
- */\r
- /**\r
- * @cfg {Boolean} preloadChildren If set to true, the loader recursively loads "children" attributes when doing the first load on nodes.\r
- */\r
- /**\r
- * @cfg {Object} baseParams (optional) An object containing properties which\r
- * specify HTTP parameters to be passed to each request for child nodes.\r
- */\r
- /**\r
- * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes\r
- * created by this loader. If the attributes sent by the server have an attribute in this object,\r
- * they take priority.\r
- */\r
- /**\r
- * @cfg {Object} uiProviders (optional) An object containing properties which\r
- * specify custom {@link Ext.tree.TreeNodeUI} implementations. If the optional\r
- * <i>uiProvider</i> attribute of a returned child node is a string rather\r
- * than a reference to a TreeNodeUI implementation, then that string value\r
- * is used as a property name in the uiProviders object.\r
- */\r
- uiProviders : {},\r
-\r
- /**\r
- * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing\r
- * child nodes before loading.\r
- */\r
- clearOnLoad : true,\r
-\r
- /**\r
- * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. Only used when using directFn.\r
- * A list of params to be executed\r
- * server side. Specify the params in the order in which they must be executed on the server-side\r
- * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,\r
- * comma, or pipe. For example,\r
- * any of the following would be acceptable:<pre><code>\r
-paramOrder: ['param1','param2','param3']\r
-paramOrder: 'param1 param2 param3'\r
-paramOrder: 'param1,param2,param3'\r
-paramOrder: 'param1|param2|param'\r
- </code></pre>\r
- */\r
- paramOrder: undefined,\r
-\r
- /**\r
- * @cfg {Boolean} paramsAsHash Only used when using directFn.\r
- * Send parameters as a collection of named arguments (defaults to <tt>false</tt>). Providing a\r
- * <tt>{@link #paramOrder}</tt> nullifies this configuration.\r
- */\r
- paramsAsHash: false,\r
-\r
- /**\r
- * @cfg {Function} directFn\r
- * Function to call when executing a request.\r
- */\r
- directFn : undefined,\r
-\r
- /**\r
- * Load an {@link Ext.tree.TreeNode} from the URL specified in the constructor.\r
- * This is called automatically when a node is expanded, but may be used to reload\r
- * a node (or append new children if the {@link #clearOnLoad} option is false.)\r
- * @param {Ext.tree.TreeNode} node\r
- * @param {Function} callback\r
- * @param (Object) scope\r
- */\r
- load : function(node, callback, scope){\r
- if(this.clearOnLoad){\r
- while(node.firstChild){\r
- node.removeChild(node.firstChild);\r
- }\r
- }\r
- if(this.doPreload(node)){ // preloaded json children\r
- this.runCallback(callback, scope || node, []);\r
- }else if(this.directFn || this.dataUrl || this.url){\r
- this.requestData(node, callback, scope || node);\r
- }\r
- },\r
-\r
- doPreload : function(node){\r
- if(node.attributes.children){\r
- if(node.childNodes.length < 1){ // preloaded?\r
- var cs = node.attributes.children;\r
- node.beginUpdate();\r
- for(var i = 0, len = cs.length; i < len; i++){\r
- var cn = node.appendChild(this.createNode(cs[i]));\r
- if(this.preloadChildren){\r
- this.doPreload(cn);\r
- }\r
- }\r
- node.endUpdate();\r
- }\r
- return true;\r
- }\r
- return false;\r
- },\r
-\r
- getParams: function(node){\r
- var buf = [], bp = this.baseParams;\r
- if(this.directFn){\r
- buf.push(node.id);\r
- if(bp){\r
- if(this.paramOrder){\r
- for(var i = 0, len = this.paramOrder.length; i < len; i++){\r
- buf.push(bp[this.paramOrder[i]]);\r
- }\r
- }else if(this.paramsAsHash){\r
- buf.push(bp);\r
- }\r
- }\r
- return buf;\r
- }else{\r
- for(var key in bp){\r
- if(!Ext.isFunction(bp[key])){\r
- buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");\r
- }\r
- }\r
- buf.push("node=", encodeURIComponent(node.id));\r
- return buf.join("");\r
- }\r
- },\r
-\r
- requestData : function(node, callback, scope){\r
- if(this.fireEvent("beforeload", this, node, callback) !== false){\r
- if(this.directFn){\r
- var args = this.getParams(node);\r
- args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));\r
- this.directFn.apply(window, args);\r
- }else{\r
- this.transId = Ext.Ajax.request({\r
- method:this.requestMethod,\r
- url: this.dataUrl||this.url,\r
- success: this.handleResponse,\r
- failure: this.handleFailure,\r
- scope: this,\r
- argument: {callback: callback, node: node, scope: scope},\r
- params: this.getParams(node)\r
- });\r
- }\r
- }else{\r
- // if the load is cancelled, make sure we notify\r
- // the node that we are done\r
- this.runCallback(callback, scope || node, []);\r
- }\r
- },\r
-\r
- processDirectResponse: function(result, response, args){\r
- if(response.status){\r
- this.handleResponse({\r
- responseData: Ext.isArray(result) ? result : null,\r
- responseText: result,\r
- argument: args\r
- });\r
- }else{\r
- this.handleFailure({\r
- argument: args\r
- });\r
- }\r
- },\r
-\r
- // private\r
- runCallback: function(cb, scope, args){\r
- if(Ext.isFunction(cb)){\r
- cb.apply(scope, args);\r
- }\r
- },\r
-\r
- isLoading : function(){\r
- return !!this.transId;\r
- },\r
-\r
- abort : function(){\r
- if(this.isLoading()){\r
- Ext.Ajax.abort(this.transId);\r
- }\r
- },\r
-\r
- /**\r
- * <p>Override this function for custom TreeNode node implementation, or to\r
- * modify the attributes at creation time.</p>\r
- * Example:<pre><code>\r
-new Ext.tree.TreePanel({\r
- ...\r
- new Ext.tree.TreeLoader({\r
- url: 'dataUrl',\r
- createNode: function(attr) {\r
-// Allow consolidation consignments to have\r
-// consignments dropped into them.\r
- if (attr.isConsolidation) {\r
- attr.iconCls = 'x-consol',\r
- attr.allowDrop = true;\r
- }\r
- return Ext.tree.TreeLoader.prototype.call(this, attr);\r
- }\r
- }),\r
- ...\r
-});\r
-</code></pre>\r
- * @param attr {Object} The attributes from which to create the new node.\r
- */\r
- createNode : function(attr){\r
- // apply baseAttrs, nice idea Corey!\r
- if(this.baseAttrs){\r
- Ext.applyIf(attr, this.baseAttrs);\r
- }\r
- if(this.applyLoader !== false){\r
- attr.loader = this;\r
- }\r
- if(typeof attr.uiProvider == 'string'){\r
- attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);\r
- }\r
- if(attr.nodeType){\r
- return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);\r
- }else{\r
- return attr.leaf ?\r
- new Ext.tree.TreeNode(attr) :\r
- new Ext.tree.AsyncTreeNode(attr);\r
- }\r
- },\r
-\r
- processResponse : function(response, node, callback, scope){\r
- var json = response.responseText;\r
- try {\r
- var o = response.responseData || Ext.decode(json);\r
- node.beginUpdate();\r
- for(var i = 0, len = o.length; i < len; i++){\r
- var n = this.createNode(o[i]);\r
- if(n){\r
- node.appendChild(n);\r
- }\r
- }\r
- node.endUpdate();\r
- this.runCallback(callback, scope || node, [node]);\r
- }catch(e){\r
- this.handleFailure(response);\r
- }\r
- },\r
-\r
- handleResponse : function(response){\r
- this.transId = false;\r
- var a = response.argument;\r
- this.processResponse(response, a.node, a.callback, a.scope);\r
- this.fireEvent("load", this, a.node, response);\r
- },\r
-\r
- handleFailure : function(response){\r
- this.transId = false;\r
- var a = response.argument;\r
- this.fireEvent("loadexception", this, a.node, response);\r
- this.runCallback(a.callback, a.scope || a.node, [a.node]);\r
- }\r
+/**
+ * @class Ext.tree.TreePanel
+ * @extends Ext.Panel
+ * <p>The TreePanel provides tree-structured UI representation of tree-structured data.</p>
+ * <p>{@link Ext.tree.TreeNode TreeNode}s added to the TreePanel may each contain metadata
+ * used by your application in their {@link Ext.tree.TreeNode#attributes attributes} property.</p>
+ * <p><b>A TreePanel must have a {@link #root} node before it is rendered.</b> This may either be
+ * specified using the {@link #root} config option, or using the {@link #setRootNode} method.
+ * <p>An example of tree rendered to an existing div:</p><pre><code>
+var tree = new Ext.tree.TreePanel({
+ renderTo: 'tree-div',
+ useArrows: true,
+ autoScroll: true,
+ animate: true,
+ enableDD: true,
+ containerScroll: true,
+ border: false,
+ // auto create TreeLoader
+ dataUrl: 'get-nodes.php',
+
+ root: {
+ nodeType: 'async',
+ text: 'Ext JS',
+ draggable: false,
+ id: 'source'
+ }
+});
+
+tree.getRootNode().expand();
+ * </code></pre>
+ * <p>The example above would work with a data packet similar to this:</p><pre><code>
+[{
+ "text": "adapter",
+ "id": "source\/adapter",
+ "cls": "folder"
+}, {
+ "text": "dd",
+ "id": "source\/dd",
+ "cls": "folder"
+}, {
+ "text": "debug.js",
+ "id": "source\/debug.js",
+ "leaf": true,
+ "cls": "file"
+}]
+ * </code></pre>
+ * <p>An example of tree within a Viewport:</p><pre><code>
+new Ext.Viewport({
+ layout: 'border',
+ items: [{
+ region: 'west',
+ collapsible: true,
+ title: 'Navigation',
+ xtype: 'treepanel',
+ width: 200,
+ autoScroll: true,
+ split: true,
+ loader: new Ext.tree.TreeLoader(),
+ root: new Ext.tree.AsyncTreeNode({
+ expanded: true,
+ children: [{
+ text: 'Menu Option 1',
+ leaf: true
+ }, {
+ text: 'Menu Option 2',
+ leaf: true
+ }, {
+ text: 'Menu Option 3',
+ leaf: true
+ }]
+ }),
+ rootVisible: false,
+ listeners: {
+ click: function(n) {
+ Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
+ }
+ }
+ }, {
+ region: 'center',
+ xtype: 'tabpanel',
+ // remaining code not shown ...
+ }]
+});
+</code></pre>
+ *
+ * @cfg {Ext.tree.TreeNode} root The root node for the tree.
+ * @cfg {Boolean} rootVisible <tt>false</tt> to hide the root node (defaults to <tt>true</tt>)
+ * @cfg {Boolean} lines <tt>false</tt> to disable tree lines (defaults to <tt>true</tt>)
+ * @cfg {Boolean} enableDD <tt>true</tt> to enable drag and drop
+ * @cfg {Boolean} enableDrag <tt>true</tt> to enable just drag
+ * @cfg {Boolean} enableDrop <tt>true</tt> to enable just drop
+ * @cfg {Object} dragConfig Custom config to pass to the {@link Ext.tree.TreeDragZone} instance
+ * @cfg {Object} dropConfig Custom config to pass to the {@link Ext.tree.TreeDropZone} instance
+ * @cfg {String} ddGroup The DD group this TreePanel belongs to
+ * @cfg {Boolean} ddAppendOnly <tt>true</tt> if the tree should only allow append drops (use for trees which are sorted)
+ * @cfg {Boolean} ddScroll <tt>true</tt> to enable body scrolling
+ * @cfg {Boolean} containerScroll <tt>true</tt> to register this container with ScrollManager
+ * @cfg {Boolean} hlDrop <tt>false</tt> to disable node highlight on drop (defaults to the value of {@link Ext#enableFx})
+ * @cfg {String} hlColor The color of the node highlight (defaults to <tt>'C3DAF9'</tt>)
+ * @cfg {Boolean} animate <tt>true</tt> to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx})
+ * @cfg {Boolean} singleExpand <tt>true</tt> if only 1 node per branch may be expanded
+ * @cfg {Object} selModel A tree selection model to use with this TreePanel (defaults to an {@link Ext.tree.DefaultSelectionModel})
+ * @cfg {Boolean} trackMouseOver <tt>false</tt> to disable mouse over highlighting
+ * @cfg {Ext.tree.TreeLoader} loader A {@link Ext.tree.TreeLoader} for use with this TreePanel
+ * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to <tt>'/'</tt>)
+ * @cfg {Boolean} useArrows <tt>true</tt> to use Vista-style arrows in the tree (defaults to <tt>false</tt>)
+ * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
+ *
+ * @constructor
+ * @param {Object} config
+ * @xtype treepanel
+ */
+Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
+ rootVisible : true,
+ animate : Ext.enableFx,
+ lines : true,
+ enableDD : false,
+ hlDrop : Ext.enableFx,
+ pathSeparator : '/',
+
+ /**
+ * @cfg {Array} bubbleEvents
+ * <p>An array of events that, when fired, should be bubbled to any parent container.
+ * See {@link Ext.util.Observable#enableBubble}.
+ * Defaults to <tt>[]</tt>.
+ */
+ bubbleEvents : [],
+
+ initComponent : function(){
+ Ext.tree.TreePanel.superclass.initComponent.call(this);
+
+ if(!this.eventModel){
+ this.eventModel = new Ext.tree.TreeEventModel(this);
+ }
+
+ // initialize the loader
+ var l = this.loader;
+ if(!l){
+ l = new Ext.tree.TreeLoader({
+ dataUrl: this.dataUrl,
+ requestMethod: this.requestMethod
+ });
+ }else if(Ext.isObject(l) && !l.load){
+ l = new Ext.tree.TreeLoader(l);
+ }
+ this.loader = l;
+
+ this.nodeHash = {};
+
+ /**
+ * The root node of this tree.
+ * @type Ext.tree.TreeNode
+ * @property root
+ */
+ if(this.root){
+ var r = this.root;
+ delete this.root;
+ this.setRootNode(r);
+ }
+
+
+ this.addEvents(
+
+ /**
+ * @event append
+ * Fires when a new child node is appended to a node in this tree.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The newly appended node
+ * @param {Number} index The index of the newly appended node
+ */
+ 'append',
+ /**
+ * @event remove
+ * Fires when a child node is removed from a node in this tree.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node removed
+ */
+ 'remove',
+ /**
+ * @event movenode
+ * Fires when a node is moved to a new location in the tree
+ * @param {Tree} tree The owner tree
+ * @param {Node} node The node moved
+ * @param {Node} oldParent The old parent of this node
+ * @param {Node} newParent The new parent of this node
+ * @param {Number} index The index it was moved to
+ */
+ 'movenode',
+ /**
+ * @event insert
+ * Fires when a new child node is inserted in a node in this tree.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node inserted
+ * @param {Node} refNode The child node the node was inserted before
+ */
+ 'insert',
+ /**
+ * @event beforeappend
+ * Fires before a new child is appended to a node in this tree, return false to cancel the append.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node to be appended
+ */
+ 'beforeappend',
+ /**
+ * @event beforeremove
+ * Fires before a child is removed from a node in this tree, return false to cancel the remove.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node to be removed
+ */
+ 'beforeremove',
+ /**
+ * @event beforemovenode
+ * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
+ * @param {Tree} tree The owner tree
+ * @param {Node} node The node being moved
+ * @param {Node} oldParent The parent of the node
+ * @param {Node} newParent The new parent the node is moving to
+ * @param {Number} index The index it is being moved to
+ */
+ 'beforemovenode',
+ /**
+ * @event beforeinsert
+ * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node to be inserted
+ * @param {Node} refNode The child node the node is being inserted before
+ */
+ 'beforeinsert',
+
+ /**
+ * @event beforeload
+ * Fires before a node is loaded, return false to cancel
+ * @param {Node} node The node being loaded
+ */
+ 'beforeload',
+ /**
+ * @event load
+ * Fires when a node is loaded
+ * @param {Node} node The node that was loaded
+ */
+ 'load',
+ /**
+ * @event textchange
+ * Fires when the text for a node is changed
+ * @param {Node} node The node
+ * @param {String} text The new text
+ * @param {String} oldText The old text
+ */
+ 'textchange',
+ /**
+ * @event beforeexpandnode
+ * Fires before a node is expanded, return false to cancel.
+ * @param {Node} node The node
+ * @param {Boolean} deep
+ * @param {Boolean} anim
+ */
+ 'beforeexpandnode',
+ /**
+ * @event beforecollapsenode
+ * Fires before a node is collapsed, return false to cancel.
+ * @param {Node} node The node
+ * @param {Boolean} deep
+ * @param {Boolean} anim
+ */
+ 'beforecollapsenode',
+ /**
+ * @event expandnode
+ * Fires when a node is expanded
+ * @param {Node} node The node
+ */
+ 'expandnode',
+ /**
+ * @event disabledchange
+ * Fires when the disabled status of a node changes
+ * @param {Node} node The node
+ * @param {Boolean} disabled
+ */
+ 'disabledchange',
+ /**
+ * @event collapsenode
+ * Fires when a node is collapsed
+ * @param {Node} node The node
+ */
+ 'collapsenode',
+ /**
+ * @event beforeclick
+ * Fires before click processing on a node. Return false to cancel the default action.
+ * @param {Node} node The node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'beforeclick',
+ /**
+ * @event click
+ * Fires when a node is clicked
+ * @param {Node} node The node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'click',
+ /**
+ * @event containerclick
+ * Fires when the tree container is clicked
+ * @param {Tree} this
+ * @param {Ext.EventObject} e The event object
+ */
+ 'containerclick',
+ /**
+ * @event checkchange
+ * Fires when a node with a checkbox's checked property changes
+ * @param {Node} this This node
+ * @param {Boolean} checked
+ */
+ 'checkchange',
+ /**
+ * @event beforedblclick
+ * Fires before double click processing on a node. Return false to cancel the default action.
+ * @param {Node} node The node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'beforedblclick',
+ /**
+ * @event dblclick
+ * Fires when a node is double clicked
+ * @param {Node} node The node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'dblclick',
+ /**
+ * @event containerdblclick
+ * Fires when the tree container is double clicked
+ * @param {Tree} this
+ * @param {Ext.EventObject} e The event object
+ */
+ 'containerdblclick',
+ /**
+ * @event contextmenu
+ * Fires when a node is right clicked. To display a context menu in response to this
+ * event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add
+ * a handler for this event:<pre><code>
+new Ext.tree.TreePanel({
+ title: 'My TreePanel',
+ root: new Ext.tree.AsyncTreeNode({
+ text: 'The Root',
+ children: [
+ { text: 'Child node 1', leaf: true },
+ { text: 'Child node 2', leaf: true }
+ ]
+ }),
+ contextMenu: new Ext.menu.Menu({
+ items: [{
+ id: 'delete-node',
+ text: 'Delete Node'
+ }],
+ listeners: {
+ itemclick: function(item) {
+ switch (item.id) {
+ case 'delete-node':
+ var n = item.parentMenu.contextNode;
+ if (n.parentNode) {
+ n.remove();
+ }
+ break;
+ }
+ }
+ }
+ }),
+ listeners: {
+ contextmenu: function(node, e) {
+// Register the context node with the menu so that a Menu Item's handler function can access
+// it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.
+ node.select();
+ var c = node.getOwnerTree().contextMenu;
+ c.contextNode = node;
+ c.showAt(e.getXY());
+ }
+ }
+});
+</code></pre>
+ * @param {Node} node The node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'contextmenu',
+ /**
+ * @event containercontextmenu
+ * Fires when the tree container is right clicked
+ * @param {Tree} this
+ * @param {Ext.EventObject} e The event object
+ */
+ 'containercontextmenu',
+ /**
+ * @event beforechildrenrendered
+ * Fires right before the child nodes for a node are rendered
+ * @param {Node} node The node
+ */
+ 'beforechildrenrendered',
+ /**
+ * @event startdrag
+ * Fires when a node starts being dragged
+ * @param {Ext.tree.TreePanel} this
+ * @param {Ext.tree.TreeNode} node
+ * @param {event} e The raw browser event
+ */
+ 'startdrag',
+ /**
+ * @event enddrag
+ * Fires when a drag operation is complete
+ * @param {Ext.tree.TreePanel} this
+ * @param {Ext.tree.TreeNode} node
+ * @param {event} e The raw browser event
+ */
+ 'enddrag',
+ /**
+ * @event dragdrop
+ * Fires when a dragged node is dropped on a valid DD target
+ * @param {Ext.tree.TreePanel} this
+ * @param {Ext.tree.TreeNode} node
+ * @param {DD} dd The dd it was dropped on
+ * @param {event} e The raw browser event
+ */
+ 'dragdrop',
+ /**
+ * @event beforenodedrop
+ * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
+ * passed to handlers has the following properties:<br />
+ * <ul style="padding:5px;padding-left:16px;">
+ * <li>tree - The TreePanel</li>
+ * <li>target - The node being targeted for the drop</li>
+ * <li>data - The drag data from the drag source</li>
+ * <li>point - The point of the drop - append, above or below</li>
+ * <li>source - The drag source</li>
+ * <li>rawEvent - Raw mouse event</li>
+ * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
+ * to be inserted by setting them on this object.</li>
+ * <li>cancel - Set this to true to cancel the drop.</li>
+ * <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true
+ * will prevent the animated 'repair' from appearing.</li>
+ * </ul>
+ * @param {Object} dropEvent
+ */
+ 'beforenodedrop',
+ /**
+ * @event nodedrop
+ * Fires after a DD object is dropped on a node in this tree. The dropEvent
+ * passed to handlers has the following properties:<br />
+ * <ul style="padding:5px;padding-left:16px;">
+ * <li>tree - The TreePanel</li>
+ * <li>target - The node being targeted for the drop</li>
+ * <li>data - The drag data from the drag source</li>
+ * <li>point - The point of the drop - append, above or below</li>
+ * <li>source - The drag source</li>
+ * <li>rawEvent - Raw mouse event</li>
+ * <li>dropNode - Dropped node(s).</li>
+ * </ul>
+ * @param {Object} dropEvent
+ */
+ 'nodedrop',
+ /**
+ * @event nodedragover
+ * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
+ * passed to handlers has the following properties:<br />
+ * <ul style="padding:5px;padding-left:16px;">
+ * <li>tree - The TreePanel</li>
+ * <li>target - The node being targeted for the drop</li>
+ * <li>data - The drag data from the drag source</li>
+ * <li>point - The point of the drop - append, above or below</li>
+ * <li>source - The drag source</li>
+ * <li>rawEvent - Raw mouse event</li>
+ * <li>dropNode - Drop node(s) provided by the source.</li>
+ * <li>cancel - Set this to true to signal drop not allowed.</li>
+ * </ul>
+ * @param {Object} dragOverEvent
+ */
+ 'nodedragover'
+ );
+ if(this.singleExpand){
+ this.on('beforeexpandnode', this.restrictExpand, this);
+ }
+ },
+
+ // private
+ proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){
+ if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){
+ ename = ename+'node';
+ }
+ // args inline for performance while bubbling events
+ return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);
+ },
+
+
+ /**
+ * Returns this root node for this tree
+ * @return {Node}
+ */
+ getRootNode : function(){
+ return this.root;
+ },
+
+ /**
+ * Sets the root node for this tree. If the TreePanel has already rendered a root node, the
+ * previous root node (and all of its descendants) are destroyed before the new root node is rendered.
+ * @param {Node} node
+ * @return {Node}
+ */
+ setRootNode : function(node){
+ this.destroyRoot();
+ if(!node.render){ // attributes passed
+ node = this.loader.createNode(node);
+ }
+ this.root = node;
+ node.ownerTree = this;
+ node.isRoot = true;
+ this.registerNode(node);
+ if(!this.rootVisible){
+ var uiP = node.attributes.uiProvider;
+ node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);
+ }
+ if(this.innerCt){
+ this.clearInnerCt();
+ this.renderRoot();
+ }
+ return node;
+ },
+
+ clearInnerCt : function(){
+ this.innerCt.update('');
+ },
+
+ // private
+ renderRoot : function(){
+ this.root.render();
+ if(!this.rootVisible){
+ this.root.renderChildren();
+ }
+ },
+
+ /**
+ * Gets a node in this tree by its id
+ * @param {String} id
+ * @return {Node}
+ */
+ getNodeById : function(id){
+ return this.nodeHash[id];
+ },
+
+ // private
+ registerNode : function(node){
+ this.nodeHash[node.id] = node;
+ },
+
+ // private
+ unregisterNode : function(node){
+ delete this.nodeHash[node.id];
+ },
+
+ // private
+ toString : function(){
+ return '[Tree'+(this.id?' '+this.id:'')+']';
+ },
+
+ // private
+ restrictExpand : function(node){
+ var p = node.parentNode;
+ if(p){
+ if(p.expandedChild && p.expandedChild.parentNode == p){
+ p.expandedChild.collapse();
+ }
+ p.expandedChild = node;
+ }
+ },
+
+ /**
+ * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. 'id')
+ * @param {String} attribute (optional) Defaults to null (return the actual nodes)
+ * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
+ * @return {Array}
+ */
+ getChecked : function(a, startNode){
+ startNode = startNode || this.root;
+ var r = [];
+ var f = function(){
+ if(this.attributes.checked){
+ r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
+ }
+ };
+ startNode.cascade(f);
+ return r;
+ },
+
+ /**
+ * Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.
+ * @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.
+ */
+ getLoader : function(){
+ return this.loader;
+ },
+
+ /**
+ * Expand all nodes
+ */
+ expandAll : function(){
+ this.root.expand(true);
+ },
+
+ /**
+ * Collapse all nodes
+ */
+ collapseAll : function(){
+ this.root.collapse(true);
+ },
+
+ /**
+ * Returns the selection model used by this TreePanel.
+ * @return {TreeSelectionModel} The selection model used by this TreePanel
+ */
+ getSelectionModel : function(){
+ if(!this.selModel){
+ this.selModel = new Ext.tree.DefaultSelectionModel();
+ }
+ return this.selModel;
+ },
+
+ /**
+ * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
+ * @param {String} path
+ * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
+ * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
+ * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
+ */
+ expandPath : function(path, attr, callback){
+ if(Ext.isEmpty(path)){
+ if(callback){
+ callback(false, undefined);
+ }
+ return;
+ }
+ attr = attr || 'id';
+ var keys = path.split(this.pathSeparator);
+ var curNode = this.root;
+ if(curNode.attributes[attr] != keys[1]){ // invalid root
+ if(callback){
+ callback(false, null);
+ }
+ return;
+ }
+ var index = 1;
+ var f = function(){
+ if(++index == keys.length){
+ if(callback){
+ callback(true, curNode);
+ }
+ return;
+ }
+ var c = curNode.findChild(attr, keys[index]);
+ if(!c){
+ if(callback){
+ callback(false, curNode);
+ }
+ return;
+ }
+ curNode = c;
+ c.expand(false, false, f);
+ };
+ curNode.expand(false, false, f);
+ },
+
+ /**
+ * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
+ * @param {String} path
+ * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
+ * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
+ * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
+ */
+ selectPath : function(path, attr, callback){
+ if(Ext.isEmpty(path)){
+ if(callback){
+ callback(false, undefined);
+ }
+ return;
+ }
+ attr = attr || 'id';
+ var keys = path.split(this.pathSeparator),
+ v = keys.pop();
+ if(keys.length > 1){
+ var f = function(success, node){
+ if(success && node){
+ var n = node.findChild(attr, v);
+ if(n){
+ n.select();
+ if(callback){
+ callback(true, n);
+ }
+ }else if(callback){
+ callback(false, n);
+ }
+ }else{
+ if(callback){
+ callback(false, n);
+ }
+ }
+ };
+ this.expandPath(keys.join(this.pathSeparator), attr, f);
+ }else{
+ this.root.select();
+ if(callback){
+ callback(true, this.root);
+ }
+ }
+ },
+
+ /**
+ * Returns the underlying Element for this tree
+ * @return {Ext.Element} The Element
+ */
+ getTreeEl : function(){
+ return this.body;
+ },
+
+ // private
+ onRender : function(ct, position){
+ Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
+ this.el.addClass('x-tree');
+ this.innerCt = this.body.createChild({tag:'ul',
+ cls:'x-tree-root-ct ' +
+ (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')});
+ },
+
+ // private
+ initEvents : function(){
+ Ext.tree.TreePanel.superclass.initEvents.call(this);
+
+ if(this.containerScroll){
+ Ext.dd.ScrollManager.register(this.body);
+ }
+ if((this.enableDD || this.enableDrop) && !this.dropZone){
+ /**
+ * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
+ * @property dropZone
+ * @type Ext.tree.TreeDropZone
+ */
+ this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
+ ddGroup: this.ddGroup || 'TreeDD', appendOnly: this.ddAppendOnly === true
+ });
+ }
+ if((this.enableDD || this.enableDrag) && !this.dragZone){
+ /**
+ * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
+ * @property dragZone
+ * @type Ext.tree.TreeDragZone
+ */
+ this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
+ ddGroup: this.ddGroup || 'TreeDD',
+ scroll: this.ddScroll
+ });
+ }
+ this.getSelectionModel().init(this);
+ },
+
+ // private
+ afterRender : function(){
+ Ext.tree.TreePanel.superclass.afterRender.call(this);
+ this.renderRoot();
+ },
+
+ beforeDestroy : function(){
+ if(this.rendered){
+ Ext.dd.ScrollManager.unregister(this.body);
+ Ext.destroy(this.dropZone, this.dragZone);
+ }
+ this.destroyRoot();
+ Ext.destroy(this.loader);
+ this.nodeHash = this.root = this.loader = null;
+ Ext.tree.TreePanel.superclass.beforeDestroy.call(this);
+ },
+
+ /**
+ * Destroy the root node. Not included by itself because we need to pass the silent parameter.
+ * @private
+ */
+ destroyRoot : function(){
+ if(this.root && this.root.destroy){
+ this.root.destroy(true);
+ }
+ }
+
+ /**
+ * @cfg {String/Number} activeItem
+ * @hide
+ */
+ /**
+ * @cfg {Boolean} autoDestroy
+ * @hide
+ */
+ /**
+ * @cfg {Object/String/Function} autoLoad
+ * @hide
+ */
+ /**
+ * @cfg {Boolean} autoWidth
+ * @hide
+ */
+ /**
+ * @cfg {Boolean/Number} bufferResize
+ * @hide
+ */
+ /**
+ * @cfg {String} defaultType
+ * @hide
+ */
+ /**
+ * @cfg {Object} defaults
+ * @hide
+ */
+ /**
+ * @cfg {Boolean} hideBorders
+ * @hide
+ */
+ /**
+ * @cfg {Mixed} items
+ * @hide
+ */
+ /**
+ * @cfg {String} layout
+ * @hide
+ */
+ /**
+ * @cfg {Object} layoutConfig
+ * @hide
+ */
+ /**
+ * @cfg {Boolean} monitorResize
+ * @hide
+ */
+ /**
+ * @property items
+ * @hide
+ */
+ /**
+ * @method cascade
+ * @hide
+ */
+ /**
+ * @method doLayout
+ * @hide
+ */
+ /**
+ * @method find
+ * @hide
+ */
+ /**
+ * @method findBy
+ * @hide
+ */
+ /**
+ * @method findById
+ * @hide
+ */
+ /**
+ * @method findByType
+ * @hide
+ */
+ /**
+ * @method getComponent
+ * @hide
+ */
+ /**
+ * @method getLayout
+ * @hide
+ */
+ /**
+ * @method getUpdater
+ * @hide
+ */
+ /**
+ * @method insert
+ * @hide
+ */
+ /**
+ * @method load
+ * @hide
+ */
+ /**
+ * @method remove
+ * @hide
+ */
+ /**
+ * @event add
+ * @hide
+ */
+ /**
+ * @method removeAll
+ * @hide
+ */
+ /**
+ * @event afterLayout
+ * @hide
+ */
+ /**
+ * @event beforeadd
+ * @hide
+ */
+ /**
+ * @event beforeremove
+ * @hide
+ */
+ /**
+ * @event remove
+ * @hide
+ */
+
+
+
+ /**
+ * @cfg {String} allowDomMove @hide
+ */
+ /**
+ * @cfg {String} autoEl @hide
+ */
+ /**
+ * @cfg {String} applyTo @hide
+ */
+ /**
+ * @cfg {String} contentEl @hide
+ */
+ /**
+ * @cfg {Mixed} data @hide
+ */
+ /**
+ * @cfg {Mixed} tpl @hide
+ */
+ /**
+ * @cfg {String} tplWriteMode @hide
+ */
+ /**
+ * @cfg {String} disabledClass @hide
+ */
+ /**
+ * @cfg {String} elements @hide
+ */
+ /**
+ * @cfg {String} html @hide
+ */
+ /**
+ * @cfg {Boolean} preventBodyReset
+ * @hide
+ */
+ /**
+ * @property disabled
+ * @hide
+ */
+ /**
+ * @method applyToMarkup
+ * @hide
+ */
+ /**
+ * @method enable
+ * @hide
+ */
+ /**
+ * @method disable
+ * @hide
+ */
+ /**
+ * @method setDisabled
+ * @hide
+ */
+});
+
+Ext.tree.TreePanel.nodeTypes = {};
+
+Ext.reg('treepanel', Ext.tree.TreePanel);Ext.tree.TreeEventModel = function(tree){
+ this.tree = tree;
+ this.tree.on('render', this.initEvents, this);
+};
+
+Ext.tree.TreeEventModel.prototype = {
+ initEvents : function(){
+ var t = this.tree;
+
+ if(t.trackMouseOver !== false){
+ t.mon(t.innerCt, {
+ scope: this,
+ mouseover: this.delegateOver,
+ mouseout: this.delegateOut
+ });
+ }
+ t.mon(t.getTreeEl(), {
+ scope: this,
+ click: this.delegateClick,
+ dblclick: this.delegateDblClick,
+ contextmenu: this.delegateContextMenu
+ });
+ },
+
+ getNode : function(e){
+ var t;
+ if(t = e.getTarget('.x-tree-node-el', 10)){
+ var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
+ if(id){
+ return this.tree.getNodeById(id);
+ }
+ }
+ return null;
+ },
+
+ getNodeTarget : function(e){
+ var t = e.getTarget('.x-tree-node-icon', 1);
+ if(!t){
+ t = e.getTarget('.x-tree-node-el', 6);
+ }
+ return t;
+ },
+
+ delegateOut : function(e, t){
+ if(!this.beforeEvent(e)){
+ return;
+ }
+ if(e.getTarget('.x-tree-ec-icon', 1)){
+ var n = this.getNode(e);
+ this.onIconOut(e, n);
+ if(n == this.lastEcOver){
+ delete this.lastEcOver;
+ }
+ }
+ if((t = this.getNodeTarget(e)) && !e.within(t, true)){
+ this.onNodeOut(e, this.getNode(e));
+ }
+ },
+
+ delegateOver : function(e, t){
+ if(!this.beforeEvent(e)){
+ return;
+ }
+ if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
+ Ext.getBody().on('mouseover', this.trackExit, this);
+ this.trackingDoc = true;
+ }
+ if(this.lastEcOver){ // prevent hung highlight
+ this.onIconOut(e, this.lastEcOver);
+ delete this.lastEcOver;
+ }
+ if(e.getTarget('.x-tree-ec-icon', 1)){
+ this.lastEcOver = this.getNode(e);
+ this.onIconOver(e, this.lastEcOver);
+ }
+ if(t = this.getNodeTarget(e)){
+ this.onNodeOver(e, this.getNode(e));
+ }
+ },
+
+ trackExit : function(e){
+ if(this.lastOverNode){
+ if(this.lastOverNode.ui && !e.within(this.lastOverNode.ui.getEl())){
+ this.onNodeOut(e, this.lastOverNode);
+ }
+ delete this.lastOverNode;
+ Ext.getBody().un('mouseover', this.trackExit, this);
+ this.trackingDoc = false;
+ }
+
+ },
+
+ delegateClick : function(e, t){
+ if(this.beforeEvent(e)){
+ if(e.getTarget('input[type=checkbox]', 1)){
+ this.onCheckboxClick(e, this.getNode(e));
+ }else if(e.getTarget('.x-tree-ec-icon', 1)){
+ this.onIconClick(e, this.getNode(e));
+ }else if(this.getNodeTarget(e)){
+ this.onNodeClick(e, this.getNode(e));
+ }
+ }else{
+ this.checkContainerEvent(e, 'click');
+ }
+ },
+
+ delegateDblClick : function(e, t){
+ if(this.beforeEvent(e)){
+ if(this.getNodeTarget(e)){
+ this.onNodeDblClick(e, this.getNode(e));
+ }
+ }else{
+ this.checkContainerEvent(e, 'dblclick');
+ }
+ },
+
+ delegateContextMenu : function(e, t){
+ if(this.beforeEvent(e)){
+ if(this.getNodeTarget(e)){
+ this.onNodeContextMenu(e, this.getNode(e));
+ }
+ }else{
+ this.checkContainerEvent(e, 'contextmenu');
+ }
+ },
+
+ checkContainerEvent: function(e, type){
+ if(this.disabled){
+ e.stopEvent();
+ return false;
+ }
+ this.onContainerEvent(e, type);
+ },
+
+ onContainerEvent: function(e, type){
+ this.tree.fireEvent('container' + type, this.tree, e);
+ },
+
+ onNodeClick : function(e, node){
+ node.ui.onClick(e);
+ },
+
+ onNodeOver : function(e, node){
+ this.lastOverNode = node;
+ node.ui.onOver(e);
+ },
+
+ onNodeOut : function(e, node){
+ node.ui.onOut(e);
+ },
+
+ onIconOver : function(e, node){
+ node.ui.addClass('x-tree-ec-over');
+ },
+
+ onIconOut : function(e, node){
+ node.ui.removeClass('x-tree-ec-over');
+ },
+
+ onIconClick : function(e, node){
+ node.ui.ecClick(e);
+ },
+
+ onCheckboxClick : function(e, node){
+ node.ui.onCheckChange(e);
+ },
+
+ onNodeDblClick : function(e, node){
+ node.ui.onDblClick(e);
+ },
+
+ onNodeContextMenu : function(e, node){
+ node.ui.onContextMenu(e);
+ },
+
+ beforeEvent : function(e){
+ var node = this.getNode(e);
+ if(this.disabled || !node || !node.ui){
+ e.stopEvent();
+ return false;
+ }
+ return true;
+ },
+
+ disable: function(){
+ this.disabled = true;
+ },
+
+ enable: function(){
+ this.disabled = false;
+ }
+};/**
+ * @class Ext.tree.DefaultSelectionModel
+ * @extends Ext.util.Observable
+ * The default single selection for a TreePanel.
+ */
+Ext.tree.DefaultSelectionModel = Ext.extend(Ext.util.Observable, {
+
+ constructor : function(config){
+ this.selNode = null;
+
+ this.addEvents(
+ /**
+ * @event selectionchange
+ * Fires when the selected node changes
+ * @param {DefaultSelectionModel} this
+ * @param {TreeNode} node the new selection
+ */
+ 'selectionchange',
+
+ /**
+ * @event beforeselect
+ * Fires before the selected node changes, return false to cancel the change
+ * @param {DefaultSelectionModel} this
+ * @param {TreeNode} node the new selection
+ * @param {TreeNode} node the old selection
+ */
+ 'beforeselect'
+ );
+
+ Ext.apply(this, config);
+ Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
+ },
+
+ init : function(tree){
+ this.tree = tree;
+ tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
+ tree.on('click', this.onNodeClick, this);
+ },
+
+ onNodeClick : function(node, e){
+ this.select(node);
+ },
+
+ /**
+ * Select a node.
+ * @param {TreeNode} node The node to select
+ * @return {TreeNode} The selected node
+ */
+ select : function(node, /* private*/ selectNextNode){
+ // If node is hidden, select the next node in whatever direction was being moved in.
+ if (!Ext.fly(node.ui.wrap).isVisible() && selectNextNode) {
+ return selectNextNode.call(this, node);
+ }
+ var last = this.selNode;
+ if(node == last){
+ node.ui.onSelectedChange(true);
+ }else if(this.fireEvent('beforeselect', this, node, last) !== false){
+ if(last && last.ui){
+ last.ui.onSelectedChange(false);
+ }
+ this.selNode = node;
+ node.ui.onSelectedChange(true);
+ this.fireEvent('selectionchange', this, node, last);
+ }
+ return node;
+ },
+
+ /**
+ * Deselect a node.
+ * @param {TreeNode} node The node to unselect
+ * @param {Boolean} silent True to stop the selectionchange event from firing.
+ */
+ unselect : function(node, silent){
+ if(this.selNode == node){
+ this.clearSelections(silent);
+ }
+ },
+
+ /**
+ * Clear all selections
+ * @param {Boolean} silent True to stop the selectionchange event from firing.
+ */
+ clearSelections : function(silent){
+ var n = this.selNode;
+ if(n){
+ n.ui.onSelectedChange(false);
+ this.selNode = null;
+ if(silent !== true){
+ this.fireEvent('selectionchange', this, null);
+ }
+ }
+ return n;
+ },
+
+ /**
+ * Get the selected node
+ * @return {TreeNode} The selected node
+ */
+ getSelectedNode : function(){
+ return this.selNode;
+ },
+
+ /**
+ * Returns true if the node is selected
+ * @param {TreeNode} node The node to check
+ * @return {Boolean}
+ */
+ isSelected : function(node){
+ return this.selNode == node;
+ },
+
+ /**
+ * Selects the node above the selected node in the tree, intelligently walking the nodes
+ * @return TreeNode The new selection
+ */
+ selectPrevious : function(/* private */ s){
+ if(!(s = s || this.selNode || this.lastSelNode)){
+ return null;
+ }
+ // Here we pass in the current function to select to indicate the direction we're moving
+ var ps = s.previousSibling;
+ if(ps){
+ if(!ps.isExpanded() || ps.childNodes.length < 1){
+ return this.select(ps, this.selectPrevious);
+ } else{
+ var lc = ps.lastChild;
+ while(lc && lc.isExpanded() && Ext.fly(lc.ui.wrap).isVisible() && lc.childNodes.length > 0){
+ lc = lc.lastChild;
+ }
+ return this.select(lc, this.selectPrevious);
+ }
+ } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
+ return this.select(s.parentNode, this.selectPrevious);
+ }
+ return null;
+ },
+
+ /**
+ * Selects the node above the selected node in the tree, intelligently walking the nodes
+ * @return TreeNode The new selection
+ */
+ selectNext : function(/* private */ s){
+ if(!(s = s || this.selNode || this.lastSelNode)){
+ return null;
+ }
+ // Here we pass in the current function to select to indicate the direction we're moving
+ if(s.firstChild && s.isExpanded() && Ext.fly(s.ui.wrap).isVisible()){
+ return this.select(s.firstChild, this.selectNext);
+ }else if(s.nextSibling){
+ return this.select(s.nextSibling, this.selectNext);
+ }else if(s.parentNode){
+ var newS = null;
+ s.parentNode.bubble(function(){
+ if(this.nextSibling){
+ newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);
+ return false;
+ }
+ });
+ return newS;
+ }
+ return null;
+ },
+
+ onKeyDown : function(e){
+ var s = this.selNode || this.lastSelNode;
+ // undesirable, but required
+ var sm = this;
+ if(!s){
+ return;
+ }
+ var k = e.getKey();
+ switch(k){
+ case e.DOWN:
+ e.stopEvent();
+ this.selectNext();
+ break;
+ case e.UP:
+ e.stopEvent();
+ this.selectPrevious();
+ break;
+ case e.RIGHT:
+ e.preventDefault();
+ if(s.hasChildNodes()){
+ if(!s.isExpanded()){
+ s.expand();
+ }else if(s.firstChild){
+ this.select(s.firstChild, e);
+ }
+ }
+ break;
+ case e.LEFT:
+ e.preventDefault();
+ if(s.hasChildNodes() && s.isExpanded()){
+ s.collapse();
+ }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
+ this.select(s.parentNode, e);
+ }
+ break;
+ };
+ }
+});
+
+/**
+ * @class Ext.tree.MultiSelectionModel
+ * @extends Ext.util.Observable
+ * Multi selection for a TreePanel.
+ */
+Ext.tree.MultiSelectionModel = Ext.extend(Ext.util.Observable, {
+
+ constructor : function(config){
+ this.selNodes = [];
+ this.selMap = {};
+ this.addEvents(
+ /**
+ * @event selectionchange
+ * Fires when the selected nodes change
+ * @param {MultiSelectionModel} this
+ * @param {Array} nodes Array of the selected nodes
+ */
+ 'selectionchange'
+ );
+ Ext.apply(this, config);
+ Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
+ },
+
+ init : function(tree){
+ this.tree = tree;
+ tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
+ tree.on('click', this.onNodeClick, this);
+ },
+
+ onNodeClick : function(node, e){
+ if(e.ctrlKey && this.isSelected(node)){
+ this.unselect(node);
+ }else{
+ this.select(node, e, e.ctrlKey);
+ }
+ },
+
+ /**
+ * Select a node.
+ * @param {TreeNode} node The node to select
+ * @param {EventObject} e (optional) An event associated with the selection
+ * @param {Boolean} keepExisting True to retain existing selections
+ * @return {TreeNode} The selected node
+ */
+ select : function(node, e, keepExisting){
+ if(keepExisting !== true){
+ this.clearSelections(true);
+ }
+ if(this.isSelected(node)){
+ this.lastSelNode = node;
+ return node;
+ }
+ this.selNodes.push(node);
+ this.selMap[node.id] = node;
+ this.lastSelNode = node;
+ node.ui.onSelectedChange(true);
+ this.fireEvent('selectionchange', this, this.selNodes);
+ return node;
+ },
+
+ /**
+ * Deselect a node.
+ * @param {TreeNode} node The node to unselect
+ */
+ unselect : function(node){
+ if(this.selMap[node.id]){
+ node.ui.onSelectedChange(false);
+ var sn = this.selNodes;
+ var index = sn.indexOf(node);
+ if(index != -1){
+ this.selNodes.splice(index, 1);
+ }
+ delete this.selMap[node.id];
+ this.fireEvent('selectionchange', this, this.selNodes);
+ }
+ },
+
+ /**
+ * Clear all selections
+ */
+ clearSelections : function(suppressEvent){
+ var sn = this.selNodes;
+ if(sn.length > 0){
+ for(var i = 0, len = sn.length; i < len; i++){
+ sn[i].ui.onSelectedChange(false);
+ }
+ this.selNodes = [];
+ this.selMap = {};
+ if(suppressEvent !== true){
+ this.fireEvent('selectionchange', this, this.selNodes);
+ }
+ }
+ },
+
+ /**
+ * Returns true if the node is selected
+ * @param {TreeNode} node The node to check
+ * @return {Boolean}
+ */
+ isSelected : function(node){
+ return this.selMap[node.id] ? true : false;
+ },
+
+ /**
+ * Returns an array of the selected nodes
+ * @return {Array}
+ */
+ getSelectedNodes : function(){
+ return this.selNodes.concat([]);
+ },
+
+ onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
+
+ selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
+
+ selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
+});/**
+ * @class Ext.data.Tree
+ * @extends Ext.util.Observable
+ * Represents a tree data structure and bubbles all the events for its nodes. The nodes
+ * in the tree have most standard DOM functionality.
+ * @constructor
+ * @param {Node} root (optional) The root node
+ */
+Ext.data.Tree = Ext.extend(Ext.util.Observable, {
+
+ constructor: function(root){
+ this.nodeHash = {};
+ /**
+ * The root node for this tree
+ * @type Node
+ */
+ this.root = null;
+ if(root){
+ this.setRootNode(root);
+ }
+ this.addEvents(
+ /**
+ * @event append
+ * Fires when a new child node is appended to a node in this tree.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The newly appended node
+ * @param {Number} index The index of the newly appended node
+ */
+ "append",
+ /**
+ * @event remove
+ * Fires when a child node is removed from a node in this tree.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node removed
+ */
+ "remove",
+ /**
+ * @event move
+ * Fires when a node is moved to a new location in the tree
+ * @param {Tree} tree The owner tree
+ * @param {Node} node The node moved
+ * @param {Node} oldParent The old parent of this node
+ * @param {Node} newParent The new parent of this node
+ * @param {Number} index The index it was moved to
+ */
+ "move",
+ /**
+ * @event insert
+ * Fires when a new child node is inserted in a node in this tree.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node inserted
+ * @param {Node} refNode The child node the node was inserted before
+ */
+ "insert",
+ /**
+ * @event beforeappend
+ * Fires before a new child is appended to a node in this tree, return false to cancel the append.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node to be appended
+ */
+ "beforeappend",
+ /**
+ * @event beforeremove
+ * Fires before a child is removed from a node in this tree, return false to cancel the remove.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node to be removed
+ */
+ "beforeremove",
+ /**
+ * @event beforemove
+ * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
+ * @param {Tree} tree The owner tree
+ * @param {Node} node The node being moved
+ * @param {Node} oldParent The parent of the node
+ * @param {Node} newParent The new parent the node is moving to
+ * @param {Number} index The index it is being moved to
+ */
+ "beforemove",
+ /**
+ * @event beforeinsert
+ * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
+ * @param {Tree} tree The owner tree
+ * @param {Node} parent The parent node
+ * @param {Node} node The child node to be inserted
+ * @param {Node} refNode The child node the node is being inserted before
+ */
+ "beforeinsert"
+ );
+ Ext.data.Tree.superclass.constructor.call(this);
+ },
+
+ /**
+ * @cfg {String} pathSeparator
+ * The token used to separate paths in node ids (defaults to '/').
+ */
+ pathSeparator: "/",
+
+ // private
+ proxyNodeEvent : function(){
+ return this.fireEvent.apply(this, arguments);
+ },
+
+ /**
+ * Returns the root node for this tree.
+ * @return {Node}
+ */
+ getRootNode : function(){
+ return this.root;
+ },
+
+ /**
+ * Sets the root node for this tree.
+ * @param {Node} node
+ * @return {Node}
+ */
+ setRootNode : function(node){
+ this.root = node;
+ node.ownerTree = this;
+ node.isRoot = true;
+ this.registerNode(node);
+ return node;
+ },
+
+ /**
+ * Gets a node in this tree by its id.
+ * @param {String} id
+ * @return {Node}
+ */
+ getNodeById : function(id){
+ return this.nodeHash[id];
+ },
+
+ // private
+ registerNode : function(node){
+ this.nodeHash[node.id] = node;
+ },
+
+ // private
+ unregisterNode : function(node){
+ delete this.nodeHash[node.id];
+ },
+
+ toString : function(){
+ return "[Tree"+(this.id?" "+this.id:"")+"]";
+ }
+});
+
+/**
+ * @class Ext.data.Node
+ * @extends Ext.util.Observable
+ * @cfg {Boolean} leaf true if this node is a leaf and does not have children
+ * @cfg {String} id The id for this node. If one is not specified, one is generated.
+ * @constructor
+ * @param {Object} attributes The attributes/config for the node
+ */
+Ext.data.Node = Ext.extend(Ext.util.Observable, {
+
+ constructor: function(attributes){
+ /**
+ * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
+ * @type {Object}
+ */
+ this.attributes = attributes || {};
+ this.leaf = this.attributes.leaf;
+ /**
+ * The node id. @type String
+ */
+ this.id = this.attributes.id;
+ if(!this.id){
+ this.id = Ext.id(null, "xnode-");
+ this.attributes.id = this.id;
+ }
+ /**
+ * All child nodes of this node. @type Array
+ */
+ this.childNodes = [];
+ /**
+ * The parent node for this node. @type Node
+ */
+ this.parentNode = null;
+ /**
+ * The first direct child node of this node, or null if this node has no child nodes. @type Node
+ */
+ this.firstChild = null;
+ /**
+ * The last direct child node of this node, or null if this node has no child nodes. @type Node
+ */
+ this.lastChild = null;
+ /**
+ * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
+ */
+ this.previousSibling = null;
+ /**
+ * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
+ */
+ this.nextSibling = null;
+
+ this.addEvents({
+ /**
+ * @event append
+ * Fires when a new child node is appended
+ * @param {Tree} tree The owner tree
+ * @param {Node} this This node
+ * @param {Node} node The newly appended node
+ * @param {Number} index The index of the newly appended node
+ */
+ "append" : true,
+ /**
+ * @event remove
+ * Fires when a child node is removed
+ * @param {Tree} tree The owner tree
+ * @param {Node} this This node
+ * @param {Node} node The removed node
+ */
+ "remove" : true,
+ /**
+ * @event move
+ * Fires when this node is moved to a new location in the tree
+ * @param {Tree} tree The owner tree
+ * @param {Node} this This node
+ * @param {Node} oldParent The old parent of this node
+ * @param {Node} newParent The new parent of this node
+ * @param {Number} index The index it was moved to
+ */
+ "move" : true,
+ /**
+ * @event insert
+ * Fires when a new child node is inserted.
+ * @param {Tree} tree The owner tree
+ * @param {Node} this This node
+ * @param {Node} node The child node inserted
+ * @param {Node} refNode The child node the node was inserted before
+ */
+ "insert" : true,
+ /**
+ * @event beforeappend
+ * Fires before a new child is appended, return false to cancel the append.
+ * @param {Tree} tree The owner tree
+ * @param {Node} this This node
+ * @param {Node} node The child node to be appended
+ */
+ "beforeappend" : true,
+ /**
+ * @event beforeremove
+ * Fires before a child is removed, return false to cancel the remove.
+ * @param {Tree} tree The owner tree
+ * @param {Node} this This node
+ * @param {Node} node The child node to be removed
+ */
+ "beforeremove" : true,
+ /**
+ * @event beforemove
+ * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
+ * @param {Tree} tree The owner tree
+ * @param {Node} this This node
+ * @param {Node} oldParent The parent of this node
+ * @param {Node} newParent The new parent this node is moving to
+ * @param {Number} index The index it is being moved to
+ */
+ "beforemove" : true,
+ /**
+ * @event beforeinsert
+ * Fires before a new child is inserted, return false to cancel the insert.
+ * @param {Tree} tree The owner tree
+ * @param {Node} this This node
+ * @param {Node} node The child node to be inserted
+ * @param {Node} refNode The child node the node is being inserted before
+ */
+ "beforeinsert" : true
+ });
+ this.listeners = this.attributes.listeners;
+ Ext.data.Node.superclass.constructor.call(this);
+ },
+
+ // private
+ fireEvent : function(evtName){
+ // first do standard event for this node
+ if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){
+ return false;
+ }
+ // then bubble it up to the tree if the event wasn't cancelled
+ var ot = this.getOwnerTree();
+ if(ot){
+ if(ot.proxyNodeEvent.apply(ot, arguments) === false){
+ return false;
+ }
+ }
+ return true;
+ },
+
+ /**
+ * Returns true if this node is a leaf
+ * @return {Boolean}
+ */
+ isLeaf : function(){
+ return this.leaf === true;
+ },
+
+ // private
+ setFirstChild : function(node){
+ this.firstChild = node;
+ },
+
+ //private
+ setLastChild : function(node){
+ this.lastChild = node;
+ },
+
+
+ /**
+ * Returns true if this node is the last child of its parent
+ * @return {Boolean}
+ */
+ isLast : function(){
+ return (!this.parentNode ? true : this.parentNode.lastChild == this);
+ },
+
+ /**
+ * Returns true if this node is the first child of its parent
+ * @return {Boolean}
+ */
+ isFirst : function(){
+ return (!this.parentNode ? true : this.parentNode.firstChild == this);
+ },
+
+ /**
+ * Returns true if this node has one or more child nodes, else false.
+ * @return {Boolean}
+ */
+ hasChildNodes : function(){
+ return !this.isLeaf() && this.childNodes.length > 0;
+ },
+
+ /**
+ * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>
+ * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
+ * @return {Boolean}
+ */
+ isExpandable : function(){
+ return this.attributes.expandable || this.hasChildNodes();
+ },
+
+ /**
+ * Insert node(s) as the last child node of this node.
+ * @param {Node/Array} node The node or Array of nodes to append
+ * @return {Node} The appended node if single append, or null if an array was passed
+ */
+ appendChild : function(node){
+ var multi = false;
+ if(Ext.isArray(node)){
+ multi = node;
+ }else if(arguments.length > 1){
+ multi = arguments;
+ }
+ // if passed an array or multiple args do them one by one
+ if(multi){
+ for(var i = 0, len = multi.length; i < len; i++) {
+ this.appendChild(multi[i]);
+ }
+ }else{
+ if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
+ return false;
+ }
+ var index = this.childNodes.length;
+ var oldParent = node.parentNode;
+ // it's a move, make sure we move it cleanly
+ if(oldParent){
+ if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
+ return false;
+ }
+ oldParent.removeChild(node);
+ }
+ index = this.childNodes.length;
+ if(index === 0){
+ this.setFirstChild(node);
+ }
+ this.childNodes.push(node);
+ node.parentNode = this;
+ var ps = this.childNodes[index-1];
+ if(ps){
+ node.previousSibling = ps;
+ ps.nextSibling = node;
+ }else{
+ node.previousSibling = null;
+ }
+ node.nextSibling = null;
+ this.setLastChild(node);
+ node.setOwnerTree(this.getOwnerTree());
+ this.fireEvent("append", this.ownerTree, this, node, index);
+ if(oldParent){
+ node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
+ }
+ return node;
+ }
+ },
+
+ /**
+ * Removes a child node from this node.
+ * @param {Node} node The node to remove
+ * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
+ * @return {Node} The removed node
+ */
+ removeChild : function(node, destroy){
+ var index = this.childNodes.indexOf(node);
+ if(index == -1){
+ return false;
+ }
+ if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
+ return false;
+ }
+
+ // remove it from childNodes collection
+ this.childNodes.splice(index, 1);
+
+ // update siblings
+ if(node.previousSibling){
+ node.previousSibling.nextSibling = node.nextSibling;
+ }
+ if(node.nextSibling){
+ node.nextSibling.previousSibling = node.previousSibling;
+ }
+
+ // update child refs
+ if(this.firstChild == node){
+ this.setFirstChild(node.nextSibling);
+ }
+ if(this.lastChild == node){
+ this.setLastChild(node.previousSibling);
+ }
+
+ this.fireEvent("remove", this.ownerTree, this, node);
+ if(destroy){
+ node.destroy(true);
+ }else{
+ node.clear();
+ }
+ return node;
+ },
+
+ // private
+ clear : function(destroy){
+ // clear any references from the node
+ this.setOwnerTree(null, destroy);
+ this.parentNode = this.previousSibling = this.nextSibling = null;
+ if(destroy){
+ this.firstChild = this.lastChild = null;
+ }
+ },
+
+ /**
+ * Destroys the node.
+ */
+ destroy : function(/* private */ silent){
+ /*
+ * Silent is to be used in a number of cases
+ * 1) When setRootNode is called.
+ * 2) When destroy on the tree is called
+ * 3) For destroying child nodes on a node
+ */
+ if(silent === true){
+ this.purgeListeners();
+ this.clear(true);
+ Ext.each(this.childNodes, function(n){
+ n.destroy(true);
+ });
+ this.childNodes = null;
+ }else{
+ this.remove(true);
+ }
+ },
+
+ /**
+ * Inserts the first node before the second node in this nodes childNodes collection.
+ * @param {Node} node The node to insert
+ * @param {Node} refNode The node to insert before (if null the node is appended)
+ * @return {Node} The inserted node
+ */
+ insertBefore : function(node, refNode){
+ if(!refNode){ // like standard Dom, refNode can be null for append
+ return this.appendChild(node);
+ }
+ // nothing to do
+ if(node == refNode){
+ return false;
+ }
+
+ if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
+ return false;
+ }
+ var index = this.childNodes.indexOf(refNode);
+ var oldParent = node.parentNode;
+ var refIndex = index;
+
+ // when moving internally, indexes will change after remove
+ if(oldParent == this && this.childNodes.indexOf(node) < index){
+ refIndex--;
+ }
+
+ // it's a move, make sure we move it cleanly
+ if(oldParent){
+ if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
+ return false;
+ }
+ oldParent.removeChild(node);
+ }
+ if(refIndex === 0){
+ this.setFirstChild(node);
+ }
+ this.childNodes.splice(refIndex, 0, node);
+ node.parentNode = this;
+ var ps = this.childNodes[refIndex-1];
+ if(ps){
+ node.previousSibling = ps;
+ ps.nextSibling = node;
+ }else{
+ node.previousSibling = null;
+ }
+ node.nextSibling = refNode;
+ refNode.previousSibling = node;
+ node.setOwnerTree(this.getOwnerTree());
+ this.fireEvent("insert", this.ownerTree, this, node, refNode);
+ if(oldParent){
+ node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
+ }
+ return node;
+ },
+
+ /**
+ * Removes this node from its parent
+ * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
+ * @return {Node} this
+ */
+ remove : function(destroy){
+ if (this.parentNode) {
+ this.parentNode.removeChild(this, destroy);
+ }
+ return this;
+ },
+
+ /**
+ * Removes all child nodes from this node.
+ * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
+ * @return {Node} this
+ */
+ removeAll : function(destroy){
+ var cn = this.childNodes,
+ n;
+ while((n = cn[0])){
+ this.removeChild(n, destroy);
+ }
+ return this;
+ },
+
+ /**
+ * Returns the child node at the specified index.
+ * @param {Number} index
+ * @return {Node}
+ */
+ item : function(index){
+ return this.childNodes[index];
+ },
+
+ /**
+ * Replaces one child node in this node with another.
+ * @param {Node} newChild The replacement node
+ * @param {Node} oldChild The node to replace
+ * @return {Node} The replaced node
+ */
+ replaceChild : function(newChild, oldChild){
+ var s = oldChild ? oldChild.nextSibling : null;
+ this.removeChild(oldChild);
+ this.insertBefore(newChild, s);
+ return oldChild;
+ },
+
+ /**
+ * Returns the index of a child node
+ * @param {Node} node
+ * @return {Number} The index of the node or -1 if it was not found
+ */
+ indexOf : function(child){
+ return this.childNodes.indexOf(child);
+ },
+
+ /**
+ * Returns the tree this node is in.
+ * @return {Tree}
+ */
+ getOwnerTree : function(){
+ // if it doesn't have one, look for one
+ if(!this.ownerTree){
+ var p = this;
+ while(p){
+ if(p.ownerTree){
+ this.ownerTree = p.ownerTree;
+ break;
+ }
+ p = p.parentNode;
+ }
+ }
+ return this.ownerTree;
+ },
+
+ /**
+ * Returns depth of this node (the root node has a depth of 0)
+ * @return {Number}
+ */
+ getDepth : function(){
+ var depth = 0;
+ var p = this;
+ while(p.parentNode){
+ ++depth;
+ p = p.parentNode;
+ }
+ return depth;
+ },
+
+ // private
+ setOwnerTree : function(tree, destroy){
+ // if it is a move, we need to update everyone
+ if(tree != this.ownerTree){
+ if(this.ownerTree){
+ this.ownerTree.unregisterNode(this);
+ }
+ this.ownerTree = tree;
+ // If we're destroying, we don't need to recurse since it will be called on each child node
+ if(destroy !== true){
+ Ext.each(this.childNodes, function(n){
+ n.setOwnerTree(tree);
+ });
+ }
+ if(tree){
+ tree.registerNode(this);
+ }
+ }
+ },
+
+ /**
+ * Changes the id of this node.
+ * @param {String} id The new id for the node.
+ */
+ setId: function(id){
+ if(id !== this.id){
+ var t = this.ownerTree;
+ if(t){
+ t.unregisterNode(this);
+ }
+ this.id = this.attributes.id = id;
+ if(t){
+ t.registerNode(this);
+ }
+ this.onIdChange(id);
+ }
+ },
+
+ // private
+ onIdChange: Ext.emptyFn,
+
+ /**
+ * Returns the path for this node. The path can be used to expand or select this node programmatically.
+ * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
+ * @return {String} The path
+ */
+ getPath : function(attr){
+ attr = attr || "id";
+ var p = this.parentNode;
+ var b = [this.attributes[attr]];
+ while(p){
+ b.unshift(p.attributes[attr]);
+ p = p.parentNode;
+ }
+ var sep = this.getOwnerTree().pathSeparator;
+ return sep + b.join(sep);
+ },
+
+ /**
+ * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function
+ * will be the args provided or the current node. If the function returns false at any point,
+ * the bubble is stopped.
+ * @param {Function} fn The function to call
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
+ * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
+ */
+ bubble : function(fn, scope, args){
+ var p = this;
+ while(p){
+ if(fn.apply(scope || p, args || [p]) === false){
+ break;
+ }
+ p = p.parentNode;
+ }
+ },
+
+ /**
+ * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function
+ * will be the args provided or the current node. If the function returns false at any point,
+ * the cascade is stopped on that branch.
+ * @param {Function} fn The function to call
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
+ * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
+ */
+ cascade : function(fn, scope, args){
+ if(fn.apply(scope || this, args || [this]) !== false){
+ var cs = this.childNodes;
+ for(var i = 0, len = cs.length; i < len; i++) {
+ cs[i].cascade(fn, scope, args);
+ }
+ }
+ },
+
+ /**
+ * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function
+ * will be the args provided or the current node. If the function returns false at any point,
+ * the iteration stops.
+ * @param {Function} fn The function to call
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node in the iteration.
+ * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
+ */
+ eachChild : function(fn, scope, args){
+ var cs = this.childNodes;
+ for(var i = 0, len = cs.length; i < len; i++) {
+ if(fn.apply(scope || cs[i], args || [cs[i]]) === false){
+ break;
+ }
+ }
+ },
+
+ /**
+ * Finds the first child that has the attribute with the specified value.
+ * @param {String} attribute The attribute name
+ * @param {Mixed} value The value to search for
+ * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
+ * @return {Node} The found child or null if none was found
+ */
+ findChild : function(attribute, value, deep){
+ return this.findChildBy(function(){
+ return this.attributes[attribute] == value;
+ }, null, deep);
+ },
+
+ /**
+ * Finds the first child by a custom function. The child matches if the function passed returns <code>true</code>.
+ * @param {Function} fn A function which must return <code>true</code> if the passed Node is the required Node.
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Node being tested.
+ * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
+ * @return {Node} The found child or null if none was found
+ */
+ findChildBy : function(fn, scope, deep){
+ var cs = this.childNodes,
+ len = cs.length,
+ i = 0,
+ n,
+ res;
+ for(; i < len; i++){
+ n = cs[i];
+ if(fn.call(scope || n, n) === true){
+ return n;
+ }else if (deep){
+ res = n.findChildBy(fn, scope, deep);
+ if(res != null){
+ return res;
+ }
+ }
+
+ }
+ return null;
+ },
+
+ /**
+ * Sorts this nodes children using the supplied sort function.
+ * @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.
+ * @param {Object} scope (optional)The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
+ */
+ sort : function(fn, scope){
+ var cs = this.childNodes;
+ var len = cs.length;
+ if(len > 0){
+ var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
+ cs.sort(sortFn);
+ for(var i = 0; i < len; i++){
+ var n = cs[i];
+ n.previousSibling = cs[i-1];
+ n.nextSibling = cs[i+1];
+ if(i === 0){
+ this.setFirstChild(n);
+ }
+ if(i == len-1){
+ this.setLastChild(n);
+ }
+ }
+ }
+ },
+
+ /**
+ * Returns true if this node is an ancestor (at any point) of the passed node.
+ * @param {Node} node
+ * @return {Boolean}
+ */
+ contains : function(node){
+ return node.isAncestor(this);
+ },
+
+ /**
+ * Returns true if the passed node is an ancestor (at any point) of this node.
+ * @param {Node} node
+ * @return {Boolean}
+ */
+ isAncestor : function(node){
+ var p = this.parentNode;
+ while(p){
+ if(p == node){
+ return true;
+ }
+ p = p.parentNode;
+ }
+ return false;
+ },
+
+ toString : function(){
+ return "[Node"+(this.id?" "+this.id:"")+"]";
+ }
+});/**
+ * @class Ext.tree.TreeNode
+ * @extends Ext.data.Node
+ * @cfg {String} text The text for this node
+ * @cfg {Boolean} expanded true to start the node expanded
+ * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)
+ * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)
+ * @cfg {Boolean} disabled true to start the node disabled
+ * @cfg {String} icon The path to an icon for the node. The preferred way to do this
+ * is to use the cls or iconCls attributes and add the icon via a CSS background image.
+ * @cfg {String} cls A css class to be added to the node
+ * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
+ * @cfg {String} href URL of the link used for the node (defaults to #)
+ * @cfg {String} hrefTarget target frame for the link
+ * @cfg {Boolean} hidden True to render hidden. (Defaults to false).
+ * @cfg {String} qtip An Ext QuickTip for the node
+ * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
+ * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
+ * @cfg {Boolean} singleClickExpand True for single click expand on this node
+ * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)
+ * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
+ * (defaults to undefined with no checkbox rendered)
+ * @cfg {Boolean} draggable True to make this node draggable (defaults to false)
+ * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)
+ * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)
+ * @cfg {Boolean} editable False to not allow this node to be edited by an {@link Ext.tree.TreeEditor} (defaults to true)
+ * @constructor
+ * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
+ */
+Ext.tree.TreeNode = Ext.extend(Ext.data.Node, {
+
+ constructor : function(attributes){
+ attributes = attributes || {};
+ if(Ext.isString(attributes)){
+ attributes = {text: attributes};
+ }
+ this.childrenRendered = false;
+ this.rendered = false;
+ Ext.tree.TreeNode.superclass.constructor.call(this, attributes);
+ this.expanded = attributes.expanded === true;
+ this.isTarget = attributes.isTarget !== false;
+ this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
+ this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
+
+ /**
+ * Read-only. The text for this node. To change it use <code>{@link #setText}</code>.
+ * @type String
+ */
+ this.text = attributes.text;
+ /**
+ * True if this node is disabled.
+ * @type Boolean
+ */
+ this.disabled = attributes.disabled === true;
+ /**
+ * True if this node is hidden.
+ * @type Boolean
+ */
+ this.hidden = attributes.hidden === true;
+
+ this.addEvents(
+ /**
+ * @event textchange
+ * Fires when the text for this node is changed
+ * @param {Node} this This node
+ * @param {String} text The new text
+ * @param {String} oldText The old text
+ */
+ 'textchange',
+ /**
+ * @event beforeexpand
+ * Fires before this node is expanded, return false to cancel.
+ * @param {Node} this This node
+ * @param {Boolean} deep
+ * @param {Boolean} anim
+ */
+ 'beforeexpand',
+ /**
+ * @event beforecollapse
+ * Fires before this node is collapsed, return false to cancel.
+ * @param {Node} this This node
+ * @param {Boolean} deep
+ * @param {Boolean} anim
+ */
+ 'beforecollapse',
+ /**
+ * @event expand
+ * Fires when this node is expanded
+ * @param {Node} this This node
+ */
+ 'expand',
+ /**
+ * @event disabledchange
+ * Fires when the disabled status of this node changes
+ * @param {Node} this This node
+ * @param {Boolean} disabled
+ */
+ 'disabledchange',
+ /**
+ * @event collapse
+ * Fires when this node is collapsed
+ * @param {Node} this This node
+ */
+ 'collapse',
+ /**
+ * @event beforeclick
+ * Fires before click processing. Return false to cancel the default action.
+ * @param {Node} this This node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'beforeclick',
+ /**
+ * @event click
+ * Fires when this node is clicked
+ * @param {Node} this This node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'click',
+ /**
+ * @event checkchange
+ * Fires when a node with a checkbox's checked property changes
+ * @param {Node} this This node
+ * @param {Boolean} checked
+ */
+ 'checkchange',
+ /**
+ * @event beforedblclick
+ * Fires before double click processing. Return false to cancel the default action.
+ * @param {Node} this This node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'beforedblclick',
+ /**
+ * @event dblclick
+ * Fires when this node is double clicked
+ * @param {Node} this This node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'dblclick',
+ /**
+ * @event contextmenu
+ * Fires when this node is right clicked
+ * @param {Node} this This node
+ * @param {Ext.EventObject} e The event object
+ */
+ 'contextmenu',
+ /**
+ * @event beforechildrenrendered
+ * Fires right before the child nodes for this node are rendered
+ * @param {Node} this This node
+ */
+ 'beforechildrenrendered'
+ );
+
+ var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;
+
+ /**
+ * Read-only. The UI for this node
+ * @type TreeNodeUI
+ */
+ this.ui = new uiClass(this);
+ },
+
+ preventHScroll : true,
+ /**
+ * Returns true if this node is expanded
+ * @return {Boolean}
+ */
+ isExpanded : function(){
+ return this.expanded;
+ },
+
+/**
+ * Returns the UI object for this node.
+ * @return {TreeNodeUI} The object which is providing the user interface for this tree
+ * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance
+ * of {@link Ext.tree.TreeNodeUI}
+ */
+ getUI : function(){
+ return this.ui;
+ },
+
+ getLoader : function(){
+ var owner;
+ return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : (this.loader = new Ext.tree.TreeLoader()));
+ },
+
+ // private override
+ setFirstChild : function(node){
+ var of = this.firstChild;
+ Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);
+ if(this.childrenRendered && of && node != of){
+ of.renderIndent(true, true);
+ }
+ if(this.rendered){
+ this.renderIndent(true, true);
+ }
+ },
+
+ // private override
+ setLastChild : function(node){
+ var ol = this.lastChild;
+ Ext.tree.TreeNode.superclass.setLastChild.call(this, node);
+ if(this.childrenRendered && ol && node != ol){
+ ol.renderIndent(true, true);
+ }
+ if(this.rendered){
+ this.renderIndent(true, true);
+ }
+ },
+
+ // these methods are overridden to provide lazy rendering support
+ // private override
+ appendChild : function(n){
+ if(!n.render && !Ext.isArray(n)){
+ n = this.getLoader().createNode(n);
+ }
+ var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);
+ if(node && this.childrenRendered){
+ node.render();
+ }
+ this.ui.updateExpandIcon();
+ return node;
+ },
+
+ // private override
+ removeChild : function(node, destroy){
+ this.ownerTree.getSelectionModel().unselect(node);
+ Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
+ // only update the ui if we're not destroying
+ if(!destroy){
+ var rendered = node.ui.rendered;
+ // if it's been rendered remove dom node
+ if(rendered){
+ node.ui.remove();
+ }
+ if(rendered && this.childNodes.length < 1){
+ this.collapse(false, false);
+ }else{
+ this.ui.updateExpandIcon();
+ }
+ if(!this.firstChild && !this.isHiddenRoot()){
+ this.childrenRendered = false;
+ }
+ }
+ return node;
+ },
+
+ // private override
+ insertBefore : function(node, refNode){
+ if(!node.render){
+ node = this.getLoader().createNode(node);
+ }
+ var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
+ if(newNode && refNode && this.childrenRendered){
+ node.render();
+ }
+ this.ui.updateExpandIcon();
+ return newNode;
+ },
+
+ /**
+ * Sets the text for this node
+ * @param {String} text
+ */
+ setText : function(text){
+ var oldText = this.text;
+ this.text = this.attributes.text = text;
+ if(this.rendered){ // event without subscribing
+ this.ui.onTextChange(this, text, oldText);
+ }
+ this.fireEvent('textchange', this, text, oldText);
+ },
+
+ /**
+ * Sets the icon class for this node.
+ * @param {String} cls
+ */
+ setIconCls : function(cls){
+ var old = this.attributes.iconCls;
+ this.attributes.iconCls = cls;
+ if(this.rendered){
+ this.ui.onIconClsChange(this, cls, old);
+ }
+ },
+
+ /**
+ * Sets the tooltip for this node.
+ * @param {String} tip The text for the tip
+ * @param {String} title (Optional) The title for the tip
+ */
+ setTooltip : function(tip, title){
+ this.attributes.qtip = tip;
+ this.attributes.qtipTitle = title;
+ if(this.rendered){
+ this.ui.onTipChange(this, tip, title);
+ }
+ },
+
+ /**
+ * Sets the icon for this node.
+ * @param {String} icon
+ */
+ setIcon : function(icon){
+ this.attributes.icon = icon;
+ if(this.rendered){
+ this.ui.onIconChange(this, icon);
+ }
+ },
+
+ /**
+ * Sets the href for the node.
+ * @param {String} href The href to set
+ * @param {String} (Optional) target The target of the href
+ */
+ setHref : function(href, target){
+ this.attributes.href = href;
+ this.attributes.hrefTarget = target;
+ if(this.rendered){
+ this.ui.onHrefChange(this, href, target);
+ }
+ },
+
+ /**
+ * Sets the class on this node.
+ * @param {String} cls
+ */
+ setCls : function(cls){
+ var old = this.attributes.cls;
+ this.attributes.cls = cls;
+ if(this.rendered){
+ this.ui.onClsChange(this, cls, old);
+ }
+ },
+
+ /**
+ * Triggers selection of this node
+ */
+ select : function(){
+ var t = this.getOwnerTree();
+ if(t){
+ t.getSelectionModel().select(this);
+ }
+ },
+
+ /**
+ * Triggers deselection of this node
+ * @param {Boolean} silent (optional) True to stop selection change events from firing.
+ */
+ unselect : function(silent){
+ var t = this.getOwnerTree();
+ if(t){
+ t.getSelectionModel().unselect(this, silent);
+ }
+ },
+
+ /**
+ * Returns true if this node is selected
+ * @return {Boolean}
+ */
+ isSelected : function(){
+ var t = this.getOwnerTree();
+ return t ? t.getSelectionModel().isSelected(this) : false;
+ },
+
+ /**
+ * Expand this node.
+ * @param {Boolean} deep (optional) True to expand all children as well
+ * @param {Boolean} anim (optional) false to cancel the default animation
+ * @param {Function} callback (optional) A callback to be called when
+ * expanding this node completes (does not wait for deep expand to complete).
+ * Called with 1 parameter, this node.
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
+ */
+ expand : function(deep, anim, callback, scope){
+ if(!this.expanded){
+ if(this.fireEvent('beforeexpand', this, deep, anim) === false){
+ return;
+ }
+ if(!this.childrenRendered){
+ this.renderChildren();
+ }
+ this.expanded = true;
+ if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
+ this.ui.animExpand(function(){
+ this.fireEvent('expand', this);
+ this.runCallback(callback, scope || this, [this]);
+ if(deep === true){
+ this.expandChildNodes(true, true);
+ }
+ }.createDelegate(this));
+ return;
+ }else{
+ this.ui.expand();
+ this.fireEvent('expand', this);
+ this.runCallback(callback, scope || this, [this]);
+ }
+ }else{
+ this.runCallback(callback, scope || this, [this]);
+ }
+ if(deep === true){
+ this.expandChildNodes(true);
+ }
+ },
+
+ runCallback : function(cb, scope, args){
+ if(Ext.isFunction(cb)){
+ cb.apply(scope, args);
+ }
+ },
+
+ isHiddenRoot : function(){
+ return this.isRoot && !this.getOwnerTree().rootVisible;
+ },
+
+ /**
+ * Collapse this node.
+ * @param {Boolean} deep (optional) True to collapse all children as well
+ * @param {Boolean} anim (optional) false to cancel the default animation
+ * @param {Function} callback (optional) A callback to be called when
+ * expanding this node completes (does not wait for deep expand to complete).
+ * Called with 1 parameter, this node.
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
+ */
+ collapse : function(deep, anim, callback, scope){
+ if(this.expanded && !this.isHiddenRoot()){
+ if(this.fireEvent('beforecollapse', this, deep, anim) === false){
+ return;
+ }
+ this.expanded = false;
+ if((this.getOwnerTree().animate && anim !== false) || anim){
+ this.ui.animCollapse(function(){
+ this.fireEvent('collapse', this);
+ this.runCallback(callback, scope || this, [this]);
+ if(deep === true){
+ this.collapseChildNodes(true);
+ }
+ }.createDelegate(this));
+ return;
+ }else{
+ this.ui.collapse();
+ this.fireEvent('collapse', this);
+ this.runCallback(callback, scope || this, [this]);
+ }
+ }else if(!this.expanded){
+ this.runCallback(callback, scope || this, [this]);
+ }
+ if(deep === true){
+ var cs = this.childNodes;
+ for(var i = 0, len = cs.length; i < len; i++) {
+ cs[i].collapse(true, false);
+ }
+ }
+ },
+
+ // private
+ delayedExpand : function(delay){
+ if(!this.expandProcId){
+ this.expandProcId = this.expand.defer(delay, this);
+ }
+ },
+
+ // private
+ cancelExpand : function(){
+ if(this.expandProcId){
+ clearTimeout(this.expandProcId);
+ }
+ this.expandProcId = false;
+ },
+
+ /**
+ * Toggles expanded/collapsed state of the node
+ */
+ toggle : function(){
+ if(this.expanded){
+ this.collapse();
+ }else{
+ this.expand();
+ }
+ },
+
+ /**
+ * Ensures all parent nodes are expanded, and if necessary, scrolls
+ * the node into view.
+ * @param {Function} callback (optional) A function to call when the node has been made visible.
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
+ */
+ ensureVisible : function(callback, scope){
+ var tree = this.getOwnerTree();
+ tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){
+ var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime
+ tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
+ this.runCallback(callback, scope || this, [this]);
+ }.createDelegate(this));
+ },
+
+ /**
+ * Expand all child nodes
+ * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
+ */
+ expandChildNodes : function(deep, anim) {
+ var cs = this.childNodes,
+ i,
+ len = cs.length;
+ for (i = 0; i < len; i++) {
+ cs[i].expand(deep, anim);
+ }
+ },
+
+ /**
+ * Collapse all child nodes
+ * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
+ */
+ collapseChildNodes : function(deep){
+ var cs = this.childNodes;
+ for(var i = 0, len = cs.length; i < len; i++) {
+ cs[i].collapse(deep);
+ }
+ },
+
+ /**
+ * Disables this node
+ */
+ disable : function(){
+ this.disabled = true;
+ this.unselect();
+ if(this.rendered && this.ui.onDisableChange){ // event without subscribing
+ this.ui.onDisableChange(this, true);
+ }
+ this.fireEvent('disabledchange', this, true);
+ },
+
+ /**
+ * Enables this node
+ */
+ enable : function(){
+ this.disabled = false;
+ if(this.rendered && this.ui.onDisableChange){ // event without subscribing
+ this.ui.onDisableChange(this, false);
+ }
+ this.fireEvent('disabledchange', this, false);
+ },
+
+ // private
+ renderChildren : function(suppressEvent){
+ if(suppressEvent !== false){
+ this.fireEvent('beforechildrenrendered', this);
+ }
+ var cs = this.childNodes;
+ for(var i = 0, len = cs.length; i < len; i++){
+ cs[i].render(true);
+ }
+ this.childrenRendered = true;
+ },
+
+ // private
+ sort : function(fn, scope){
+ Ext.tree.TreeNode.superclass.sort.apply(this, arguments);
+ if(this.childrenRendered){
+ var cs = this.childNodes;
+ for(var i = 0, len = cs.length; i < len; i++){
+ cs[i].render(true);
+ }
+ }
+ },
+
+ // private
+ render : function(bulkRender){
+ this.ui.render(bulkRender);
+ if(!this.rendered){
+ // make sure it is registered
+ this.getOwnerTree().registerNode(this);
+ this.rendered = true;
+ if(this.expanded){
+ this.expanded = false;
+ this.expand(false, false);
+ }
+ }
+ },
+
+ // private
+ renderIndent : function(deep, refresh){
+ if(refresh){
+ this.ui.childIndent = null;
+ }
+ this.ui.renderIndent();
+ if(deep === true && this.childrenRendered){
+ var cs = this.childNodes;
+ for(var i = 0, len = cs.length; i < len; i++){
+ cs[i].renderIndent(true, refresh);
+ }
+ }
+ },
+
+ beginUpdate : function(){
+ this.childrenRendered = false;
+ },
+
+ endUpdate : function(){
+ if(this.expanded && this.rendered){
+ this.renderChildren();
+ }
+ },
+
+ //inherit docs
+ destroy : function(silent){
+ if(silent === true){
+ this.unselect(true);
+ }
+ Ext.tree.TreeNode.superclass.destroy.call(this, silent);
+ Ext.destroy(this.ui, this.loader);
+ this.ui = this.loader = null;
+ },
+
+ // private
+ onIdChange : function(id){
+ this.ui.onIdChange(id);
+ }
+});
+
+Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;/**
+ * @class Ext.tree.AsyncTreeNode
+ * @extends Ext.tree.TreeNode
+ * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
+ * @constructor
+ * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
+ */
+ Ext.tree.AsyncTreeNode = function(config){
+ this.loaded = config && config.loaded === true;
+ this.loading = false;
+ Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
+ /**
+ * @event beforeload
+ * Fires before this node is loaded, return false to cancel
+ * @param {Node} this This node
+ */
+ this.addEvents('beforeload', 'load');
+ /**
+ * @event load
+ * Fires when this node is loaded
+ * @param {Node} this This node
+ */
+ /**
+ * The loader used by this node (defaults to using the tree's defined loader)
+ * @type TreeLoader
+ * @property loader
+ */
+};
+Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
+ expand : function(deep, anim, callback, scope){
+ if(this.loading){ // if an async load is already running, waiting til it's done
+ var timer;
+ var f = function(){
+ if(!this.loading){ // done loading
+ clearInterval(timer);
+ this.expand(deep, anim, callback, scope);
+ }
+ }.createDelegate(this);
+ timer = setInterval(f, 200);
+ return;
+ }
+ if(!this.loaded){
+ if(this.fireEvent("beforeload", this) === false){
+ return;
+ }
+ this.loading = true;
+ this.ui.beforeLoad(this);
+ var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
+ if(loader){
+ loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
+ return;
+ }
+ }
+ Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
+ },
+
+ /**
+ * Returns true if this node is currently loading
+ * @return {Boolean}
+ */
+ isLoading : function(){
+ return this.loading;
+ },
+
+ loadComplete : function(deep, anim, callback, scope){
+ this.loading = false;
+ this.loaded = true;
+ this.ui.afterLoad(this);
+ this.fireEvent("load", this);
+ this.expand(deep, anim, callback, scope);
+ },
+
+ /**
+ * Returns true if this node has been loaded
+ * @return {Boolean}
+ */
+ isLoaded : function(){
+ return this.loaded;
+ },
+
+ hasChildNodes : function(){
+ if(!this.isLeaf() && !this.loaded){
+ return true;
+ }else{
+ return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
+ }
+ },
+
+ /**
+ * Trigger a reload for this node
+ * @param {Function} callback
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Node.
+ */
+ reload : function(callback, scope){
+ this.collapse(false, false);
+ while(this.firstChild){
+ this.removeChild(this.firstChild).destroy();
+ }
+ this.childrenRendered = false;
+ this.loaded = false;
+ if(this.isHiddenRoot()){
+ this.expanded = false;
+ }
+ this.expand(false, false, callback, scope);
+ }
+});
+
+Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;/**
+ * @class Ext.tree.TreeNodeUI
+ * This class provides the default UI implementation for Ext TreeNodes.
+ * The TreeNode UI implementation is separate from the
+ * tree implementation, and allows customizing of the appearance of
+ * tree nodes.<br>
+ * <p>
+ * If you are customizing the Tree's user interface, you
+ * may need to extend this class, but you should never need to instantiate this class.<br>
+ * <p>
+ * This class provides access to the user interface components of an Ext TreeNode, through
+ * {@link Ext.tree.TreeNode#getUI}
+ */
+Ext.tree.TreeNodeUI = Ext.extend(Object, {
+
+ constructor : function(node){
+ Ext.apply(this, {
+ node: node,
+ rendered: false,
+ animating: false,
+ wasLeaf: true,
+ ecc: 'x-tree-ec-icon x-tree-elbow',
+ emptyIcon: Ext.BLANK_IMAGE_URL
+ });
+ },
+
+ // private
+ removeChild : function(node){
+ if(this.rendered){
+ this.ctNode.removeChild(node.ui.getEl());
+ }
+ },
+
+ // private
+ beforeLoad : function(){
+ this.addClass("x-tree-node-loading");
+ },
+
+ // private
+ afterLoad : function(){
+ this.removeClass("x-tree-node-loading");
+ },
+
+ // private
+ onTextChange : function(node, text, oldText){
+ if(this.rendered){
+ this.textNode.innerHTML = text;
+ }
+ },
+
+ // private
+ onIconClsChange : function(node, cls, oldCls){
+ if(this.rendered){
+ Ext.fly(this.iconNode).replaceClass(oldCls, cls);
+ }
+ },
+
+ // private
+ onIconChange : function(node, icon){
+ if(this.rendered){
+ //'<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
+ var empty = Ext.isEmpty(icon);
+ this.iconNode.src = empty ? this.emptyIcon : icon;
+ Ext.fly(this.iconNode)[empty ? 'removeClass' : 'addClass']('x-tree-node-inline-icon');
+ }
+ },
+
+ // private
+ onTipChange : function(node, tip, title){
+ if(this.rendered){
+ var hasTitle = Ext.isDefined(title);
+ if(this.textNode.setAttributeNS){
+ this.textNode.setAttributeNS("ext", "qtip", tip);
+ if(hasTitle){
+ this.textNode.setAttributeNS("ext", "qtitle", title);
+ }
+ }else{
+ this.textNode.setAttribute("ext:qtip", tip);
+ if(hasTitle){
+ this.textNode.setAttribute("ext:qtitle", title);
+ }
+ }
+ }
+ },
+
+ // private
+ onHrefChange : function(node, href, target){
+ if(this.rendered){
+ this.anchor.href = this.getHref(href);
+ if(Ext.isDefined(target)){
+ this.anchor.target = target;
+ }
+ }
+ },
+
+ // private
+ onClsChange : function(node, cls, oldCls){
+ if(this.rendered){
+ Ext.fly(this.elNode).replaceClass(oldCls, cls);
+ }
+ },
+
+ // private
+ onDisableChange : function(node, state){
+ this.disabled = state;
+ if (this.checkbox) {
+ this.checkbox.disabled = state;
+ }
+ this[state ? 'addClass' : 'removeClass']('x-tree-node-disabled');
+ },
+
+ // private
+ onSelectedChange : function(state){
+ if(state){
+ this.focus();
+ this.addClass("x-tree-selected");
+ }else{
+ //this.blur();
+ this.removeClass("x-tree-selected");
+ }
+ },
+
+ // private
+ onMove : function(tree, node, oldParent, newParent, index, refNode){
+ this.childIndent = null;
+ if(this.rendered){
+ var targetNode = newParent.ui.getContainer();
+ if(!targetNode){//target not rendered
+ this.holder = document.createElement("div");
+ this.holder.appendChild(this.wrap);
+ return;
+ }
+ var insertBefore = refNode ? refNode.ui.getEl() : null;
+ if(insertBefore){
+ targetNode.insertBefore(this.wrap, insertBefore);
+ }else{
+ targetNode.appendChild(this.wrap);
+ }
+ this.node.renderIndent(true, oldParent != newParent);
+ }
+ },
+
+/**
+ * Adds one or more CSS classes to the node's UI element.
+ * Duplicate classes are automatically filtered out.
+ * @param {String/Array} className The CSS class to add, or an array of classes
+ */
+ addClass : function(cls){
+ if(this.elNode){
+ Ext.fly(this.elNode).addClass(cls);
+ }
+ },
+
+/**
+ * Removes one or more CSS classes from the node's UI element.
+ * @param {String/Array} className The CSS class to remove, or an array of classes
+ */
+ removeClass : function(cls){
+ if(this.elNode){
+ Ext.fly(this.elNode).removeClass(cls);
+ }
+ },
+
+ // private
+ remove : function(){
+ if(this.rendered){
+ this.holder = document.createElement("div");
+ this.holder.appendChild(this.wrap);
+ }
+ },
+
+ // private
+ fireEvent : function(){
+ return this.node.fireEvent.apply(this.node, arguments);
+ },
+
+ // private
+ initEvents : function(){
+ this.node.on("move", this.onMove, this);
+
+ if(this.node.disabled){
+ this.onDisableChange(this.node, true);
+ }
+ if(this.node.hidden){
+ this.hide();
+ }
+ var ot = this.node.getOwnerTree();
+ var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
+ if(dd && (!this.node.isRoot || ot.rootVisible)){
+ Ext.dd.Registry.register(this.elNode, {
+ node: this.node,
+ handles: this.getDDHandles(),
+ isHandle: false
+ });
+ }
+ },
+
+ // private
+ getDDHandles : function(){
+ return [this.iconNode, this.textNode, this.elNode];
+ },
+
+/**
+ * Hides this node.
+ */
+ hide : function(){
+ this.node.hidden = true;
+ if(this.wrap){
+ this.wrap.style.display = "none";
+ }
+ },
+
+/**
+ * Shows this node.
+ */
+ show : function(){
+ this.node.hidden = false;
+ if(this.wrap){
+ this.wrap.style.display = "";
+ }
+ },
+
+ // private
+ onContextMenu : function(e){
+ if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
+ e.preventDefault();
+ this.focus();
+ this.fireEvent("contextmenu", this.node, e);
+ }
+ },
+
+ // private
+ onClick : function(e){
+ if(this.dropping){
+ e.stopEvent();
+ return;
+ }
+ if(this.fireEvent("beforeclick", this.node, e) !== false){
+ var a = e.getTarget('a');
+ if(!this.disabled && this.node.attributes.href && a){
+ this.fireEvent("click", this.node, e);
+ return;
+ }else if(a && e.ctrlKey){
+ e.stopEvent();
+ }
+ e.preventDefault();
+ if(this.disabled){
+ return;
+ }
+
+ if(this.node.attributes.singleClickExpand && !this.animating && this.node.isExpandable()){
+ this.node.toggle();
+ }
+
+ this.fireEvent("click", this.node, e);
+ }else{
+ e.stopEvent();
+ }
+ },
+
+ // private
+ onDblClick : function(e){
+ e.preventDefault();
+ if(this.disabled){
+ return;
+ }
+ if(this.fireEvent("beforedblclick", this.node, e) !== false){
+ if(this.checkbox){
+ this.toggleCheck();
+ }
+ if(!this.animating && this.node.isExpandable()){
+ this.node.toggle();
+ }
+ this.fireEvent("dblclick", this.node, e);
+ }
+ },
+
+ onOver : function(e){
+ this.addClass('x-tree-node-over');
+ },
+
+ onOut : function(e){
+ this.removeClass('x-tree-node-over');
+ },
+
+ // private
+ onCheckChange : function(){
+ var checked = this.checkbox.checked;
+ // fix for IE6
+ this.checkbox.defaultChecked = checked;
+ this.node.attributes.checked = checked;
+ this.fireEvent('checkchange', this.node, checked);
+ },
+
+ // private
+ ecClick : function(e){
+ if(!this.animating && this.node.isExpandable()){
+ this.node.toggle();
+ }
+ },
+
+ // private
+ startDrop : function(){
+ this.dropping = true;
+ },
+
+ // delayed drop so the click event doesn't get fired on a drop
+ endDrop : function(){
+ setTimeout(function(){
+ this.dropping = false;
+ }.createDelegate(this), 50);
+ },
+
+ // private
+ expand : function(){
+ this.updateExpandIcon();
+ this.ctNode.style.display = "";
+ },
+
+ // private
+ focus : function(){
+ if(!this.node.preventHScroll){
+ try{this.anchor.focus();
+ }catch(e){}
+ }else{
+ try{
+ var noscroll = this.node.getOwnerTree().getTreeEl().dom;
+ var l = noscroll.scrollLeft;
+ this.anchor.focus();
+ noscroll.scrollLeft = l;
+ }catch(e){}
+ }
+ },
+
+/**
+ * Sets the checked status of the tree node to the passed value, or, if no value was passed,
+ * toggles the checked status. If the node was rendered with no checkbox, this has no effect.
+ * @param {Boolean} value (optional) The new checked status.
+ */
+ toggleCheck : function(value){
+ var cb = this.checkbox;
+ if(cb){
+ cb.checked = (value === undefined ? !cb.checked : value);
+ this.onCheckChange();
+ }
+ },
+
+ // private
+ blur : function(){
+ try{
+ this.anchor.blur();
+ }catch(e){}
+ },
+
+ // private
+ animExpand : function(callback){
+ var ct = Ext.get(this.ctNode);
+ ct.stopFx();
+ if(!this.node.isExpandable()){
+ this.updateExpandIcon();
+ this.ctNode.style.display = "";
+ Ext.callback(callback);
+ return;
+ }
+ this.animating = true;
+ this.updateExpandIcon();
+
+ ct.slideIn('t', {
+ callback : function(){
+ this.animating = false;
+ Ext.callback(callback);
+ },
+ scope: this,
+ duration: this.node.ownerTree.duration || .25
+ });
+ },
+
+ // private
+ highlight : function(){
+ var tree = this.node.getOwnerTree();
+ Ext.fly(this.wrap).highlight(
+ tree.hlColor || "C3DAF9",
+ {endColor: tree.hlBaseColor}
+ );
+ },
+
+ // private
+ collapse : function(){
+ this.updateExpandIcon();
+ this.ctNode.style.display = "none";
+ },
+
+ // private
+ animCollapse : function(callback){
+ var ct = Ext.get(this.ctNode);
+ ct.enableDisplayMode('block');
+ ct.stopFx();
+
+ this.animating = true;
+ this.updateExpandIcon();
+
+ ct.slideOut('t', {
+ callback : function(){
+ this.animating = false;
+ Ext.callback(callback);
+ },
+ scope: this,
+ duration: this.node.ownerTree.duration || .25
+ });
+ },
+
+ // private
+ getContainer : function(){
+ return this.ctNode;
+ },
+
+/**
+ * Returns the element which encapsulates this node.
+ * @return {HtmlElement} The DOM element. The default implementation uses a <code><li></code>.
+ */
+ getEl : function(){
+ return this.wrap;
+ },
+
+ // private
+ appendDDGhost : function(ghostNode){
+ ghostNode.appendChild(this.elNode.cloneNode(true));
+ },
+
+ // private
+ getDDRepairXY : function(){
+ return Ext.lib.Dom.getXY(this.iconNode);
+ },
+
+ // private
+ onRender : function(){
+ this.render();
+ },
+
+ // private
+ render : function(bulkRender){
+ var n = this.node, a = n.attributes;
+ var targetNode = n.parentNode ?
+ n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
+
+ if(!this.rendered){
+ this.rendered = true;
+
+ this.renderElements(n, a, targetNode, bulkRender);
+
+ if(a.qtip){
+ this.onTipChange(n, a.qtip, a.qtipTitle);
+ }else if(a.qtipCfg){
+ a.qtipCfg.target = Ext.id(this.textNode);
+ Ext.QuickTips.register(a.qtipCfg);
+ }
+ this.initEvents();
+ if(!this.node.expanded){
+ this.updateExpandIcon(true);
+ }
+ }else{
+ if(bulkRender === true) {
+ targetNode.appendChild(this.wrap);
+ }
+ }
+ },
+
+ // private
+ renderElements : function(n, a, targetNode, bulkRender){
+ // add some indent caching, this helps performance when rendering a large tree
+ this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
+
+ var cb = Ext.isBoolean(a.checked),
+ nel,
+ href = this.getHref(a.href),
+ buf = ['<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf x-unselectable ', a.cls,'" unselectable="on">',
+ '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
+ '<img alt="" src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
+ '<img alt="" src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
+ cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',
+ '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ',
+ a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",
+ '<ul class="x-tree-node-ct" style="display:none;"></ul>',
+ "</li>"].join('');
+
+ if(bulkRender !== true && n.nextSibling && (nel = n.nextSibling.ui.getEl())){
+ this.wrap = Ext.DomHelper.insertHtml("beforeBegin", nel, buf);
+ }else{
+ this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf);
+ }
+
+ this.elNode = this.wrap.childNodes[0];
+ this.ctNode = this.wrap.childNodes[1];
+ var cs = this.elNode.childNodes;
+ this.indentNode = cs[0];
+ this.ecNode = cs[1];
+ this.iconNode = cs[2];
+ var index = 3;
+ if(cb){
+ this.checkbox = cs[3];
+ // fix for IE6
+ this.checkbox.defaultChecked = this.checkbox.checked;
+ index++;
+ }
+ this.anchor = cs[index];
+ this.textNode = cs[index].firstChild;
+ },
+
+ /**
+ * @private Gets a normalized href for the node.
+ * @param {String} href
+ */
+ getHref : function(href){
+ return Ext.isEmpty(href) ? (Ext.isGecko ? '' : '#') : href;
+ },
+
+/**
+ * Returns the <a> element that provides focus for the node's UI.
+ * @return {HtmlElement} The DOM anchor element.
+ */
+ getAnchor : function(){
+ return this.anchor;
+ },
+
+/**
+ * Returns the text node.
+ * @return {HtmlNode} The DOM text node.
+ */
+ getTextEl : function(){
+ return this.textNode;
+ },
+
+/**
+ * Returns the icon <img> element.
+ * @return {HtmlElement} The DOM image element.
+ */
+ getIconEl : function(){
+ return this.iconNode;
+ },
+
+/**
+ * Returns the checked status of the node. If the node was rendered with no
+ * checkbox, it returns false.
+ * @return {Boolean} The checked flag.
+ */
+ isChecked : function(){
+ return this.checkbox ? this.checkbox.checked : false;
+ },
+
+ // private
+ updateExpandIcon : function(){
+ if(this.rendered){
+ var n = this.node,
+ c1,
+ c2,
+ cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow",
+ hasChild = n.hasChildNodes();
+ if(hasChild || n.attributes.expandable){
+ if(n.expanded){
+ cls += "-minus";
+ c1 = "x-tree-node-collapsed";
+ c2 = "x-tree-node-expanded";
+ }else{
+ cls += "-plus";
+ c1 = "x-tree-node-expanded";
+ c2 = "x-tree-node-collapsed";
+ }
+ if(this.wasLeaf){
+ this.removeClass("x-tree-node-leaf");
+ this.wasLeaf = false;
+ }
+ if(this.c1 != c1 || this.c2 != c2){
+ Ext.fly(this.elNode).replaceClass(c1, c2);
+ this.c1 = c1; this.c2 = c2;
+ }
+ }else{
+ if(!this.wasLeaf){
+ Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-collapsed");
+ delete this.c1;
+ delete this.c2;
+ this.wasLeaf = true;
+ }
+ }
+ var ecc = "x-tree-ec-icon "+cls;
+ if(this.ecc != ecc){
+ this.ecNode.className = ecc;
+ this.ecc = ecc;
+ }
+ }
+ },
+
+ // private
+ onIdChange: function(id){
+ if(this.rendered){
+ this.elNode.setAttribute('ext:tree-node-id', id);
+ }
+ },
+
+ // private
+ getChildIndent : function(){
+ if(!this.childIndent){
+ var buf = [],
+ p = this.node;
+ while(p){
+ if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
+ if(!p.isLast()) {
+ buf.unshift('<img alt="" src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
+ } else {
+ buf.unshift('<img alt="" src="'+this.emptyIcon+'" class="x-tree-icon" />');
+ }
+ }
+ p = p.parentNode;
+ }
+ this.childIndent = buf.join("");
+ }
+ return this.childIndent;
+ },
+
+ // private
+ renderIndent : function(){
+ if(this.rendered){
+ var indent = "",
+ p = this.node.parentNode;
+ if(p){
+ indent = p.ui.getChildIndent();
+ }
+ if(this.indentMarkup != indent){ // don't rerender if not required
+ this.indentNode.innerHTML = indent;
+ this.indentMarkup = indent;
+ }
+ this.updateExpandIcon();
+ }
+ },
+
+ destroy : function(){
+ if(this.elNode){
+ Ext.dd.Registry.unregister(this.elNode.id);
+ }
+
+ Ext.each(['textnode', 'anchor', 'checkbox', 'indentNode', 'ecNode', 'iconNode', 'elNode', 'ctNode', 'wrap', 'holder'], function(el){
+ if(this[el]){
+ Ext.fly(this[el]).remove();
+ delete this[el];
+ }
+ }, this);
+ delete this.node;
+ }
+});
+
+/**
+ * @class Ext.tree.RootTreeNodeUI
+ * This class provides the default UI implementation for <b>root</b> Ext TreeNodes.
+ * The RootTreeNode UI implementation allows customizing the appearance of the root tree node.<br>
+ * <p>
+ * If you are customizing the Tree's user interface, you
+ * may need to extend this class, but you should never need to instantiate this class.<br>
+ */
+Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
+ // private
+ render : function(){
+ if(!this.rendered){
+ var targetNode = this.node.ownerTree.innerCt.dom;
+ this.node.expanded = true;
+ targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
+ this.wrap = this.ctNode = targetNode.firstChild;
+ }
+ },
+ collapse : Ext.emptyFn,
+ expand : Ext.emptyFn
+});/**
+ * @class Ext.tree.TreeLoader
+ * @extends Ext.util.Observable
+ * A TreeLoader provides for lazy loading of an {@link Ext.tree.TreeNode}'s child
+ * nodes from a specified URL. The response must be a JavaScript Array definition
+ * whose elements are node definition objects. e.g.:
+ * <pre><code>
+ [{
+ id: 1,
+ text: 'A leaf Node',
+ leaf: true
+ },{
+ id: 2,
+ text: 'A folder Node',
+ children: [{
+ id: 3,
+ text: 'A child Node',
+ leaf: true
+ }]
+ }]
+</code></pre>
+ * <br><br>
+ * A server request is sent, and child nodes are loaded only when a node is expanded.
+ * The loading node's id is passed to the server under the parameter name "node" to
+ * enable the server to produce the correct child nodes.
+ * <br><br>
+ * To pass extra parameters, an event handler may be attached to the "beforeload"
+ * event, and the parameters specified in the TreeLoader's baseParams property:
+ * <pre><code>
+ myTreeLoader.on("beforeload", function(treeLoader, node) {
+ this.baseParams.category = node.attributes.category;
+ }, this);
+</code></pre>
+ * This would pass an HTTP parameter called "category" to the server containing
+ * the value of the Node's "category" attribute.
+ * @constructor
+ * Creates a new Treeloader.
+ * @param {Object} config A config object containing config properties.
+ */
+Ext.tree.TreeLoader = function(config){
+ this.baseParams = {};
+ Ext.apply(this, config);
+
+ this.addEvents(
+ /**
+ * @event beforeload
+ * Fires before a network request is made to retrieve the Json text which specifies a node's children.
+ * @param {Object} This TreeLoader object.
+ * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
+ * @param {Object} callback The callback function specified in the {@link #load} call.
+ */
+ "beforeload",
+ /**
+ * @event load
+ * Fires when the node has been successfuly loaded.
+ * @param {Object} This TreeLoader object.
+ * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
+ * @param {Object} response The response object containing the data from the server.
+ */
+ "load",
+ /**
+ * @event loadexception
+ * Fires if the network request failed.
+ * @param {Object} This TreeLoader object.
+ * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
+ * @param {Object} response The response object containing the data from the server.
+ */
+ "loadexception"
+ );
+ Ext.tree.TreeLoader.superclass.constructor.call(this);
+ if(Ext.isString(this.paramOrder)){
+ this.paramOrder = this.paramOrder.split(/[\s,|]/);
+ }
+};
+
+Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, {
+ /**
+ * @cfg {String} dataUrl The URL from which to request a Json string which
+ * specifies an array of node definition objects representing the child nodes
+ * to be loaded.
+ */
+ /**
+ * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
+ */
+ /**
+ * @cfg {String} url Equivalent to {@link #dataUrl}.
+ */
+ /**
+ * @cfg {Boolean} preloadChildren If set to true, the loader recursively loads "children" attributes when doing the first load on nodes.
+ */
+ /**
+ * @cfg {Object} baseParams (optional) An object containing properties which
+ * specify HTTP parameters to be passed to each request for child nodes.
+ */
+ /**
+ * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
+ * created by this loader. If the attributes sent by the server have an attribute in this object,
+ * they take priority.
+ */
+ /**
+ * @cfg {Object} uiProviders (optional) An object containing properties which
+ * specify custom {@link Ext.tree.TreeNodeUI} implementations. If the optional
+ * <i>uiProvider</i> attribute of a returned child node is a string rather
+ * than a reference to a TreeNodeUI implementation, then that string value
+ * is used as a property name in the uiProviders object.
+ */
+ uiProviders : {},
+
+ /**
+ * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
+ * child nodes before loading.
+ */
+ clearOnLoad : true,
+
+ /**
+ * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. Only used when using directFn.
+ * Specifies the params in the order in which they must be passed to the server-side Direct method
+ * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
+ * comma, or pipe. For example,
+ * any of the following would be acceptable:<pre><code>
+nodeParameter: 'node',
+paramOrder: ['param1','param2','param3']
+paramOrder: 'node param1 param2 param3'
+paramOrder: 'param1,node,param2,param3'
+paramOrder: 'param1|param2|param|node'
+ </code></pre>
+ */
+ paramOrder: undefined,
+
+ /**
+ * @cfg {Boolean} paramsAsHash Only used when using directFn.
+ * Send parameters as a collection of named arguments (defaults to <tt>false</tt>). Providing a
+ * <tt>{@link #paramOrder}</tt> nullifies this configuration.
+ */
+ paramsAsHash: false,
+
+ /**
+ * @cfg {String} nodeParameter The name of the parameter sent to the server which contains
+ * the identifier of the node. Defaults to <tt>'node'</tt>.
+ */
+ nodeParameter: 'node',
+
+ /**
+ * @cfg {Function} directFn
+ * Function to call when executing a request.
+ */
+ directFn : undefined,
+
+ /**
+ * Load an {@link Ext.tree.TreeNode} from the URL specified in the constructor.
+ * This is called automatically when a node is expanded, but may be used to reload
+ * a node (or append new children if the {@link #clearOnLoad} option is false.)
+ * @param {Ext.tree.TreeNode} node
+ * @param {Function} callback Function to call after the node has been loaded. The
+ * function is passed the TreeNode which was requested to be loaded.
+ * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed.
+ * defaults to the loaded TreeNode.
+ */
+ load : function(node, callback, scope){
+ if(this.clearOnLoad){
+ while(node.firstChild){
+ node.removeChild(node.firstChild);
+ }
+ }
+ if(this.doPreload(node)){ // preloaded json children
+ this.runCallback(callback, scope || node, [node]);
+ }else if(this.directFn || this.dataUrl || this.url){
+ this.requestData(node, callback, scope || node);
+ }
+ },
+
+ doPreload : function(node){
+ if(node.attributes.children){
+ if(node.childNodes.length < 1){ // preloaded?
+ var cs = node.attributes.children;
+ node.beginUpdate();
+ for(var i = 0, len = cs.length; i < len; i++){
+ var cn = node.appendChild(this.createNode(cs[i]));
+ if(this.preloadChildren){
+ this.doPreload(cn);
+ }
+ }
+ node.endUpdate();
+ }
+ return true;
+ }
+ return false;
+ },
+
+ getParams: function(node){
+ var bp = Ext.apply({}, this.baseParams),
+ np = this.nodeParameter,
+ po = this.paramOrder;
+
+ np && (bp[ np ] = node.id);
+
+ if(this.directFn){
+ var buf = [node.id];
+ if(po){
+ // reset 'buf' if the nodeParameter was included in paramOrder
+ if(np && po.indexOf(np) > -1){
+ buf = [];
+ }
+
+ for(var i = 0, len = po.length; i < len; i++){
+ buf.push(bp[ po[i] ]);
+ }
+ }else if(this.paramsAsHash){
+ buf = [bp];
+ }
+ return buf;
+ }else{
+ return bp;
+ }
+ },
+
+ requestData : function(node, callback, scope){
+ if(this.fireEvent("beforeload", this, node, callback) !== false){
+ if(this.directFn){
+ var args = this.getParams(node);
+ args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));
+ this.directFn.apply(window, args);
+ }else{
+ this.transId = Ext.Ajax.request({
+ method:this.requestMethod,
+ url: this.dataUrl||this.url,
+ success: this.handleResponse,
+ failure: this.handleFailure,
+ scope: this,
+ argument: {callback: callback, node: node, scope: scope},
+ params: this.getParams(node)
+ });
+ }
+ }else{
+ // if the load is cancelled, make sure we notify
+ // the node that we are done
+ this.runCallback(callback, scope || node, []);
+ }
+ },
+
+ processDirectResponse: function(result, response, args){
+ if(response.status){
+ this.handleResponse({
+ responseData: Ext.isArray(result) ? result : null,
+ responseText: result,
+ argument: args
+ });
+ }else{
+ this.handleFailure({
+ argument: args
+ });
+ }
+ },
+
+ // private
+ runCallback: function(cb, scope, args){
+ if(Ext.isFunction(cb)){
+ cb.apply(scope, args);
+ }
+ },
+
+ isLoading : function(){
+ return !!this.transId;
+ },
+
+ abort : function(){
+ if(this.isLoading()){
+ Ext.Ajax.abort(this.transId);
+ }
+ },
+
+ /**
+ * <p>Override this function for custom TreeNode node implementation, or to
+ * modify the attributes at creation time.</p>
+ * Example:<pre><code>
+new Ext.tree.TreePanel({
+ ...
+ loader: new Ext.tree.TreeLoader({
+ url: 'dataUrl',
+ createNode: function(attr) {
+// Allow consolidation consignments to have
+// consignments dropped into them.
+ if (attr.isConsolidation) {
+ attr.iconCls = 'x-consol',
+ attr.allowDrop = true;
+ }
+ return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
+ }
+ }),
+ ...
+});
+</code></pre>
+ * @param attr {Object} The attributes from which to create the new node.
+ */
+ createNode : function(attr){
+ // apply baseAttrs, nice idea Corey!
+ if(this.baseAttrs){
+ Ext.applyIf(attr, this.baseAttrs);
+ }
+ if(this.applyLoader !== false && !attr.loader){
+ attr.loader = this;
+ }
+ if(Ext.isString(attr.uiProvider)){
+ attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
+ }
+ if(attr.nodeType){
+ return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
+ }else{
+ return attr.leaf ?
+ new Ext.tree.TreeNode(attr) :
+ new Ext.tree.AsyncTreeNode(attr);
+ }
+ },
+
+ processResponse : function(response, node, callback, scope){
+ var json = response.responseText;
+ try {
+ var o = response.responseData || Ext.decode(json);
+ node.beginUpdate();
+ for(var i = 0, len = o.length; i < len; i++){
+ var n = this.createNode(o[i]);
+ if(n){
+ node.appendChild(n);
+ }
+ }
+ node.endUpdate();
+ this.runCallback(callback, scope || node, [node]);
+ }catch(e){
+ this.handleFailure(response);
+ }
+ },
+
+ handleResponse : function(response){
+ this.transId = false;
+ var a = response.argument;
+ this.processResponse(response, a.node, a.callback, a.scope);
+ this.fireEvent("load", this, a.node, response);
+ },
+
+ handleFailure : function(response){
+ this.transId = false;
+ var a = response.argument;
+ this.fireEvent("loadexception", this, a.node, response);
+ this.runCallback(a.callback, a.scope || a.node, [a.node]);
+ },
+
+ destroy : function(){
+ this.abort();
+ this.purgeListeners();
+ }