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){
642 var keys = path.split(this.pathSeparator);
643 var curNode = this.root;
644 if(curNode.attributes[attr] != keys[1]){ // invalid root
646 callback(false, null);
652 if(++index == keys.length){
654 callback(true, curNode);
658 var c = curNode.findChild(attr, keys[index]);
661 callback(false, curNode);
666 c.expand(false, false, f);
668 curNode.expand(false, false, f);
672 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
673 * @param {String} path
674 * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
675 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
676 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
678 selectPath : function(path, attr, callback){
680 var keys = path.split(this.pathSeparator),
683 var f = function(success, node){
685 var n = node.findChild(attr, v);
700 this.expandPath(keys.join(this.pathSeparator), attr, f);
704 callback(true, this.root);
710 * Returns the underlying Element for this tree
711 * @return {Ext.Element} The Element
713 getTreeEl : function(){
718 onRender : function(ct, position){
719 Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
720 this.el.addClass('x-tree');
721 this.innerCt = this.body.createChild({tag:'ul',
722 cls:'x-tree-root-ct ' +
723 (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')});
727 initEvents : function(){
728 Ext.tree.TreePanel.superclass.initEvents.call(this);
730 if(this.containerScroll){
731 Ext.dd.ScrollManager.register(this.body);
733 if((this.enableDD || this.enableDrop) && !this.dropZone){
735 * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
737 * @type Ext.tree.TreeDropZone
739 this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
740 ddGroup: this.ddGroup || 'TreeDD', appendOnly: this.ddAppendOnly === true
743 if((this.enableDD || this.enableDrag) && !this.dragZone){
745 * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
747 * @type Ext.tree.TreeDragZone
749 this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
750 ddGroup: this.ddGroup || 'TreeDD',
751 scroll: this.ddScroll
754 this.getSelectionModel().init(this);
758 afterRender : function(){
759 Ext.tree.TreePanel.superclass.afterRender.call(this);
763 beforeDestroy : function(){
765 Ext.dd.ScrollManager.unregister(this.body);
766 Ext.destroy(this.dropZone, this.dragZone);
769 Ext.destroy(this.loader);
770 this.nodeHash = this.root = this.loader = null;
771 Ext.tree.TreePanel.superclass.beforeDestroy.call(this);
775 * Destroy the root node. Not included by itself because we need to pass the silent parameter.
778 destroyRoot : function(){
779 if(this.root && this.root.destroy){
780 this.root.destroy(true);
785 * @cfg {String/Number} activeItem
789 * @cfg {Boolean} autoDestroy
793 * @cfg {Object/String/Function} autoLoad
797 * @cfg {Boolean} autoWidth
801 * @cfg {Boolean/Number} bufferResize
805 * @cfg {String} defaultType
809 * @cfg {Object} defaults
813 * @cfg {Boolean} hideBorders
821 * @cfg {String} layout
825 * @cfg {Object} layoutConfig
829 * @cfg {Boolean} monitorResize
861 * @method getComponent
901 * @event beforeremove
912 * @cfg {String} allowDomMove @hide
915 * @cfg {String} autoEl @hide
918 * @cfg {String} applyTo @hide
921 * @cfg {String} contentEl @hide
924 * @cfg {Mixed} data @hide
927 * @cfg {Mixed} tpl @hide
930 * @cfg {String} tplWriteMode @hide
933 * @cfg {String} disabledClass @hide
936 * @cfg {String} elements @hide
939 * @cfg {String} html @hide
942 * @cfg {Boolean} preventBodyReset
950 * @method applyToMarkup
962 * @method setDisabled
967 Ext.tree.TreePanel.nodeTypes = {};
969 Ext.reg('treepanel', Ext.tree.TreePanel);Ext.tree.TreeEventModel = function(tree){
971 this.tree.on('render', this.initEvents, this);
974 Ext.tree.TreeEventModel.prototype = {
975 initEvents : function(){
978 if(t.trackMouseOver !== false){
981 mouseover: this.delegateOver,
982 mouseout: this.delegateOut
985 t.mon(t.getTreeEl(), {
987 click: this.delegateClick,
988 dblclick: this.delegateDblClick,
989 contextmenu: this.delegateContextMenu
993 getNode : function(e){
995 if(t = e.getTarget('.x-tree-node-el', 10)){
996 var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
998 return this.tree.getNodeById(id);
1004 getNodeTarget : function(e){
1005 var t = e.getTarget('.x-tree-node-icon', 1);
1007 t = e.getTarget('.x-tree-node-el', 6);
1012 delegateOut : function(e, t){
1013 if(!this.beforeEvent(e)){
1016 if(e.getTarget('.x-tree-ec-icon', 1)){
1017 var n = this.getNode(e);
1018 this.onIconOut(e, n);
1019 if(n == this.lastEcOver){
1020 delete this.lastEcOver;
1023 if((t = this.getNodeTarget(e)) && !e.within(t, true)){
1024 this.onNodeOut(e, this.getNode(e));
1028 delegateOver : function(e, t){
1029 if(!this.beforeEvent(e)){
1032 if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
1033 Ext.getBody().on('mouseover', this.trackExit, this);
1034 this.trackingDoc = true;
1036 if(this.lastEcOver){ // prevent hung highlight
1037 this.onIconOut(e, this.lastEcOver);
1038 delete this.lastEcOver;
1040 if(e.getTarget('.x-tree-ec-icon', 1)){
1041 this.lastEcOver = this.getNode(e);
1042 this.onIconOver(e, this.lastEcOver);
1044 if(t = this.getNodeTarget(e)){
1045 this.onNodeOver(e, this.getNode(e));
1049 trackExit : function(e){
1050 if(this.lastOverNode){
1051 if(this.lastOverNode.ui && !e.within(this.lastOverNode.ui.getEl())){
1052 this.onNodeOut(e, this.lastOverNode);
1054 delete this.lastOverNode;
1055 Ext.getBody().un('mouseover', this.trackExit, this);
1056 this.trackingDoc = false;
1061 delegateClick : function(e, t){
1062 if(this.beforeEvent(e)){
1063 if(e.getTarget('input[type=checkbox]', 1)){
1064 this.onCheckboxClick(e, this.getNode(e));
1065 }else if(e.getTarget('.x-tree-ec-icon', 1)){
1066 this.onIconClick(e, this.getNode(e));
1067 }else if(this.getNodeTarget(e)){
1068 this.onNodeClick(e, this.getNode(e));
1071 this.checkContainerEvent(e, 'click');
1075 delegateDblClick : function(e, t){
1076 if(this.beforeEvent(e)){
1077 if(this.getNodeTarget(e)){
1078 this.onNodeDblClick(e, this.getNode(e));
1081 this.checkContainerEvent(e, 'dblclick');
1085 delegateContextMenu : function(e, t){
1086 if(this.beforeEvent(e)){
1087 if(this.getNodeTarget(e)){
1088 this.onNodeContextMenu(e, this.getNode(e));
1091 this.checkContainerEvent(e, 'contextmenu');
1095 checkContainerEvent: function(e, type){
1100 this.onContainerEvent(e, type);
1103 onContainerEvent: function(e, type){
1104 this.tree.fireEvent('container' + type, this.tree, e);
1107 onNodeClick : function(e, node){
1111 onNodeOver : function(e, node){
1112 this.lastOverNode = node;
1116 onNodeOut : function(e, node){
1120 onIconOver : function(e, node){
1121 node.ui.addClass('x-tree-ec-over');
1124 onIconOut : function(e, node){
1125 node.ui.removeClass('x-tree-ec-over');
1128 onIconClick : function(e, node){
1132 onCheckboxClick : function(e, node){
1133 node.ui.onCheckChange(e);
1136 onNodeDblClick : function(e, node){
1137 node.ui.onDblClick(e);
1140 onNodeContextMenu : function(e, node){
1141 node.ui.onContextMenu(e);
1144 beforeEvent : function(e){
1145 var node = this.getNode(e);
1146 if(this.disabled || !node || !node.ui){
1153 disable: function(){
1154 this.disabled = true;
1158 this.disabled = false;
1161 * @class Ext.tree.DefaultSelectionModel
1162 * @extends Ext.util.Observable
1163 * The default single selection for a TreePanel.
1165 Ext.tree.DefaultSelectionModel = Ext.extend(Ext.util.Observable, {
1167 constructor : function(config){
1168 this.selNode = null;
1172 * @event selectionchange
1173 * Fires when the selected node changes
1174 * @param {DefaultSelectionModel} this
1175 * @param {TreeNode} node the new selection
1180 * @event beforeselect
1181 * Fires before the selected node changes, return false to cancel the change
1182 * @param {DefaultSelectionModel} this
1183 * @param {TreeNode} node the new selection
1184 * @param {TreeNode} node the old selection
1189 Ext.apply(this, config);
1190 Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
1193 init : function(tree){
1195 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
1196 tree.on('click', this.onNodeClick, this);
1199 onNodeClick : function(node, e){
1205 * @param {TreeNode} node The node to select
1206 * @return {TreeNode} The selected node
1208 select : function(node, /* private*/ selectNextNode){
1209 // If node is hidden, select the next node in whatever direction was being moved in.
1210 if (!Ext.fly(node.ui.wrap).isVisible() && selectNextNode) {
1211 return selectNextNode.call(this, node);
1213 var last = this.selNode;
1215 node.ui.onSelectedChange(true);
1216 }else if(this.fireEvent('beforeselect', this, node, last) !== false){
1217 if(last && last.ui){
1218 last.ui.onSelectedChange(false);
1220 this.selNode = node;
1221 node.ui.onSelectedChange(true);
1222 this.fireEvent('selectionchange', this, node, last);
1229 * @param {TreeNode} node The node to unselect
1230 * @param {Boolean} silent True to stop the selectionchange event from firing.
1232 unselect : function(node, silent){
1233 if(this.selNode == node){
1234 this.clearSelections(silent);
1239 * Clear all selections
1240 * @param {Boolean} silent True to stop the selectionchange event from firing.
1242 clearSelections : function(silent){
1243 var n = this.selNode;
1245 n.ui.onSelectedChange(false);
1246 this.selNode = null;
1247 if(silent !== true){
1248 this.fireEvent('selectionchange', this, null);
1255 * Get the selected node
1256 * @return {TreeNode} The selected node
1258 getSelectedNode : function(){
1259 return this.selNode;
1263 * Returns true if the node is selected
1264 * @param {TreeNode} node The node to check
1267 isSelected : function(node){
1268 return this.selNode == node;
1272 * Selects the node above the selected node in the tree, intelligently walking the nodes
1273 * @return TreeNode The new selection
1275 selectPrevious : function(/* private */ s){
1276 if(!(s = s || this.selNode || this.lastSelNode)){
1279 // Here we pass in the current function to select to indicate the direction we're moving
1280 var ps = s.previousSibling;
1282 if(!ps.isExpanded() || ps.childNodes.length < 1){
1283 return this.select(ps, this.selectPrevious);
1285 var lc = ps.lastChild;
1286 while(lc && lc.isExpanded() && Ext.fly(lc.ui.wrap).isVisible() && lc.childNodes.length > 0){
1289 return this.select(lc, this.selectPrevious);
1291 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
1292 return this.select(s.parentNode, this.selectPrevious);
1298 * Selects the node above the selected node in the tree, intelligently walking the nodes
1299 * @return TreeNode The new selection
1301 selectNext : function(/* private */ s){
1302 if(!(s = s || this.selNode || this.lastSelNode)){
1305 // Here we pass in the current function to select to indicate the direction we're moving
1306 if(s.firstChild && s.isExpanded() && Ext.fly(s.ui.wrap).isVisible()){
1307 return this.select(s.firstChild, this.selectNext);
1308 }else if(s.nextSibling){
1309 return this.select(s.nextSibling, this.selectNext);
1310 }else if(s.parentNode){
1312 s.parentNode.bubble(function(){
1313 if(this.nextSibling){
1314 newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);
1323 onKeyDown : function(e){
1324 var s = this.selNode || this.lastSelNode;
1325 // undesirable, but required
1338 this.selectPrevious();
1342 if(s.hasChildNodes()){
1343 if(!s.isExpanded()){
1345 }else if(s.firstChild){
1346 this.select(s.firstChild, e);
1352 if(s.hasChildNodes() && s.isExpanded()){
1354 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
1355 this.select(s.parentNode, e);
1363 * @class Ext.tree.MultiSelectionModel
1364 * @extends Ext.util.Observable
1365 * Multi selection for a TreePanel.
1367 Ext.tree.MultiSelectionModel = Ext.extend(Ext.util.Observable, {
1369 constructor : function(config){
1374 * @event selectionchange
1375 * Fires when the selected nodes change
1376 * @param {MultiSelectionModel} this
1377 * @param {Array} nodes Array of the selected nodes
1381 Ext.apply(this, config);
1382 Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
1385 init : function(tree){
1387 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
1388 tree.on('click', this.onNodeClick, this);
1391 onNodeClick : function(node, e){
1392 if(e.ctrlKey && this.isSelected(node)){
1393 this.unselect(node);
1395 this.select(node, e, e.ctrlKey);
1401 * @param {TreeNode} node The node to select
1402 * @param {EventObject} e (optional) An event associated with the selection
1403 * @param {Boolean} keepExisting True to retain existing selections
1404 * @return {TreeNode} The selected node
1406 select : function(node, e, keepExisting){
1407 if(keepExisting !== true){
1408 this.clearSelections(true);
1410 if(this.isSelected(node)){
1411 this.lastSelNode = node;
1414 this.selNodes.push(node);
1415 this.selMap[node.id] = node;
1416 this.lastSelNode = node;
1417 node.ui.onSelectedChange(true);
1418 this.fireEvent('selectionchange', this, this.selNodes);
1424 * @param {TreeNode} node The node to unselect
1426 unselect : function(node){
1427 if(this.selMap[node.id]){
1428 node.ui.onSelectedChange(false);
1429 var sn = this.selNodes;
1430 var index = sn.indexOf(node);
1432 this.selNodes.splice(index, 1);
1434 delete this.selMap[node.id];
1435 this.fireEvent('selectionchange', this, this.selNodes);
1440 * Clear all selections
1442 clearSelections : function(suppressEvent){
1443 var sn = this.selNodes;
1445 for(var i = 0, len = sn.length; i < len; i++){
1446 sn[i].ui.onSelectedChange(false);
1450 if(suppressEvent !== true){
1451 this.fireEvent('selectionchange', this, this.selNodes);
1457 * Returns true if the node is selected
1458 * @param {TreeNode} node The node to check
1461 isSelected : function(node){
1462 return this.selMap[node.id] ? true : false;
1466 * Returns an array of the selected nodes
1469 getSelectedNodes : function(){
1470 return this.selNodes.concat([]);
1473 onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
1475 selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
1477 selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
1479 * @class Ext.data.Tree
1480 * @extends Ext.util.Observable
1481 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
1482 * in the tree have most standard DOM functionality.
1484 * @param {Node} root (optional) The root node
1486 Ext.data.Tree = function(root){
1489 * The root node for this tree
1494 this.setRootNode(root);
1499 * Fires when a new child node is appended to a node in this tree.
1500 * @param {Tree} tree The owner tree
1501 * @param {Node} parent The parent node
1502 * @param {Node} node The newly appended node
1503 * @param {Number} index The index of the newly appended node
1508 * Fires when a child node is removed from a node in this tree.
1509 * @param {Tree} tree The owner tree
1510 * @param {Node} parent The parent node
1511 * @param {Node} node The child node removed
1516 * Fires when a node is moved to a new location in the tree
1517 * @param {Tree} tree The owner tree
1518 * @param {Node} node The node moved
1519 * @param {Node} oldParent The old parent of this node
1520 * @param {Node} newParent The new parent of this node
1521 * @param {Number} index The index it was moved to
1526 * Fires when a new child node is inserted in a node in this tree.
1527 * @param {Tree} tree The owner tree
1528 * @param {Node} parent The parent node
1529 * @param {Node} node The child node inserted
1530 * @param {Node} refNode The child node the node was inserted before
1534 * @event beforeappend
1535 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
1536 * @param {Tree} tree The owner tree
1537 * @param {Node} parent The parent node
1538 * @param {Node} node The child node to be appended
1542 * @event beforeremove
1543 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
1544 * @param {Tree} tree The owner tree
1545 * @param {Node} parent The parent node
1546 * @param {Node} node The child node to be removed
1551 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
1552 * @param {Tree} tree The owner tree
1553 * @param {Node} node The node being moved
1554 * @param {Node} oldParent The parent of the node
1555 * @param {Node} newParent The new parent the node is moving to
1556 * @param {Number} index The index it is being moved to
1560 * @event beforeinsert
1561 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
1562 * @param {Tree} tree The owner tree
1563 * @param {Node} parent The parent node
1564 * @param {Node} node The child node to be inserted
1565 * @param {Node} refNode The child node the node is being inserted before
1570 Ext.data.Tree.superclass.constructor.call(this);
1573 Ext.extend(Ext.data.Tree, Ext.util.Observable, {
1575 * @cfg {String} pathSeparator
1576 * The token used to separate paths in node ids (defaults to '/').
1581 proxyNodeEvent : function(){
1582 return this.fireEvent.apply(this, arguments);
1586 * Returns the root node for this tree.
1589 getRootNode : function(){
1594 * Sets the root node for this tree.
1595 * @param {Node} node
1598 setRootNode : function(node){
1600 node.ownerTree = this;
1602 this.registerNode(node);
1607 * Gets a node in this tree by its id.
1608 * @param {String} id
1611 getNodeById : function(id){
1612 return this.nodeHash[id];
1616 registerNode : function(node){
1617 this.nodeHash[node.id] = node;
1621 unregisterNode : function(node){
1622 delete this.nodeHash[node.id];
1625 toString : function(){
1626 return "[Tree"+(this.id?" "+this.id:"")+"]";
1631 * @class Ext.data.Node
1632 * @extends Ext.util.Observable
1633 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
1634 * @cfg {String} id The id for this node. If one is not specified, one is generated.
1636 * @param {Object} attributes The attributes/config for the node
1638 Ext.data.Node = function(attributes){
1640 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
1643 this.attributes = attributes || {};
1644 this.leaf = this.attributes.leaf;
1646 * The node id. @type String
1648 this.id = this.attributes.id;
1650 this.id = Ext.id(null, "xnode-");
1651 this.attributes.id = this.id;
1654 * All child nodes of this node. @type Array
1656 this.childNodes = [];
1657 if(!this.childNodes.indexOf){ // indexOf is a must
1658 this.childNodes.indexOf = function(o){
1659 for(var i = 0, len = this.length; i < len; i++){
1668 * The parent node for this node. @type Node
1670 this.parentNode = null;
1672 * The first direct child node of this node, or null if this node has no child nodes. @type Node
1674 this.firstChild = null;
1676 * The last direct child node of this node, or null if this node has no child nodes. @type Node
1678 this.lastChild = null;
1680 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
1682 this.previousSibling = null;
1684 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
1686 this.nextSibling = null;
1691 * Fires when a new child node is appended
1692 * @param {Tree} tree The owner tree
1693 * @param {Node} this This node
1694 * @param {Node} node The newly appended node
1695 * @param {Number} index The index of the newly appended node
1700 * Fires when a child node is removed
1701 * @param {Tree} tree The owner tree
1702 * @param {Node} this This node
1703 * @param {Node} node The removed node
1708 * Fires when this node is moved to a new location in the tree
1709 * @param {Tree} tree The owner tree
1710 * @param {Node} this This node
1711 * @param {Node} oldParent The old parent of this node
1712 * @param {Node} newParent The new parent of this node
1713 * @param {Number} index The index it was moved to
1718 * Fires when a new child node is inserted.
1719 * @param {Tree} tree The owner tree
1720 * @param {Node} this This node
1721 * @param {Node} node The child node inserted
1722 * @param {Node} refNode The child node the node was inserted before
1726 * @event beforeappend
1727 * Fires before a new child is appended, return false to cancel the append.
1728 * @param {Tree} tree The owner tree
1729 * @param {Node} this This node
1730 * @param {Node} node The child node to be appended
1732 "beforeappend" : true,
1734 * @event beforeremove
1735 * Fires before a child is removed, return false to cancel the remove.
1736 * @param {Tree} tree The owner tree
1737 * @param {Node} this This node
1738 * @param {Node} node The child node to be removed
1740 "beforeremove" : true,
1743 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
1744 * @param {Tree} tree The owner tree
1745 * @param {Node} this This node
1746 * @param {Node} oldParent The parent of this node
1747 * @param {Node} newParent The new parent this node is moving to
1748 * @param {Number} index The index it is being moved to
1750 "beforemove" : true,
1752 * @event beforeinsert
1753 * Fires before a new child is inserted, return false to cancel the insert.
1754 * @param {Tree} tree The owner tree
1755 * @param {Node} this This node
1756 * @param {Node} node The child node to be inserted
1757 * @param {Node} refNode The child node the node is being inserted before
1759 "beforeinsert" : true
1761 this.listeners = this.attributes.listeners;
1762 Ext.data.Node.superclass.constructor.call(this);
1765 Ext.extend(Ext.data.Node, Ext.util.Observable, {
1767 fireEvent : function(evtName){
1768 // first do standard event for this node
1769 if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){
1772 // then bubble it up to the tree if the event wasn't cancelled
1773 var ot = this.getOwnerTree();
1775 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
1783 * Returns true if this node is a leaf
1786 isLeaf : function(){
1787 return this.leaf === true;
1791 setFirstChild : function(node){
1792 this.firstChild = node;
1796 setLastChild : function(node){
1797 this.lastChild = node;
1802 * Returns true if this node is the last child of its parent
1805 isLast : function(){
1806 return (!this.parentNode ? true : this.parentNode.lastChild == this);
1810 * Returns true if this node is the first child of its parent
1813 isFirst : function(){
1814 return (!this.parentNode ? true : this.parentNode.firstChild == this);
1818 * Returns true if this node has one or more child nodes, else false.
1821 hasChildNodes : function(){
1822 return !this.isLeaf() && this.childNodes.length > 0;
1826 * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>
1827 * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
1830 isExpandable : function(){
1831 return this.attributes.expandable || this.hasChildNodes();
1835 * Insert node(s) as the last child node of this node.
1836 * @param {Node/Array} node The node or Array of nodes to append
1837 * @return {Node} The appended node if single append, or null if an array was passed
1839 appendChild : function(node){
1841 if(Ext.isArray(node)){
1843 }else if(arguments.length > 1){
1846 // if passed an array or multiple args do them one by one
1848 for(var i = 0, len = multi.length; i < len; i++) {
1849 this.appendChild(multi[i]);
1852 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
1855 var index = this.childNodes.length;
1856 var oldParent = node.parentNode;
1857 // it's a move, make sure we move it cleanly
1859 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
1862 oldParent.removeChild(node);
1864 index = this.childNodes.length;
1866 this.setFirstChild(node);
1868 this.childNodes.push(node);
1869 node.parentNode = this;
1870 var ps = this.childNodes[index-1];
1872 node.previousSibling = ps;
1873 ps.nextSibling = node;
1875 node.previousSibling = null;
1877 node.nextSibling = null;
1878 this.setLastChild(node);
1879 node.setOwnerTree(this.getOwnerTree());
1880 this.fireEvent("append", this.ownerTree, this, node, index);
1882 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
1889 * Removes a child node from this node.
1890 * @param {Node} node The node to remove
1891 * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
1892 * @return {Node} The removed node
1894 removeChild : function(node, destroy){
1895 var index = this.childNodes.indexOf(node);
1899 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
1903 // remove it from childNodes collection
1904 this.childNodes.splice(index, 1);
1907 if(node.previousSibling){
1908 node.previousSibling.nextSibling = node.nextSibling;
1910 if(node.nextSibling){
1911 node.nextSibling.previousSibling = node.previousSibling;
1914 // update child refs
1915 if(this.firstChild == node){
1916 this.setFirstChild(node.nextSibling);
1918 if(this.lastChild == node){
1919 this.setLastChild(node.previousSibling);
1922 this.fireEvent("remove", this.ownerTree, this, node);
1932 clear : function(destroy){
1933 // clear any references from the node
1934 this.setOwnerTree(null, destroy);
1935 this.parentNode = this.previousSibling = this.nextSibling = null;
1937 this.firstChild = this.lastChild = null;
1942 * Destroys the node.
1944 destroy : function(/* private */ silent){
1946 * Silent is to be used in a number of cases
1947 * 1) When setRootNode is called.
1948 * 2) When destroy on the tree is called
1949 * 3) For destroying child nodes on a node
1951 if(silent === true){
1952 this.purgeListeners();
1954 Ext.each(this.childNodes, function(n){
1957 this.childNodes = null;
1964 * Inserts the first node before the second node in this nodes childNodes collection.
1965 * @param {Node} node The node to insert
1966 * @param {Node} refNode The node to insert before (if null the node is appended)
1967 * @return {Node} The inserted node
1969 insertBefore : function(node, refNode){
1970 if(!refNode){ // like standard Dom, refNode can be null for append
1971 return this.appendChild(node);
1974 if(node == refNode){
1978 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
1981 var index = this.childNodes.indexOf(refNode);
1982 var oldParent = node.parentNode;
1983 var refIndex = index;
1985 // when moving internally, indexes will change after remove
1986 if(oldParent == this && this.childNodes.indexOf(node) < index){
1990 // it's a move, make sure we move it cleanly
1992 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
1995 oldParent.removeChild(node);
1998 this.setFirstChild(node);
2000 this.childNodes.splice(refIndex, 0, node);
2001 node.parentNode = this;
2002 var ps = this.childNodes[refIndex-1];
2004 node.previousSibling = ps;
2005 ps.nextSibling = node;
2007 node.previousSibling = null;
2009 node.nextSibling = refNode;
2010 refNode.previousSibling = node;
2011 node.setOwnerTree(this.getOwnerTree());
2012 this.fireEvent("insert", this.ownerTree, this, node, refNode);
2014 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
2020 * Removes this node from its parent
2021 * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
2022 * @return {Node} this
2024 remove : function(destroy){
2025 if (this.parentNode) {
2026 this.parentNode.removeChild(this, destroy);
2032 * Removes all child nodes from this node.
2033 * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
2034 * @return {Node} this
2036 removeAll : function(destroy){
2037 var cn = this.childNodes,
2040 this.removeChild(n, destroy);
2046 * Returns the child node at the specified index.
2047 * @param {Number} index
2050 item : function(index){
2051 return this.childNodes[index];
2055 * Replaces one child node in this node with another.
2056 * @param {Node} newChild The replacement node
2057 * @param {Node} oldChild The node to replace
2058 * @return {Node} The replaced node
2060 replaceChild : function(newChild, oldChild){
2061 var s = oldChild ? oldChild.nextSibling : null;
2062 this.removeChild(oldChild);
2063 this.insertBefore(newChild, s);
2068 * Returns the index of a child node
2069 * @param {Node} node
2070 * @return {Number} The index of the node or -1 if it was not found
2072 indexOf : function(child){
2073 return this.childNodes.indexOf(child);
2077 * Returns the tree this node is in.
2080 getOwnerTree : function(){
2081 // if it doesn't have one, look for one
2082 if(!this.ownerTree){
2086 this.ownerTree = p.ownerTree;
2092 return this.ownerTree;
2096 * Returns depth of this node (the root node has a depth of 0)
2099 getDepth : function(){
2102 while(p.parentNode){
2110 setOwnerTree : function(tree, destroy){
2111 // if it is a move, we need to update everyone
2112 if(tree != this.ownerTree){
2114 this.ownerTree.unregisterNode(this);
2116 this.ownerTree = tree;
2117 // If we're destroying, we don't need to recurse since it will be called on each child node
2118 if(destroy !== true){
2119 Ext.each(this.childNodes, function(n){
2120 n.setOwnerTree(tree);
2124 tree.registerNode(this);
2130 * Changes the id of this node.
2131 * @param {String} id The new id for the node.
2133 setId: function(id){
2135 var t = this.ownerTree;
2137 t.unregisterNode(this);
2139 this.id = this.attributes.id = id;
2141 t.registerNode(this);
2143 this.onIdChange(id);
2148 onIdChange: Ext.emptyFn,
2151 * Returns the path for this node. The path can be used to expand or select this node programmatically.
2152 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
2153 * @return {String} The path
2155 getPath : function(attr){
2156 attr = attr || "id";
2157 var p = this.parentNode;
2158 var b = [this.attributes[attr]];
2160 b.unshift(p.attributes[attr]);
2163 var sep = this.getOwnerTree().pathSeparator;
2164 return sep + b.join(sep);
2168 * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function
2169 * will be the args provided or the current node. If the function returns false at any point,
2170 * the bubble is stopped.
2171 * @param {Function} fn The function to call
2172 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
2173 * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
2175 bubble : function(fn, scope, args){
2178 if(fn.apply(scope || p, args || [p]) === false){
2186 * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function
2187 * will be the args provided or the current node. If the function returns false at any point,
2188 * the cascade is stopped on that branch.
2189 * @param {Function} fn The function to call
2190 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
2191 * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
2193 cascade : function(fn, scope, args){
2194 if(fn.apply(scope || this, args || [this]) !== false){
2195 var cs = this.childNodes;
2196 for(var i = 0, len = cs.length; i < len; i++) {
2197 cs[i].cascade(fn, scope, args);
2203 * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function
2204 * will be the args provided or the current node. If the function returns false at any point,
2205 * the iteration stops.
2206 * @param {Function} fn The function to call
2207 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node in the iteration.
2208 * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
2210 eachChild : function(fn, scope, args){
2211 var cs = this.childNodes;
2212 for(var i = 0, len = cs.length; i < len; i++) {
2213 if(fn.apply(scope || this, args || [cs[i]]) === false){
2220 * Finds the first child that has the attribute with the specified value.
2221 * @param {String} attribute The attribute name
2222 * @param {Mixed} value The value to search for
2223 * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
2224 * @return {Node} The found child or null if none was found
2226 findChild : function(attribute, value, deep){
2227 return this.findChildBy(function(){
2228 return this.attributes[attribute] == value;
2233 * Finds the first child by a custom function. The child matches if the function passed returns <code>true</code>.
2234 * @param {Function} fn A function which must return <code>true</code> if the passed Node is the required Node.
2235 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Node being tested.
2236 * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
2237 * @return {Node} The found child or null if none was found
2239 findChildBy : function(fn, scope, deep){
2240 var cs = this.childNodes,
2245 for(; i < len; i++){
2247 if(fn.call(scope || n, n) === true){
2250 res = n.findChildBy(fn, scope, deep);
2261 * Sorts this nodes children using the supplied sort function.
2262 * @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.
2263 * @param {Object} scope (optional)The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
2265 sort : function(fn, scope){
2266 var cs = this.childNodes;
2267 var len = cs.length;
2269 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
2271 for(var i = 0; i < len; i++){
2273 n.previousSibling = cs[i-1];
2274 n.nextSibling = cs[i+1];
2276 this.setFirstChild(n);
2279 this.setLastChild(n);
2286 * Returns true if this node is an ancestor (at any point) of the passed node.
2287 * @param {Node} node
2290 contains : function(node){
2291 return node.isAncestor(this);
2295 * Returns true if the passed node is an ancestor (at any point) of this node.
2296 * @param {Node} node
2299 isAncestor : function(node){
2300 var p = this.parentNode;
2310 toString : function(){
2311 return "[Node"+(this.id?" "+this.id:"")+"]";
2314 * @class Ext.tree.TreeNode
2315 * @extends Ext.data.Node
2316 * @cfg {String} text The text for this node
2317 * @cfg {Boolean} expanded true to start the node expanded
2318 * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)
2319 * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)
2320 * @cfg {Boolean} disabled true to start the node disabled
2321 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
2322 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
2323 * @cfg {String} cls A css class to be added to the node
2324 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
2325 * @cfg {String} href URL of the link used for the node (defaults to #)
2326 * @cfg {String} hrefTarget target frame for the link
2327 * @cfg {Boolean} hidden True to render hidden. (Defaults to false).
2328 * @cfg {String} qtip An Ext QuickTip for the node
2329 * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
2330 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
2331 * @cfg {Boolean} singleClickExpand True for single click expand on this node
2332 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)
2333 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
2334 * (defaults to undefined with no checkbox rendered)
2335 * @cfg {Boolean} draggable True to make this node draggable (defaults to false)
2336 * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)
2337 * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)
2338 * @cfg {Boolean} editable False to not allow this node to be edited by an {@link Ext.tree.TreeEditor} (defaults to true)
2340 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
2342 Ext.tree.TreeNode = function(attributes){
2343 attributes = attributes || {};
2344 if(Ext.isString(attributes)){
2345 attributes = {text: attributes};
2347 this.childrenRendered = false;
2348 this.rendered = false;
2349 Ext.tree.TreeNode.superclass.constructor.call(this, attributes);
2350 this.expanded = attributes.expanded === true;
2351 this.isTarget = attributes.isTarget !== false;
2352 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
2353 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
2356 * Read-only. The text for this node. To change it use <code>{@link #setText}</code>.
2359 this.text = attributes.text;
2361 * True if this node is disabled.
2364 this.disabled = attributes.disabled === true;
2366 * True if this node is hidden.
2369 this.hidden = attributes.hidden === true;
2374 * Fires when the text for this node is changed
2375 * @param {Node} this This node
2376 * @param {String} text The new text
2377 * @param {String} oldText The old text
2381 * @event beforeexpand
2382 * Fires before this node is expanded, return false to cancel.
2383 * @param {Node} this This node
2384 * @param {Boolean} deep
2385 * @param {Boolean} anim
2389 * @event beforecollapse
2390 * Fires before this node is collapsed, return false to cancel.
2391 * @param {Node} this This node
2392 * @param {Boolean} deep
2393 * @param {Boolean} anim
2398 * Fires when this node is expanded
2399 * @param {Node} this This node
2403 * @event disabledchange
2404 * Fires when the disabled status of this node changes
2405 * @param {Node} this This node
2406 * @param {Boolean} disabled
2411 * Fires when this node is collapsed
2412 * @param {Node} this This node
2416 * @event beforeclick
2417 * Fires before click processing. Return false to cancel the default action.
2418 * @param {Node} this This node
2419 * @param {Ext.EventObject} e The event object
2424 * Fires when this node is clicked
2425 * @param {Node} this This node
2426 * @param {Ext.EventObject} e The event object
2430 * @event checkchange
2431 * Fires when a node with a checkbox's checked property changes
2432 * @param {Node} this This node
2433 * @param {Boolean} checked
2437 * @event beforedblclick
2438 * Fires before double click processing. Return false to cancel the default action.
2439 * @param {Node} this This node
2440 * @param {Ext.EventObject} e The event object
2445 * Fires when this node is double clicked
2446 * @param {Node} this This node
2447 * @param {Ext.EventObject} e The event object
2451 * @event contextmenu
2452 * Fires when this node is right clicked
2453 * @param {Node} this This node
2454 * @param {Ext.EventObject} e The event object
2458 * @event beforechildrenrendered
2459 * Fires right before the child nodes for this node are rendered
2460 * @param {Node} this This node
2462 'beforechildrenrendered'
2465 var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;
2468 * Read-only. The UI for this node
2471 this.ui = new uiClass(this);
2473 Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
2474 preventHScroll : true,
2476 * Returns true if this node is expanded
2479 isExpanded : function(){
2480 return this.expanded;
2484 * Returns the UI object for this node.
2485 * @return {TreeNodeUI} The object which is providing the user interface for this tree
2486 * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance
2487 * of {@link Ext.tree.TreeNodeUI}
2493 getLoader : function(){
2495 return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : (this.loader = new Ext.tree.TreeLoader()));
2499 setFirstChild : function(node){
2500 var of = this.firstChild;
2501 Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);
2502 if(this.childrenRendered && of && node != of){
2503 of.renderIndent(true, true);
2506 this.renderIndent(true, true);
2511 setLastChild : function(node){
2512 var ol = this.lastChild;
2513 Ext.tree.TreeNode.superclass.setLastChild.call(this, node);
2514 if(this.childrenRendered && ol && node != ol){
2515 ol.renderIndent(true, true);
2518 this.renderIndent(true, true);
2522 // these methods are overridden to provide lazy rendering support
2524 appendChild : function(n){
2525 if(!n.render && !Ext.isArray(n)){
2526 n = this.getLoader().createNode(n);
2528 var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);
2529 if(node && this.childrenRendered){
2532 this.ui.updateExpandIcon();
2537 removeChild : function(node, destroy){
2538 this.ownerTree.getSelectionModel().unselect(node);
2539 Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
2540 // only update the ui if we're not destroying
2542 // if it's been rendered remove dom node
2543 if(node.ui.rendered){
2546 if(this.childNodes.length < 1){
2547 this.collapse(false, false);
2549 this.ui.updateExpandIcon();
2551 if(!this.firstChild && !this.isHiddenRoot()){
2552 this.childrenRendered = false;
2559 insertBefore : function(node, refNode){
2561 node = this.getLoader().createNode(node);
2563 var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
2564 if(newNode && refNode && this.childrenRendered){
2567 this.ui.updateExpandIcon();
2572 * Sets the text for this node
2573 * @param {String} text
2575 setText : function(text){
2576 var oldText = this.text;
2577 this.text = this.attributes.text = text;
2578 if(this.rendered){ // event without subscribing
2579 this.ui.onTextChange(this, text, oldText);
2581 this.fireEvent('textchange', this, text, oldText);
2585 * Triggers selection of this node
2587 select : function(){
2588 var t = this.getOwnerTree();
2590 t.getSelectionModel().select(this);
2595 * Triggers deselection of this node
2596 * @param {Boolean} silent (optional) True to stop selection change events from firing.
2598 unselect : function(silent){
2599 var t = this.getOwnerTree();
2601 t.getSelectionModel().unselect(this, silent);
2606 * Returns true if this node is selected
2609 isSelected : function(){
2610 var t = this.getOwnerTree();
2611 return t ? t.getSelectionModel().isSelected(this) : false;
2616 * @param {Boolean} deep (optional) True to expand all children as well
2617 * @param {Boolean} anim (optional) false to cancel the default animation
2618 * @param {Function} callback (optional) A callback to be called when
2619 * expanding this node completes (does not wait for deep expand to complete).
2620 * Called with 1 parameter, this node.
2621 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
2623 expand : function(deep, anim, callback, scope){
2625 if(this.fireEvent('beforeexpand', this, deep, anim) === false){
2628 if(!this.childrenRendered){
2629 this.renderChildren();
2631 this.expanded = true;
2632 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
2633 this.ui.animExpand(function(){
2634 this.fireEvent('expand', this);
2635 this.runCallback(callback, scope || this, [this]);
2637 this.expandChildNodes(true);
2639 }.createDelegate(this));
2643 this.fireEvent('expand', this);
2644 this.runCallback(callback, scope || this, [this]);
2647 this.runCallback(callback, scope || this, [this]);
2650 this.expandChildNodes(true);
2654 runCallback : function(cb, scope, args){
2655 if(Ext.isFunction(cb)){
2656 cb.apply(scope, args);
2660 isHiddenRoot : function(){
2661 return this.isRoot && !this.getOwnerTree().rootVisible;
2665 * Collapse this node.
2666 * @param {Boolean} deep (optional) True to collapse all children as well
2667 * @param {Boolean} anim (optional) false to cancel the default animation
2668 * @param {Function} callback (optional) A callback to be called when
2669 * expanding this node completes (does not wait for deep expand to complete).
2670 * Called with 1 parameter, this node.
2671 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
2673 collapse : function(deep, anim, callback, scope){
2674 if(this.expanded && !this.isHiddenRoot()){
2675 if(this.fireEvent('beforecollapse', this, deep, anim) === false){
2678 this.expanded = false;
2679 if((this.getOwnerTree().animate && anim !== false) || anim){
2680 this.ui.animCollapse(function(){
2681 this.fireEvent('collapse', this);
2682 this.runCallback(callback, scope || this, [this]);
2684 this.collapseChildNodes(true);
2686 }.createDelegate(this));
2690 this.fireEvent('collapse', this);
2691 this.runCallback(callback, scope || this, [this]);
2693 }else if(!this.expanded){
2694 this.runCallback(callback, scope || this, [this]);
2697 var cs = this.childNodes;
2698 for(var i = 0, len = cs.length; i < len; i++) {
2699 cs[i].collapse(true, false);
2705 delayedExpand : function(delay){
2706 if(!this.expandProcId){
2707 this.expandProcId = this.expand.defer(delay, this);
2712 cancelExpand : function(){
2713 if(this.expandProcId){
2714 clearTimeout(this.expandProcId);
2716 this.expandProcId = false;
2720 * Toggles expanded/collapsed state of the node
2722 toggle : function(){
2731 * Ensures all parent nodes are expanded, and if necessary, scrolls
2732 * the node into view.
2733 * @param {Function} callback (optional) A function to call when the node has been made visible.
2734 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
2736 ensureVisible : function(callback, scope){
2737 var tree = this.getOwnerTree();
2738 tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){
2739 var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime
2740 tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
2741 this.runCallback(callback, scope || this, [this]);
2742 }.createDelegate(this));
2746 * Expand all child nodes
2747 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
2749 expandChildNodes : function(deep){
2750 var cs = this.childNodes;
2751 for(var i = 0, len = cs.length; i < len; i++) {
2757 * Collapse all child nodes
2758 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
2760 collapseChildNodes : function(deep){
2761 var cs = this.childNodes;
2762 for(var i = 0, len = cs.length; i < len; i++) {
2763 cs[i].collapse(deep);
2768 * Disables this node
2770 disable : function(){
2771 this.disabled = true;
2773 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
2774 this.ui.onDisableChange(this, true);
2776 this.fireEvent('disabledchange', this, true);
2782 enable : function(){
2783 this.disabled = false;
2784 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
2785 this.ui.onDisableChange(this, false);
2787 this.fireEvent('disabledchange', this, false);
2791 renderChildren : function(suppressEvent){
2792 if(suppressEvent !== false){
2793 this.fireEvent('beforechildrenrendered', this);
2795 var cs = this.childNodes;
2796 for(var i = 0, len = cs.length; i < len; i++){
2799 this.childrenRendered = true;
2803 sort : function(fn, scope){
2804 Ext.tree.TreeNode.superclass.sort.apply(this, arguments);
2805 if(this.childrenRendered){
2806 var cs = this.childNodes;
2807 for(var i = 0, len = cs.length; i < len; i++){
2814 render : function(bulkRender){
2815 this.ui.render(bulkRender);
2817 // make sure it is registered
2818 this.getOwnerTree().registerNode(this);
2819 this.rendered = true;
2821 this.expanded = false;
2822 this.expand(false, false);
2828 renderIndent : function(deep, refresh){
2830 this.ui.childIndent = null;
2832 this.ui.renderIndent();
2833 if(deep === true && this.childrenRendered){
2834 var cs = this.childNodes;
2835 for(var i = 0, len = cs.length; i < len; i++){
2836 cs[i].renderIndent(true, refresh);
2841 beginUpdate : function(){
2842 this.childrenRendered = false;
2845 endUpdate : function(){
2846 if(this.expanded && this.rendered){
2847 this.renderChildren();
2852 destroy : function(silent){
2853 if(silent === true){
2854 this.unselect(true);
2856 Ext.tree.TreeNode.superclass.destroy.call(this, silent);
2857 Ext.destroy(this.ui, this.loader);
2858 this.ui = this.loader = null;
2862 onIdChange : function(id){
2863 this.ui.onIdChange(id);
2867 Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;/**
2868 * @class Ext.tree.AsyncTreeNode
2869 * @extends Ext.tree.TreeNode
2870 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
2872 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
2874 Ext.tree.AsyncTreeNode = function(config){
2875 this.loaded = config && config.loaded === true;
2876 this.loading = false;
2877 Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
2880 * Fires before this node is loaded, return false to cancel
2881 * @param {Node} this This node
2883 this.addEvents('beforeload', 'load');
2886 * Fires when this node is loaded
2887 * @param {Node} this This node
2890 * The loader used by this node (defaults to using the tree's defined loader)
2895 Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
2896 expand : function(deep, anim, callback, scope){
2897 if(this.loading){ // if an async load is already running, waiting til it's done
2900 if(!this.loading){ // done loading
2901 clearInterval(timer);
2902 this.expand(deep, anim, callback, scope);
2904 }.createDelegate(this);
2905 timer = setInterval(f, 200);
2909 if(this.fireEvent("beforeload", this) === false){
2912 this.loading = true;
2913 this.ui.beforeLoad(this);
2914 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
2916 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
2920 Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
2924 * Returns true if this node is currently loading
2927 isLoading : function(){
2928 return this.loading;
2931 loadComplete : function(deep, anim, callback, scope){
2932 this.loading = false;
2934 this.ui.afterLoad(this);
2935 this.fireEvent("load", this);
2936 this.expand(deep, anim, callback, scope);
2940 * Returns true if this node has been loaded
2943 isLoaded : function(){
2947 hasChildNodes : function(){
2948 if(!this.isLeaf() && !this.loaded){
2951 return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
2956 * Trigger a reload for this node
2957 * @param {Function} callback
2958 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Node.
2960 reload : function(callback, scope){
2961 this.collapse(false, false);
2962 while(this.firstChild){
2963 this.removeChild(this.firstChild).destroy();
2965 this.childrenRendered = false;
2966 this.loaded = false;
2967 if(this.isHiddenRoot()){
2968 this.expanded = false;
2970 this.expand(false, false, callback, scope);
2974 Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;/**
2975 * @class Ext.tree.TreeNodeUI
2976 * This class provides the default UI implementation for Ext TreeNodes.
2977 * The TreeNode UI implementation is separate from the
2978 * tree implementation, and allows customizing of the appearance of
2981 * If you are customizing the Tree's user interface, you
2982 * may need to extend this class, but you should never need to instantiate this class.<br>
2984 * This class provides access to the user interface components of an Ext TreeNode, through
2985 * {@link Ext.tree.TreeNode#getUI}
2987 Ext.tree.TreeNodeUI = function(node){
2989 this.rendered = false;
2990 this.animating = false;
2991 this.wasLeaf = true;
2992 this.ecc = 'x-tree-ec-icon x-tree-elbow';
2993 this.emptyIcon = Ext.BLANK_IMAGE_URL;
2996 Ext.tree.TreeNodeUI.prototype = {
2998 removeChild : function(node){
3000 this.ctNode.removeChild(node.ui.getEl());
3005 beforeLoad : function(){
3006 this.addClass("x-tree-node-loading");
3010 afterLoad : function(){
3011 this.removeClass("x-tree-node-loading");
3015 onTextChange : function(node, text, oldText){
3017 this.textNode.innerHTML = text;
3022 onDisableChange : function(node, state){
3023 this.disabled = state;
3024 if (this.checkbox) {
3025 this.checkbox.disabled = state;
3028 this.addClass("x-tree-node-disabled");
3030 this.removeClass("x-tree-node-disabled");
3035 onSelectedChange : function(state){
3038 this.addClass("x-tree-selected");
3041 this.removeClass("x-tree-selected");
3046 onMove : function(tree, node, oldParent, newParent, index, refNode){
3047 this.childIndent = null;
3049 var targetNode = newParent.ui.getContainer();
3050 if(!targetNode){//target not rendered
3051 this.holder = document.createElement("div");
3052 this.holder.appendChild(this.wrap);
3055 var insertBefore = refNode ? refNode.ui.getEl() : null;
3057 targetNode.insertBefore(this.wrap, insertBefore);
3059 targetNode.appendChild(this.wrap);
3061 this.node.renderIndent(true, oldParent != newParent);
3066 * Adds one or more CSS classes to the node's UI element.
3067 * Duplicate classes are automatically filtered out.
3068 * @param {String/Array} className The CSS class to add, or an array of classes
3070 addClass : function(cls){
3072 Ext.fly(this.elNode).addClass(cls);
3077 * Removes one or more CSS classes from the node's UI element.
3078 * @param {String/Array} className The CSS class to remove, or an array of classes
3080 removeClass : function(cls){
3082 Ext.fly(this.elNode).removeClass(cls);
3087 remove : function(){
3089 this.holder = document.createElement("div");
3090 this.holder.appendChild(this.wrap);
3095 fireEvent : function(){
3096 return this.node.fireEvent.apply(this.node, arguments);
3100 initEvents : function(){
3101 this.node.on("move", this.onMove, this);
3103 if(this.node.disabled){
3104 this.onDisableChange(this.node, true);
3106 if(this.node.hidden){
3109 var ot = this.node.getOwnerTree();
3110 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
3111 if(dd && (!this.node.isRoot || ot.rootVisible)){
3112 Ext.dd.Registry.register(this.elNode, {
3114 handles: this.getDDHandles(),
3121 getDDHandles : function(){
3122 return [this.iconNode, this.textNode, this.elNode];
3129 this.node.hidden = true;
3131 this.wrap.style.display = "none";
3139 this.node.hidden = false;
3141 this.wrap.style.display = "";
3146 onContextMenu : function(e){
3147 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
3150 this.fireEvent("contextmenu", this.node, e);
3155 onClick : function(e){
3160 if(this.fireEvent("beforeclick", this.node, e) !== false){
3161 var a = e.getTarget('a');
3162 if(!this.disabled && this.node.attributes.href && a){
3163 this.fireEvent("click", this.node, e);
3165 }else if(a && e.ctrlKey){
3173 if(this.node.attributes.singleClickExpand && !this.animating && this.node.isExpandable()){
3177 this.fireEvent("click", this.node, e);
3184 onDblClick : function(e){
3189 if(this.fireEvent("beforedblclick", this.node, e) !== false){
3193 if(!this.animating && this.node.isExpandable()){
3196 this.fireEvent("dblclick", this.node, e);
3200 onOver : function(e){
3201 this.addClass('x-tree-node-over');
3204 onOut : function(e){
3205 this.removeClass('x-tree-node-over');
3209 onCheckChange : function(){
3210 var checked = this.checkbox.checked;
3212 this.checkbox.defaultChecked = checked;
3213 this.node.attributes.checked = checked;
3214 this.fireEvent('checkchange', this.node, checked);
3218 ecClick : function(e){
3219 if(!this.animating && this.node.isExpandable()){
3225 startDrop : function(){
3226 this.dropping = true;
3229 // delayed drop so the click event doesn't get fired on a drop
3230 endDrop : function(){
3231 setTimeout(function(){
3232 this.dropping = false;
3233 }.createDelegate(this), 50);
3237 expand : function(){
3238 this.updateExpandIcon();
3239 this.ctNode.style.display = "";
3244 if(!this.node.preventHScroll){
3245 try{this.anchor.focus();
3249 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
3250 var l = noscroll.scrollLeft;
3251 this.anchor.focus();
3252 noscroll.scrollLeft = l;
3258 * Sets the checked status of the tree node to the passed value, or, if no value was passed,
3259 * toggles the checked status. If the node was rendered with no checkbox, this has no effect.
3260 * @param {Boolean} value (optional) The new checked status.
3262 toggleCheck : function(value){
3263 var cb = this.checkbox;
3265 cb.checked = (value === undefined ? !cb.checked : value);
3266 this.onCheckChange();
3278 animExpand : function(callback){
3279 var ct = Ext.get(this.ctNode);
3281 if(!this.node.isExpandable()){
3282 this.updateExpandIcon();
3283 this.ctNode.style.display = "";
3284 Ext.callback(callback);
3287 this.animating = true;
3288 this.updateExpandIcon();
3291 callback : function(){
3292 this.animating = false;
3293 Ext.callback(callback);
3296 duration: this.node.ownerTree.duration || .25
3301 highlight : function(){
3302 var tree = this.node.getOwnerTree();
3303 Ext.fly(this.wrap).highlight(
3304 tree.hlColor || "C3DAF9",
3305 {endColor: tree.hlBaseColor}
3310 collapse : function(){
3311 this.updateExpandIcon();
3312 this.ctNode.style.display = "none";
3316 animCollapse : function(callback){
3317 var ct = Ext.get(this.ctNode);
3318 ct.enableDisplayMode('block');
3321 this.animating = true;
3322 this.updateExpandIcon();
3325 callback : function(){
3326 this.animating = false;
3327 Ext.callback(callback);
3330 duration: this.node.ownerTree.duration || .25
3335 getContainer : function(){
3340 * Returns the element which encapsulates this node.
3341 * @return {HtmlElement} The DOM element. The default implementation uses a <code><li></code>.
3348 appendDDGhost : function(ghostNode){
3349 ghostNode.appendChild(this.elNode.cloneNode(true));
3353 getDDRepairXY : function(){
3354 return Ext.lib.Dom.getXY(this.iconNode);
3358 onRender : function(){
3363 render : function(bulkRender){
3364 var n = this.node, a = n.attributes;
3365 var targetNode = n.parentNode ?
3366 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
3369 this.rendered = true;
3371 this.renderElements(n, a, targetNode, bulkRender);
3374 if(this.textNode.setAttributeNS){
3375 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
3377 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
3380 this.textNode.setAttribute("ext:qtip", a.qtip);
3382 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
3385 }else if(a.qtipCfg){
3386 a.qtipCfg.target = Ext.id(this.textNode);
3387 Ext.QuickTips.register(a.qtipCfg);
3390 if(!this.node.expanded){
3391 this.updateExpandIcon(true);
3394 if(bulkRender === true) {
3395 targetNode.appendChild(this.wrap);
3401 renderElements : function(n, a, targetNode, bulkRender){
3402 // add some indent caching, this helps performance when rendering a large tree
3403 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
3405 var cb = Ext.isBoolean(a.checked),
3407 href = a.href ? a.href : Ext.isGecko ? "" : "#",
3408 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">',
3409 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
3410 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
3411 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
3412 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',
3413 '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ',
3414 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",
3415 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
3418 if(bulkRender !== true && n.nextSibling && (nel = n.nextSibling.ui.getEl())){
3419 this.wrap = Ext.DomHelper.insertHtml("beforeBegin", nel, buf);
3421 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf);
3424 this.elNode = this.wrap.childNodes[0];
3425 this.ctNode = this.wrap.childNodes[1];
3426 var cs = this.elNode.childNodes;
3427 this.indentNode = cs[0];
3428 this.ecNode = cs[1];
3429 this.iconNode = cs[2];
3432 this.checkbox = cs[3];
3434 this.checkbox.defaultChecked = this.checkbox.checked;
3437 this.anchor = cs[index];
3438 this.textNode = cs[index].firstChild;
3442 * Returns the <a> element that provides focus for the node's UI.
3443 * @return {HtmlElement} The DOM anchor element.
3445 getAnchor : function(){
3450 * Returns the text node.
3451 * @return {HtmlNode} The DOM text node.
3453 getTextEl : function(){
3454 return this.textNode;
3458 * Returns the icon <img> element.
3459 * @return {HtmlElement} The DOM image element.
3461 getIconEl : function(){
3462 return this.iconNode;
3466 * Returns the checked status of the node. If the node was rendered with no
3467 * checkbox, it returns false.
3468 * @return {Boolean} The checked flag.
3470 isChecked : function(){
3471 return this.checkbox ? this.checkbox.checked : false;
3475 updateExpandIcon : function(){
3480 cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow",
3481 hasChild = n.hasChildNodes();
3482 if(hasChild || n.attributes.expandable){
3485 c1 = "x-tree-node-collapsed";
3486 c2 = "x-tree-node-expanded";
3489 c1 = "x-tree-node-expanded";
3490 c2 = "x-tree-node-collapsed";
3493 this.removeClass("x-tree-node-leaf");
3494 this.wasLeaf = false;
3496 if(this.c1 != c1 || this.c2 != c2){
3497 Ext.fly(this.elNode).replaceClass(c1, c2);
3498 this.c1 = c1; this.c2 = c2;
3502 Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-collapsed");
3505 this.wasLeaf = true;
3508 var ecc = "x-tree-ec-icon "+cls;
3509 if(this.ecc != ecc){
3510 this.ecNode.className = ecc;
3517 onIdChange: function(id){
3519 this.elNode.setAttribute('ext:tree-node-id', id);
3524 getChildIndent : function(){
3525 if(!this.childIndent){
3529 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
3531 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
3533 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
3538 this.childIndent = buf.join("");
3540 return this.childIndent;
3544 renderIndent : function(){
3547 p = this.node.parentNode;
3549 indent = p.ui.getChildIndent();
3551 if(this.indentMarkup != indent){ // don't rerender if not required
3552 this.indentNode.innerHTML = indent;
3553 this.indentMarkup = indent;
3555 this.updateExpandIcon();
3559 destroy : function(){
3561 Ext.dd.Registry.unregister(this.elNode.id);
3564 Ext.each(['textnode', 'anchor', 'checkbox', 'indentNode', 'ecNode', 'iconNode', 'elNode', 'ctNode', 'wrap', 'holder'], function(el){
3566 Ext.fly(this[el]).remove();
3575 * @class Ext.tree.RootTreeNodeUI
3576 * This class provides the default UI implementation for <b>root</b> Ext TreeNodes.
3577 * The RootTreeNode UI implementation allows customizing the appearance of the root tree node.<br>
3579 * If you are customizing the Tree's user interface, you
3580 * may need to extend this class, but you should never need to instantiate this class.<br>
3582 Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
3584 render : function(){
3586 var targetNode = this.node.ownerTree.innerCt.dom;
3587 this.node.expanded = true;
3588 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
3589 this.wrap = this.ctNode = targetNode.firstChild;
3592 collapse : Ext.emptyFn,
3593 expand : Ext.emptyFn
3595 * @class Ext.tree.TreeLoader
3596 * @extends Ext.util.Observable
3597 * A TreeLoader provides for lazy loading of an {@link Ext.tree.TreeNode}'s child
3598 * nodes from a specified URL. The response must be a JavaScript Array definition
3599 * whose elements are node definition objects. e.g.:
3603 text: 'A leaf Node',
3607 text: 'A folder Node',
3610 text: 'A child Node',
3616 * A server request is sent, and child nodes are loaded only when a node is expanded.
3617 * The loading node's id is passed to the server under the parameter name "node" to
3618 * enable the server to produce the correct child nodes.
3620 * To pass extra parameters, an event handler may be attached to the "beforeload"
3621 * event, and the parameters specified in the TreeLoader's baseParams property:
3623 myTreeLoader.on("beforeload", function(treeLoader, node) {
3624 this.baseParams.category = node.attributes.category;
3627 * This would pass an HTTP parameter called "category" to the server containing
3628 * the value of the Node's "category" attribute.
3630 * Creates a new Treeloader.
3631 * @param {Object} config A config object containing config properties.
3633 Ext.tree.TreeLoader = function(config){
3634 this.baseParams = {};
3635 Ext.apply(this, config);
3640 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
3641 * @param {Object} This TreeLoader object.
3642 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
3643 * @param {Object} callback The callback function specified in the {@link #load} call.
3648 * Fires when the node has been successfuly loaded.
3649 * @param {Object} This TreeLoader object.
3650 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
3651 * @param {Object} response The response object containing the data from the server.
3655 * @event loadexception
3656 * Fires if the network request failed.
3657 * @param {Object} This TreeLoader object.
3658 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
3659 * @param {Object} response The response object containing the data from the server.
3663 Ext.tree.TreeLoader.superclass.constructor.call(this);
3664 if(Ext.isString(this.paramOrder)){
3665 this.paramOrder = this.paramOrder.split(/[\s,|]/);
3669 Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, {
3671 * @cfg {String} dataUrl The URL from which to request a Json string which
3672 * specifies an array of node definition objects representing the child nodes
3676 * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
3679 * @cfg {String} url Equivalent to {@link #dataUrl}.
3682 * @cfg {Boolean} preloadChildren If set to true, the loader recursively loads "children" attributes when doing the first load on nodes.
3685 * @cfg {Object} baseParams (optional) An object containing properties which
3686 * specify HTTP parameters to be passed to each request for child nodes.
3689 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
3690 * created by this loader. If the attributes sent by the server have an attribute in this object,
3691 * they take priority.
3694 * @cfg {Object} uiProviders (optional) An object containing properties which
3695 * specify custom {@link Ext.tree.TreeNodeUI} implementations. If the optional
3696 * <i>uiProvider</i> attribute of a returned child node is a string rather
3697 * than a reference to a TreeNodeUI implementation, then that string value
3698 * is used as a property name in the uiProviders object.
3703 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
3704 * child nodes before loading.
3709 * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. Only used when using directFn.
3710 * Specifies the params in the order in which they must be passed to the server-side Direct method
3711 * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
3712 * comma, or pipe. For example,
3713 * any of the following would be acceptable:<pre><code>
3714 nodeParameter: 'node',
3715 paramOrder: ['param1','param2','param3']
3716 paramOrder: 'node param1 param2 param3'
3717 paramOrder: 'param1,node,param2,param3'
3718 paramOrder: 'param1|param2|param|node'
3721 paramOrder: undefined,
3724 * @cfg {Boolean} paramsAsHash Only used when using directFn.
3725 * Send parameters as a collection of named arguments (defaults to <tt>false</tt>). Providing a
3726 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
3728 paramsAsHash: false,
3731 * @cfg {String} nodeParameter The name of the parameter sent to the server which contains
3732 * the identifier of the node. Defaults to <tt>'node'</tt>.
3734 nodeParameter: 'node',
3737 * @cfg {Function} directFn
3738 * Function to call when executing a request.
3740 directFn : undefined,
3743 * Load an {@link Ext.tree.TreeNode} from the URL specified in the constructor.
3744 * This is called automatically when a node is expanded, but may be used to reload
3745 * a node (or append new children if the {@link #clearOnLoad} option is false.)
3746 * @param {Ext.tree.TreeNode} node
3747 * @param {Function} callback Function to call after the node has been loaded. The
3748 * function is passed the TreeNode which was requested to be loaded.
3749 * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed.
3750 * defaults to the loaded TreeNode.
3752 load : function(node, callback, scope){
3753 if(this.clearOnLoad){
3754 while(node.firstChild){
3755 node.removeChild(node.firstChild);
3758 if(this.doPreload(node)){ // preloaded json children
3759 this.runCallback(callback, scope || node, [node]);
3760 }else if(this.directFn || this.dataUrl || this.url){
3761 this.requestData(node, callback, scope || node);
3765 doPreload : function(node){
3766 if(node.attributes.children){
3767 if(node.childNodes.length < 1){ // preloaded?
3768 var cs = node.attributes.children;
3770 for(var i = 0, len = cs.length; i < len; i++){
3771 var cn = node.appendChild(this.createNode(cs[i]));
3772 if(this.preloadChildren){
3783 getParams: function(node){
3784 var bp = Ext.apply({}, this.baseParams),
3785 np = this.nodeParameter,
3786 po = this.paramOrder;
3788 np && (bp[ np ] = node.id);
3791 var buf = [node.id];
3793 // reset 'buf' if the nodeParameter was included in paramOrder
3794 if(np && po.indexOf(np) > -1){
3798 for(var i = 0, len = po.length; i < len; i++){
3799 buf.push(bp[ po[i] ]);
3801 }else if(this.paramsAsHash){
3810 requestData : function(node, callback, scope){
3811 if(this.fireEvent("beforeload", this, node, callback) !== false){
3813 var args = this.getParams(node);
3814 args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));
3815 this.directFn.apply(window, args);
3817 this.transId = Ext.Ajax.request({
3818 method:this.requestMethod,
3819 url: this.dataUrl||this.url,
3820 success: this.handleResponse,
3821 failure: this.handleFailure,
3823 argument: {callback: callback, node: node, scope: scope},
3824 params: this.getParams(node)
3828 // if the load is cancelled, make sure we notify
3829 // the node that we are done
3830 this.runCallback(callback, scope || node, []);
3834 processDirectResponse: function(result, response, args){
3835 if(response.status){
3836 this.handleResponse({
3837 responseData: Ext.isArray(result) ? result : null,
3838 responseText: result,
3842 this.handleFailure({
3849 runCallback: function(cb, scope, args){
3850 if(Ext.isFunction(cb)){
3851 cb.apply(scope, args);
3855 isLoading : function(){
3856 return !!this.transId;
3860 if(this.isLoading()){
3861 Ext.Ajax.abort(this.transId);
3866 * <p>Override this function for custom TreeNode node implementation, or to
3867 * modify the attributes at creation time.</p>
3868 * Example:<pre><code>
3869 new Ext.tree.TreePanel({
3871 loader: new Ext.tree.TreeLoader({
3873 createNode: function(attr) {
3874 // Allow consolidation consignments to have
3875 // consignments dropped into them.
3876 if (attr.isConsolidation) {
3877 attr.iconCls = 'x-consol',
3878 attr.allowDrop = true;
3880 return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
3886 * @param attr {Object} The attributes from which to create the new node.
3888 createNode : function(attr){
3889 // apply baseAttrs, nice idea Corey!
3891 Ext.applyIf(attr, this.baseAttrs);
3893 if(this.applyLoader !== false && !attr.loader){
3896 if(Ext.isString(attr.uiProvider)){
3897 attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
3900 return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
3903 new Ext.tree.TreeNode(attr) :
3904 new Ext.tree.AsyncTreeNode(attr);
3908 processResponse : function(response, node, callback, scope){
3909 var json = response.responseText;
3911 var o = response.responseData || Ext.decode(json);
3913 for(var i = 0, len = o.length; i < len; i++){
3914 var n = this.createNode(o[i]);
3916 node.appendChild(n);
3920 this.runCallback(callback, scope || node, [node]);
3922 this.handleFailure(response);
3926 handleResponse : function(response){
3927 this.transId = false;
3928 var a = response.argument;
3929 this.processResponse(response, a.node, a.callback, a.scope);
3930 this.fireEvent("load", this, a.node, response);
3933 handleFailure : function(response){
3934 this.transId = false;
3935 var a = response.argument;
3936 this.fireEvent("loadexception", this, a.node, response);
3937 this.runCallback(a.callback, a.scope || a.node, [a.node]);
3940 destroy : function(){
3942 this.purgeListeners();
3945 * @class Ext.tree.TreeFilter
3946 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
3947 * @param {TreePanel} tree
3948 * @param {Object} config (optional)
3950 Ext.tree.TreeFilter = function(tree, config){
3953 Ext.apply(this, config);
3956 Ext.tree.TreeFilter.prototype = {
3963 * Filter the data by a specific attribute.
3964 * @param {String/RegExp} value Either string that the attribute value
3965 * should start with or a RegExp to test against the attribute
3966 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
3967 * @param {TreeNode} startNode (optional) The node to start the filter at.
3969 filter : function(value, attr, startNode){
3970 attr = attr || "text";
3972 if(typeof value == "string"){
3973 var vlen = value.length;
3974 // auto clear empty filter
3975 if(vlen == 0 && this.clearBlank){
3979 value = value.toLowerCase();
3981 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
3983 }else if(value.exec){ // regex?
3985 return value.test(n.attributes[attr]);
3988 throw 'Illegal filter type, must be string or regex';
3990 this.filterBy(f, null, startNode);
3994 * Filter by a function. The passed function will be called with each
3995 * node in the tree (or from the startNode). If the function returns true, the node is kept
3996 * otherwise it is filtered. If a node is filtered, its children are also filtered.
3997 * @param {Function} fn The filter function
3998 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
4000 filterBy : function(fn, scope, startNode){
4001 startNode = startNode || this.tree.root;
4005 var af = this.filtered, rv = this.reverse;
4006 var f = function(n){
4013 var m = fn.call(scope || n, n);
4021 startNode.cascade(f);
4024 if(typeof id != "function"){
4026 if(n && n.parentNode){
4027 n.parentNode.removeChild(n);
4035 * Clears the current filter. Note: with the "remove" option
4036 * set a filter cannot be cleared.
4040 var af = this.filtered;
4042 if(typeof id != "function"){
4053 * @class Ext.tree.TreeSorter
4054 * Provides sorting of nodes in a {@link Ext.tree.TreePanel}. The TreeSorter automatically monitors events on the
4055 * associated TreePanel that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
4056 * Example usage:<br />
4058 new Ext.tree.TreeSorter(myTree, {
4061 sortType: function(node) {
4062 // sort by a custom, typed attribute:
4063 return parseInt(node.id, 10);
4068 * @param {TreePanel} tree
4069 * @param {Object} config
4071 Ext.tree.TreeSorter = function(tree, config){
4073 * @cfg {Boolean} folderSort True to sort leaf nodes under non-leaf nodes (defaults to false)
4076 * @cfg {String} property The named attribute on the node to sort by (defaults to "text"). Note that this
4077 * property is only used if no {@link #sortType} function is specified, otherwise it is ignored.
4080 * @cfg {String} dir The direction to sort ("asc" or "desc," case-insensitive, defaults to "asc")
4083 * @cfg {String} leafAttr The attribute used to determine leaf nodes when {@link #folderSort} = true (defaults to "leaf")
4086 * @cfg {Boolean} caseSensitive true for case-sensitive sort (defaults to false)
4089 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting. The function
4090 * will be called with a single parameter (the {@link Ext.tree.TreeNode} being evaluated) and is expected to return
4091 * the node's sort value cast to the specific data type required for sorting. This could be used, for example, when
4092 * a node's text (or other attribute) should be sorted as a date or numeric value. See the class description for
4093 * example usage. Note that if a sortType is specified, any {@link #property} config will be ignored.
4096 Ext.apply(this, config);
4097 tree.on("beforechildrenrendered", this.doSort, this);
4098 tree.on("append", this.updateSort, this);
4099 tree.on("insert", this.updateSort, this);
4100 tree.on("textchange", this.updateSortParent, this);
4102 var dsc = this.dir && this.dir.toLowerCase() == "desc";
4103 var p = this.property || "text";
4104 var sortType = this.sortType;
4105 var fs = this.folderSort;
4106 var cs = this.caseSensitive === true;
4107 var leafAttr = this.leafAttr || 'leaf';
4109 this.sortFn = function(n1, n2){
4111 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
4114 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
4118 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
4119 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
4121 return dsc ? +1 : -1;
4123 return dsc ? -1 : +1;
4130 Ext.tree.TreeSorter.prototype = {
4131 doSort : function(node){
4132 node.sort(this.sortFn);
4135 compareNodes : function(n1, n2){
4136 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
4139 updateSort : function(tree, node){
4140 if(node.childrenRendered){
4141 this.doSort.defer(1, this, [node]);
4145 updateSortParent : function(node){
4146 var p = node.parentNode;
4147 if(p && p.childrenRendered){
4148 this.doSort.defer(1, this, [p]);
4152 * @class Ext.tree.TreeDropZone
4153 * @extends Ext.dd.DropZone
4155 * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dropping
4156 * @param {Object} config
4158 if(Ext.dd.DropZone){
4160 Ext.tree.TreeDropZone = function(tree, config){
4162 * @cfg {Boolean} allowParentInsert
4163 * Allow inserting a dragged node between an expanded parent node and its first child that will become a
4164 * sibling of the parent when dropped (defaults to false)
4166 this.allowParentInsert = config.allowParentInsert || false;
4168 * @cfg {String} allowContainerDrop
4169 * True if drops on the tree container (outside of a specific tree node) are allowed (defaults to false)
4171 this.allowContainerDrop = config.allowContainerDrop || false;
4173 * @cfg {String} appendOnly
4174 * True if the tree should only allow append drops (use for trees which are sorted, defaults to false)
4176 this.appendOnly = config.appendOnly || false;
4178 Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.getTreeEl(), config);
4180 * The TreePanel for this drop zone
4181 * @type Ext.tree.TreePanel
4186 * Arbitrary data that can be associated with this tree and will be included in the event object that gets
4187 * passed to any nodedragover event handler (defaults to {})
4188 * @type Ext.tree.TreePanel
4191 this.dragOverData = {};
4193 this.lastInsertClass = "x-tree-no-status";
4196 Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, {
4198 * @cfg {String} ddGroup
4199 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
4200 * interact with other drag drop objects in the same group (defaults to 'TreeDD').
4205 * @cfg {String} expandDelay
4206 * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node
4207 * over the target (defaults to 1000)
4212 expandNode : function(node){
4213 if(node.hasChildNodes() && !node.isExpanded()){
4214 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
4219 queueExpand : function(node){
4220 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
4224 cancelExpand : function(){
4225 if(this.expandProcId){
4226 clearTimeout(this.expandProcId);
4227 this.expandProcId = false;
4232 isValidDropPoint : function(n, pt, dd, e, data){
4233 if(!n || !data){ return false; }
4234 var targetNode = n.node;
4235 var dropNode = data.node;
4236 // default drop rules
4237 if(!(targetNode && targetNode.isTarget && pt)){
4240 if(pt == "append" && targetNode.allowChildren === false){
4243 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
4246 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
4250 var overEvent = this.dragOverData;
4251 overEvent.tree = this.tree;
4252 overEvent.target = targetNode;
4253 overEvent.data = data;
4254 overEvent.point = pt;
4255 overEvent.source = dd;
4256 overEvent.rawEvent = e;
4257 overEvent.dropNode = dropNode;
4258 overEvent.cancel = false;
4259 var result = this.tree.fireEvent("nodedragover", overEvent);
4260 return overEvent.cancel === false && result !== false;
4264 getDropPoint : function(e, n, dd){
4267 return tn.allowChildren !== false ? "append" : false; // always append for root
4269 var dragEl = n.ddel;
4270 var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
4271 var y = Ext.lib.Event.getPageY(e);
4272 var noAppend = tn.allowChildren === false || tn.isLeaf();
4273 if(this.appendOnly || tn.parentNode.allowChildren === false){
4274 return noAppend ? false : "append";
4276 var noBelow = false;
4277 if(!this.allowParentInsert){
4278 noBelow = tn.hasChildNodes() && tn.isExpanded();
4280 var q = (b - t) / (noAppend ? 2 : 3);
4281 if(y >= t && y < (t + q)){
4283 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
4291 onNodeEnter : function(n, dd, e, data){
4292 this.cancelExpand();
4295 onContainerOver : function(dd, e, data) {
4296 if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
4297 return this.dropAllowed;
4299 return this.dropNotAllowed;
4303 onNodeOver : function(n, dd, e, data){
4304 var pt = this.getDropPoint(e, n, dd);
4307 // auto node expand check
4308 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
4309 this.queueExpand(node);
4310 }else if(pt != "append"){
4311 this.cancelExpand();
4314 // set the insert point style on the target node
4315 var returnCls = this.dropNotAllowed;
4316 if(this.isValidDropPoint(n, pt, dd, e, data)){
4321 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
4322 cls = "x-tree-drag-insert-above";
4323 }else if(pt == "below"){
4324 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
4325 cls = "x-tree-drag-insert-below";
4327 returnCls = "x-tree-drop-ok-append";
4328 cls = "x-tree-drag-append";
4330 if(this.lastInsertClass != cls){
4331 Ext.fly(el).replaceClass(this.lastInsertClass, cls);
4332 this.lastInsertClass = cls;
4340 onNodeOut : function(n, dd, e, data){
4341 this.cancelExpand();
4342 this.removeDropIndicators(n);
4346 onNodeDrop : function(n, dd, e, data){
4347 var point = this.getDropPoint(e, n, dd);
4348 var targetNode = n.node;
4349 targetNode.ui.startDrop();
4350 if(!this.isValidDropPoint(n, point, dd, e, data)){
4351 targetNode.ui.endDrop();
4354 // first try to find the drop node
4355 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
4356 return this.processDrop(targetNode, data, point, dd, e, dropNode);
4359 onContainerDrop : function(dd, e, data){
4360 if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
4361 var targetNode = this.tree.getRootNode();
4362 targetNode.ui.startDrop();
4363 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, 'append', e) : null);
4364 return this.processDrop(targetNode, data, 'append', dd, e, dropNode);
4370 processDrop: function(target, data, point, dd, e, dropNode){
4382 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
4383 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
4384 target.ui.endDrop();
4385 return dropEvent.dropStatus;
4388 target = dropEvent.target;
4389 if(point == 'append' && !target.isExpanded()){
4390 target.expand(false, null, function(){
4391 this.completeDrop(dropEvent);
4392 }.createDelegate(this));
4394 this.completeDrop(dropEvent);
4400 completeDrop : function(de){
4401 var ns = de.dropNode, p = de.point, t = de.target;
4402 if(!Ext.isArray(ns)){
4406 for(var i = 0, len = ns.length; i < len; i++){
4409 t.parentNode.insertBefore(n, t);
4410 }else if(p == "below"){
4411 t.parentNode.insertBefore(n, t.nextSibling);
4417 if(Ext.enableFx && this.tree.hlDrop){
4421 this.tree.fireEvent("nodedrop", de);
4425 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
4426 if(Ext.enableFx && this.tree.hlDrop){
4427 dropNode.ui.focus();
4428 dropNode.ui.highlight();
4430 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
4434 getTree : function(){
4439 removeDropIndicators : function(n){
4442 Ext.fly(el).removeClass([
4443 "x-tree-drag-insert-above",
4444 "x-tree-drag-insert-below",
4445 "x-tree-drag-append"]);
4446 this.lastInsertClass = "_noclass";
4451 beforeDragDrop : function(target, e, id){
4452 this.cancelExpand();
4457 afterRepair : function(data){
4458 if(data && Ext.enableFx){
4459 data.node.ui.highlight();
4466 * @class Ext.tree.TreeDragZone
4467 * @extends Ext.dd.DragZone
4469 * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dragging
4470 * @param {Object} config
4472 if(Ext.dd.DragZone){
4473 Ext.tree.TreeDragZone = function(tree, config){
4474 Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.innerCt, config);
4476 * The TreePanel for this drag zone
4477 * @type Ext.tree.TreePanel
4483 Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, {
4485 * @cfg {String} ddGroup
4486 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
4487 * interact with other drag drop objects in the same group (defaults to 'TreeDD').
4492 onBeforeDrag : function(data, e){
4494 return n && n.draggable && !n.disabled;
4498 onInitDrag : function(e){
4499 var data = this.dragData;
4500 this.tree.getSelectionModel().select(data.node);
4501 this.tree.eventModel.disable();
4502 this.proxy.update("");
4503 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
4504 this.tree.fireEvent("startdrag", this.tree, data.node, e);
4508 getRepairXY : function(e, data){
4509 return data.node.ui.getDDRepairXY();
4513 onEndDrag : function(data, e){
4514 this.tree.eventModel.enable.defer(100, this.tree.eventModel);
4515 this.tree.fireEvent("enddrag", this.tree, data.node, e);
4519 onValidDrop : function(dd, e, id){
4520 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
4525 beforeInvalidDrop : function(e, id){
4526 // this scrolls the original position back into view
4527 var sm = this.tree.getSelectionModel();
4528 sm.clearSelections();
4529 sm.select(this.dragData.node);
4533 afterRepair : function(){
4534 if (Ext.enableFx && this.tree.hlDrop) {
4535 Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
4537 this.dragging = false;
4541 * @class Ext.tree.TreeEditor
4542 * @extends Ext.Editor
4543 * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
4544 * as the editor field.
4546 * @param {TreePanel} tree
4547 * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
4548 * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
4549 * @param {Object} config (optional) A TreeEditor config object
4551 Ext.tree.TreeEditor = function(tree, fc, config){
4553 var field = fc.events ? fc : new Ext.form.TextField(fc);
4555 Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
4560 tree.on('render', this.initEditor, this);
4562 this.initEditor(tree);
4566 Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
4568 * @cfg {String} alignment
4569 * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "l-l").
4575 * @cfg {Boolean} hideEl
4576 * True to hide the bound element while the editor is displayed (defaults to false)
4581 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
4583 cls: "x-small-editor x-tree-editor",
4585 * @cfg {Boolean} shim
4586 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
4592 * @cfg {Number} maxWidth
4593 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
4594 * the containing tree element's size, it will be automatically limited for you to the container width, taking
4595 * scroll and client offsets into account prior to each edit.
4599 * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
4600 * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
4601 * the editor for the node will display, otherwise it will be processed as a regular click.
4605 initEditor : function(tree){
4608 beforeclick: this.beforeNodeClick,
4609 dblclick : this.onNodeDblClick
4614 complete : this.updateNode,
4615 beforestartedit: this.fitToTree,
4616 specialkey : this.onSpecialKey
4619 this.on('startedit', this.bindScroll, this, {delay:10});
4623 fitToTree : function(ed, el){
4624 var td = this.tree.getTreeEl().dom, nd = el.dom;
4625 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
4626 td.scrollLeft = nd.offsetLeft;
4630 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
4631 this.setSize(w, '');
4635 * Edit the text of the passed {@link Ext.tree.TreeNode TreeNode}.
4636 * @param node {Ext.tree.TreeNode} The TreeNode to edit. The TreeNode must be {@link Ext.tree.TreeNode#editable editable}.
4638 triggerEdit : function(node, defer){
4639 this.completeEdit();
4640 if(node.attributes.editable !== false){
4642 * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
4643 * @type Ext.tree.TreeNode
4644 * @property editNode
4646 this.editNode = node;
4647 if(this.tree.autoScroll){
4648 Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
4650 var value = node.text || '';
4651 if (!Ext.isGecko && Ext.isEmpty(node.text)){
4652 node.setText(' ');
4654 this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
4660 bindScroll : function(){
4661 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
4665 beforeNodeClick : function(node, e){
4666 clearTimeout(this.autoEditTimer);
4667 if(this.tree.getSelectionModel().isSelected(node)){
4669 return this.triggerEdit(node);
4673 onNodeDblClick : function(node, e){
4674 clearTimeout(this.autoEditTimer);
4678 updateNode : function(ed, value){
4679 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
4680 this.editNode.setText(value);
4684 onHide : function(){
4685 Ext.tree.TreeEditor.superclass.onHide.call(this);
4687 this.editNode.ui.focus.defer(50, this.editNode.ui);
4692 onSpecialKey : function(field, e){
4697 }else if(k == e.ENTER && !e.hasModifier()){
4699 this.completeEdit();
4703 onDestroy : function(){
4704 clearTimeout(this.autoEditTimer);
4705 Ext.tree.TreeEditor.superclass.onDestroy.call(this);
4706 var tree = this.tree;
4707 tree.un('beforeclick', this.beforeNodeClick, this);
4708 tree.un('dblclick', this.onNodeDblClick, this);