--- /dev/null
+/*!
+ * Ext JS Library 3.0.0
+ * Copyright(c) 2006-2009 Ext JS, LLC
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+/**\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.TreeFilter
+ * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
+ * @param {TreePanel} tree
+ * @param {Object} config (optional)
+ */
+Ext.tree.TreeFilter = function(tree, config){
+ this.tree = tree;
+ this.filtered = {};
+ Ext.apply(this, config);
+};
+
+Ext.tree.TreeFilter.prototype = {
+ clearBlank:false,
+ reverse:false,
+ autoClear:false,
+ remove:false,
+
+ /**
+ * Filter the data by a specific attribute.
+ * @param {String/RegExp} value Either string that the attribute value
+ * should start with or a RegExp to test against the attribute
+ * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
+ * @param {TreeNode} startNode (optional) The node to start the filter at.
+ */
+ filter : function(value, attr, startNode){
+ attr = attr || "text";
+ var f;
+ if(typeof value == "string"){
+ var vlen = value.length;
+ // auto clear empty filter
+ if(vlen == 0 && this.clearBlank){
+ this.clear();
+ return;
+ }
+ value = value.toLowerCase();
+ f = function(n){
+ return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
+ };
+ }else if(value.exec){ // regex?
+ f = function(n){
+ return value.test(n.attributes[attr]);
+ };
+ }else{
+ throw 'Illegal filter type, must be string or regex';
+ }
+ this.filterBy(f, null, startNode);
+ },
+
+ /**
+ * Filter by a function. The passed function will be called with each
+ * node in the tree (or from the startNode). If the function returns true, the node is kept
+ * otherwise it is filtered. If a node is filtered, its children are also filtered.
+ * @param {Function} fn The filter function
+ * @param {Object} scope (optional) The scope of the function (defaults to the current node)
+ */
+ filterBy : function(fn, scope, startNode){
+ startNode = startNode || this.tree.root;
+ if(this.autoClear){
+ this.clear();
+ }
+ var af = this.filtered, rv = this.reverse;
+ var f = function(n){
+ if(n == startNode){
+ return true;
+ }
+ if(af[n.id]){
+ return false;
+ }
+ var m = fn.call(scope || n, n);
+ if(!m || rv){
+ af[n.id] = n;
+ n.ui.hide();
+ return false;
+ }
+ return true;
+ };
+ startNode.cascade(f);
+ if(this.remove){
+ for(var id in af){
+ if(typeof id != "function"){
+ var n = af[id];
+ if(n && n.parentNode){
+ n.parentNode.removeChild(n);
+ }
+ }
+ }
+ }
+ },
+
+ /**
+ * Clears the current filter. Note: with the "remove" option
+ * set a filter cannot be cleared.
+ */
+ clear : function(){
+ var t = this.tree;
+ var af = this.filtered;
+ for(var id in af){
+ if(typeof id != "function"){
+ var n = af[id];
+ if(n){
+ n.ui.show();
+ }
+ }
+ }
+ this.filtered = {};
+ }
+};
+/**\r
+ * @class Ext.tree.TreeSorter\r
+ * Provides sorting of nodes in a {@link Ext.tree.TreePanel}. The TreeSorter automatically monitors events on the \r
+ * associated TreePanel that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).\r
+ * Example usage:<br />\r
+ * <pre><code>\r
+new Ext.tree.TreeSorter(myTree, {\r
+ folderSort: true,\r
+ dir: "desc",\r
+ sortType: function(node) {\r
+ // sort by a custom, typed attribute:\r
+ return parseInt(node.id, 10);\r
+ }\r
+});\r
+</code></pre>\r
+ * @constructor\r
+ * @param {TreePanel} tree\r
+ * @param {Object} config\r
+ */\r
+Ext.tree.TreeSorter = function(tree, config){\r
+ /**\r
+ * @cfg {Boolean} folderSort True to sort leaf nodes under non-leaf nodes (defaults to false)\r
+ */\r
+ /** \r
+ * @cfg {String} property The named attribute on the node to sort by (defaults to "text"). Note that this \r
+ * property is only used if no {@link #sortType} function is specified, otherwise it is ignored.\r
+ */\r
+ /** \r
+ * @cfg {String} dir The direction to sort ("asc" or "desc," case-insensitive, defaults to "asc")\r
+ */\r
+ /** \r
+ * @cfg {String} leafAttr The attribute used to determine leaf nodes when {@link #folderSort} = true (defaults to "leaf")\r
+ */\r
+ /** \r
+ * @cfg {Boolean} caseSensitive true for case-sensitive sort (defaults to false)\r
+ */\r
+ /** \r
+ * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting. The function\r
+ * will be called with a single parameter (the {@link Ext.tree.TreeNode} being evaluated) and is expected to return\r
+ * the node's sort value cast to the specific data type required for sorting. This could be used, for example, when\r
+ * a node's text (or other attribute) should be sorted as a date or numeric value. See the class description for \r
+ * example usage. Note that if a sortType is specified, any {@link #property} config will be ignored.\r
+ */\r
+ \r
+ Ext.apply(this, config);\r
+ tree.on("beforechildrenrendered", this.doSort, this);\r
+ tree.on("append", this.updateSort, this);\r
+ tree.on("insert", this.updateSort, this);\r
+ tree.on("textchange", this.updateSortParent, this);\r
+ \r
+ var dsc = this.dir && this.dir.toLowerCase() == "desc";\r
+ var p = this.property || "text";\r
+ var sortType = this.sortType;\r
+ var fs = this.folderSort;\r
+ var cs = this.caseSensitive === true;\r
+ var leafAttr = this.leafAttr || 'leaf';\r
+\r
+ this.sortFn = function(n1, n2){\r
+ if(fs){\r
+ if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){\r
+ return 1;\r
+ }\r
+ if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){\r
+ return -1;\r
+ }\r
+ }\r
+ var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());\r
+ var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());\r
+ if(v1 < v2){\r
+ return dsc ? +1 : -1;\r
+ }else if(v1 > v2){\r
+ return dsc ? -1 : +1;\r
+ }else{\r
+ return 0;\r
+ }\r
+ };\r
+};\r
+\r
+Ext.tree.TreeSorter.prototype = {\r
+ doSort : function(node){\r
+ node.sort(this.sortFn);\r
+ },\r
+ \r
+ compareNodes : function(n1, n2){\r
+ return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);\r
+ },\r
+ \r
+ updateSort : function(tree, node){\r
+ if(node.childrenRendered){\r
+ this.doSort.defer(1, this, [node]);\r
+ }\r
+ },\r
+ \r
+ updateSortParent : function(node){\r
+ var p = node.parentNode;\r
+ if(p && p.childrenRendered){\r
+ this.doSort.defer(1, this, [p]);\r
+ }\r
+ }\r
+};/**\r
+ * @class Ext.tree.TreeDropZone\r
+ * @extends Ext.dd.DropZone\r
+ * @constructor\r
+ * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dropping\r
+ * @param {Object} config\r
+ */\r
+if(Ext.dd.DropZone){\r
+ \r
+Ext.tree.TreeDropZone = function(tree, config){\r
+ /**\r
+ * @cfg {Boolean} allowParentInsert\r
+ * Allow inserting a dragged node between an expanded parent node and its first child that will become a\r
+ * sibling of the parent when dropped (defaults to false)\r
+ */\r
+ this.allowParentInsert = config.allowParentInsert || false;\r
+ /**\r
+ * @cfg {String} allowContainerDrop\r
+ * True if drops on the tree container (outside of a specific tree node) are allowed (defaults to false)\r
+ */\r
+ this.allowContainerDrop = config.allowContainerDrop || false;\r
+ /**\r
+ * @cfg {String} appendOnly\r
+ * True if the tree should only allow append drops (use for trees which are sorted, defaults to false)\r
+ */\r
+ this.appendOnly = config.appendOnly || false;\r
+\r
+ Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.getTreeEl(), config);\r
+ /**\r
+ * The TreePanel for this drop zone\r
+ * @type Ext.tree.TreePanel\r
+ * @property\r
+ */\r
+ this.tree = tree;\r
+ /**\r
+ * Arbitrary data that can be associated with this tree and will be included in the event object that gets\r
+ * passed to any nodedragover event handler (defaults to {})\r
+ * @type Ext.tree.TreePanel\r
+ * @property\r
+ */\r
+ this.dragOverData = {};\r
+ // private\r
+ this.lastInsertClass = "x-tree-no-status";\r
+};\r
+\r
+Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, {\r
+ /**\r
+ * @cfg {String} ddGroup\r
+ * A named drag drop group to which this object belongs. If a group is specified, then this object will only\r
+ * interact with other drag drop objects in the same group (defaults to 'TreeDD').\r
+ */\r
+ ddGroup : "TreeDD",\r
+\r
+ /**\r
+ * @cfg {String} expandDelay\r
+ * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node\r
+ * over the target (defaults to 1000)\r
+ */\r
+ expandDelay : 1000,\r
+\r
+ // private\r
+ expandNode : function(node){\r
+ if(node.hasChildNodes() && !node.isExpanded()){\r
+ node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));\r
+ }\r
+ },\r
+\r
+ // private\r
+ queueExpand : function(node){\r
+ this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);\r
+ },\r
+\r
+ // private\r
+ cancelExpand : function(){\r
+ if(this.expandProcId){\r
+ clearTimeout(this.expandProcId);\r
+ this.expandProcId = false;\r
+ }\r
+ },\r
+\r
+ // private\r
+ isValidDropPoint : function(n, pt, dd, e, data){\r
+ if(!n || !data){ return false; }\r
+ var targetNode = n.node;\r
+ var dropNode = data.node;\r
+ // default drop rules\r
+ if(!(targetNode && targetNode.isTarget && pt)){\r
+ return false;\r
+ }\r
+ if(pt == "append" && targetNode.allowChildren === false){\r
+ return false;\r
+ }\r
+ if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){\r
+ return false;\r
+ }\r
+ if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){\r
+ return false;\r
+ }\r
+ // reuse the object\r
+ var overEvent = this.dragOverData;\r
+ overEvent.tree = this.tree;\r
+ overEvent.target = targetNode;\r
+ overEvent.data = data;\r
+ overEvent.point = pt;\r
+ overEvent.source = dd;\r
+ overEvent.rawEvent = e;\r
+ overEvent.dropNode = dropNode;\r
+ overEvent.cancel = false; \r
+ var result = this.tree.fireEvent("nodedragover", overEvent);\r
+ return overEvent.cancel === false && result !== false;\r
+ },\r
+\r
+ // private\r
+ getDropPoint : function(e, n, dd){\r
+ var tn = n.node;\r
+ if(tn.isRoot){\r
+ return tn.allowChildren !== false ? "append" : false; // always append for root\r
+ }\r
+ var dragEl = n.ddel;\r
+ var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;\r
+ var y = Ext.lib.Event.getPageY(e);\r
+ var noAppend = tn.allowChildren === false || tn.isLeaf();\r
+ if(this.appendOnly || tn.parentNode.allowChildren === false){\r
+ return noAppend ? false : "append";\r
+ }\r
+ var noBelow = false;\r
+ if(!this.allowParentInsert){\r
+ noBelow = tn.hasChildNodes() && tn.isExpanded();\r
+ }\r
+ var q = (b - t) / (noAppend ? 2 : 3);\r
+ if(y >= t && y < (t + q)){\r
+ return "above";\r
+ }else if(!noBelow && (noAppend || y >= b-q && y <= b)){\r
+ return "below";\r
+ }else{\r
+ return "append";\r
+ }\r
+ },\r
+\r
+ // private\r
+ onNodeEnter : function(n, dd, e, data){\r
+ this.cancelExpand();\r
+ },\r
+ \r
+ onContainerOver : function(dd, e, data) {\r
+ if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {\r
+ return this.dropAllowed;\r
+ }\r
+ return this.dropNotAllowed;\r
+ },\r
+\r
+ // private\r
+ onNodeOver : function(n, dd, e, data){\r
+ var pt = this.getDropPoint(e, n, dd);\r
+ var node = n.node;\r
+ \r
+ // auto node expand check\r
+ if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){\r
+ this.queueExpand(node);\r
+ }else if(pt != "append"){\r
+ this.cancelExpand();\r
+ }\r
+ \r
+ // set the insert point style on the target node\r
+ var returnCls = this.dropNotAllowed;\r
+ if(this.isValidDropPoint(n, pt, dd, e, data)){\r
+ if(pt){\r
+ var el = n.ddel;\r
+ var cls;\r
+ if(pt == "above"){\r
+ returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";\r
+ cls = "x-tree-drag-insert-above";\r
+ }else if(pt == "below"){\r
+ returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";\r
+ cls = "x-tree-drag-insert-below";\r
+ }else{\r
+ returnCls = "x-tree-drop-ok-append";\r
+ cls = "x-tree-drag-append";\r
+ }\r
+ if(this.lastInsertClass != cls){\r
+ Ext.fly(el).replaceClass(this.lastInsertClass, cls);\r
+ this.lastInsertClass = cls;\r
+ }\r
+ }\r
+ }\r
+ return returnCls;\r
+ },\r
+\r
+ // private\r
+ onNodeOut : function(n, dd, e, data){\r
+ this.cancelExpand();\r
+ this.removeDropIndicators(n);\r
+ },\r
+\r
+ // private\r
+ onNodeDrop : function(n, dd, e, data){\r
+ var point = this.getDropPoint(e, n, dd);\r
+ var targetNode = n.node;\r
+ targetNode.ui.startDrop();\r
+ if(!this.isValidDropPoint(n, point, dd, e, data)){\r
+ targetNode.ui.endDrop();\r
+ return false;\r
+ }\r
+ // first try to find the drop node\r
+ var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);\r
+ return this.processDrop(targetNode, data, point, dd, e, dropNode);\r
+ },\r
+ \r
+ onContainerDrop : function(dd, e, data){\r
+ if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {\r
+ var targetNode = this.tree.getRootNode(); \r
+ targetNode.ui.startDrop();\r
+ var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, 'append', e) : null);\r
+ return this.processDrop(targetNode, data, 'append', dd, e, dropNode);\r
+ }\r
+ return false;\r
+ },\r
+ \r
+ // private\r
+ processDrop: function(target, data, point, dd, e, dropNode){\r
+ var dropEvent = {\r
+ tree : this.tree,\r
+ target: target,\r
+ data: data,\r
+ point: point,\r
+ source: dd,\r
+ rawEvent: e,\r
+ dropNode: dropNode,\r
+ cancel: !dropNode,\r
+ dropStatus: false\r
+ };\r
+ var retval = this.tree.fireEvent("beforenodedrop", dropEvent);\r
+ if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){\r
+ target.ui.endDrop();\r
+ return dropEvent.dropStatus;\r
+ }\r
+ \r
+ target = dropEvent.target;\r
+ if(point == 'append' && !target.isExpanded()){\r
+ target.expand(false, null, function(){\r
+ this.completeDrop(dropEvent);\r
+ }.createDelegate(this));\r
+ }else{\r
+ this.completeDrop(dropEvent);\r
+ }\r
+ return true;\r
+ },\r
+\r
+ // private\r
+ completeDrop : function(de){\r
+ var ns = de.dropNode, p = de.point, t = de.target;\r
+ if(!Ext.isArray(ns)){\r
+ ns = [ns];\r
+ }\r
+ var n;\r
+ for(var i = 0, len = ns.length; i < len; i++){\r
+ n = ns[i];\r
+ if(p == "above"){\r
+ t.parentNode.insertBefore(n, t);\r
+ }else if(p == "below"){\r
+ t.parentNode.insertBefore(n, t.nextSibling);\r
+ }else{\r
+ t.appendChild(n);\r
+ }\r
+ }\r
+ n.ui.focus();\r
+ if(Ext.enableFx && this.tree.hlDrop){\r
+ n.ui.highlight();\r
+ }\r
+ t.ui.endDrop();\r
+ this.tree.fireEvent("nodedrop", de);\r
+ },\r
+\r
+ // private\r
+ afterNodeMoved : function(dd, data, e, targetNode, dropNode){\r
+ if(Ext.enableFx && this.tree.hlDrop){\r
+ dropNode.ui.focus();\r
+ dropNode.ui.highlight();\r
+ }\r
+ this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);\r
+ },\r
+\r
+ // private\r
+ getTree : function(){\r
+ return this.tree;\r
+ },\r
+\r
+ // private\r
+ removeDropIndicators : function(n){\r
+ if(n && n.ddel){\r
+ var el = n.ddel;\r
+ Ext.fly(el).removeClass([\r
+ "x-tree-drag-insert-above",\r
+ "x-tree-drag-insert-below",\r
+ "x-tree-drag-append"]);\r
+ this.lastInsertClass = "_noclass";\r
+ }\r
+ },\r
+\r
+ // private\r
+ beforeDragDrop : function(target, e, id){\r
+ this.cancelExpand();\r
+ return true;\r
+ },\r
+\r
+ // private\r
+ afterRepair : function(data){\r
+ if(data && Ext.enableFx){\r
+ data.node.ui.highlight();\r
+ }\r
+ this.hideProxy();\r
+ } \r
+});\r
+\r
+}/**\r
+ * @class Ext.tree.TreeDragZone\r
+ * @extends Ext.dd.DragZone\r
+ * @constructor\r
+ * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dragging\r
+ * @param {Object} config\r
+ */\r
+if(Ext.dd.DragZone){\r
+Ext.tree.TreeDragZone = function(tree, config){\r
+ Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.innerCt, config);\r
+ /**\r
+ * The TreePanel for this drag zone\r
+ * @type Ext.tree.TreePanel\r
+ * @property\r
+ */\r
+ this.tree = tree;\r
+};\r
+\r
+Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, {\r
+ /**\r
+ * @cfg {String} ddGroup\r
+ * A named drag drop group to which this object belongs. If a group is specified, then this object will only\r
+ * interact with other drag drop objects in the same group (defaults to 'TreeDD').\r
+ */\r
+ ddGroup : "TreeDD",\r
+\r
+ // private\r
+ onBeforeDrag : function(data, e){\r
+ var n = data.node;\r
+ return n && n.draggable && !n.disabled;\r
+ },\r
+\r
+ // private\r
+ onInitDrag : function(e){\r
+ var data = this.dragData;\r
+ this.tree.getSelectionModel().select(data.node);\r
+ this.tree.eventModel.disable();\r
+ this.proxy.update("");\r
+ data.node.ui.appendDDGhost(this.proxy.ghost.dom);\r
+ this.tree.fireEvent("startdrag", this.tree, data.node, e);\r
+ },\r
+\r
+ // private\r
+ getRepairXY : function(e, data){\r
+ return data.node.ui.getDDRepairXY();\r
+ },\r
+\r
+ // private\r
+ onEndDrag : function(data, e){\r
+ this.tree.eventModel.enable.defer(100, this.tree.eventModel);\r
+ this.tree.fireEvent("enddrag", this.tree, data.node, e);\r
+ },\r
+\r
+ // private\r
+ onValidDrop : function(dd, e, id){\r
+ this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);\r
+ this.hideProxy();\r
+ },\r
+\r
+ // private\r
+ beforeInvalidDrop : function(e, id){\r
+ // this scrolls the original position back into view\r
+ var sm = this.tree.getSelectionModel();\r
+ sm.clearSelections();\r
+ sm.select(this.dragData.node);\r
+ },\r
+ \r
+ // private\r
+ afterRepair : function(){\r
+ if (Ext.enableFx && this.tree.hlDrop) {\r
+ Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");\r
+ }\r
+ this.dragging = false;\r
+ }\r
+});\r
+}/**
+ * @class Ext.tree.TreeEditor
+ * @extends Ext.Editor
+ * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
+ * as the editor field.
+ * @constructor
+ * @param {TreePanel} tree
+ * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
+ * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
+ * @param {Object} config (optional) A TreeEditor config object
+ */
+Ext.tree.TreeEditor = function(tree, fc, config){
+ fc = fc || {};
+ var field = fc.events ? fc : new Ext.form.TextField(fc);
+ Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
+
+ this.tree = tree;
+
+ if(!tree.rendered){
+ tree.on('render', this.initEditor, this);
+ }else{
+ this.initEditor(tree);
+ }
+};
+
+Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
+ /**
+ * @cfg {String} alignment
+ * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "l-l").
+ */
+ alignment: "l-l",
+ // inherit
+ autoSize: false,
+ /**
+ * @cfg {Boolean} hideEl
+ * True to hide the bound element while the editor is displayed (defaults to false)
+ */
+ hideEl : false,
+ /**
+ * @cfg {String} cls
+ * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
+ */
+ cls: "x-small-editor x-tree-editor",
+ /**
+ * @cfg {Boolean} shim
+ * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
+ */
+ shim:false,
+ // inherit
+ shadow:"frame",
+ /**
+ * @cfg {Number} maxWidth
+ * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
+ * the containing tree element's size, it will be automatically limited for you to the container width, taking
+ * scroll and client offsets into account prior to each edit.
+ */
+ maxWidth: 250,
+ /**
+ * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
+ * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
+ * the editor for the node will display, otherwise it will be processed as a regular click.
+ */
+ editDelay : 350,
+
+ initEditor : function(tree){
+ tree.on('beforeclick', this.beforeNodeClick, this);
+ tree.on('dblclick', this.onNodeDblClick, this);
+ this.on('complete', this.updateNode, this);
+ this.on('beforestartedit', this.fitToTree, this);
+ this.on('startedit', this.bindScroll, this, {delay:10});
+ this.on('specialkey', this.onSpecialKey, this);
+ },
+
+ // private
+ fitToTree : function(ed, el){
+ var td = this.tree.getTreeEl().dom, nd = el.dom;
+ if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
+ td.scrollLeft = nd.offsetLeft;
+ }
+ var w = Math.min(
+ this.maxWidth,
+ (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
+ this.setSize(w, '');
+ },
+
+ /**
+ * Edit the text of the passed {@link Ext.tree.TreeNode TreeNode}.
+ * @param node {Ext.tree.TreeNode} The TreeNode to edit. The TreeNode must be {@link Ext.tree.TreeNode#editable editable}.
+ */
+ triggerEdit : function(node, defer){
+ this.completeEdit();
+ if(node.attributes.editable !== false){
+ /**
+ * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
+ * @type Ext.tree.TreeNode
+ * @property editNode
+ */
+ this.editNode = node;
+ if(this.tree.autoScroll){
+ Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
+ }
+ var value = node.text || '';
+ if (!Ext.isGecko && Ext.isEmpty(node.text)){
+ node.setText(' ');
+ }
+ this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
+ return false;
+ }
+ },
+
+ // private
+ bindScroll : function(){
+ this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
+ },
+
+ // private
+ beforeNodeClick : function(node, e){
+ clearTimeout(this.autoEditTimer);
+ if(this.tree.getSelectionModel().isSelected(node)){
+ e.stopEvent();
+ return this.triggerEdit(node);
+ }
+ },
+
+ onNodeDblClick : function(node, e){
+ clearTimeout(this.autoEditTimer);
+ },
+
+ // private
+ updateNode : function(ed, value){
+ this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
+ this.editNode.setText(value);
+ },
+
+ // private
+ onHide : function(){
+ Ext.tree.TreeEditor.superclass.onHide.call(this);
+ if(this.editNode){
+ this.editNode.ui.focus.defer(50, this.editNode.ui);
+ }
+ },
+
+ // private
+ onSpecialKey : function(field, e){
+ var k = e.getKey();
+ if(k == e.ESC){
+ e.stopEvent();
+ this.cancelEdit();
+ }else if(k == e.ENTER && !e.hasModifier()){
+ e.stopEvent();
+ this.completeEdit();
+ }
+ }
+});
\ No newline at end of file