3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 * @class Ext.tree.TreePanel
10 * <p>The TreePanel provides tree-structured UI representation of tree-structured data.</p>
11 * <p>{@link Ext.tree.TreeNode TreeNode}s added to the TreePanel may each contain metadata
12 * used by your application in their {@link Ext.tree.TreeNode#attributes attributes} property.</p>
13 * <p><b>A TreePanel must have a {@link #root} node before it is rendered.</b> This may either be
14 * specified using the {@link #root} config option, or using the {@link #setRootNode} method.
15 * <p>An example of tree rendered to an existing div:</p><pre><code>
16 var tree = new Ext.tree.TreePanel({
22 containerScroll: true,
24 // auto create TreeLoader
25 dataUrl: 'get-nodes.php',
35 tree.getRootNode().expand();
37 * <p>The example above would work with a data packet similar to this:</p><pre><code>
40 "id": "source\/adapter",
48 "id": "source\/debug.js",
53 * <p>An example of tree within a Viewport:</p><pre><code>
64 loader: new Ext.tree.TreeLoader(),
65 root: new Ext.tree.AsyncTreeNode({
68 text: 'Menu Option 1',
71 text: 'Menu Option 2',
74 text: 'Menu Option 3',
81 Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
87 // remaining code not shown ...
92 * @cfg {Ext.tree.TreeNode} root The root node for the tree.
93 * @cfg {Boolean} rootVisible <tt>false</tt> to hide the root node (defaults to <tt>true</tt>)
94 * @cfg {Boolean} lines <tt>false</tt> to disable tree lines (defaults to <tt>true</tt>)
95 * @cfg {Boolean} enableDD <tt>true</tt> to enable drag and drop
96 * @cfg {Boolean} enableDrag <tt>true</tt> to enable just drag
97 * @cfg {Boolean} enableDrop <tt>true</tt> to enable just drop
98 * @cfg {Object} dragConfig Custom config to pass to the {@link Ext.tree.TreeDragZone} instance
99 * @cfg {Object} dropConfig Custom config to pass to the {@link Ext.tree.TreeDropZone} instance
100 * @cfg {String} ddGroup The DD group this TreePanel belongs to
101 * @cfg {Boolean} ddAppendOnly <tt>true</tt> if the tree should only allow append drops (use for trees which are sorted)
102 * @cfg {Boolean} ddScroll <tt>true</tt> to enable body scrolling
103 * @cfg {Boolean} containerScroll <tt>true</tt> to register this container with ScrollManager
104 * @cfg {Boolean} hlDrop <tt>false</tt> to disable node highlight on drop (defaults to the value of {@link Ext#enableFx})
105 * @cfg {String} hlColor The color of the node highlight (defaults to <tt>'C3DAF9'</tt>)
106 * @cfg {Boolean} animate <tt>true</tt> to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx})
107 * @cfg {Boolean} singleExpand <tt>true</tt> if only 1 node per branch may be expanded
108 * @cfg {Object} selModel A tree selection model to use with this TreePanel (defaults to an {@link Ext.tree.DefaultSelectionModel})
109 * @cfg {Boolean} trackMouseOver <tt>false</tt> to disable mouse over highlighting
110 * @cfg {Ext.tree.TreeLoader} loader A {@link Ext.tree.TreeLoader} for use with this TreePanel
111 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to <tt>'/'</tt>)
112 * @cfg {Boolean} useArrows <tt>true</tt> to use Vista-style arrows in the tree (defaults to <tt>false</tt>)
113 * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
116 * @param {Object} config
119 Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
121 animate : Ext.enableFx,
124 hlDrop : Ext.enableFx,
128 * @cfg {Array} bubbleEvents
129 * <p>An array of events that, when fired, should be bubbled to any parent container.
130 * See {@link Ext.util.Observable#enableBubble}.
131 * Defaults to <tt>[]</tt>.
135 initComponent : function(){
136 Ext.tree.TreePanel.superclass.initComponent.call(this);
138 if(!this.eventModel){
139 this.eventModel = new Ext.tree.TreeEventModel(this);
142 // initialize the loader
145 l = new Ext.tree.TreeLoader({
146 dataUrl: this.dataUrl,
147 requestMethod: this.requestMethod
149 }else if(Ext.isObject(l) && !l.load){
150 l = new Ext.tree.TreeLoader(l);
157 * The root node of this tree.
158 * @type Ext.tree.TreeNode
172 * Fires when a new child node is appended to a node in this tree.
173 * @param {Tree} tree The owner tree
174 * @param {Node} parent The parent node
175 * @param {Node} node The newly appended node
176 * @param {Number} index The index of the newly appended node
181 * Fires when a child node is removed from a node in this tree.
182 * @param {Tree} tree The owner tree
183 * @param {Node} parent The parent node
184 * @param {Node} node The child node removed
189 * Fires when a node is moved to a new location in the tree
190 * @param {Tree} tree The owner tree
191 * @param {Node} node The node moved
192 * @param {Node} oldParent The old parent of this node
193 * @param {Node} newParent The new parent of this node
194 * @param {Number} index The index it was moved to
199 * Fires when a new child node is inserted in a node in this tree.
200 * @param {Tree} tree The owner tree
201 * @param {Node} parent The parent node
202 * @param {Node} node The child node inserted
203 * @param {Node} refNode The child node the node was inserted before
207 * @event beforeappend
208 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
209 * @param {Tree} tree The owner tree
210 * @param {Node} parent The parent node
211 * @param {Node} node The child node to be appended
215 * @event beforeremove
216 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
217 * @param {Tree} tree The owner tree
218 * @param {Node} parent The parent node
219 * @param {Node} node The child node to be removed
223 * @event beforemovenode
224 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
225 * @param {Tree} tree The owner tree
226 * @param {Node} node The node being moved
227 * @param {Node} oldParent The parent of the node
228 * @param {Node} newParent The new parent the node is moving to
229 * @param {Number} index The index it is being moved to
233 * @event beforeinsert
234 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
235 * @param {Tree} tree The owner tree
236 * @param {Node} parent The parent node
237 * @param {Node} node The child node to be inserted
238 * @param {Node} refNode The child node the node is being inserted before
244 * Fires before a node is loaded, return false to cancel
245 * @param {Node} node The node being loaded
250 * Fires when a node is loaded
251 * @param {Node} node The node that was loaded
256 * Fires when the text for a node is changed
257 * @param {Node} node The node
258 * @param {String} text The new text
259 * @param {String} oldText The old text
263 * @event beforeexpandnode
264 * Fires before a node is expanded, return false to cancel.
265 * @param {Node} node The node
266 * @param {Boolean} deep
267 * @param {Boolean} anim
271 * @event beforecollapsenode
272 * Fires before a node is collapsed, return false to cancel.
273 * @param {Node} node The node
274 * @param {Boolean} deep
275 * @param {Boolean} anim
277 'beforecollapsenode',
280 * Fires when a node is expanded
281 * @param {Node} node The node
285 * @event disabledchange
286 * Fires when the disabled status of a node changes
287 * @param {Node} node The node
288 * @param {Boolean} disabled
292 * @event collapsenode
293 * Fires when a node is collapsed
294 * @param {Node} node The node
299 * Fires before click processing on a node. Return false to cancel the default action.
300 * @param {Node} node The node
301 * @param {Ext.EventObject} e The event object
306 * Fires when a node is clicked
307 * @param {Node} node The node
308 * @param {Ext.EventObject} e The event object
312 * @event containerclick
313 * Fires when the tree container is clicked
315 * @param {Ext.EventObject} e The event object
320 * Fires when a node with a checkbox's checked property changes
321 * @param {Node} this This node
322 * @param {Boolean} checked
326 * @event beforedblclick
327 * Fires before double click processing on a node. Return false to cancel the default action.
328 * @param {Node} node The node
329 * @param {Ext.EventObject} e The event object
334 * Fires when a node is double clicked
335 * @param {Node} node The node
336 * @param {Ext.EventObject} e The event object
340 * @event containerdblclick
341 * Fires when the tree container is double clicked
343 * @param {Ext.EventObject} e The event object
348 * Fires when a node is right clicked. To display a context menu in response to this
349 * event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add
350 * a handler for this event:<pre><code>
351 new Ext.tree.TreePanel({
352 title: 'My TreePanel',
353 root: new Ext.tree.AsyncTreeNode({
356 { text: 'Child node 1', leaf: true },
357 { text: 'Child node 2', leaf: true }
360 contextMenu: new Ext.menu.Menu({
366 itemclick: function(item) {
369 var n = item.parentMenu.contextNode;
379 contextmenu: function(node, e) {
380 // Register the context node with the menu so that a Menu Item's handler function can access
381 // it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.
383 var c = node.getOwnerTree().contextMenu;
384 c.contextNode = node;
390 * @param {Node} node The node
391 * @param {Ext.EventObject} e The event object
395 * @event containercontextmenu
396 * Fires when the tree container is right clicked
398 * @param {Ext.EventObject} e The event object
400 'containercontextmenu',
402 * @event beforechildrenrendered
403 * Fires right before the child nodes for a node are rendered
404 * @param {Node} node The node
406 'beforechildrenrendered',
409 * Fires when a node starts being dragged
410 * @param {Ext.tree.TreePanel} this
411 * @param {Ext.tree.TreeNode} node
412 * @param {event} e The raw browser event
417 * Fires when a drag operation is complete
418 * @param {Ext.tree.TreePanel} this
419 * @param {Ext.tree.TreeNode} node
420 * @param {event} e The raw browser event
425 * Fires when a dragged node is dropped on a valid DD target
426 * @param {Ext.tree.TreePanel} this
427 * @param {Ext.tree.TreeNode} node
428 * @param {DD} dd The dd it was dropped on
429 * @param {event} e The raw browser event
433 * @event beforenodedrop
434 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
435 * passed to handlers has the following properties:<br />
436 * <ul style="padding:5px;padding-left:16px;">
437 * <li>tree - The TreePanel</li>
438 * <li>target - The node being targeted for the drop</li>
439 * <li>data - The drag data from the drag source</li>
440 * <li>point - The point of the drop - append, above or below</li>
441 * <li>source - The drag source</li>
442 * <li>rawEvent - Raw mouse event</li>
443 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
444 * to be inserted by setting them on this object.</li>
445 * <li>cancel - Set this to true to cancel the drop.</li>
446 * <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true
447 * will prevent the animated 'repair' from appearing.</li>
449 * @param {Object} dropEvent
454 * Fires after a DD object is dropped on a node in this tree. The dropEvent
455 * passed to handlers has the following properties:<br />
456 * <ul style="padding:5px;padding-left:16px;">
457 * <li>tree - The TreePanel</li>
458 * <li>target - The node being targeted for the drop</li>
459 * <li>data - The drag data from the drag source</li>
460 * <li>point - The point of the drop - append, above or below</li>
461 * <li>source - The drag source</li>
462 * <li>rawEvent - Raw mouse event</li>
463 * <li>dropNode - Dropped node(s).</li>
465 * @param {Object} dropEvent
469 * @event nodedragover
470 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
471 * passed to handlers has the following properties:<br />
472 * <ul style="padding:5px;padding-left:16px;">
473 * <li>tree - The TreePanel</li>
474 * <li>target - The node being targeted for the drop</li>
475 * <li>data - The drag data from the drag source</li>
476 * <li>point - The point of the drop - append, above or below</li>
477 * <li>source - The drag source</li>
478 * <li>rawEvent - Raw mouse event</li>
479 * <li>dropNode - Drop node(s) provided by the source.</li>
480 * <li>cancel - Set this to true to signal drop not allowed.</li>
482 * @param {Object} dragOverEvent
486 if(this.singleExpand){
487 this.on('beforeexpandnode', this.restrictExpand, this);
492 proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){
493 if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){
494 ename = ename+'node';
496 // args inline for performance while bubbling events
497 return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);
502 * Returns this root node for this tree
505 getRootNode : function(){
510 * Sets the root node for this tree. If the TreePanel has already rendered a root node, the
511 * previous root node (and all of its descendants) are destroyed before the new root node is rendered.
515 setRootNode : function(node){
517 if(!node.render){ // attributes passed
518 node = this.loader.createNode(node);
521 node.ownerTree = this;
523 this.registerNode(node);
524 if(!this.rootVisible){
525 var uiP = node.attributes.uiProvider;
526 node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);
535 clearInnerCt : function(){
536 this.innerCt.update('');
540 renderRoot : function(){
542 if(!this.rootVisible){
543 this.root.renderChildren();
548 * Gets a node in this tree by its id
552 getNodeById : function(id){
553 return this.nodeHash[id];
557 registerNode : function(node){
558 this.nodeHash[node.id] = node;
562 unregisterNode : function(node){
563 delete this.nodeHash[node.id];
567 toString : function(){
568 return '[Tree'+(this.id?' '+this.id:'')+']';
572 restrictExpand : function(node){
573 var p = node.parentNode;
575 if(p.expandedChild && p.expandedChild.parentNode == p){
576 p.expandedChild.collapse();
578 p.expandedChild = node;
583 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. 'id')
584 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
585 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
588 getChecked : function(a, startNode){
589 startNode = startNode || this.root;
592 if(this.attributes.checked){
593 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
596 startNode.cascade(f);
601 * Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.
602 * @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.
604 getLoader : function(){
611 expandAll : function(){
612 this.root.expand(true);
618 collapseAll : function(){
619 this.root.collapse(true);
623 * Returns the selection model used by this TreePanel.
624 * @return {TreeSelectionModel} The selection model used by this TreePanel
626 getSelectionModel : function(){
628 this.selModel = new Ext.tree.DefaultSelectionModel();
630 return this.selModel;
634 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
635 * @param {String} path
636 * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
637 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
638 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
640 expandPath : function(path, attr, callback){
641 if(Ext.isEmpty(path)){
643 callback(false, undefined);
648 var keys = path.split(this.pathSeparator);
649 var curNode = this.root;
650 if(curNode.attributes[attr] != keys[1]){ // invalid root
652 callback(false, null);
658 if(++index == keys.length){
660 callback(true, curNode);
664 var c = curNode.findChild(attr, keys[index]);
667 callback(false, curNode);
672 c.expand(false, false, f);
674 curNode.expand(false, false, f);
678 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
679 * @param {String} path
680 * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
681 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
682 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
684 selectPath : function(path, attr, callback){
685 if(Ext.isEmpty(path)){
687 callback(false, undefined);
692 var keys = path.split(this.pathSeparator),
695 var f = function(success, node){
697 var n = node.findChild(attr, v);
712 this.expandPath(keys.join(this.pathSeparator), attr, f);
716 callback(true, this.root);
722 * Returns the underlying Element for this tree
723 * @return {Ext.Element} The Element
725 getTreeEl : function(){
730 onRender : function(ct, position){
731 Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
732 this.el.addClass('x-tree');
733 this.innerCt = this.body.createChild({tag:'ul',
734 cls:'x-tree-root-ct ' +
735 (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')});
739 initEvents : function(){
740 Ext.tree.TreePanel.superclass.initEvents.call(this);
742 if(this.containerScroll){
743 Ext.dd.ScrollManager.register(this.body);
745 if((this.enableDD || this.enableDrop) && !this.dropZone){
747 * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
749 * @type Ext.tree.TreeDropZone
751 this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
752 ddGroup: this.ddGroup || 'TreeDD', appendOnly: this.ddAppendOnly === true
755 if((this.enableDD || this.enableDrag) && !this.dragZone){
757 * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
759 * @type Ext.tree.TreeDragZone
761 this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
762 ddGroup: this.ddGroup || 'TreeDD',
763 scroll: this.ddScroll
766 this.getSelectionModel().init(this);
770 afterRender : function(){
771 Ext.tree.TreePanel.superclass.afterRender.call(this);
775 beforeDestroy : function(){
777 Ext.dd.ScrollManager.unregister(this.body);
778 Ext.destroy(this.dropZone, this.dragZone);
781 Ext.destroy(this.loader);
782 this.nodeHash = this.root = this.loader = null;
783 Ext.tree.TreePanel.superclass.beforeDestroy.call(this);
787 * Destroy the root node. Not included by itself because we need to pass the silent parameter.
790 destroyRoot : function(){
791 if(this.root && this.root.destroy){
792 this.root.destroy(true);
797 * @cfg {String/Number} activeItem
801 * @cfg {Boolean} autoDestroy
805 * @cfg {Object/String/Function} autoLoad
809 * @cfg {Boolean} autoWidth
813 * @cfg {Boolean/Number} bufferResize
817 * @cfg {String} defaultType
821 * @cfg {Object} defaults
825 * @cfg {Boolean} hideBorders
833 * @cfg {String} layout
837 * @cfg {Object} layoutConfig
841 * @cfg {Boolean} monitorResize
873 * @method getComponent
913 * @event beforeremove
924 * @cfg {String} allowDomMove @hide
927 * @cfg {String} autoEl @hide
930 * @cfg {String} applyTo @hide
933 * @cfg {String} contentEl @hide
936 * @cfg {Mixed} data @hide
939 * @cfg {Mixed} tpl @hide
942 * @cfg {String} tplWriteMode @hide
945 * @cfg {String} disabledClass @hide
948 * @cfg {String} elements @hide
951 * @cfg {String} html @hide
954 * @cfg {Boolean} preventBodyReset
962 * @method applyToMarkup
974 * @method setDisabled
979 Ext.tree.TreePanel.nodeTypes = {};
981 Ext.reg('treepanel', Ext.tree.TreePanel);Ext.tree.TreeEventModel = function(tree){
983 this.tree.on('render', this.initEvents, this);
986 Ext.tree.TreeEventModel.prototype = {
987 initEvents : function(){
990 if(t.trackMouseOver !== false){
993 mouseover: this.delegateOver,
994 mouseout: this.delegateOut
997 t.mon(t.getTreeEl(), {
999 click: this.delegateClick,
1000 dblclick: this.delegateDblClick,
1001 contextmenu: this.delegateContextMenu
1005 getNode : function(e){
1007 if(t = e.getTarget('.x-tree-node-el', 10)){
1008 var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
1010 return this.tree.getNodeById(id);
1016 getNodeTarget : function(e){
1017 var t = e.getTarget('.x-tree-node-icon', 1);
1019 t = e.getTarget('.x-tree-node-el', 6);
1024 delegateOut : function(e, t){
1025 if(!this.beforeEvent(e)){
1028 if(e.getTarget('.x-tree-ec-icon', 1)){
1029 var n = this.getNode(e);
1030 this.onIconOut(e, n);
1031 if(n == this.lastEcOver){
1032 delete this.lastEcOver;
1035 if((t = this.getNodeTarget(e)) && !e.within(t, true)){
1036 this.onNodeOut(e, this.getNode(e));
1040 delegateOver : function(e, t){
1041 if(!this.beforeEvent(e)){
1044 if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
1045 Ext.getBody().on('mouseover', this.trackExit, this);
1046 this.trackingDoc = true;
1048 if(this.lastEcOver){ // prevent hung highlight
1049 this.onIconOut(e, this.lastEcOver);
1050 delete this.lastEcOver;
1052 if(e.getTarget('.x-tree-ec-icon', 1)){
1053 this.lastEcOver = this.getNode(e);
1054 this.onIconOver(e, this.lastEcOver);
1056 if(t = this.getNodeTarget(e)){
1057 this.onNodeOver(e, this.getNode(e));
1061 trackExit : function(e){
1062 if(this.lastOverNode){
1063 if(this.lastOverNode.ui && !e.within(this.lastOverNode.ui.getEl())){
1064 this.onNodeOut(e, this.lastOverNode);
1066 delete this.lastOverNode;
1067 Ext.getBody().un('mouseover', this.trackExit, this);
1068 this.trackingDoc = false;
1073 delegateClick : function(e, t){
1074 if(this.beforeEvent(e)){
1075 if(e.getTarget('input[type=checkbox]', 1)){
1076 this.onCheckboxClick(e, this.getNode(e));
1077 }else if(e.getTarget('.x-tree-ec-icon', 1)){
1078 this.onIconClick(e, this.getNode(e));
1079 }else if(this.getNodeTarget(e)){
1080 this.onNodeClick(e, this.getNode(e));
1083 this.checkContainerEvent(e, 'click');
1087 delegateDblClick : function(e, t){
1088 if(this.beforeEvent(e)){
1089 if(this.getNodeTarget(e)){
1090 this.onNodeDblClick(e, this.getNode(e));
1093 this.checkContainerEvent(e, 'dblclick');
1097 delegateContextMenu : function(e, t){
1098 if(this.beforeEvent(e)){
1099 if(this.getNodeTarget(e)){
1100 this.onNodeContextMenu(e, this.getNode(e));
1103 this.checkContainerEvent(e, 'contextmenu');
1107 checkContainerEvent: function(e, type){
1112 this.onContainerEvent(e, type);
1115 onContainerEvent: function(e, type){
1116 this.tree.fireEvent('container' + type, this.tree, e);
1119 onNodeClick : function(e, node){
1123 onNodeOver : function(e, node){
1124 this.lastOverNode = node;
1128 onNodeOut : function(e, node){
1132 onIconOver : function(e, node){
1133 node.ui.addClass('x-tree-ec-over');
1136 onIconOut : function(e, node){
1137 node.ui.removeClass('x-tree-ec-over');
1140 onIconClick : function(e, node){
1144 onCheckboxClick : function(e, node){
1145 node.ui.onCheckChange(e);
1148 onNodeDblClick : function(e, node){
1149 node.ui.onDblClick(e);
1152 onNodeContextMenu : function(e, node){
1153 node.ui.onContextMenu(e);
1156 beforeEvent : function(e){
1157 var node = this.getNode(e);
1158 if(this.disabled || !node || !node.ui){
1165 disable: function(){
1166 this.disabled = true;
1170 this.disabled = false;
1173 * @class Ext.tree.DefaultSelectionModel
1174 * @extends Ext.util.Observable
1175 * The default single selection for a TreePanel.
1177 Ext.tree.DefaultSelectionModel = Ext.extend(Ext.util.Observable, {
1179 constructor : function(config){
1180 this.selNode = null;
1184 * @event selectionchange
1185 * Fires when the selected node changes
1186 * @param {DefaultSelectionModel} this
1187 * @param {TreeNode} node the new selection
1192 * @event beforeselect
1193 * Fires before the selected node changes, return false to cancel the change
1194 * @param {DefaultSelectionModel} this
1195 * @param {TreeNode} node the new selection
1196 * @param {TreeNode} node the old selection
1201 Ext.apply(this, config);
1202 Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
1205 init : function(tree){
1207 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
1208 tree.on('click', this.onNodeClick, this);
1211 onNodeClick : function(node, e){
1217 * @param {TreeNode} node The node to select
1218 * @return {TreeNode} The selected node
1220 select : function(node, /* private*/ selectNextNode){
1221 // If node is hidden, select the next node in whatever direction was being moved in.
1222 if (!Ext.fly(node.ui.wrap).isVisible() && selectNextNode) {
1223 return selectNextNode.call(this, node);
1225 var last = this.selNode;
1227 node.ui.onSelectedChange(true);
1228 }else if(this.fireEvent('beforeselect', this, node, last) !== false){
1229 if(last && last.ui){
1230 last.ui.onSelectedChange(false);
1232 this.selNode = node;
1233 node.ui.onSelectedChange(true);
1234 this.fireEvent('selectionchange', this, node, last);
1241 * @param {TreeNode} node The node to unselect
1242 * @param {Boolean} silent True to stop the selectionchange event from firing.
1244 unselect : function(node, silent){
1245 if(this.selNode == node){
1246 this.clearSelections(silent);
1251 * Clear all selections
1252 * @param {Boolean} silent True to stop the selectionchange event from firing.
1254 clearSelections : function(silent){
1255 var n = this.selNode;
1257 n.ui.onSelectedChange(false);
1258 this.selNode = null;
1259 if(silent !== true){
1260 this.fireEvent('selectionchange', this, null);
1267 * Get the selected node
1268 * @return {TreeNode} The selected node
1270 getSelectedNode : function(){
1271 return this.selNode;
1275 * Returns true if the node is selected
1276 * @param {TreeNode} node The node to check
1279 isSelected : function(node){
1280 return this.selNode == node;
1284 * Selects the node above the selected node in the tree, intelligently walking the nodes
1285 * @return TreeNode The new selection
1287 selectPrevious : function(/* private */ s){
1288 if(!(s = s || this.selNode || this.lastSelNode)){
1291 // Here we pass in the current function to select to indicate the direction we're moving
1292 var ps = s.previousSibling;
1294 if(!ps.isExpanded() || ps.childNodes.length < 1){
1295 return this.select(ps, this.selectPrevious);
1297 var lc = ps.lastChild;
1298 while(lc && lc.isExpanded() && Ext.fly(lc.ui.wrap).isVisible() && lc.childNodes.length > 0){
1301 return this.select(lc, this.selectPrevious);
1303 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
1304 return this.select(s.parentNode, this.selectPrevious);
1310 * Selects the node above the selected node in the tree, intelligently walking the nodes
1311 * @return TreeNode The new selection
1313 selectNext : function(/* private */ s){
1314 if(!(s = s || this.selNode || this.lastSelNode)){
1317 // Here we pass in the current function to select to indicate the direction we're moving
1318 if(s.firstChild && s.isExpanded() && Ext.fly(s.ui.wrap).isVisible()){
1319 return this.select(s.firstChild, this.selectNext);
1320 }else if(s.nextSibling){
1321 return this.select(s.nextSibling, this.selectNext);
1322 }else if(s.parentNode){
1324 s.parentNode.bubble(function(){
1325 if(this.nextSibling){
1326 newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);
1335 onKeyDown : function(e){
1336 var s = this.selNode || this.lastSelNode;
1337 // undesirable, but required
1350 this.selectPrevious();
1354 if(s.hasChildNodes()){
1355 if(!s.isExpanded()){
1357 }else if(s.firstChild){
1358 this.select(s.firstChild, e);
1364 if(s.hasChildNodes() && s.isExpanded()){
1366 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
1367 this.select(s.parentNode, e);
1375 * @class Ext.tree.MultiSelectionModel
1376 * @extends Ext.util.Observable
1377 * Multi selection for a TreePanel.
1379 Ext.tree.MultiSelectionModel = Ext.extend(Ext.util.Observable, {
1381 constructor : function(config){
1386 * @event selectionchange
1387 * Fires when the selected nodes change
1388 * @param {MultiSelectionModel} this
1389 * @param {Array} nodes Array of the selected nodes
1393 Ext.apply(this, config);
1394 Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
1397 init : function(tree){
1399 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
1400 tree.on('click', this.onNodeClick, this);
1403 onNodeClick : function(node, e){
1404 if(e.ctrlKey && this.isSelected(node)){
1405 this.unselect(node);
1407 this.select(node, e, e.ctrlKey);
1413 * @param {TreeNode} node The node to select
1414 * @param {EventObject} e (optional) An event associated with the selection
1415 * @param {Boolean} keepExisting True to retain existing selections
1416 * @return {TreeNode} The selected node
1418 select : function(node, e, keepExisting){
1419 if(keepExisting !== true){
1420 this.clearSelections(true);
1422 if(this.isSelected(node)){
1423 this.lastSelNode = node;
1426 this.selNodes.push(node);
1427 this.selMap[node.id] = node;
1428 this.lastSelNode = node;
1429 node.ui.onSelectedChange(true);
1430 this.fireEvent('selectionchange', this, this.selNodes);
1436 * @param {TreeNode} node The node to unselect
1438 unselect : function(node){
1439 if(this.selMap[node.id]){
1440 node.ui.onSelectedChange(false);
1441 var sn = this.selNodes;
1442 var index = sn.indexOf(node);
1444 this.selNodes.splice(index, 1);
1446 delete this.selMap[node.id];
1447 this.fireEvent('selectionchange', this, this.selNodes);
1452 * Clear all selections
1454 clearSelections : function(suppressEvent){
1455 var sn = this.selNodes;
1457 for(var i = 0, len = sn.length; i < len; i++){
1458 sn[i].ui.onSelectedChange(false);
1462 if(suppressEvent !== true){
1463 this.fireEvent('selectionchange', this, this.selNodes);
1469 * Returns true if the node is selected
1470 * @param {TreeNode} node The node to check
1473 isSelected : function(node){
1474 return this.selMap[node.id] ? true : false;
1478 * Returns an array of the selected nodes
1481 getSelectedNodes : function(){
1482 return this.selNodes.concat([]);
1485 onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
1487 selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
1489 selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
1491 * @class Ext.data.Tree
1492 * @extends Ext.util.Observable
1493 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
1494 * in the tree have most standard DOM functionality.
1496 * @param {Node} root (optional) The root node
1498 Ext.data.Tree = function(root){
1501 * The root node for this tree
1506 this.setRootNode(root);
1511 * Fires when a new child node is appended to a node in this tree.
1512 * @param {Tree} tree The owner tree
1513 * @param {Node} parent The parent node
1514 * @param {Node} node The newly appended node
1515 * @param {Number} index The index of the newly appended node
1520 * Fires when a child node is removed from a node in this tree.
1521 * @param {Tree} tree The owner tree
1522 * @param {Node} parent The parent node
1523 * @param {Node} node The child node removed
1528 * Fires when a node is moved to a new location in the tree
1529 * @param {Tree} tree The owner tree
1530 * @param {Node} node The node moved
1531 * @param {Node} oldParent The old parent of this node
1532 * @param {Node} newParent The new parent of this node
1533 * @param {Number} index The index it was moved to
1538 * Fires when a new child node is inserted in a node in this tree.
1539 * @param {Tree} tree The owner tree
1540 * @param {Node} parent The parent node
1541 * @param {Node} node The child node inserted
1542 * @param {Node} refNode The child node the node was inserted before
1546 * @event beforeappend
1547 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
1548 * @param {Tree} tree The owner tree
1549 * @param {Node} parent The parent node
1550 * @param {Node} node The child node to be appended
1554 * @event beforeremove
1555 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
1556 * @param {Tree} tree The owner tree
1557 * @param {Node} parent The parent node
1558 * @param {Node} node The child node to be removed
1563 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
1564 * @param {Tree} tree The owner tree
1565 * @param {Node} node The node being moved
1566 * @param {Node} oldParent The parent of the node
1567 * @param {Node} newParent The new parent the node is moving to
1568 * @param {Number} index The index it is being moved to
1572 * @event beforeinsert
1573 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
1574 * @param {Tree} tree The owner tree
1575 * @param {Node} parent The parent node
1576 * @param {Node} node The child node to be inserted
1577 * @param {Node} refNode The child node the node is being inserted before
1582 Ext.data.Tree.superclass.constructor.call(this);
1585 Ext.extend(Ext.data.Tree, Ext.util.Observable, {
1587 * @cfg {String} pathSeparator
1588 * The token used to separate paths in node ids (defaults to '/').
1593 proxyNodeEvent : function(){
1594 return this.fireEvent.apply(this, arguments);
1598 * Returns the root node for this tree.
1601 getRootNode : function(){
1606 * Sets the root node for this tree.
1607 * @param {Node} node
1610 setRootNode : function(node){
1612 node.ownerTree = this;
1614 this.registerNode(node);
1619 * Gets a node in this tree by its id.
1620 * @param {String} id
1623 getNodeById : function(id){
1624 return this.nodeHash[id];
1628 registerNode : function(node){
1629 this.nodeHash[node.id] = node;
1633 unregisterNode : function(node){
1634 delete this.nodeHash[node.id];
1637 toString : function(){
1638 return "[Tree"+(this.id?" "+this.id:"")+"]";
1643 * @class Ext.data.Node
1644 * @extends Ext.util.Observable
1645 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
1646 * @cfg {String} id The id for this node. If one is not specified, one is generated.
1648 * @param {Object} attributes The attributes/config for the node
1650 Ext.data.Node = function(attributes){
1652 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
1655 this.attributes = attributes || {};
1656 this.leaf = this.attributes.leaf;
1658 * The node id. @type String
1660 this.id = this.attributes.id;
1662 this.id = Ext.id(null, "xnode-");
1663 this.attributes.id = this.id;
1666 * All child nodes of this node. @type Array
1668 this.childNodes = [];
1669 if(!this.childNodes.indexOf){ // indexOf is a must
1670 this.childNodes.indexOf = function(o){
1671 for(var i = 0, len = this.length; i < len; i++){
1680 * The parent node for this node. @type Node
1682 this.parentNode = null;
1684 * The first direct child node of this node, or null if this node has no child nodes. @type Node
1686 this.firstChild = null;
1688 * The last direct child node of this node, or null if this node has no child nodes. @type Node
1690 this.lastChild = null;
1692 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
1694 this.previousSibling = null;
1696 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
1698 this.nextSibling = null;
1703 * Fires when a new child node is appended
1704 * @param {Tree} tree The owner tree
1705 * @param {Node} this This node
1706 * @param {Node} node The newly appended node
1707 * @param {Number} index The index of the newly appended node
1712 * Fires when a child node is removed
1713 * @param {Tree} tree The owner tree
1714 * @param {Node} this This node
1715 * @param {Node} node The removed node
1720 * Fires when this node is moved to a new location in the tree
1721 * @param {Tree} tree The owner tree
1722 * @param {Node} this This node
1723 * @param {Node} oldParent The old parent of this node
1724 * @param {Node} newParent The new parent of this node
1725 * @param {Number} index The index it was moved to
1730 * Fires when a new child node is inserted.
1731 * @param {Tree} tree The owner tree
1732 * @param {Node} this This node
1733 * @param {Node} node The child node inserted
1734 * @param {Node} refNode The child node the node was inserted before
1738 * @event beforeappend
1739 * Fires before a new child is appended, return false to cancel the append.
1740 * @param {Tree} tree The owner tree
1741 * @param {Node} this This node
1742 * @param {Node} node The child node to be appended
1744 "beforeappend" : true,
1746 * @event beforeremove
1747 * Fires before a child is removed, return false to cancel the remove.
1748 * @param {Tree} tree The owner tree
1749 * @param {Node} this This node
1750 * @param {Node} node The child node to be removed
1752 "beforeremove" : true,
1755 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
1756 * @param {Tree} tree The owner tree
1757 * @param {Node} this This node
1758 * @param {Node} oldParent The parent of this node
1759 * @param {Node} newParent The new parent this node is moving to
1760 * @param {Number} index The index it is being moved to
1762 "beforemove" : true,
1764 * @event beforeinsert
1765 * Fires before a new child is inserted, return false to cancel the insert.
1766 * @param {Tree} tree The owner tree
1767 * @param {Node} this This node
1768 * @param {Node} node The child node to be inserted
1769 * @param {Node} refNode The child node the node is being inserted before
1771 "beforeinsert" : true
1773 this.listeners = this.attributes.listeners;
1774 Ext.data.Node.superclass.constructor.call(this);
1777 Ext.extend(Ext.data.Node, Ext.util.Observable, {
1779 fireEvent : function(evtName){
1780 // first do standard event for this node
1781 if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){
1784 // then bubble it up to the tree if the event wasn't cancelled
1785 var ot = this.getOwnerTree();
1787 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
1795 * Returns true if this node is a leaf
1798 isLeaf : function(){
1799 return this.leaf === true;
1803 setFirstChild : function(node){
1804 this.firstChild = node;
1808 setLastChild : function(node){
1809 this.lastChild = node;
1814 * Returns true if this node is the last child of its parent
1817 isLast : function(){
1818 return (!this.parentNode ? true : this.parentNode.lastChild == this);
1822 * Returns true if this node is the first child of its parent
1825 isFirst : function(){
1826 return (!this.parentNode ? true : this.parentNode.firstChild == this);
1830 * Returns true if this node has one or more child nodes, else false.
1833 hasChildNodes : function(){
1834 return !this.isLeaf() && this.childNodes.length > 0;
1838 * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>
1839 * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
1842 isExpandable : function(){
1843 return this.attributes.expandable || this.hasChildNodes();
1847 * Insert node(s) as the last child node of this node.
1848 * @param {Node/Array} node The node or Array of nodes to append
1849 * @return {Node} The appended node if single append, or null if an array was passed
1851 appendChild : function(node){
1853 if(Ext.isArray(node)){
1855 }else if(arguments.length > 1){
1858 // if passed an array or multiple args do them one by one
1860 for(var i = 0, len = multi.length; i < len; i++) {
1861 this.appendChild(multi[i]);
1864 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
1867 var index = this.childNodes.length;
1868 var oldParent = node.parentNode;
1869 // it's a move, make sure we move it cleanly
1871 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
1874 oldParent.removeChild(node);
1876 index = this.childNodes.length;
1878 this.setFirstChild(node);
1880 this.childNodes.push(node);
1881 node.parentNode = this;
1882 var ps = this.childNodes[index-1];
1884 node.previousSibling = ps;
1885 ps.nextSibling = node;
1887 node.previousSibling = null;
1889 node.nextSibling = null;
1890 this.setLastChild(node);
1891 node.setOwnerTree(this.getOwnerTree());
1892 this.fireEvent("append", this.ownerTree, this, node, index);
1894 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
1901 * Removes a child node from this node.
1902 * @param {Node} node The node to remove
1903 * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
1904 * @return {Node} The removed node
1906 removeChild : function(node, destroy){
1907 var index = this.childNodes.indexOf(node);
1911 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
1915 // remove it from childNodes collection
1916 this.childNodes.splice(index, 1);
1919 if(node.previousSibling){
1920 node.previousSibling.nextSibling = node.nextSibling;
1922 if(node.nextSibling){
1923 node.nextSibling.previousSibling = node.previousSibling;
1926 // update child refs
1927 if(this.firstChild == node){
1928 this.setFirstChild(node.nextSibling);
1930 if(this.lastChild == node){
1931 this.setLastChild(node.previousSibling);
1934 this.fireEvent("remove", this.ownerTree, this, node);
1944 clear : function(destroy){
1945 // clear any references from the node
1946 this.setOwnerTree(null, destroy);
1947 this.parentNode = this.previousSibling = this.nextSibling = null;
1949 this.firstChild = this.lastChild = null;
1954 * Destroys the node.
1956 destroy : function(/* private */ silent){
1958 * Silent is to be used in a number of cases
1959 * 1) When setRootNode is called.
1960 * 2) When destroy on the tree is called
1961 * 3) For destroying child nodes on a node
1963 if(silent === true){
1964 this.purgeListeners();
1966 Ext.each(this.childNodes, function(n){
1969 this.childNodes = null;
1976 * Inserts the first node before the second node in this nodes childNodes collection.
1977 * @param {Node} node The node to insert
1978 * @param {Node} refNode The node to insert before (if null the node is appended)
1979 * @return {Node} The inserted node
1981 insertBefore : function(node, refNode){
1982 if(!refNode){ // like standard Dom, refNode can be null for append
1983 return this.appendChild(node);
1986 if(node == refNode){
1990 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
1993 var index = this.childNodes.indexOf(refNode);
1994 var oldParent = node.parentNode;
1995 var refIndex = index;
1997 // when moving internally, indexes will change after remove
1998 if(oldParent == this && this.childNodes.indexOf(node) < index){
2002 // it's a move, make sure we move it cleanly
2004 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
2007 oldParent.removeChild(node);
2010 this.setFirstChild(node);
2012 this.childNodes.splice(refIndex, 0, node);
2013 node.parentNode = this;
2014 var ps = this.childNodes[refIndex-1];
2016 node.previousSibling = ps;
2017 ps.nextSibling = node;
2019 node.previousSibling = null;
2021 node.nextSibling = refNode;
2022 refNode.previousSibling = node;
2023 node.setOwnerTree(this.getOwnerTree());
2024 this.fireEvent("insert", this.ownerTree, this, node, refNode);
2026 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
2032 * Removes this node from its parent
2033 * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
2034 * @return {Node} this
2036 remove : function(destroy){
2037 if (this.parentNode) {
2038 this.parentNode.removeChild(this, destroy);
2044 * Removes all child nodes from this node.
2045 * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
2046 * @return {Node} this
2048 removeAll : function(destroy){
2049 var cn = this.childNodes,
2052 this.removeChild(n, destroy);
2058 * Returns the child node at the specified index.
2059 * @param {Number} index
2062 item : function(index){
2063 return this.childNodes[index];
2067 * Replaces one child node in this node with another.
2068 * @param {Node} newChild The replacement node
2069 * @param {Node} oldChild The node to replace
2070 * @return {Node} The replaced node
2072 replaceChild : function(newChild, oldChild){
2073 var s = oldChild ? oldChild.nextSibling : null;
2074 this.removeChild(oldChild);
2075 this.insertBefore(newChild, s);
2080 * Returns the index of a child node
2081 * @param {Node} node
2082 * @return {Number} The index of the node or -1 if it was not found
2084 indexOf : function(child){
2085 return this.childNodes.indexOf(child);
2089 * Returns the tree this node is in.
2092 getOwnerTree : function(){
2093 // if it doesn't have one, look for one
2094 if(!this.ownerTree){
2098 this.ownerTree = p.ownerTree;
2104 return this.ownerTree;
2108 * Returns depth of this node (the root node has a depth of 0)
2111 getDepth : function(){
2114 while(p.parentNode){
2122 setOwnerTree : function(tree, destroy){
2123 // if it is a move, we need to update everyone
2124 if(tree != this.ownerTree){
2126 this.ownerTree.unregisterNode(this);
2128 this.ownerTree = tree;
2129 // If we're destroying, we don't need to recurse since it will be called on each child node
2130 if(destroy !== true){
2131 Ext.each(this.childNodes, function(n){
2132 n.setOwnerTree(tree);
2136 tree.registerNode(this);
2142 * Changes the id of this node.
2143 * @param {String} id The new id for the node.
2145 setId: function(id){
2147 var t = this.ownerTree;
2149 t.unregisterNode(this);
2151 this.id = this.attributes.id = id;
2153 t.registerNode(this);
2155 this.onIdChange(id);
2160 onIdChange: Ext.emptyFn,
2163 * Returns the path for this node. The path can be used to expand or select this node programmatically.
2164 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
2165 * @return {String} The path
2167 getPath : function(attr){
2168 attr = attr || "id";
2169 var p = this.parentNode;
2170 var b = [this.attributes[attr]];
2172 b.unshift(p.attributes[attr]);
2175 var sep = this.getOwnerTree().pathSeparator;
2176 return sep + b.join(sep);
2180 * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function
2181 * will be the args provided or the current node. If the function returns false at any point,
2182 * the bubble is stopped.
2183 * @param {Function} fn The function to call
2184 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
2185 * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
2187 bubble : function(fn, scope, args){
2190 if(fn.apply(scope || p, args || [p]) === false){
2198 * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function
2199 * will be the args provided or the current node. If the function returns false at any point,
2200 * the cascade is stopped on that branch.
2201 * @param {Function} fn The function to call
2202 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
2203 * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
2205 cascade : function(fn, scope, args){
2206 if(fn.apply(scope || this, args || [this]) !== false){
2207 var cs = this.childNodes;
2208 for(var i = 0, len = cs.length; i < len; i++) {
2209 cs[i].cascade(fn, scope, args);
2215 * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function
2216 * will be the args provided or the current node. If the function returns false at any point,
2217 * the iteration stops.
2218 * @param {Function} fn The function to call
2219 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node in the iteration.
2220 * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
2222 eachChild : function(fn, scope, args){
2223 var cs = this.childNodes;
2224 for(var i = 0, len = cs.length; i < len; i++) {
2225 if(fn.apply(scope || this, args || [cs[i]]) === false){
2232 * Finds the first child that has the attribute with the specified value.
2233 * @param {String} attribute The attribute name
2234 * @param {Mixed} value The value to search for
2235 * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
2236 * @return {Node} The found child or null if none was found
2238 findChild : function(attribute, value, deep){
2239 return this.findChildBy(function(){
2240 return this.attributes[attribute] == value;
2245 * Finds the first child by a custom function. The child matches if the function passed returns <code>true</code>.
2246 * @param {Function} fn A function which must return <code>true</code> if the passed Node is the required Node.
2247 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Node being tested.
2248 * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
2249 * @return {Node} The found child or null if none was found
2251 findChildBy : function(fn, scope, deep){
2252 var cs = this.childNodes,
2257 for(; i < len; i++){
2259 if(fn.call(scope || n, n) === true){
2262 res = n.findChildBy(fn, scope, deep);
2273 * Sorts this nodes children using the supplied sort function.
2274 * @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.
2275 * @param {Object} scope (optional)The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
2277 sort : function(fn, scope){
2278 var cs = this.childNodes;
2279 var len = cs.length;
2281 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
2283 for(var i = 0; i < len; i++){
2285 n.previousSibling = cs[i-1];
2286 n.nextSibling = cs[i+1];
2288 this.setFirstChild(n);
2291 this.setLastChild(n);
2298 * Returns true if this node is an ancestor (at any point) of the passed node.
2299 * @param {Node} node
2302 contains : function(node){
2303 return node.isAncestor(this);
2307 * Returns true if the passed node is an ancestor (at any point) of this node.
2308 * @param {Node} node
2311 isAncestor : function(node){
2312 var p = this.parentNode;
2322 toString : function(){
2323 return "[Node"+(this.id?" "+this.id:"")+"]";
2326 * @class Ext.tree.TreeNode
2327 * @extends Ext.data.Node
2328 * @cfg {String} text The text for this node
2329 * @cfg {Boolean} expanded true to start the node expanded
2330 * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)
2331 * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)
2332 * @cfg {Boolean} disabled true to start the node disabled
2333 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
2334 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
2335 * @cfg {String} cls A css class to be added to the node
2336 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
2337 * @cfg {String} href URL of the link used for the node (defaults to #)
2338 * @cfg {String} hrefTarget target frame for the link
2339 * @cfg {Boolean} hidden True to render hidden. (Defaults to false).
2340 * @cfg {String} qtip An Ext QuickTip for the node
2341 * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
2342 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
2343 * @cfg {Boolean} singleClickExpand True for single click expand on this node
2344 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)
2345 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
2346 * (defaults to undefined with no checkbox rendered)
2347 * @cfg {Boolean} draggable True to make this node draggable (defaults to false)
2348 * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)
2349 * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)
2350 * @cfg {Boolean} editable False to not allow this node to be edited by an {@link Ext.tree.TreeEditor} (defaults to true)
2352 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
2354 Ext.tree.TreeNode = function(attributes){
2355 attributes = attributes || {};
2356 if(Ext.isString(attributes)){
2357 attributes = {text: attributes};
2359 this.childrenRendered = false;
2360 this.rendered = false;
2361 Ext.tree.TreeNode.superclass.constructor.call(this, attributes);
2362 this.expanded = attributes.expanded === true;
2363 this.isTarget = attributes.isTarget !== false;
2364 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
2365 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
2368 * Read-only. The text for this node. To change it use <code>{@link #setText}</code>.
2371 this.text = attributes.text;
2373 * True if this node is disabled.
2376 this.disabled = attributes.disabled === true;
2378 * True if this node is hidden.
2381 this.hidden = attributes.hidden === true;
2386 * Fires when the text for this node is changed
2387 * @param {Node} this This node
2388 * @param {String} text The new text
2389 * @param {String} oldText The old text
2393 * @event beforeexpand
2394 * Fires before this node is expanded, return false to cancel.
2395 * @param {Node} this This node
2396 * @param {Boolean} deep
2397 * @param {Boolean} anim
2401 * @event beforecollapse
2402 * Fires before this node is collapsed, return false to cancel.
2403 * @param {Node} this This node
2404 * @param {Boolean} deep
2405 * @param {Boolean} anim
2410 * Fires when this node is expanded
2411 * @param {Node} this This node
2415 * @event disabledchange
2416 * Fires when the disabled status of this node changes
2417 * @param {Node} this This node
2418 * @param {Boolean} disabled
2423 * Fires when this node is collapsed
2424 * @param {Node} this This node
2428 * @event beforeclick
2429 * Fires before click processing. Return false to cancel the default action.
2430 * @param {Node} this This node
2431 * @param {Ext.EventObject} e The event object
2436 * Fires when this node is clicked
2437 * @param {Node} this This node
2438 * @param {Ext.EventObject} e The event object
2442 * @event checkchange
2443 * Fires when a node with a checkbox's checked property changes
2444 * @param {Node} this This node
2445 * @param {Boolean} checked
2449 * @event beforedblclick
2450 * Fires before double click processing. Return false to cancel the default action.
2451 * @param {Node} this This node
2452 * @param {Ext.EventObject} e The event object
2457 * Fires when this node is double clicked
2458 * @param {Node} this This node
2459 * @param {Ext.EventObject} e The event object
2463 * @event contextmenu
2464 * Fires when this node is right clicked
2465 * @param {Node} this This node
2466 * @param {Ext.EventObject} e The event object
2470 * @event beforechildrenrendered
2471 * Fires right before the child nodes for this node are rendered
2472 * @param {Node} this This node
2474 'beforechildrenrendered'
2477 var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;
2480 * Read-only. The UI for this node
2483 this.ui = new uiClass(this);
2485 Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
2486 preventHScroll : true,
2488 * Returns true if this node is expanded
2491 isExpanded : function(){
2492 return this.expanded;
2496 * Returns the UI object for this node.
2497 * @return {TreeNodeUI} The object which is providing the user interface for this tree
2498 * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance
2499 * of {@link Ext.tree.TreeNodeUI}
2505 getLoader : function(){
2507 return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : (this.loader = new Ext.tree.TreeLoader()));
2511 setFirstChild : function(node){
2512 var of = this.firstChild;
2513 Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);
2514 if(this.childrenRendered && of && node != of){
2515 of.renderIndent(true, true);
2518 this.renderIndent(true, true);
2523 setLastChild : function(node){
2524 var ol = this.lastChild;
2525 Ext.tree.TreeNode.superclass.setLastChild.call(this, node);
2526 if(this.childrenRendered && ol && node != ol){
2527 ol.renderIndent(true, true);
2530 this.renderIndent(true, true);
2534 // these methods are overridden to provide lazy rendering support
2536 appendChild : function(n){
2537 if(!n.render && !Ext.isArray(n)){
2538 n = this.getLoader().createNode(n);
2540 var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);
2541 if(node && this.childrenRendered){
2544 this.ui.updateExpandIcon();
2549 removeChild : function(node, destroy){
2550 this.ownerTree.getSelectionModel().unselect(node);
2551 Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
2552 // only update the ui if we're not destroying
2554 // if it's been rendered remove dom node
2555 if(node.ui.rendered){
2558 if(this.childNodes.length < 1){
2559 this.collapse(false, false);
2561 this.ui.updateExpandIcon();
2563 if(!this.firstChild && !this.isHiddenRoot()){
2564 this.childrenRendered = false;
2571 insertBefore : function(node, refNode){
2573 node = this.getLoader().createNode(node);
2575 var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
2576 if(newNode && refNode && this.childrenRendered){
2579 this.ui.updateExpandIcon();
2584 * Sets the text for this node
2585 * @param {String} text
2587 setText : function(text){
2588 var oldText = this.text;
2589 this.text = this.attributes.text = text;
2590 if(this.rendered){ // event without subscribing
2591 this.ui.onTextChange(this, text, oldText);
2593 this.fireEvent('textchange', this, text, oldText);
2597 * Triggers selection of this node
2599 select : function(){
2600 var t = this.getOwnerTree();
2602 t.getSelectionModel().select(this);
2607 * Triggers deselection of this node
2608 * @param {Boolean} silent (optional) True to stop selection change events from firing.
2610 unselect : function(silent){
2611 var t = this.getOwnerTree();
2613 t.getSelectionModel().unselect(this, silent);
2618 * Returns true if this node is selected
2621 isSelected : function(){
2622 var t = this.getOwnerTree();
2623 return t ? t.getSelectionModel().isSelected(this) : false;
2628 * @param {Boolean} deep (optional) True to expand all children as well
2629 * @param {Boolean} anim (optional) false to cancel the default animation
2630 * @param {Function} callback (optional) A callback to be called when
2631 * expanding this node completes (does not wait for deep expand to complete).
2632 * Called with 1 parameter, this node.
2633 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
2635 expand : function(deep, anim, callback, scope){
2637 if(this.fireEvent('beforeexpand', this, deep, anim) === false){
2640 if(!this.childrenRendered){
2641 this.renderChildren();
2643 this.expanded = true;
2644 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
2645 this.ui.animExpand(function(){
2646 this.fireEvent('expand', this);
2647 this.runCallback(callback, scope || this, [this]);
2649 this.expandChildNodes(true);
2651 }.createDelegate(this));
2655 this.fireEvent('expand', this);
2656 this.runCallback(callback, scope || this, [this]);
2659 this.runCallback(callback, scope || this, [this]);
2662 this.expandChildNodes(true);
2666 runCallback : function(cb, scope, args){
2667 if(Ext.isFunction(cb)){
2668 cb.apply(scope, args);
2672 isHiddenRoot : function(){
2673 return this.isRoot && !this.getOwnerTree().rootVisible;
2677 * Collapse this node.
2678 * @param {Boolean} deep (optional) True to collapse all children as well
2679 * @param {Boolean} anim (optional) false to cancel the default animation
2680 * @param {Function} callback (optional) A callback to be called when
2681 * expanding this node completes (does not wait for deep expand to complete).
2682 * Called with 1 parameter, this node.
2683 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
2685 collapse : function(deep, anim, callback, scope){
2686 if(this.expanded && !this.isHiddenRoot()){
2687 if(this.fireEvent('beforecollapse', this, deep, anim) === false){
2690 this.expanded = false;
2691 if((this.getOwnerTree().animate && anim !== false) || anim){
2692 this.ui.animCollapse(function(){
2693 this.fireEvent('collapse', this);
2694 this.runCallback(callback, scope || this, [this]);
2696 this.collapseChildNodes(true);
2698 }.createDelegate(this));
2702 this.fireEvent('collapse', this);
2703 this.runCallback(callback, scope || this, [this]);
2705 }else if(!this.expanded){
2706 this.runCallback(callback, scope || this, [this]);
2709 var cs = this.childNodes;
2710 for(var i = 0, len = cs.length; i < len; i++) {
2711 cs[i].collapse(true, false);
2717 delayedExpand : function(delay){
2718 if(!this.expandProcId){
2719 this.expandProcId = this.expand.defer(delay, this);
2724 cancelExpand : function(){
2725 if(this.expandProcId){
2726 clearTimeout(this.expandProcId);
2728 this.expandProcId = false;
2732 * Toggles expanded/collapsed state of the node
2734 toggle : function(){
2743 * Ensures all parent nodes are expanded, and if necessary, scrolls
2744 * the node into view.
2745 * @param {Function} callback (optional) A function to call when the node has been made visible.
2746 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
2748 ensureVisible : function(callback, scope){
2749 var tree = this.getOwnerTree();
2750 tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){
2751 var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime
2752 tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
2753 this.runCallback(callback, scope || this, [this]);
2754 }.createDelegate(this));
2758 * Expand all child nodes
2759 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
2761 expandChildNodes : function(deep){
2762 var cs = this.childNodes;
2763 for(var i = 0, len = cs.length; i < len; i++) {
2769 * Collapse all child nodes
2770 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
2772 collapseChildNodes : function(deep){
2773 var cs = this.childNodes;
2774 for(var i = 0, len = cs.length; i < len; i++) {
2775 cs[i].collapse(deep);
2780 * Disables this node
2782 disable : function(){
2783 this.disabled = true;
2785 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
2786 this.ui.onDisableChange(this, true);
2788 this.fireEvent('disabledchange', this, true);
2794 enable : function(){
2795 this.disabled = false;
2796 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
2797 this.ui.onDisableChange(this, false);
2799 this.fireEvent('disabledchange', this, false);
2803 renderChildren : function(suppressEvent){
2804 if(suppressEvent !== false){
2805 this.fireEvent('beforechildrenrendered', this);
2807 var cs = this.childNodes;
2808 for(var i = 0, len = cs.length; i < len; i++){
2811 this.childrenRendered = true;
2815 sort : function(fn, scope){
2816 Ext.tree.TreeNode.superclass.sort.apply(this, arguments);
2817 if(this.childrenRendered){
2818 var cs = this.childNodes;
2819 for(var i = 0, len = cs.length; i < len; i++){
2826 render : function(bulkRender){
2827 this.ui.render(bulkRender);
2829 // make sure it is registered
2830 this.getOwnerTree().registerNode(this);
2831 this.rendered = true;
2833 this.expanded = false;
2834 this.expand(false, false);
2840 renderIndent : function(deep, refresh){
2842 this.ui.childIndent = null;
2844 this.ui.renderIndent();
2845 if(deep === true && this.childrenRendered){
2846 var cs = this.childNodes;
2847 for(var i = 0, len = cs.length; i < len; i++){
2848 cs[i].renderIndent(true, refresh);
2853 beginUpdate : function(){
2854 this.childrenRendered = false;
2857 endUpdate : function(){
2858 if(this.expanded && this.rendered){
2859 this.renderChildren();
2864 destroy : function(silent){
2865 if(silent === true){
2866 this.unselect(true);
2868 Ext.tree.TreeNode.superclass.destroy.call(this, silent);
2869 Ext.destroy(this.ui, this.loader);
2870 this.ui = this.loader = null;
2874 onIdChange : function(id){
2875 this.ui.onIdChange(id);
2879 Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;/**
2880 * @class Ext.tree.AsyncTreeNode
2881 * @extends Ext.tree.TreeNode
2882 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
2884 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
2886 Ext.tree.AsyncTreeNode = function(config){
2887 this.loaded = config && config.loaded === true;
2888 this.loading = false;
2889 Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
2892 * Fires before this node is loaded, return false to cancel
2893 * @param {Node} this This node
2895 this.addEvents('beforeload', 'load');
2898 * Fires when this node is loaded
2899 * @param {Node} this This node
2902 * The loader used by this node (defaults to using the tree's defined loader)
2907 Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
2908 expand : function(deep, anim, callback, scope){
2909 if(this.loading){ // if an async load is already running, waiting til it's done
2912 if(!this.loading){ // done loading
2913 clearInterval(timer);
2914 this.expand(deep, anim, callback, scope);
2916 }.createDelegate(this);
2917 timer = setInterval(f, 200);
2921 if(this.fireEvent("beforeload", this) === false){
2924 this.loading = true;
2925 this.ui.beforeLoad(this);
2926 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
2928 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
2932 Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
2936 * Returns true if this node is currently loading
2939 isLoading : function(){
2940 return this.loading;
2943 loadComplete : function(deep, anim, callback, scope){
2944 this.loading = false;
2946 this.ui.afterLoad(this);
2947 this.fireEvent("load", this);
2948 this.expand(deep, anim, callback, scope);
2952 * Returns true if this node has been loaded
2955 isLoaded : function(){
2959 hasChildNodes : function(){
2960 if(!this.isLeaf() && !this.loaded){
2963 return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
2968 * Trigger a reload for this node
2969 * @param {Function} callback
2970 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Node.
2972 reload : function(callback, scope){
2973 this.collapse(false, false);
2974 while(this.firstChild){
2975 this.removeChild(this.firstChild).destroy();
2977 this.childrenRendered = false;
2978 this.loaded = false;
2979 if(this.isHiddenRoot()){
2980 this.expanded = false;
2982 this.expand(false, false, callback, scope);
2986 Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;/**
2987 * @class Ext.tree.TreeNodeUI
2988 * This class provides the default UI implementation for Ext TreeNodes.
2989 * The TreeNode UI implementation is separate from the
2990 * tree implementation, and allows customizing of the appearance of
2993 * If you are customizing the Tree's user interface, you
2994 * may need to extend this class, but you should never need to instantiate this class.<br>
2996 * This class provides access to the user interface components of an Ext TreeNode, through
2997 * {@link Ext.tree.TreeNode#getUI}
2999 Ext.tree.TreeNodeUI = function(node){
3001 this.rendered = false;
3002 this.animating = false;
3003 this.wasLeaf = true;
3004 this.ecc = 'x-tree-ec-icon x-tree-elbow';
3005 this.emptyIcon = Ext.BLANK_IMAGE_URL;
3008 Ext.tree.TreeNodeUI.prototype = {
3010 removeChild : function(node){
3012 this.ctNode.removeChild(node.ui.getEl());
3017 beforeLoad : function(){
3018 this.addClass("x-tree-node-loading");
3022 afterLoad : function(){
3023 this.removeClass("x-tree-node-loading");
3027 onTextChange : function(node, text, oldText){
3029 this.textNode.innerHTML = text;
3034 onDisableChange : function(node, state){
3035 this.disabled = state;
3036 if (this.checkbox) {
3037 this.checkbox.disabled = state;
3040 this.addClass("x-tree-node-disabled");
3042 this.removeClass("x-tree-node-disabled");
3047 onSelectedChange : function(state){
3050 this.addClass("x-tree-selected");
3053 this.removeClass("x-tree-selected");
3058 onMove : function(tree, node, oldParent, newParent, index, refNode){
3059 this.childIndent = null;
3061 var targetNode = newParent.ui.getContainer();
3062 if(!targetNode){//target not rendered
3063 this.holder = document.createElement("div");
3064 this.holder.appendChild(this.wrap);
3067 var insertBefore = refNode ? refNode.ui.getEl() : null;
3069 targetNode.insertBefore(this.wrap, insertBefore);
3071 targetNode.appendChild(this.wrap);
3073 this.node.renderIndent(true, oldParent != newParent);
3078 * Adds one or more CSS classes to the node's UI element.
3079 * Duplicate classes are automatically filtered out.
3080 * @param {String/Array} className The CSS class to add, or an array of classes
3082 addClass : function(cls){
3084 Ext.fly(this.elNode).addClass(cls);
3089 * Removes one or more CSS classes from the node's UI element.
3090 * @param {String/Array} className The CSS class to remove, or an array of classes
3092 removeClass : function(cls){
3094 Ext.fly(this.elNode).removeClass(cls);
3099 remove : function(){
3101 this.holder = document.createElement("div");
3102 this.holder.appendChild(this.wrap);
3107 fireEvent : function(){
3108 return this.node.fireEvent.apply(this.node, arguments);
3112 initEvents : function(){
3113 this.node.on("move", this.onMove, this);
3115 if(this.node.disabled){
3116 this.onDisableChange(this.node, true);
3118 if(this.node.hidden){
3121 var ot = this.node.getOwnerTree();
3122 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
3123 if(dd && (!this.node.isRoot || ot.rootVisible)){
3124 Ext.dd.Registry.register(this.elNode, {
3126 handles: this.getDDHandles(),
3133 getDDHandles : function(){
3134 return [this.iconNode, this.textNode, this.elNode];
3141 this.node.hidden = true;
3143 this.wrap.style.display = "none";
3151 this.node.hidden = false;
3153 this.wrap.style.display = "";
3158 onContextMenu : function(e){
3159 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
3162 this.fireEvent("contextmenu", this.node, e);
3167 onClick : function(e){
3172 if(this.fireEvent("beforeclick", this.node, e) !== false){
3173 var a = e.getTarget('a');
3174 if(!this.disabled && this.node.attributes.href && a){
3175 this.fireEvent("click", this.node, e);
3177 }else if(a && e.ctrlKey){
3185 if(this.node.attributes.singleClickExpand && !this.animating && this.node.isExpandable()){
3189 this.fireEvent("click", this.node, e);
3196 onDblClick : function(e){
3201 if(this.fireEvent("beforedblclick", this.node, e) !== false){
3205 if(!this.animating && this.node.isExpandable()){
3208 this.fireEvent("dblclick", this.node, e);
3212 onOver : function(e){
3213 this.addClass('x-tree-node-over');
3216 onOut : function(e){
3217 this.removeClass('x-tree-node-over');
3221 onCheckChange : function(){
3222 var checked = this.checkbox.checked;
3224 this.checkbox.defaultChecked = checked;
3225 this.node.attributes.checked = checked;
3226 this.fireEvent('checkchange', this.node, checked);
3230 ecClick : function(e){
3231 if(!this.animating && this.node.isExpandable()){
3237 startDrop : function(){
3238 this.dropping = true;
3241 // delayed drop so the click event doesn't get fired on a drop
3242 endDrop : function(){
3243 setTimeout(function(){
3244 this.dropping = false;
3245 }.createDelegate(this), 50);
3249 expand : function(){
3250 this.updateExpandIcon();
3251 this.ctNode.style.display = "";
3256 if(!this.node.preventHScroll){
3257 try{this.anchor.focus();
3261 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
3262 var l = noscroll.scrollLeft;
3263 this.anchor.focus();
3264 noscroll.scrollLeft = l;
3270 * Sets the checked status of the tree node to the passed value, or, if no value was passed,
3271 * toggles the checked status. If the node was rendered with no checkbox, this has no effect.
3272 * @param {Boolean} value (optional) The new checked status.
3274 toggleCheck : function(value){
3275 var cb = this.checkbox;
3277 cb.checked = (value === undefined ? !cb.checked : value);
3278 this.onCheckChange();
3290 animExpand : function(callback){
3291 var ct = Ext.get(this.ctNode);
3293 if(!this.node.isExpandable()){
3294 this.updateExpandIcon();
3295 this.ctNode.style.display = "";
3296 Ext.callback(callback);
3299 this.animating = true;
3300 this.updateExpandIcon();
3303 callback : function(){
3304 this.animating = false;
3305 Ext.callback(callback);
3308 duration: this.node.ownerTree.duration || .25
3313 highlight : function(){
3314 var tree = this.node.getOwnerTree();
3315 Ext.fly(this.wrap).highlight(
3316 tree.hlColor || "C3DAF9",
3317 {endColor: tree.hlBaseColor}
3322 collapse : function(){
3323 this.updateExpandIcon();
3324 this.ctNode.style.display = "none";
3328 animCollapse : function(callback){
3329 var ct = Ext.get(this.ctNode);
3330 ct.enableDisplayMode('block');
3333 this.animating = true;
3334 this.updateExpandIcon();
3337 callback : function(){
3338 this.animating = false;
3339 Ext.callback(callback);
3342 duration: this.node.ownerTree.duration || .25
3347 getContainer : function(){
3352 * Returns the element which encapsulates this node.
3353 * @return {HtmlElement} The DOM element. The default implementation uses a <code><li></code>.
3360 appendDDGhost : function(ghostNode){
3361 ghostNode.appendChild(this.elNode.cloneNode(true));
3365 getDDRepairXY : function(){
3366 return Ext.lib.Dom.getXY(this.iconNode);
3370 onRender : function(){
3375 render : function(bulkRender){
3376 var n = this.node, a = n.attributes;
3377 var targetNode = n.parentNode ?
3378 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
3381 this.rendered = true;
3383 this.renderElements(n, a, targetNode, bulkRender);
3386 if(this.textNode.setAttributeNS){
3387 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
3389 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
3392 this.textNode.setAttribute("ext:qtip", a.qtip);
3394 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
3397 }else if(a.qtipCfg){
3398 a.qtipCfg.target = Ext.id(this.textNode);
3399 Ext.QuickTips.register(a.qtipCfg);
3402 if(!this.node.expanded){
3403 this.updateExpandIcon(true);
3406 if(bulkRender === true) {
3407 targetNode.appendChild(this.wrap);
3413 renderElements : function(n, a, targetNode, bulkRender){
3414 // add some indent caching, this helps performance when rendering a large tree
3415 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
3417 var cb = Ext.isBoolean(a.checked),
3419 href = a.href ? a.href : Ext.isGecko ? "" : "#",
3420 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">',
3421 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
3422 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
3423 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
3424 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',
3425 '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ',
3426 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",
3427 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
3430 if(bulkRender !== true && n.nextSibling && (nel = n.nextSibling.ui.getEl())){
3431 this.wrap = Ext.DomHelper.insertHtml("beforeBegin", nel, buf);
3433 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf);
3436 this.elNode = this.wrap.childNodes[0];
3437 this.ctNode = this.wrap.childNodes[1];
3438 var cs = this.elNode.childNodes;
3439 this.indentNode = cs[0];
3440 this.ecNode = cs[1];
3441 this.iconNode = cs[2];
3444 this.checkbox = cs[3];
3446 this.checkbox.defaultChecked = this.checkbox.checked;
3449 this.anchor = cs[index];
3450 this.textNode = cs[index].firstChild;
3454 * Returns the <a> element that provides focus for the node's UI.
3455 * @return {HtmlElement} The DOM anchor element.
3457 getAnchor : function(){
3462 * Returns the text node.
3463 * @return {HtmlNode} The DOM text node.
3465 getTextEl : function(){
3466 return this.textNode;
3470 * Returns the icon <img> element.
3471 * @return {HtmlElement} The DOM image element.
3473 getIconEl : function(){
3474 return this.iconNode;
3478 * Returns the checked status of the node. If the node was rendered with no
3479 * checkbox, it returns false.
3480 * @return {Boolean} The checked flag.
3482 isChecked : function(){
3483 return this.checkbox ? this.checkbox.checked : false;
3487 updateExpandIcon : function(){
3492 cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow",
3493 hasChild = n.hasChildNodes();
3494 if(hasChild || n.attributes.expandable){
3497 c1 = "x-tree-node-collapsed";
3498 c2 = "x-tree-node-expanded";
3501 c1 = "x-tree-node-expanded";
3502 c2 = "x-tree-node-collapsed";
3505 this.removeClass("x-tree-node-leaf");
3506 this.wasLeaf = false;
3508 if(this.c1 != c1 || this.c2 != c2){
3509 Ext.fly(this.elNode).replaceClass(c1, c2);
3510 this.c1 = c1; this.c2 = c2;
3514 Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-collapsed");
3517 this.wasLeaf = true;
3520 var ecc = "x-tree-ec-icon "+cls;
3521 if(this.ecc != ecc){
3522 this.ecNode.className = ecc;
3529 onIdChange: function(id){
3531 this.elNode.setAttribute('ext:tree-node-id', id);
3536 getChildIndent : function(){
3537 if(!this.childIndent){
3541 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
3543 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
3545 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
3550 this.childIndent = buf.join("");
3552 return this.childIndent;
3556 renderIndent : function(){
3559 p = this.node.parentNode;
3561 indent = p.ui.getChildIndent();
3563 if(this.indentMarkup != indent){ // don't rerender if not required
3564 this.indentNode.innerHTML = indent;
3565 this.indentMarkup = indent;
3567 this.updateExpandIcon();
3571 destroy : function(){
3573 Ext.dd.Registry.unregister(this.elNode.id);
3576 Ext.each(['textnode', 'anchor', 'checkbox', 'indentNode', 'ecNode', 'iconNode', 'elNode', 'ctNode', 'wrap', 'holder'], function(el){
3578 Ext.fly(this[el]).remove();
3587 * @class Ext.tree.RootTreeNodeUI
3588 * This class provides the default UI implementation for <b>root</b> Ext TreeNodes.
3589 * The RootTreeNode UI implementation allows customizing the appearance of the root tree node.<br>
3591 * If you are customizing the Tree's user interface, you
3592 * may need to extend this class, but you should never need to instantiate this class.<br>
3594 Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
3596 render : function(){
3598 var targetNode = this.node.ownerTree.innerCt.dom;
3599 this.node.expanded = true;
3600 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
3601 this.wrap = this.ctNode = targetNode.firstChild;
3604 collapse : Ext.emptyFn,
3605 expand : Ext.emptyFn
3607 * @class Ext.tree.TreeLoader
3608 * @extends Ext.util.Observable
3609 * A TreeLoader provides for lazy loading of an {@link Ext.tree.TreeNode}'s child
3610 * nodes from a specified URL. The response must be a JavaScript Array definition
3611 * whose elements are node definition objects. e.g.:
3615 text: 'A leaf Node',
3619 text: 'A folder Node',
3622 text: 'A child Node',
3628 * A server request is sent, and child nodes are loaded only when a node is expanded.
3629 * The loading node's id is passed to the server under the parameter name "node" to
3630 * enable the server to produce the correct child nodes.
3632 * To pass extra parameters, an event handler may be attached to the "beforeload"
3633 * event, and the parameters specified in the TreeLoader's baseParams property:
3635 myTreeLoader.on("beforeload", function(treeLoader, node) {
3636 this.baseParams.category = node.attributes.category;
3639 * This would pass an HTTP parameter called "category" to the server containing
3640 * the value of the Node's "category" attribute.
3642 * Creates a new Treeloader.
3643 * @param {Object} config A config object containing config properties.
3645 Ext.tree.TreeLoader = function(config){
3646 this.baseParams = {};
3647 Ext.apply(this, config);
3652 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
3653 * @param {Object} This TreeLoader object.
3654 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
3655 * @param {Object} callback The callback function specified in the {@link #load} call.
3660 * Fires when the node has been successfuly loaded.
3661 * @param {Object} This TreeLoader object.
3662 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
3663 * @param {Object} response The response object containing the data from the server.
3667 * @event loadexception
3668 * Fires if the network request failed.
3669 * @param {Object} This TreeLoader object.
3670 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
3671 * @param {Object} response The response object containing the data from the server.
3675 Ext.tree.TreeLoader.superclass.constructor.call(this);
3676 if(Ext.isString(this.paramOrder)){
3677 this.paramOrder = this.paramOrder.split(/[\s,|]/);
3681 Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, {
3683 * @cfg {String} dataUrl The URL from which to request a Json string which
3684 * specifies an array of node definition objects representing the child nodes
3688 * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
3691 * @cfg {String} url Equivalent to {@link #dataUrl}.
3694 * @cfg {Boolean} preloadChildren If set to true, the loader recursively loads "children" attributes when doing the first load on nodes.
3697 * @cfg {Object} baseParams (optional) An object containing properties which
3698 * specify HTTP parameters to be passed to each request for child nodes.
3701 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
3702 * created by this loader. If the attributes sent by the server have an attribute in this object,
3703 * they take priority.
3706 * @cfg {Object} uiProviders (optional) An object containing properties which
3707 * specify custom {@link Ext.tree.TreeNodeUI} implementations. If the optional
3708 * <i>uiProvider</i> attribute of a returned child node is a string rather
3709 * than a reference to a TreeNodeUI implementation, then that string value
3710 * is used as a property name in the uiProviders object.
3715 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
3716 * child nodes before loading.
3721 * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. Only used when using directFn.
3722 * Specifies the params in the order in which they must be passed to the server-side Direct method
3723 * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
3724 * comma, or pipe. For example,
3725 * any of the following would be acceptable:<pre><code>
3726 nodeParameter: 'node',
3727 paramOrder: ['param1','param2','param3']
3728 paramOrder: 'node param1 param2 param3'
3729 paramOrder: 'param1,node,param2,param3'
3730 paramOrder: 'param1|param2|param|node'
3733 paramOrder: undefined,
3736 * @cfg {Boolean} paramsAsHash Only used when using directFn.
3737 * Send parameters as a collection of named arguments (defaults to <tt>false</tt>). Providing a
3738 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
3740 paramsAsHash: false,
3743 * @cfg {String} nodeParameter The name of the parameter sent to the server which contains
3744 * the identifier of the node. Defaults to <tt>'node'</tt>.
3746 nodeParameter: 'node',
3749 * @cfg {Function} directFn
3750 * Function to call when executing a request.
3752 directFn : undefined,
3755 * Load an {@link Ext.tree.TreeNode} from the URL specified in the constructor.
3756 * This is called automatically when a node is expanded, but may be used to reload
3757 * a node (or append new children if the {@link #clearOnLoad} option is false.)
3758 * @param {Ext.tree.TreeNode} node
3759 * @param {Function} callback Function to call after the node has been loaded. The
3760 * function is passed the TreeNode which was requested to be loaded.
3761 * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed.
3762 * defaults to the loaded TreeNode.
3764 load : function(node, callback, scope){
3765 if(this.clearOnLoad){
3766 while(node.firstChild){
3767 node.removeChild(node.firstChild);
3770 if(this.doPreload(node)){ // preloaded json children
3771 this.runCallback(callback, scope || node, [node]);
3772 }else if(this.directFn || this.dataUrl || this.url){
3773 this.requestData(node, callback, scope || node);
3777 doPreload : function(node){
3778 if(node.attributes.children){
3779 if(node.childNodes.length < 1){ // preloaded?
3780 var cs = node.attributes.children;
3782 for(var i = 0, len = cs.length; i < len; i++){
3783 var cn = node.appendChild(this.createNode(cs[i]));
3784 if(this.preloadChildren){
3795 getParams: function(node){
3796 var bp = Ext.apply({}, this.baseParams),
3797 np = this.nodeParameter,
3798 po = this.paramOrder;
3800 np && (bp[ np ] = node.id);
3803 var buf = [node.id];
3805 // reset 'buf' if the nodeParameter was included in paramOrder
3806 if(np && po.indexOf(np) > -1){
3810 for(var i = 0, len = po.length; i < len; i++){
3811 buf.push(bp[ po[i] ]);
3813 }else if(this.paramsAsHash){
3822 requestData : function(node, callback, scope){
3823 if(this.fireEvent("beforeload", this, node, callback) !== false){
3825 var args = this.getParams(node);
3826 args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));
3827 this.directFn.apply(window, args);
3829 this.transId = Ext.Ajax.request({
3830 method:this.requestMethod,
3831 url: this.dataUrl||this.url,
3832 success: this.handleResponse,
3833 failure: this.handleFailure,
3835 argument: {callback: callback, node: node, scope: scope},
3836 params: this.getParams(node)
3840 // if the load is cancelled, make sure we notify
3841 // the node that we are done
3842 this.runCallback(callback, scope || node, []);
3846 processDirectResponse: function(result, response, args){
3847 if(response.status){
3848 this.handleResponse({
3849 responseData: Ext.isArray(result) ? result : null,
3850 responseText: result,
3854 this.handleFailure({
3861 runCallback: function(cb, scope, args){
3862 if(Ext.isFunction(cb)){
3863 cb.apply(scope, args);
3867 isLoading : function(){
3868 return !!this.transId;
3872 if(this.isLoading()){
3873 Ext.Ajax.abort(this.transId);
3878 * <p>Override this function for custom TreeNode node implementation, or to
3879 * modify the attributes at creation time.</p>
3880 * Example:<pre><code>
3881 new Ext.tree.TreePanel({
3883 loader: new Ext.tree.TreeLoader({
3885 createNode: function(attr) {
3886 // Allow consolidation consignments to have
3887 // consignments dropped into them.
3888 if (attr.isConsolidation) {
3889 attr.iconCls = 'x-consol',
3890 attr.allowDrop = true;
3892 return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
3898 * @param attr {Object} The attributes from which to create the new node.
3900 createNode : function(attr){
3901 // apply baseAttrs, nice idea Corey!
3903 Ext.applyIf(attr, this.baseAttrs);
3905 if(this.applyLoader !== false && !attr.loader){
3908 if(Ext.isString(attr.uiProvider)){
3909 attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
3912 return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
3915 new Ext.tree.TreeNode(attr) :
3916 new Ext.tree.AsyncTreeNode(attr);
3920 processResponse : function(response, node, callback, scope){
3921 var json = response.responseText;
3923 var o = response.responseData || Ext.decode(json);
3925 for(var i = 0, len = o.length; i < len; i++){
3926 var n = this.createNode(o[i]);
3928 node.appendChild(n);
3932 this.runCallback(callback, scope || node, [node]);
3934 this.handleFailure(response);
3938 handleResponse : function(response){
3939 this.transId = false;
3940 var a = response.argument;
3941 this.processResponse(response, a.node, a.callback, a.scope);
3942 this.fireEvent("load", this, a.node, response);
3945 handleFailure : function(response){
3946 this.transId = false;
3947 var a = response.argument;
3948 this.fireEvent("loadexception", this, a.node, response);
3949 this.runCallback(a.callback, a.scope || a.node, [a.node]);
3952 destroy : function(){
3954 this.purgeListeners();
3957 * @class Ext.tree.TreeFilter
3958 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
3959 * @param {TreePanel} tree
3960 * @param {Object} config (optional)
3962 Ext.tree.TreeFilter = function(tree, config){
3965 Ext.apply(this, config);
3968 Ext.tree.TreeFilter.prototype = {
3975 * Filter the data by a specific attribute.
3976 * @param {String/RegExp} value Either string that the attribute value
3977 * should start with or a RegExp to test against the attribute
3978 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
3979 * @param {TreeNode} startNode (optional) The node to start the filter at.
3981 filter : function(value, attr, startNode){
3982 attr = attr || "text";
3984 if(typeof value == "string"){
3985 var vlen = value.length;
3986 // auto clear empty filter
3987 if(vlen == 0 && this.clearBlank){
3991 value = value.toLowerCase();
3993 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
3995 }else if(value.exec){ // regex?
3997 return value.test(n.attributes[attr]);
4000 throw 'Illegal filter type, must be string or regex';
4002 this.filterBy(f, null, startNode);
4006 * Filter by a function. The passed function will be called with each
4007 * node in the tree (or from the startNode). If the function returns true, the node is kept
4008 * otherwise it is filtered. If a node is filtered, its children are also filtered.
4009 * @param {Function} fn The filter function
4010 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
4012 filterBy : function(fn, scope, startNode){
4013 startNode = startNode || this.tree.root;
4017 var af = this.filtered, rv = this.reverse;
4018 var f = function(n){
4025 var m = fn.call(scope || n, n);
4033 startNode.cascade(f);
4036 if(typeof id != "function"){
4038 if(n && n.parentNode){
4039 n.parentNode.removeChild(n);
4047 * Clears the current filter. Note: with the "remove" option
4048 * set a filter cannot be cleared.
4052 var af = this.filtered;
4054 if(typeof id != "function"){
4065 * @class Ext.tree.TreeSorter
4066 * Provides sorting of nodes in a {@link Ext.tree.TreePanel}. The TreeSorter automatically monitors events on the
4067 * associated TreePanel that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
4068 * Example usage:<br />
4070 new Ext.tree.TreeSorter(myTree, {
4073 sortType: function(node) {
4074 // sort by a custom, typed attribute:
4075 return parseInt(node.id, 10);
4080 * @param {TreePanel} tree
4081 * @param {Object} config
4083 Ext.tree.TreeSorter = function(tree, config){
4085 * @cfg {Boolean} folderSort True to sort leaf nodes under non-leaf nodes (defaults to false)
4088 * @cfg {String} property The named attribute on the node to sort by (defaults to "text"). Note that this
4089 * property is only used if no {@link #sortType} function is specified, otherwise it is ignored.
4092 * @cfg {String} dir The direction to sort ("asc" or "desc," case-insensitive, defaults to "asc")
4095 * @cfg {String} leafAttr The attribute used to determine leaf nodes when {@link #folderSort} = true (defaults to "leaf")
4098 * @cfg {Boolean} caseSensitive true for case-sensitive sort (defaults to false)
4101 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting. The function
4102 * will be called with a single parameter (the {@link Ext.tree.TreeNode} being evaluated) and is expected to return
4103 * the node's sort value cast to the specific data type required for sorting. This could be used, for example, when
4104 * a node's text (or other attribute) should be sorted as a date or numeric value. See the class description for
4105 * example usage. Note that if a sortType is specified, any {@link #property} config will be ignored.
4108 Ext.apply(this, config);
4109 tree.on("beforechildrenrendered", this.doSort, this);
4110 tree.on("append", this.updateSort, this);
4111 tree.on("insert", this.updateSort, this);
4112 tree.on("textchange", this.updateSortParent, this);
4114 var dsc = this.dir && this.dir.toLowerCase() == "desc";
4115 var p = this.property || "text";
4116 var sortType = this.sortType;
4117 var fs = this.folderSort;
4118 var cs = this.caseSensitive === true;
4119 var leafAttr = this.leafAttr || 'leaf';
4121 this.sortFn = function(n1, n2){
4123 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
4126 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
4130 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
4131 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
4133 return dsc ? +1 : -1;
4135 return dsc ? -1 : +1;
4142 Ext.tree.TreeSorter.prototype = {
4143 doSort : function(node){
4144 node.sort(this.sortFn);
4147 compareNodes : function(n1, n2){
4148 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
4151 updateSort : function(tree, node){
4152 if(node.childrenRendered){
4153 this.doSort.defer(1, this, [node]);
4157 updateSortParent : function(node){
4158 var p = node.parentNode;
4159 if(p && p.childrenRendered){
4160 this.doSort.defer(1, this, [p]);
4164 * @class Ext.tree.TreeDropZone
4165 * @extends Ext.dd.DropZone
4167 * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dropping
4168 * @param {Object} config
4170 if(Ext.dd.DropZone){
4172 Ext.tree.TreeDropZone = function(tree, config){
4174 * @cfg {Boolean} allowParentInsert
4175 * Allow inserting a dragged node between an expanded parent node and its first child that will become a
4176 * sibling of the parent when dropped (defaults to false)
4178 this.allowParentInsert = config.allowParentInsert || false;
4180 * @cfg {String} allowContainerDrop
4181 * True if drops on the tree container (outside of a specific tree node) are allowed (defaults to false)
4183 this.allowContainerDrop = config.allowContainerDrop || false;
4185 * @cfg {String} appendOnly
4186 * True if the tree should only allow append drops (use for trees which are sorted, defaults to false)
4188 this.appendOnly = config.appendOnly || false;
4190 Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.getTreeEl(), config);
4192 * The TreePanel for this drop zone
4193 * @type Ext.tree.TreePanel
4198 * Arbitrary data that can be associated with this tree and will be included in the event object that gets
4199 * passed to any nodedragover event handler (defaults to {})
4200 * @type Ext.tree.TreePanel
4203 this.dragOverData = {};
4205 this.lastInsertClass = "x-tree-no-status";
4208 Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, {
4210 * @cfg {String} ddGroup
4211 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
4212 * interact with other drag drop objects in the same group (defaults to 'TreeDD').
4217 * @cfg {String} expandDelay
4218 * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node
4219 * over the target (defaults to 1000)
4224 expandNode : function(node){
4225 if(node.hasChildNodes() && !node.isExpanded()){
4226 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
4231 queueExpand : function(node){
4232 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
4236 cancelExpand : function(){
4237 if(this.expandProcId){
4238 clearTimeout(this.expandProcId);
4239 this.expandProcId = false;
4244 isValidDropPoint : function(n, pt, dd, e, data){
4245 if(!n || !data){ return false; }
4246 var targetNode = n.node;
4247 var dropNode = data.node;
4248 // default drop rules
4249 if(!(targetNode && targetNode.isTarget && pt)){
4252 if(pt == "append" && targetNode.allowChildren === false){
4255 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
4258 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
4262 var overEvent = this.dragOverData;
4263 overEvent.tree = this.tree;
4264 overEvent.target = targetNode;
4265 overEvent.data = data;
4266 overEvent.point = pt;
4267 overEvent.source = dd;
4268 overEvent.rawEvent = e;
4269 overEvent.dropNode = dropNode;
4270 overEvent.cancel = false;
4271 var result = this.tree.fireEvent("nodedragover", overEvent);
4272 return overEvent.cancel === false && result !== false;
4276 getDropPoint : function(e, n, dd){
4279 return tn.allowChildren !== false ? "append" : false; // always append for root
4281 var dragEl = n.ddel;
4282 var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
4283 var y = Ext.lib.Event.getPageY(e);
4284 var noAppend = tn.allowChildren === false || tn.isLeaf();
4285 if(this.appendOnly || tn.parentNode.allowChildren === false){
4286 return noAppend ? false : "append";
4288 var noBelow = false;
4289 if(!this.allowParentInsert){
4290 noBelow = tn.hasChildNodes() && tn.isExpanded();
4292 var q = (b - t) / (noAppend ? 2 : 3);
4293 if(y >= t && y < (t + q)){
4295 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
4303 onNodeEnter : function(n, dd, e, data){
4304 this.cancelExpand();
4307 onContainerOver : function(dd, e, data) {
4308 if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
4309 return this.dropAllowed;
4311 return this.dropNotAllowed;
4315 onNodeOver : function(n, dd, e, data){
4316 var pt = this.getDropPoint(e, n, dd);
4319 // auto node expand check
4320 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
4321 this.queueExpand(node);
4322 }else if(pt != "append"){
4323 this.cancelExpand();
4326 // set the insert point style on the target node
4327 var returnCls = this.dropNotAllowed;
4328 if(this.isValidDropPoint(n, pt, dd, e, data)){
4333 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
4334 cls = "x-tree-drag-insert-above";
4335 }else if(pt == "below"){
4336 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
4337 cls = "x-tree-drag-insert-below";
4339 returnCls = "x-tree-drop-ok-append";
4340 cls = "x-tree-drag-append";
4342 if(this.lastInsertClass != cls){
4343 Ext.fly(el).replaceClass(this.lastInsertClass, cls);
4344 this.lastInsertClass = cls;
4352 onNodeOut : function(n, dd, e, data){
4353 this.cancelExpand();
4354 this.removeDropIndicators(n);
4358 onNodeDrop : function(n, dd, e, data){
4359 var point = this.getDropPoint(e, n, dd);
4360 var targetNode = n.node;
4361 targetNode.ui.startDrop();
4362 if(!this.isValidDropPoint(n, point, dd, e, data)){
4363 targetNode.ui.endDrop();
4366 // first try to find the drop node
4367 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
4368 return this.processDrop(targetNode, data, point, dd, e, dropNode);
4371 onContainerDrop : function(dd, e, data){
4372 if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
4373 var targetNode = this.tree.getRootNode();
4374 targetNode.ui.startDrop();
4375 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, 'append', e) : null);
4376 return this.processDrop(targetNode, data, 'append', dd, e, dropNode);
4382 processDrop: function(target, data, point, dd, e, dropNode){
4394 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
4395 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
4396 target.ui.endDrop();
4397 return dropEvent.dropStatus;
4400 target = dropEvent.target;
4401 if(point == 'append' && !target.isExpanded()){
4402 target.expand(false, null, function(){
4403 this.completeDrop(dropEvent);
4404 }.createDelegate(this));
4406 this.completeDrop(dropEvent);
4412 completeDrop : function(de){
4413 var ns = de.dropNode, p = de.point, t = de.target;
4414 if(!Ext.isArray(ns)){
4418 for(var i = 0, len = ns.length; i < len; i++){
4421 t.parentNode.insertBefore(n, t);
4422 }else if(p == "below"){
4423 t.parentNode.insertBefore(n, t.nextSibling);
4429 if(Ext.enableFx && this.tree.hlDrop){
4433 this.tree.fireEvent("nodedrop", de);
4437 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
4438 if(Ext.enableFx && this.tree.hlDrop){
4439 dropNode.ui.focus();
4440 dropNode.ui.highlight();
4442 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
4446 getTree : function(){
4451 removeDropIndicators : function(n){
4454 Ext.fly(el).removeClass([
4455 "x-tree-drag-insert-above",
4456 "x-tree-drag-insert-below",
4457 "x-tree-drag-append"]);
4458 this.lastInsertClass = "_noclass";
4463 beforeDragDrop : function(target, e, id){
4464 this.cancelExpand();
4469 afterRepair : function(data){
4470 if(data && Ext.enableFx){
4471 data.node.ui.highlight();
4478 * @class Ext.tree.TreeDragZone
4479 * @extends Ext.dd.DragZone
4481 * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dragging
4482 * @param {Object} config
4484 if(Ext.dd.DragZone){
4485 Ext.tree.TreeDragZone = function(tree, config){
4486 Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.innerCt, config);
4488 * The TreePanel for this drag zone
4489 * @type Ext.tree.TreePanel
4495 Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, {
4497 * @cfg {String} ddGroup
4498 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
4499 * interact with other drag drop objects in the same group (defaults to 'TreeDD').
4504 onBeforeDrag : function(data, e){
4506 return n && n.draggable && !n.disabled;
4510 onInitDrag : function(e){
4511 var data = this.dragData;
4512 this.tree.getSelectionModel().select(data.node);
4513 this.tree.eventModel.disable();
4514 this.proxy.update("");
4515 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
4516 this.tree.fireEvent("startdrag", this.tree, data.node, e);
4520 getRepairXY : function(e, data){
4521 return data.node.ui.getDDRepairXY();
4525 onEndDrag : function(data, e){
4526 this.tree.eventModel.enable.defer(100, this.tree.eventModel);
4527 this.tree.fireEvent("enddrag", this.tree, data.node, e);
4531 onValidDrop : function(dd, e, id){
4532 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
4537 beforeInvalidDrop : function(e, id){
4538 // this scrolls the original position back into view
4539 var sm = this.tree.getSelectionModel();
4540 sm.clearSelections();
4541 sm.select(this.dragData.node);
4545 afterRepair : function(){
4546 if (Ext.enableFx && this.tree.hlDrop) {
4547 Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
4549 this.dragging = false;
4553 * @class Ext.tree.TreeEditor
4554 * @extends Ext.Editor
4555 * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
4556 * as the editor field.
4558 * @param {TreePanel} tree
4559 * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
4560 * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
4561 * @param {Object} config (optional) A TreeEditor config object
4563 Ext.tree.TreeEditor = function(tree, fc, config){
4565 var field = fc.events ? fc : new Ext.form.TextField(fc);
4567 Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
4572 tree.on('render', this.initEditor, this);
4574 this.initEditor(tree);
4578 Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
4580 * @cfg {String} alignment
4581 * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "l-l").
4587 * @cfg {Boolean} hideEl
4588 * True to hide the bound element while the editor is displayed (defaults to false)
4593 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
4595 cls: "x-small-editor x-tree-editor",
4597 * @cfg {Boolean} shim
4598 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
4604 * @cfg {Number} maxWidth
4605 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
4606 * the containing tree element's size, it will be automatically limited for you to the container width, taking
4607 * scroll and client offsets into account prior to each edit.
4611 * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
4612 * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
4613 * the editor for the node will display, otherwise it will be processed as a regular click.
4617 initEditor : function(tree){
4620 beforeclick: this.beforeNodeClick,
4621 dblclick : this.onNodeDblClick
4626 complete : this.updateNode,
4627 beforestartedit: this.fitToTree,
4628 specialkey : this.onSpecialKey
4631 this.on('startedit', this.bindScroll, this, {delay:10});
4635 fitToTree : function(ed, el){
4636 var td = this.tree.getTreeEl().dom, nd = el.dom;
4637 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
4638 td.scrollLeft = nd.offsetLeft;
4642 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
4643 this.setSize(w, '');
4647 * Edit the text of the passed {@link Ext.tree.TreeNode TreeNode}.
4648 * @param node {Ext.tree.TreeNode} The TreeNode to edit. The TreeNode must be {@link Ext.tree.TreeNode#editable editable}.
4650 triggerEdit : function(node, defer){
4651 this.completeEdit();
4652 if(node.attributes.editable !== false){
4654 * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
4655 * @type Ext.tree.TreeNode
4656 * @property editNode
4658 this.editNode = node;
4659 if(this.tree.autoScroll){
4660 Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
4662 var value = node.text || '';
4663 if (!Ext.isGecko && Ext.isEmpty(node.text)){
4664 node.setText(' ');
4666 this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
4672 bindScroll : function(){
4673 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
4677 beforeNodeClick : function(node, e){
4678 clearTimeout(this.autoEditTimer);
4679 if(this.tree.getSelectionModel().isSelected(node)){
4681 return this.triggerEdit(node);
4685 onNodeDblClick : function(node, e){
4686 clearTimeout(this.autoEditTimer);
4690 updateNode : function(ed, value){
4691 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
4692 this.editNode.setText(value);
4696 onHide : function(){
4697 Ext.tree.TreeEditor.superclass.onHide.call(this);
4699 this.editNode.ui.focus.defer(50, this.editNode.ui);
4704 onSpecialKey : function(field, e){
4709 }else if(k == e.ENTER && !e.hasModifier()){
4711 this.completeEdit();
4715 onDestroy : function(){
4716 clearTimeout(this.autoEditTimer);
4717 Ext.tree.TreeEditor.superclass.onDestroy.call(this);
4718 var tree = this.tree;
4719 tree.un('beforeclick', this.beforeNodeClick, this);
4720 tree.un('dblclick', this.onNodeDblClick, this);