3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.tree.TreePanel
\r
10 * <p>The TreePanel provides tree-structured UI representation of tree-structured data.</p>
\r
11 * <p>{@link Ext.tree.TreeNode TreeNode}s added to the TreePanel may each contain metadata
\r
12 * used by your application in their {@link Ext.tree.TreeNode#attributes attributes} property.</p>
\r
13 * <p><b>A TreePanel must have a {@link #root} node before it is rendered.</b> This may either be
\r
14 * specified using the {@link #root} config option, or using the {@link #setRootNode} method.
\r
15 * <p>An example of tree rendered to an existing div:</p><pre><code>
\r
16 var tree = new Ext.tree.TreePanel({
\r
17 renderTo: 'tree-div',
\r
22 containerScroll: true,
\r
24 // auto create TreeLoader
\r
25 dataUrl: 'get-nodes.php',
\r
35 tree.getRootNode().expand();
\r
37 * <p>The example above would work with a data packet similar to this:</p><pre><code>
\r
40 "id": "source\/adapter",
\r
48 "id": "source\/debug.js",
\r
53 * <p>An example of tree within a Viewport:</p><pre><code>
\r
59 title: 'Navigation',
\r
64 loader: new Ext.tree.TreeLoader(),
\r
65 root: new Ext.tree.AsyncTreeNode({
\r
68 text: 'Menu Option 1',
\r
71 text: 'Menu Option 2',
\r
74 text: 'Menu Option 3',
\r
80 click: function(n) {
\r
81 Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
\r
87 // remaining code not shown ...
\r
92 * @cfg {Ext.tree.TreeNode} root The root node for the tree.
\r
93 * @cfg {Boolean} rootVisible <tt>false</tt> to hide the root node (defaults to <tt>true</tt>)
\r
94 * @cfg {Boolean} lines <tt>false</tt> to disable tree lines (defaults to <tt>true</tt>)
\r
95 * @cfg {Boolean} enableDD <tt>true</tt> to enable drag and drop
\r
96 * @cfg {Boolean} enableDrag <tt>true</tt> to enable just drag
\r
97 * @cfg {Boolean} enableDrop <tt>true</tt> to enable just drop
\r
98 * @cfg {Object} dragConfig Custom config to pass to the {@link Ext.tree.TreeDragZone} instance
\r
99 * @cfg {Object} dropConfig Custom config to pass to the {@link Ext.tree.TreeDropZone} instance
\r
100 * @cfg {String} ddGroup The DD group this TreePanel belongs to
\r
101 * @cfg {Boolean} ddAppendOnly <tt>true</tt> if the tree should only allow append drops (use for trees which are sorted)
\r
102 * @cfg {Boolean} ddScroll <tt>true</tt> to enable body scrolling
\r
103 * @cfg {Boolean} containerScroll <tt>true</tt> to register this container with ScrollManager
\r
104 * @cfg {Boolean} hlDrop <tt>false</tt> to disable node highlight on drop (defaults to the value of {@link Ext#enableFx})
\r
105 * @cfg {String} hlColor The color of the node highlight (defaults to <tt>'C3DAF9'</tt>)
\r
106 * @cfg {Boolean} animate <tt>true</tt> to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx})
\r
107 * @cfg {Boolean} singleExpand <tt>true</tt> if only 1 node per branch may be expanded
\r
108 * @cfg {Object} selModel A tree selection model to use with this TreePanel (defaults to an {@link Ext.tree.DefaultSelectionModel})
\r
109 * @cfg {Boolean} trackMouseOver <tt>false</tt> to disable mouse over highlighting
\r
110 * @cfg {Ext.tree.TreeLoader} loader A {@link Ext.tree.TreeLoader} for use with this TreePanel
\r
111 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to <tt>'/'</tt>)
\r
112 * @cfg {Boolean} useArrows <tt>true</tt> to use Vista-style arrows in the tree (defaults to <tt>false</tt>)
\r
113 * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
\r
116 * @param {Object} config
\r
119 Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
\r
120 rootVisible : true,
\r
121 animate : Ext.enableFx,
\r
124 hlDrop : Ext.enableFx,
\r
125 pathSeparator : '/',
\r
128 * @cfg {Array} bubbleEvents
\r
129 * <p>An array of events that, when fired, should be bubbled to any parent container.
\r
130 * See {@link Ext.util.Observable#enableBubble}.
\r
131 * Defaults to <tt>[]</tt>.
\r
135 initComponent : function(){
\r
136 Ext.tree.TreePanel.superclass.initComponent.call(this);
\r
138 if(!this.eventModel){
\r
139 this.eventModel = new Ext.tree.TreeEventModel(this);
\r
142 // initialize the loader
\r
143 var l = this.loader;
\r
145 l = new Ext.tree.TreeLoader({
\r
146 dataUrl: this.dataUrl,
\r
147 requestMethod: this.requestMethod
\r
149 }else if(Ext.isObject(l) && !l.load){
\r
150 l = new Ext.tree.TreeLoader(l);
\r
154 this.nodeHash = {};
\r
157 * The root node of this tree.
\r
158 * @type Ext.tree.TreeNode
\r
164 this.setRootNode(r);
\r
172 * Fires when a new child node is appended to a node in this tree.
\r
173 * @param {Tree} tree The owner tree
\r
174 * @param {Node} parent The parent node
\r
175 * @param {Node} node The newly appended node
\r
176 * @param {Number} index The index of the newly appended node
\r
181 * Fires when a child node is removed from a node in this tree.
\r
182 * @param {Tree} tree The owner tree
\r
183 * @param {Node} parent The parent node
\r
184 * @param {Node} node The child node removed
\r
189 * Fires when a node is moved to a new location in the tree
\r
190 * @param {Tree} tree The owner tree
\r
191 * @param {Node} node The node moved
\r
192 * @param {Node} oldParent The old parent of this node
\r
193 * @param {Node} newParent The new parent of this node
\r
194 * @param {Number} index The index it was moved to
\r
199 * Fires when a new child node is inserted in a node in this tree.
\r
200 * @param {Tree} tree The owner tree
\r
201 * @param {Node} parent The parent node
\r
202 * @param {Node} node The child node inserted
\r
203 * @param {Node} refNode The child node the node was inserted before
\r
207 * @event beforeappend
\r
208 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
\r
209 * @param {Tree} tree The owner tree
\r
210 * @param {Node} parent The parent node
\r
211 * @param {Node} node The child node to be appended
\r
215 * @event beforeremove
\r
216 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
\r
217 * @param {Tree} tree The owner tree
\r
218 * @param {Node} parent The parent node
\r
219 * @param {Node} node The child node to be removed
\r
223 * @event beforemovenode
\r
224 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
\r
225 * @param {Tree} tree The owner tree
\r
226 * @param {Node} node The node being moved
\r
227 * @param {Node} oldParent The parent of the node
\r
228 * @param {Node} newParent The new parent the node is moving to
\r
229 * @param {Number} index The index it is being moved to
\r
233 * @event beforeinsert
\r
234 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
\r
235 * @param {Tree} tree The owner tree
\r
236 * @param {Node} parent The parent node
\r
237 * @param {Node} node The child node to be inserted
\r
238 * @param {Node} refNode The child node the node is being inserted before
\r
243 * @event beforeload
\r
244 * Fires before a node is loaded, return false to cancel
\r
245 * @param {Node} node The node being loaded
\r
250 * Fires when a node is loaded
\r
251 * @param {Node} node The node that was loaded
\r
255 * @event textchange
\r
256 * Fires when the text for a node is changed
\r
257 * @param {Node} node The node
\r
258 * @param {String} text The new text
\r
259 * @param {String} oldText The old text
\r
263 * @event beforeexpandnode
\r
264 * Fires before a node is expanded, return false to cancel.
\r
265 * @param {Node} node The node
\r
266 * @param {Boolean} deep
\r
267 * @param {Boolean} anim
\r
269 'beforeexpandnode',
\r
271 * @event beforecollapsenode
\r
272 * Fires before a node is collapsed, return false to cancel.
\r
273 * @param {Node} node The node
\r
274 * @param {Boolean} deep
\r
275 * @param {Boolean} anim
\r
277 'beforecollapsenode',
\r
279 * @event expandnode
\r
280 * Fires when a node is expanded
\r
281 * @param {Node} node The node
\r
285 * @event disabledchange
\r
286 * Fires when the disabled status of a node changes
\r
287 * @param {Node} node The node
\r
288 * @param {Boolean} disabled
\r
292 * @event collapsenode
\r
293 * Fires when a node is collapsed
\r
294 * @param {Node} node The node
\r
298 * @event beforeclick
\r
299 * Fires before click processing on a node. Return false to cancel the default action.
\r
300 * @param {Node} node The node
\r
301 * @param {Ext.EventObject} e The event object
\r
306 * Fires when a node is clicked
\r
307 * @param {Node} node The node
\r
308 * @param {Ext.EventObject} e The event object
\r
312 * @event containerclick
\r
313 * Fires when the tree container is clicked
\r
314 * @param {Tree} this
\r
315 * @param {Ext.EventObject} e The event object
\r
319 * @event checkchange
\r
320 * Fires when a node with a checkbox's checked property changes
\r
321 * @param {Node} this This node
\r
322 * @param {Boolean} checked
\r
326 * @event beforedblclick
\r
327 * Fires before double click processing on a node. Return false to cancel the default action.
\r
328 * @param {Node} node The node
\r
329 * @param {Ext.EventObject} e The event object
\r
334 * Fires when a node is double clicked
\r
335 * @param {Node} node The node
\r
336 * @param {Ext.EventObject} e The event object
\r
340 * @event containerdblclick
\r
341 * Fires when the tree container is double clicked
\r
342 * @param {Tree} this
\r
343 * @param {Ext.EventObject} e The event object
\r
345 'containerdblclick',
\r
347 * @event contextmenu
\r
348 * Fires when a node is right clicked. To display a context menu in response to this
\r
349 * event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add
\r
350 * a handler for this event:<pre><code>
\r
351 new Ext.tree.TreePanel({
\r
352 title: 'My TreePanel',
\r
353 root: new Ext.tree.AsyncTreeNode({
\r
356 { text: 'Child node 1', leaf: true },
\r
357 { text: 'Child node 2', leaf: true }
\r
360 contextMenu: new Ext.menu.Menu({
\r
363 text: 'Delete Node'
\r
366 itemclick: function(item) {
\r
368 case 'delete-node':
\r
369 var n = item.parentMenu.contextNode;
\r
370 if (n.parentNode) {
\r
379 contextmenu: function(node, e) {
\r
380 // Register the context node with the menu so that a Menu Item's handler function can access
\r
381 // it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.
\r
383 var c = node.getOwnerTree().contextMenu;
\r
384 c.contextNode = node;
\r
385 c.showAt(e.getXY());
\r
390 * @param {Node} node The node
\r
391 * @param {Ext.EventObject} e The event object
\r
395 * @event containercontextmenu
\r
396 * Fires when the tree container is right clicked
\r
397 * @param {Tree} this
\r
398 * @param {Ext.EventObject} e The event object
\r
400 'containercontextmenu',
\r
402 * @event beforechildrenrendered
\r
403 * Fires right before the child nodes for a node are rendered
\r
404 * @param {Node} node The node
\r
406 'beforechildrenrendered',
\r
409 * Fires when a node starts being dragged
\r
410 * @param {Ext.tree.TreePanel} this
\r
411 * @param {Ext.tree.TreeNode} node
\r
412 * @param {event} e The raw browser event
\r
417 * Fires when a drag operation is complete
\r
418 * @param {Ext.tree.TreePanel} this
\r
419 * @param {Ext.tree.TreeNode} node
\r
420 * @param {event} e The raw browser event
\r
425 * Fires when a dragged node is dropped on a valid DD target
\r
426 * @param {Ext.tree.TreePanel} this
\r
427 * @param {Ext.tree.TreeNode} node
\r
428 * @param {DD} dd The dd it was dropped on
\r
429 * @param {event} e The raw browser event
\r
433 * @event beforenodedrop
\r
434 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
\r
435 * passed to handlers has the following properties:<br />
\r
436 * <ul style="padding:5px;padding-left:16px;">
\r
437 * <li>tree - The TreePanel</li>
\r
438 * <li>target - The node being targeted for the drop</li>
\r
439 * <li>data - The drag data from the drag source</li>
\r
440 * <li>point - The point of the drop - append, above or below</li>
\r
441 * <li>source - The drag source</li>
\r
442 * <li>rawEvent - Raw mouse event</li>
\r
443 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
\r
444 * to be inserted by setting them on this object.</li>
\r
445 * <li>cancel - Set this to true to cancel the drop.</li>
\r
446 * <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true
\r
447 * will prevent the animated 'repair' from appearing.</li>
\r
449 * @param {Object} dropEvent
\r
454 * Fires after a DD object is dropped on a node in this tree. The dropEvent
\r
455 * passed to handlers has the following properties:<br />
\r
456 * <ul style="padding:5px;padding-left:16px;">
\r
457 * <li>tree - The TreePanel</li>
\r
458 * <li>target - The node being targeted for the drop</li>
\r
459 * <li>data - The drag data from the drag source</li>
\r
460 * <li>point - The point of the drop - append, above or below</li>
\r
461 * <li>source - The drag source</li>
\r
462 * <li>rawEvent - Raw mouse event</li>
\r
463 * <li>dropNode - Dropped node(s).</li>
\r
465 * @param {Object} dropEvent
\r
469 * @event nodedragover
\r
470 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
\r
471 * passed to handlers has the following properties:<br />
\r
472 * <ul style="padding:5px;padding-left:16px;">
\r
473 * <li>tree - The TreePanel</li>
\r
474 * <li>target - The node being targeted for the drop</li>
\r
475 * <li>data - The drag data from the drag source</li>
\r
476 * <li>point - The point of the drop - append, above or below</li>
\r
477 * <li>source - The drag source</li>
\r
478 * <li>rawEvent - Raw mouse event</li>
\r
479 * <li>dropNode - Drop node(s) provided by the source.</li>
\r
480 * <li>cancel - Set this to true to signal drop not allowed.</li>
\r
482 * @param {Object} dragOverEvent
\r
486 if(this.singleExpand){
\r
487 this.on('beforeexpandnode', this.restrictExpand, this);
\r
492 proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){
\r
493 if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){
\r
494 ename = ename+'node';
\r
496 // args inline for performance while bubbling events
\r
497 return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);
\r
502 * Returns this root node for this tree
\r
505 getRootNode : function(){
\r
510 * Sets the root node for this tree. If the TreePanel has already rendered a root node, the
\r
511 * previous root node (and all of its descendants) are destroyed before the new root node is rendered.
\r
512 * @param {Node} node
\r
515 setRootNode : function(node){
\r
516 Ext.destroy(this.root);
\r
517 if(!node.render){ // attributes passed
\r
518 node = this.loader.createNode(node);
\r
521 node.ownerTree = this;
\r
522 node.isRoot = true;
\r
523 this.registerNode(node);
\r
524 if(!this.rootVisible){
\r
525 var uiP = node.attributes.uiProvider;
\r
526 node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);
\r
528 if (this.innerCt) {
\r
529 this.innerCt.update('');
\r
530 this.afterRender();
\r
536 * Gets a node in this tree by its id
\r
537 * @param {String} id
\r
540 getNodeById : function(id){
\r
541 return this.nodeHash[id];
\r
545 registerNode : function(node){
\r
546 this.nodeHash[node.id] = node;
\r
550 unregisterNode : function(node){
\r
551 delete this.nodeHash[node.id];
\r
555 toString : function(){
\r
556 return '[Tree'+(this.id?' '+this.id:'')+']';
\r
560 restrictExpand : function(node){
\r
561 var p = node.parentNode;
\r
563 if(p.expandedChild && p.expandedChild.parentNode == p){
\r
564 p.expandedChild.collapse();
\r
566 p.expandedChild = node;
\r
571 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. 'id')
\r
572 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
\r
573 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
\r
576 getChecked : function(a, startNode){
\r
577 startNode = startNode || this.root;
\r
579 var f = function(){
\r
580 if(this.attributes.checked){
\r
581 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
\r
584 startNode.cascade(f);
\r
589 * Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.
\r
590 * @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.
\r
592 getLoader : function(){
\r
593 return this.loader;
\r
599 expandAll : function(){
\r
600 this.root.expand(true);
\r
604 * Collapse all nodes
\r
606 collapseAll : function(){
\r
607 this.root.collapse(true);
\r
611 * Returns the selection model used by this TreePanel.
\r
612 * @return {TreeSelectionModel} The selection model used by this TreePanel
\r
614 getSelectionModel : function(){
\r
615 if(!this.selModel){
\r
616 this.selModel = new Ext.tree.DefaultSelectionModel();
\r
618 return this.selModel;
\r
622 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
\r
623 * @param {String} path
\r
624 * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
\r
625 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
\r
626 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
\r
628 expandPath : function(path, attr, callback){
\r
629 attr = attr || 'id';
\r
630 var keys = path.split(this.pathSeparator);
\r
631 var curNode = this.root;
\r
632 if(curNode.attributes[attr] != keys[1]){ // invalid root
\r
634 callback(false, null);
\r
639 var f = function(){
\r
640 if(++index == keys.length){
\r
642 callback(true, curNode);
\r
646 var c = curNode.findChild(attr, keys[index]);
\r
649 callback(false, curNode);
\r
654 c.expand(false, false, f);
\r
656 curNode.expand(false, false, f);
\r
660 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
\r
661 * @param {String} path
\r
662 * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
\r
663 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
\r
664 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
\r
666 selectPath : function(path, attr, callback){
\r
667 attr = attr || 'id';
\r
668 var keys = path.split(this.pathSeparator),
\r
670 if(keys.length > 1){
\r
671 var f = function(success, node){
\r
672 if(success && node){
\r
673 var n = node.findChild(attr, v);
\r
679 }else if(callback){
\r
680 callback(false, n);
\r
684 callback(false, n);
\r
688 this.expandPath(keys.join(this.pathSeparator), attr, f);
\r
690 this.root.select();
\r
692 callback(true, this.root);
\r
698 * Returns the underlying Element for this tree
\r
699 * @return {Ext.Element} The Element
\r
701 getTreeEl : function(){
\r
706 onRender : function(ct, position){
\r
707 Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
\r
708 this.el.addClass('x-tree');
\r
709 this.innerCt = this.body.createChild({tag:'ul',
\r
710 cls:'x-tree-root-ct ' +
\r
711 (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')});
\r
715 initEvents : function(){
\r
716 Ext.tree.TreePanel.superclass.initEvents.call(this);
\r
718 if(this.containerScroll){
\r
719 Ext.dd.ScrollManager.register(this.body);
\r
721 if((this.enableDD || this.enableDrop) && !this.dropZone){
\r
723 * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
\r
724 * @property dropZone
\r
725 * @type Ext.tree.TreeDropZone
\r
727 this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
\r
728 ddGroup: this.ddGroup || 'TreeDD', appendOnly: this.ddAppendOnly === true
\r
731 if((this.enableDD || this.enableDrag) && !this.dragZone){
\r
733 * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
\r
734 * @property dragZone
\r
735 * @type Ext.tree.TreeDragZone
\r
737 this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
\r
738 ddGroup: this.ddGroup || 'TreeDD',
\r
739 scroll: this.ddScroll
\r
742 this.getSelectionModel().init(this);
\r
746 afterRender : function(){
\r
747 Ext.tree.TreePanel.superclass.afterRender.call(this);
\r
748 this.root.render();
\r
749 if(!this.rootVisible){
\r
750 this.root.renderChildren();
\r
754 beforeDestroy : function(){
\r
756 Ext.dd.ScrollManager.unregister(this.body);
\r
757 Ext.destroy(this.dropZone, this.dragZone);
\r
759 Ext.destroy(this.root, this.loader);
\r
760 this.nodeHash = this.root = this.loader = null;
\r
761 Ext.tree.TreePanel.superclass.beforeDestroy.call(this);
\r
765 * @cfg {String/Number} activeItem
\r
769 * @cfg {Boolean} autoDestroy
\r
773 * @cfg {Object/String/Function} autoLoad
\r
777 * @cfg {Boolean} autoWidth
\r
781 * @cfg {Boolean/Number} bufferResize
\r
785 * @cfg {String} defaultType
\r
789 * @cfg {Object} defaults
\r
793 * @cfg {Boolean} hideBorders
\r
797 * @cfg {Mixed} items
\r
801 * @cfg {String} layout
\r
805 * @cfg {Object} layoutConfig
\r
809 * @cfg {Boolean} monitorResize
\r
837 * @method findByType
\r
841 * @method getComponent
\r
845 * @method getLayout
\r
849 * @method getUpdater
\r
869 * @method removeAll
\r
873 * @event afterLayout
\r
881 * @event beforeremove
\r
892 * @cfg {String} allowDomMove @hide
\r
895 * @cfg {String} autoEl @hide
\r
898 * @cfg {String} applyTo @hide
\r
901 * @cfg {String} contentEl @hide
\r
904 * @cfg {String} disabledClass @hide
\r
907 * @cfg {String} elements @hide
\r
910 * @cfg {String} html @hide
\r
913 * @cfg {Boolean} preventBodyReset
\r
917 * @property disabled
\r
921 * @method applyToMarkup
\r
933 * @method setDisabled
\r
938 Ext.tree.TreePanel.nodeTypes = {};
\r
940 Ext.reg('treepanel', Ext.tree.TreePanel);Ext.tree.TreeEventModel = function(tree){
\r
942 this.tree.on('render', this.initEvents, this);
\r
945 Ext.tree.TreeEventModel.prototype = {
\r
946 initEvents : function(){
\r
949 if(t.trackMouseOver !== false){
\r
952 mouseover: this.delegateOver,
\r
953 mouseout: this.delegateOut
\r
956 t.mon(t.getTreeEl(), {
\r
958 click: this.delegateClick,
\r
959 dblclick: this.delegateDblClick,
\r
960 contextmenu: this.delegateContextMenu
\r
964 getNode : function(e){
\r
966 if(t = e.getTarget('.x-tree-node-el', 10)){
\r
967 var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
\r
969 return this.tree.getNodeById(id);
\r
975 getNodeTarget : function(e){
\r
976 var t = e.getTarget('.x-tree-node-icon', 1);
\r
978 t = e.getTarget('.x-tree-node-el', 6);
\r
983 delegateOut : function(e, t){
\r
984 if(!this.beforeEvent(e)){
\r
987 if(e.getTarget('.x-tree-ec-icon', 1)){
\r
988 var n = this.getNode(e);
\r
989 this.onIconOut(e, n);
\r
990 if(n == this.lastEcOver){
\r
991 delete this.lastEcOver;
\r
994 if((t = this.getNodeTarget(e)) && !e.within(t, true)){
\r
995 this.onNodeOut(e, this.getNode(e));
\r
999 delegateOver : function(e, t){
\r
1000 if(!this.beforeEvent(e)){
\r
1003 if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
\r
1004 Ext.getBody().on('mouseover', this.trackExit, this);
\r
1005 this.trackingDoc = true;
\r
1007 if(this.lastEcOver){ // prevent hung highlight
\r
1008 this.onIconOut(e, this.lastEcOver);
\r
1009 delete this.lastEcOver;
\r
1011 if(e.getTarget('.x-tree-ec-icon', 1)){
\r
1012 this.lastEcOver = this.getNode(e);
\r
1013 this.onIconOver(e, this.lastEcOver);
\r
1015 if(t = this.getNodeTarget(e)){
\r
1016 this.onNodeOver(e, this.getNode(e));
\r
1020 trackExit : function(e){
\r
1021 if(this.lastOverNode && !e.within(this.lastOverNode.ui.getEl())){
\r
1022 this.onNodeOut(e, this.lastOverNode);
\r
1023 delete this.lastOverNode;
\r
1024 Ext.getBody().un('mouseover', this.trackExit, this);
\r
1025 this.trackingDoc = false;
\r
1029 delegateClick : function(e, t){
\r
1030 if(this.beforeEvent(e)){
\r
1031 if(e.getTarget('input[type=checkbox]', 1)){
\r
1032 this.onCheckboxClick(e, this.getNode(e));
\r
1033 }else if(e.getTarget('.x-tree-ec-icon', 1)){
\r
1034 this.onIconClick(e, this.getNode(e));
\r
1035 }else if(this.getNodeTarget(e)){
\r
1036 this.onNodeClick(e, this.getNode(e));
\r
1038 this.onContainerEvent(e, 'click');
\r
1043 delegateDblClick : function(e, t){
\r
1044 if(this.beforeEvent(e)){
\r
1045 if(this.getNodeTarget(e)){
\r
1046 this.onNodeDblClick(e, this.getNode(e));
\r
1048 this.onContainerEvent(e, 'dblclick');
\r
1053 delegateContextMenu : function(e, t){
\r
1054 if(this.beforeEvent(e)){
\r
1055 if(this.getNodeTarget(e)){
\r
1056 this.onNodeContextMenu(e, this.getNode(e));
\r
1058 this.onContainerEvent(e, 'contextmenu');
\r
1063 onContainerEvent: function(e, type){
\r
1064 this.tree.fireEvent('container' + type, this.tree, e);
\r
1067 onNodeClick : function(e, node){
\r
1068 node.ui.onClick(e);
\r
1071 onNodeOver : function(e, node){
\r
1072 this.lastOverNode = node;
\r
1073 node.ui.onOver(e);
\r
1076 onNodeOut : function(e, node){
\r
1080 onIconOver : function(e, node){
\r
1081 node.ui.addClass('x-tree-ec-over');
\r
1084 onIconOut : function(e, node){
\r
1085 node.ui.removeClass('x-tree-ec-over');
\r
1088 onIconClick : function(e, node){
\r
1089 node.ui.ecClick(e);
\r
1092 onCheckboxClick : function(e, node){
\r
1093 node.ui.onCheckChange(e);
\r
1096 onNodeDblClick : function(e, node){
\r
1097 node.ui.onDblClick(e);
\r
1100 onNodeContextMenu : function(e, node){
\r
1101 node.ui.onContextMenu(e);
\r
1104 beforeEvent : function(e){
\r
1105 if(this.disabled){
\r
1112 disable: function(){
\r
1113 this.disabled = true;
\r
1116 enable: function(){
\r
1117 this.disabled = false;
\r
1120 * @class Ext.tree.DefaultSelectionModel
\r
1121 * @extends Ext.util.Observable
\r
1122 * The default single selection for a TreePanel.
\r
1124 Ext.tree.DefaultSelectionModel = function(config){
\r
1125 this.selNode = null;
\r
1129 * @event selectionchange
\r
1130 * Fires when the selected node changes
\r
1131 * @param {DefaultSelectionModel} this
\r
1132 * @param {TreeNode} node the new selection
\r
1134 'selectionchange',
\r
1137 * @event beforeselect
\r
1138 * Fires before the selected node changes, return false to cancel the change
\r
1139 * @param {DefaultSelectionModel} this
\r
1140 * @param {TreeNode} node the new selection
\r
1141 * @param {TreeNode} node the old selection
\r
1146 Ext.apply(this, config);
\r
1147 Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
\r
1150 Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {
\r
1151 init : function(tree){
\r
1153 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
\r
1154 tree.on('click', this.onNodeClick, this);
\r
1157 onNodeClick : function(node, e){
\r
1158 this.select(node);
\r
1163 * @param {TreeNode} node The node to select
\r
1164 * @return {TreeNode} The selected node
\r
1166 select : function(node, /* private*/ selectNextNode){
\r
1167 // If node is hidden, select the next node in whatever direction was being moved in.
\r
1168 if (!Ext.fly(node.ui.wrap).isVisible() && selectNextNode) {
\r
1169 return selectNextNode.call(this, node);
\r
1171 var last = this.selNode;
\r
1173 node.ui.onSelectedChange(true);
\r
1174 }else if(this.fireEvent('beforeselect', this, node, last) !== false){
\r
1175 if(last && last.ui){
\r
1176 last.ui.onSelectedChange(false);
\r
1178 this.selNode = node;
\r
1179 node.ui.onSelectedChange(true);
\r
1180 this.fireEvent('selectionchange', this, node, last);
\r
1186 * Deselect a node.
\r
1187 * @param {TreeNode} node The node to unselect
\r
1188 * @param {Boolean} silent True to stop the selectionchange event from firing.
\r
1190 unselect : function(node, silent){
\r
1191 if(this.selNode == node){
\r
1192 this.clearSelections(silent);
\r
1197 * Clear all selections
\r
1198 * @param {Boolean} silent True to stop the selectionchange event from firing.
\r
1200 clearSelections : function(silent){
\r
1201 var n = this.selNode;
\r
1203 n.ui.onSelectedChange(false);
\r
1204 this.selNode = null;
\r
1205 if(silent !== true){
\r
1206 this.fireEvent('selectionchange', this, null);
\r
1213 * Get the selected node
\r
1214 * @return {TreeNode} The selected node
\r
1216 getSelectedNode : function(){
\r
1217 return this.selNode;
\r
1221 * Returns true if the node is selected
\r
1222 * @param {TreeNode} node The node to check
\r
1223 * @return {Boolean}
\r
1225 isSelected : function(node){
\r
1226 return this.selNode == node;
\r
1230 * Selects the node above the selected node in the tree, intelligently walking the nodes
\r
1231 * @return TreeNode The new selection
\r
1233 selectPrevious : function(/* private */ s){
\r
1234 if(!(s = s || this.selNode || this.lastSelNode)){
\r
1237 // Here we pass in the current function to select to indicate the direction we're moving
\r
1238 var ps = s.previousSibling;
\r
1240 if(!ps.isExpanded() || ps.childNodes.length < 1){
\r
1241 return this.select(ps, this.selectPrevious);
\r
1243 var lc = ps.lastChild;
\r
1244 while(lc && lc.isExpanded() && Ext.fly(lc.ui.wrap).isVisible() && lc.childNodes.length > 0){
\r
1245 lc = lc.lastChild;
\r
1247 return this.select(lc, this.selectPrevious);
\r
1249 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
\r
1250 return this.select(s.parentNode, this.selectPrevious);
\r
1256 * Selects the node above the selected node in the tree, intelligently walking the nodes
\r
1257 * @return TreeNode The new selection
\r
1259 selectNext : function(/* private */ s){
\r
1260 if(!(s = s || this.selNode || this.lastSelNode)){
\r
1263 // Here we pass in the current function to select to indicate the direction we're moving
\r
1264 if(s.firstChild && s.isExpanded() && Ext.fly(s.ui.wrap).isVisible()){
\r
1265 return this.select(s.firstChild, this.selectNext);
\r
1266 }else if(s.nextSibling){
\r
1267 return this.select(s.nextSibling, this.selectNext);
\r
1268 }else if(s.parentNode){
\r
1270 s.parentNode.bubble(function(){
\r
1271 if(this.nextSibling){
\r
1272 newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);
\r
1281 onKeyDown : function(e){
\r
1282 var s = this.selNode || this.lastSelNode;
\r
1283 // undesirable, but required
\r
1288 var k = e.getKey();
\r
1292 this.selectNext();
\r
1296 this.selectPrevious();
\r
1299 e.preventDefault();
\r
1300 if(s.hasChildNodes()){
\r
1301 if(!s.isExpanded()){
\r
1303 }else if(s.firstChild){
\r
1304 this.select(s.firstChild, e);
\r
1309 e.preventDefault();
\r
1310 if(s.hasChildNodes() && s.isExpanded()){
\r
1312 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
\r
1313 this.select(s.parentNode, e);
\r
1321 * @class Ext.tree.MultiSelectionModel
\r
1322 * @extends Ext.util.Observable
\r
1323 * Multi selection for a TreePanel.
\r
1325 Ext.tree.MultiSelectionModel = function(config){
\r
1326 this.selNodes = [];
\r
1330 * @event selectionchange
\r
1331 * Fires when the selected nodes change
\r
1332 * @param {MultiSelectionModel} this
\r
1333 * @param {Array} nodes Array of the selected nodes
\r
1337 Ext.apply(this, config);
\r
1338 Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
\r
1341 Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {
\r
1342 init : function(tree){
\r
1344 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
\r
1345 tree.on('click', this.onNodeClick, this);
\r
1348 onNodeClick : function(node, e){
\r
1349 if(e.ctrlKey && this.isSelected(node)){
\r
1350 this.unselect(node);
\r
1352 this.select(node, e, e.ctrlKey);
\r
1358 * @param {TreeNode} node The node to select
\r
1359 * @param {EventObject} e (optional) An event associated with the selection
\r
1360 * @param {Boolean} keepExisting True to retain existing selections
\r
1361 * @return {TreeNode} The selected node
\r
1363 select : function(node, e, keepExisting){
\r
1364 if(keepExisting !== true){
\r
1365 this.clearSelections(true);
\r
1367 if(this.isSelected(node)){
\r
1368 this.lastSelNode = node;
\r
1371 this.selNodes.push(node);
\r
1372 this.selMap[node.id] = node;
\r
1373 this.lastSelNode = node;
\r
1374 node.ui.onSelectedChange(true);
\r
1375 this.fireEvent('selectionchange', this, this.selNodes);
\r
1380 * Deselect a node.
\r
1381 * @param {TreeNode} node The node to unselect
\r
1383 unselect : function(node){
\r
1384 if(this.selMap[node.id]){
\r
1385 node.ui.onSelectedChange(false);
\r
1386 var sn = this.selNodes;
\r
1387 var index = sn.indexOf(node);
\r
1389 this.selNodes.splice(index, 1);
\r
1391 delete this.selMap[node.id];
\r
1392 this.fireEvent('selectionchange', this, this.selNodes);
\r
1397 * Clear all selections
\r
1399 clearSelections : function(suppressEvent){
\r
1400 var sn = this.selNodes;
\r
1401 if(sn.length > 0){
\r
1402 for(var i = 0, len = sn.length; i < len; i++){
\r
1403 sn[i].ui.onSelectedChange(false);
\r
1405 this.selNodes = [];
\r
1407 if(suppressEvent !== true){
\r
1408 this.fireEvent('selectionchange', this, this.selNodes);
\r
1414 * Returns true if the node is selected
\r
1415 * @param {TreeNode} node The node to check
\r
1416 * @return {Boolean}
\r
1418 isSelected : function(node){
\r
1419 return this.selMap[node.id] ? true : false;
\r
1423 * Returns an array of the selected nodes
\r
1426 getSelectedNodes : function(){
\r
1427 return this.selNodes;
\r
1430 onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
\r
1432 selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
\r
1434 selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
\r
1436 * @class Ext.data.Tree
\r
1437 * @extends Ext.util.Observable
\r
1438 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
\r
1439 * in the tree have most standard DOM functionality.
\r
1441 * @param {Node} root (optional) The root node
\r
1443 Ext.data.Tree = function(root){
\r
1444 this.nodeHash = {};
\r
1446 * The root node for this tree
\r
1451 this.setRootNode(root);
\r
1456 * Fires when a new child node is appended to a node in this tree.
\r
1457 * @param {Tree} tree The owner tree
\r
1458 * @param {Node} parent The parent node
\r
1459 * @param {Node} node The newly appended node
\r
1460 * @param {Number} index The index of the newly appended node
\r
1465 * Fires when a child node is removed from a node in this tree.
\r
1466 * @param {Tree} tree The owner tree
\r
1467 * @param {Node} parent The parent node
\r
1468 * @param {Node} node The child node removed
\r
1473 * Fires when a node is moved to a new location in the tree
\r
1474 * @param {Tree} tree The owner tree
\r
1475 * @param {Node} node The node moved
\r
1476 * @param {Node} oldParent The old parent of this node
\r
1477 * @param {Node} newParent The new parent of this node
\r
1478 * @param {Number} index The index it was moved to
\r
1483 * Fires when a new child node is inserted in a node in this tree.
\r
1484 * @param {Tree} tree The owner tree
\r
1485 * @param {Node} parent The parent node
\r
1486 * @param {Node} node The child node inserted
\r
1487 * @param {Node} refNode The child node the node was inserted before
\r
1491 * @event beforeappend
\r
1492 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
\r
1493 * @param {Tree} tree The owner tree
\r
1494 * @param {Node} parent The parent node
\r
1495 * @param {Node} node The child node to be appended
\r
1499 * @event beforeremove
\r
1500 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
\r
1501 * @param {Tree} tree The owner tree
\r
1502 * @param {Node} parent The parent node
\r
1503 * @param {Node} node The child node to be removed
\r
1507 * @event beforemove
\r
1508 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
\r
1509 * @param {Tree} tree The owner tree
\r
1510 * @param {Node} node The node being moved
\r
1511 * @param {Node} oldParent The parent of the node
\r
1512 * @param {Node} newParent The new parent the node is moving to
\r
1513 * @param {Number} index The index it is being moved to
\r
1517 * @event beforeinsert
\r
1518 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
\r
1519 * @param {Tree} tree The owner tree
\r
1520 * @param {Node} parent The parent node
\r
1521 * @param {Node} node The child node to be inserted
\r
1522 * @param {Node} refNode The child node the node is being inserted before
\r
1527 Ext.data.Tree.superclass.constructor.call(this);
\r
1530 Ext.extend(Ext.data.Tree, Ext.util.Observable, {
\r
1532 * @cfg {String} pathSeparator
\r
1533 * The token used to separate paths in node ids (defaults to '/').
\r
1535 pathSeparator: "/",
\r
1538 proxyNodeEvent : function(){
\r
1539 return this.fireEvent.apply(this, arguments);
\r
1543 * Returns the root node for this tree.
\r
1546 getRootNode : function(){
\r
1551 * Sets the root node for this tree.
\r
1552 * @param {Node} node
\r
1555 setRootNode : function(node){
\r
1557 node.ownerTree = this;
\r
1558 node.isRoot = true;
\r
1559 this.registerNode(node);
\r
1564 * Gets a node in this tree by its id.
\r
1565 * @param {String} id
\r
1568 getNodeById : function(id){
\r
1569 return this.nodeHash[id];
\r
1573 registerNode : function(node){
\r
1574 this.nodeHash[node.id] = node;
\r
1578 unregisterNode : function(node){
\r
1579 delete this.nodeHash[node.id];
\r
1582 toString : function(){
\r
1583 return "[Tree"+(this.id?" "+this.id:"")+"]";
\r
1588 * @class Ext.data.Node
\r
1589 * @extends Ext.util.Observable
\r
1590 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
\r
1591 * @cfg {String} id The id for this node. If one is not specified, one is generated.
\r
1593 * @param {Object} attributes The attributes/config for the node
\r
1595 Ext.data.Node = function(attributes){
\r
1597 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
\r
1600 this.attributes = attributes || {};
\r
1601 this.leaf = this.attributes.leaf;
\r
1603 * The node id. @type String
\r
1605 this.id = this.attributes.id;
\r
1607 this.id = Ext.id(null, "xnode-");
\r
1608 this.attributes.id = this.id;
\r
1611 * All child nodes of this node. @type Array
\r
1613 this.childNodes = [];
\r
1614 if(!this.childNodes.indexOf){ // indexOf is a must
\r
1615 this.childNodes.indexOf = function(o){
\r
1616 for(var i = 0, len = this.length; i < len; i++){
\r
1625 * The parent node for this node. @type Node
\r
1627 this.parentNode = null;
\r
1629 * The first direct child node of this node, or null if this node has no child nodes. @type Node
\r
1631 this.firstChild = null;
\r
1633 * The last direct child node of this node, or null if this node has no child nodes. @type Node
\r
1635 this.lastChild = null;
\r
1637 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
\r
1639 this.previousSibling = null;
\r
1641 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
\r
1643 this.nextSibling = null;
\r
1648 * Fires when a new child node is appended
\r
1649 * @param {Tree} tree The owner tree
\r
1650 * @param {Node} this This node
\r
1651 * @param {Node} node The newly appended node
\r
1652 * @param {Number} index The index of the newly appended node
\r
1657 * Fires when a child node is removed
\r
1658 * @param {Tree} tree The owner tree
\r
1659 * @param {Node} this This node
\r
1660 * @param {Node} node The removed node
\r
1665 * Fires when this node is moved to a new location in the tree
\r
1666 * @param {Tree} tree The owner tree
\r
1667 * @param {Node} this This node
\r
1668 * @param {Node} oldParent The old parent of this node
\r
1669 * @param {Node} newParent The new parent of this node
\r
1670 * @param {Number} index The index it was moved to
\r
1675 * Fires when a new child node is inserted.
\r
1676 * @param {Tree} tree The owner tree
\r
1677 * @param {Node} this This node
\r
1678 * @param {Node} node The child node inserted
\r
1679 * @param {Node} refNode The child node the node was inserted before
\r
1683 * @event beforeappend
\r
1684 * Fires before a new child is appended, return false to cancel the append.
\r
1685 * @param {Tree} tree The owner tree
\r
1686 * @param {Node} this This node
\r
1687 * @param {Node} node The child node to be appended
\r
1689 "beforeappend" : true,
\r
1691 * @event beforeremove
\r
1692 * Fires before a child is removed, return false to cancel the remove.
\r
1693 * @param {Tree} tree The owner tree
\r
1694 * @param {Node} this This node
\r
1695 * @param {Node} node The child node to be removed
\r
1697 "beforeremove" : true,
\r
1699 * @event beforemove
\r
1700 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
\r
1701 * @param {Tree} tree The owner tree
\r
1702 * @param {Node} this This node
\r
1703 * @param {Node} oldParent The parent of this node
\r
1704 * @param {Node} newParent The new parent this node is moving to
\r
1705 * @param {Number} index The index it is being moved to
\r
1707 "beforemove" : true,
\r
1709 * @event beforeinsert
\r
1710 * Fires before a new child is inserted, return false to cancel the insert.
\r
1711 * @param {Tree} tree The owner tree
\r
1712 * @param {Node} this This node
\r
1713 * @param {Node} node The child node to be inserted
\r
1714 * @param {Node} refNode The child node the node is being inserted before
\r
1716 "beforeinsert" : true
\r
1718 this.listeners = this.attributes.listeners;
\r
1719 Ext.data.Node.superclass.constructor.call(this);
\r
1722 Ext.extend(Ext.data.Node, Ext.util.Observable, {
\r
1724 fireEvent : function(evtName){
\r
1725 // first do standard event for this node
\r
1726 if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){
\r
1729 // then bubble it up to the tree if the event wasn't cancelled
\r
1730 var ot = this.getOwnerTree();
\r
1732 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
\r
1740 * Returns true if this node is a leaf
\r
1741 * @return {Boolean}
\r
1743 isLeaf : function(){
\r
1744 return this.leaf === true;
\r
1748 setFirstChild : function(node){
\r
1749 this.firstChild = node;
\r
1753 setLastChild : function(node){
\r
1754 this.lastChild = node;
\r
1759 * Returns true if this node is the last child of its parent
\r
1760 * @return {Boolean}
\r
1762 isLast : function(){
\r
1763 return (!this.parentNode ? true : this.parentNode.lastChild == this);
\r
1767 * Returns true if this node is the first child of its parent
\r
1768 * @return {Boolean}
\r
1770 isFirst : function(){
\r
1771 return (!this.parentNode ? true : this.parentNode.firstChild == this);
\r
1775 * Returns true if this node has one or more child nodes, else false.
\r
1776 * @return {Boolean}
\r
1778 hasChildNodes : function(){
\r
1779 return !this.isLeaf() && this.childNodes.length > 0;
\r
1783 * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>
\r
1784 * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
\r
1785 * @return {Boolean}
\r
1787 isExpandable : function(){
\r
1788 return this.attributes.expandable || this.hasChildNodes();
\r
1792 * Insert node(s) as the last child node of this node.
\r
1793 * @param {Node/Array} node The node or Array of nodes to append
\r
1794 * @return {Node} The appended node if single append, or null if an array was passed
\r
1796 appendChild : function(node){
\r
1797 var multi = false;
\r
1798 if(Ext.isArray(node)){
\r
1800 }else if(arguments.length > 1){
\r
1801 multi = arguments;
\r
1803 // if passed an array or multiple args do them one by one
\r
1805 for(var i = 0, len = multi.length; i < len; i++) {
\r
1806 this.appendChild(multi[i]);
\r
1809 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
\r
1812 var index = this.childNodes.length;
\r
1813 var oldParent = node.parentNode;
\r
1814 // it's a move, make sure we move it cleanly
\r
1816 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
\r
1819 oldParent.removeChild(node);
\r
1821 index = this.childNodes.length;
\r
1823 this.setFirstChild(node);
\r
1825 this.childNodes.push(node);
\r
1826 node.parentNode = this;
\r
1827 var ps = this.childNodes[index-1];
\r
1829 node.previousSibling = ps;
\r
1830 ps.nextSibling = node;
\r
1832 node.previousSibling = null;
\r
1834 node.nextSibling = null;
\r
1835 this.setLastChild(node);
\r
1836 node.setOwnerTree(this.getOwnerTree());
\r
1837 this.fireEvent("append", this.ownerTree, this, node, index);
\r
1839 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
\r
1846 * Removes a child node from this node.
\r
1847 * @param {Node} node The node to remove
\r
1848 * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
\r
1849 * @return {Node} The removed node
\r
1851 removeChild : function(node, destroy){
\r
1852 var index = this.childNodes.indexOf(node);
\r
1856 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
\r
1860 // remove it from childNodes collection
\r
1861 this.childNodes.splice(index, 1);
\r
1863 // update siblings
\r
1864 if(node.previousSibling){
\r
1865 node.previousSibling.nextSibling = node.nextSibling;
\r
1867 if(node.nextSibling){
\r
1868 node.nextSibling.previousSibling = node.previousSibling;
\r
1871 // update child refs
\r
1872 if(this.firstChild == node){
\r
1873 this.setFirstChild(node.nextSibling);
\r
1875 if(this.lastChild == node){
\r
1876 this.setLastChild(node.previousSibling);
\r
1880 this.fireEvent("remove", this.ownerTree, this, node);
\r
1888 clear : function(destroy){
\r
1889 // clear any references from the node
\r
1890 this.setOwnerTree(null, destroy);
\r
1891 this.parentNode = this.previousSibling = this.nextSibling = null
\r
1893 this.firstChild = this.lastChild = null;
\r
1898 * Destroys the node.
\r
1900 destroy : function(){
\r
1901 this.purgeListeners();
\r
1902 this.clear(true);
\r
1903 Ext.each(this.childNodes, function(n){
\r
1906 this.childNodes = null;
\r
1910 * Inserts the first node before the second node in this nodes childNodes collection.
\r
1911 * @param {Node} node The node to insert
\r
1912 * @param {Node} refNode The node to insert before (if null the node is appended)
\r
1913 * @return {Node} The inserted node
\r
1915 insertBefore : function(node, refNode){
\r
1916 if(!refNode){ // like standard Dom, refNode can be null for append
\r
1917 return this.appendChild(node);
\r
1920 if(node == refNode){
\r
1924 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
\r
1927 var index = this.childNodes.indexOf(refNode);
\r
1928 var oldParent = node.parentNode;
\r
1929 var refIndex = index;
\r
1931 // when moving internally, indexes will change after remove
\r
1932 if(oldParent == this && this.childNodes.indexOf(node) < index){
\r
1936 // it's a move, make sure we move it cleanly
\r
1938 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
\r
1941 oldParent.removeChild(node);
\r
1943 if(refIndex === 0){
\r
1944 this.setFirstChild(node);
\r
1946 this.childNodes.splice(refIndex, 0, node);
\r
1947 node.parentNode = this;
\r
1948 var ps = this.childNodes[refIndex-1];
\r
1950 node.previousSibling = ps;
\r
1951 ps.nextSibling = node;
\r
1953 node.previousSibling = null;
\r
1955 node.nextSibling = refNode;
\r
1956 refNode.previousSibling = node;
\r
1957 node.setOwnerTree(this.getOwnerTree());
\r
1958 this.fireEvent("insert", this.ownerTree, this, node, refNode);
\r
1960 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
\r
1966 * Removes this node from its parent
\r
1967 * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
\r
1968 * @return {Node} this
\r
1970 remove : function(destroy){
\r
1971 this.parentNode.removeChild(this, destroy);
\r
1976 * Returns the child node at the specified index.
\r
1977 * @param {Number} index
\r
1980 item : function(index){
\r
1981 return this.childNodes[index];
\r
1985 * Replaces one child node in this node with another.
\r
1986 * @param {Node} newChild The replacement node
\r
1987 * @param {Node} oldChild The node to replace
\r
1988 * @return {Node} The replaced node
\r
1990 replaceChild : function(newChild, oldChild){
\r
1991 var s = oldChild ? oldChild.nextSibling : null;
\r
1992 this.removeChild(oldChild);
\r
1993 this.insertBefore(newChild, s);
\r
1998 * Returns the index of a child node
\r
1999 * @param {Node} node
\r
2000 * @return {Number} The index of the node or -1 if it was not found
\r
2002 indexOf : function(child){
\r
2003 return this.childNodes.indexOf(child);
\r
2007 * Returns the tree this node is in.
\r
2010 getOwnerTree : function(){
\r
2011 // if it doesn't have one, look for one
\r
2012 if(!this.ownerTree){
\r
2016 this.ownerTree = p.ownerTree;
\r
2022 return this.ownerTree;
\r
2026 * Returns depth of this node (the root node has a depth of 0)
\r
2027 * @return {Number}
\r
2029 getDepth : function(){
\r
2032 while(p.parentNode){
\r
2040 setOwnerTree : function(tree, destroy){
\r
2041 // if it is a move, we need to update everyone
\r
2042 if(tree != this.ownerTree){
\r
2043 if(this.ownerTree){
\r
2044 this.ownerTree.unregisterNode(this);
\r
2046 this.ownerTree = tree;
\r
2047 // If we're destroying, we don't need to recurse since it will be called on each child node
\r
2048 if(destroy !== true){
\r
2049 Ext.each(this.childNodes, function(n){
\r
2050 n.setOwnerTree(tree);
\r
2054 tree.registerNode(this);
\r
2060 * Changes the id of this node.
\r
2061 * @param {String} id The new id for the node.
\r
2063 setId: function(id){
\r
2064 if(id !== this.id){
\r
2065 var t = this.ownerTree;
\r
2067 t.unregisterNode(this);
\r
2069 this.id = this.attributes.id = id;
\r
2071 t.registerNode(this);
\r
2073 this.onIdChange(id);
\r
2078 onIdChange: Ext.emptyFn,
\r
2081 * Returns the path for this node. The path can be used to expand or select this node programmatically.
\r
2082 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
\r
2083 * @return {String} The path
\r
2085 getPath : function(attr){
\r
2086 attr = attr || "id";
\r
2087 var p = this.parentNode;
\r
2088 var b = [this.attributes[attr]];
\r
2090 b.unshift(p.attributes[attr]);
\r
2093 var sep = this.getOwnerTree().pathSeparator;
\r
2094 return sep + b.join(sep);
\r
2098 * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function
\r
2099 * will be the args provided or the current node. If the function returns false at any point,
\r
2100 * the bubble is stopped.
\r
2101 * @param {Function} fn The function to call
\r
2102 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
\r
2103 * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
\r
2105 bubble : function(fn, scope, args){
\r
2108 if(fn.apply(scope || p, args || [p]) === false){
\r
2116 * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function
\r
2117 * will be the args provided or the current node. If the function returns false at any point,
\r
2118 * the cascade is stopped on that branch.
\r
2119 * @param {Function} fn The function to call
\r
2120 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
\r
2121 * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
\r
2123 cascade : function(fn, scope, args){
\r
2124 if(fn.apply(scope || this, args || [this]) !== false){
\r
2125 var cs = this.childNodes;
\r
2126 for(var i = 0, len = cs.length; i < len; i++) {
\r
2127 cs[i].cascade(fn, scope, args);
\r
2133 * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function
\r
2134 * will be the args provided or the current node. If the function returns false at any point,
\r
2135 * the iteration stops.
\r
2136 * @param {Function} fn The function to call
\r
2137 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node in the iteration.
\r
2138 * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
\r
2140 eachChild : function(fn, scope, args){
\r
2141 var cs = this.childNodes;
\r
2142 for(var i = 0, len = cs.length; i < len; i++) {
\r
2143 if(fn.apply(scope || this, args || [cs[i]]) === false){
\r
2150 * Finds the first child that has the attribute with the specified value.
\r
2151 * @param {String} attribute The attribute name
\r
2152 * @param {Mixed} value The value to search for
\r
2153 * @return {Node} The found child or null if none was found
\r
2155 findChild : function(attribute, value){
\r
2156 var cs = this.childNodes;
\r
2157 for(var i = 0, len = cs.length; i < len; i++) {
\r
2158 if(cs[i].attributes[attribute] == value){
\r
2166 * Finds the first child by a custom function. The child matches if the function passed returns <code>true</code>.
\r
2167 * @param {Function} fn A function which must return <code>true</code> if the passed Node is the required Node.
\r
2168 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Node being tested.
\r
2169 * @return {Node} The found child or null if none was found
\r
2171 findChildBy : function(fn, scope){
\r
2172 var cs = this.childNodes;
\r
2173 for(var i = 0, len = cs.length; i < len; i++) {
\r
2174 if(fn.call(scope||cs[i], cs[i]) === true){
\r
2182 * Sorts this nodes children using the supplied sort function.
\r
2183 * @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.
\r
2184 * @param {Object} scope (optional)The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
\r
2186 sort : function(fn, scope){
\r
2187 var cs = this.childNodes;
\r
2188 var len = cs.length;
\r
2190 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
\r
2192 for(var i = 0; i < len; i++){
\r
2194 n.previousSibling = cs[i-1];
\r
2195 n.nextSibling = cs[i+1];
\r
2197 this.setFirstChild(n);
\r
2200 this.setLastChild(n);
\r
2207 * Returns true if this node is an ancestor (at any point) of the passed node.
\r
2208 * @param {Node} node
\r
2209 * @return {Boolean}
\r
2211 contains : function(node){
\r
2212 return node.isAncestor(this);
\r
2216 * Returns true if the passed node is an ancestor (at any point) of this node.
\r
2217 * @param {Node} node
\r
2218 * @return {Boolean}
\r
2220 isAncestor : function(node){
\r
2221 var p = this.parentNode;
\r
2231 toString : function(){
\r
2232 return "[Node"+(this.id?" "+this.id:"")+"]";
\r
2235 * @class Ext.tree.TreeNode
\r
2236 * @extends Ext.data.Node
\r
2237 * @cfg {String} text The text for this node
\r
2238 * @cfg {Boolean} expanded true to start the node expanded
\r
2239 * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)
\r
2240 * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)
\r
2241 * @cfg {Boolean} disabled true to start the node disabled
\r
2242 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
\r
2243 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
\r
2244 * @cfg {String} cls A css class to be added to the node
\r
2245 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
\r
2246 * @cfg {String} href URL of the link used for the node (defaults to #)
\r
2247 * @cfg {String} hrefTarget target frame for the link
\r
2248 * @cfg {Boolean} hidden True to render hidden. (Defaults to false).
\r
2249 * @cfg {String} qtip An Ext QuickTip for the node
\r
2250 * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
\r
2251 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
\r
2252 * @cfg {Boolean} singleClickExpand True for single click expand on this node
\r
2253 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)
\r
2254 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
\r
2255 * (defaults to undefined with no checkbox rendered)
\r
2256 * @cfg {Boolean} draggable True to make this node draggable (defaults to false)
\r
2257 * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)
\r
2258 * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)
\r
2259 * @cfg {Boolean} editable False to not allow this node to be edited by an {@link Ext.tree.TreeEditor} (defaults to true)
\r
2261 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
\r
2263 Ext.tree.TreeNode = function(attributes){
\r
2264 attributes = attributes || {};
\r
2265 if(Ext.isString(attributes)){
\r
2266 attributes = {text: attributes};
\r
2268 this.childrenRendered = false;
\r
2269 this.rendered = false;
\r
2270 Ext.tree.TreeNode.superclass.constructor.call(this, attributes);
\r
2271 this.expanded = attributes.expanded === true;
\r
2272 this.isTarget = attributes.isTarget !== false;
\r
2273 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
\r
2274 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
\r
2277 * Read-only. The text for this node. To change it use <code>{@link #setText}</code>.
\r
2280 this.text = attributes.text;
\r
2282 * True if this node is disabled.
\r
2285 this.disabled = attributes.disabled === true;
\r
2287 * True if this node is hidden.
\r
2290 this.hidden = attributes.hidden === true;
\r
2294 * @event textchange
\r
2295 * Fires when the text for this node is changed
\r
2296 * @param {Node} this This node
\r
2297 * @param {String} text The new text
\r
2298 * @param {String} oldText The old text
\r
2302 * @event beforeexpand
\r
2303 * Fires before this node is expanded, return false to cancel.
\r
2304 * @param {Node} this This node
\r
2305 * @param {Boolean} deep
\r
2306 * @param {Boolean} anim
\r
2310 * @event beforecollapse
\r
2311 * Fires before this node is collapsed, return false to cancel.
\r
2312 * @param {Node} this This node
\r
2313 * @param {Boolean} deep
\r
2314 * @param {Boolean} anim
\r
2319 * Fires when this node is expanded
\r
2320 * @param {Node} this This node
\r
2324 * @event disabledchange
\r
2325 * Fires when the disabled status of this node changes
\r
2326 * @param {Node} this This node
\r
2327 * @param {Boolean} disabled
\r
2332 * Fires when this node is collapsed
\r
2333 * @param {Node} this This node
\r
2337 * @event beforeclick
\r
2338 * Fires before click processing. Return false to cancel the default action.
\r
2339 * @param {Node} this This node
\r
2340 * @param {Ext.EventObject} e The event object
\r
2345 * Fires when this node is clicked
\r
2346 * @param {Node} this This node
\r
2347 * @param {Ext.EventObject} e The event object
\r
2351 * @event checkchange
\r
2352 * Fires when a node with a checkbox's checked property changes
\r
2353 * @param {Node} this This node
\r
2354 * @param {Boolean} checked
\r
2358 * @event beforedblclick
\r
2359 * Fires before double click processing. Return false to cancel the default action.
\r
2360 * @param {Node} this This node
\r
2361 * @param {Ext.EventObject} e The event object
\r
2366 * Fires when this node is double clicked
\r
2367 * @param {Node} this This node
\r
2368 * @param {Ext.EventObject} e The event object
\r
2372 * @event contextmenu
\r
2373 * Fires when this node is right clicked
\r
2374 * @param {Node} this This node
\r
2375 * @param {Ext.EventObject} e The event object
\r
2379 * @event beforechildrenrendered
\r
2380 * Fires right before the child nodes for this node are rendered
\r
2381 * @param {Node} this This node
\r
2383 'beforechildrenrendered'
\r
2386 var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;
\r
2389 * Read-only. The UI for this node
\r
2390 * @type TreeNodeUI
\r
2392 this.ui = new uiClass(this);
\r
2394 Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
\r
2395 preventHScroll : true,
\r
2397 * Returns true if this node is expanded
\r
2398 * @return {Boolean}
\r
2400 isExpanded : function(){
\r
2401 return this.expanded;
\r
2405 * Returns the UI object for this node.
\r
2406 * @return {TreeNodeUI} The object which is providing the user interface for this tree
\r
2407 * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance
\r
2408 * of {@link Ext.tree.TreeNodeUI}
\r
2410 getUI : function(){
\r
2414 getLoader : function(){
\r
2416 return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : (this.loader = new Ext.tree.TreeLoader()));
\r
2419 // private override
\r
2420 setFirstChild : function(node){
\r
2421 var of = this.firstChild;
\r
2422 Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);
\r
2423 if(this.childrenRendered && of && node != of){
\r
2424 of.renderIndent(true, true);
\r
2426 if(this.rendered){
\r
2427 this.renderIndent(true, true);
\r
2431 // private override
\r
2432 setLastChild : function(node){
\r
2433 var ol = this.lastChild;
\r
2434 Ext.tree.TreeNode.superclass.setLastChild.call(this, node);
\r
2435 if(this.childrenRendered && ol && node != ol){
\r
2436 ol.renderIndent(true, true);
\r
2438 if(this.rendered){
\r
2439 this.renderIndent(true, true);
\r
2443 // these methods are overridden to provide lazy rendering support
\r
2444 // private override
\r
2445 appendChild : function(n){
\r
2446 if(!n.render && !Ext.isArray(n)){
\r
2447 n = this.getLoader().createNode(n);
\r
2449 var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);
\r
2450 if(node && this.childrenRendered){
\r
2453 this.ui.updateExpandIcon();
\r
2457 // private override
\r
2458 removeChild : function(node, destroy){
\r
2459 this.ownerTree.getSelectionModel().unselect(node);
\r
2460 Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
\r
2461 // if it's been rendered remove dom node
\r
2462 if(node.ui.rendered){
\r
2465 if(this.childNodes.length < 1){
\r
2466 this.collapse(false, false);
\r
2468 this.ui.updateExpandIcon();
\r
2470 if(!this.firstChild && !this.isHiddenRoot()) {
\r
2471 this.childrenRendered = false;
\r
2476 // private override
\r
2477 insertBefore : function(node, refNode){
\r
2479 node = this.getLoader().createNode(node);
\r
2481 var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
\r
2482 if(newNode && refNode && this.childrenRendered){
\r
2485 this.ui.updateExpandIcon();
\r
2490 * Sets the text for this node
\r
2491 * @param {String} text
\r
2493 setText : function(text){
\r
2494 var oldText = this.text;
\r
2495 this.text = this.attributes.text = text;
\r
2496 if(this.rendered){ // event without subscribing
\r
2497 this.ui.onTextChange(this, text, oldText);
\r
2499 this.fireEvent('textchange', this, text, oldText);
\r
2503 * Triggers selection of this node
\r
2505 select : function(){
\r
2506 var t = this.getOwnerTree();
\r
2508 t.getSelectionModel().select(this);
\r
2513 * Triggers deselection of this node
\r
2514 * @param {Boolean} silent (optional) True to stop selection change events from firing.
\r
2516 unselect : function(silent){
\r
2517 var t = this.getOwnerTree();
\r
2519 t.getSelectionModel().unselect(this, silent);
\r
2524 * Returns true if this node is selected
\r
2525 * @return {Boolean}
\r
2527 isSelected : function(){
\r
2528 var t = this.getOwnerTree();
\r
2529 return t ? t.getSelectionModel().isSelected(this) : false;
\r
2533 * Expand this node.
\r
2534 * @param {Boolean} deep (optional) True to expand all children as well
\r
2535 * @param {Boolean} anim (optional) false to cancel the default animation
\r
2536 * @param {Function} callback (optional) A callback to be called when
\r
2537 * expanding this node completes (does not wait for deep expand to complete).
\r
2538 * Called with 1 parameter, this node.
\r
2539 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
\r
2541 expand : function(deep, anim, callback, scope){
\r
2542 if(!this.expanded){
\r
2543 if(this.fireEvent('beforeexpand', this, deep, anim) === false){
\r
2546 if(!this.childrenRendered){
\r
2547 this.renderChildren();
\r
2549 this.expanded = true;
\r
2550 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
\r
2551 this.ui.animExpand(function(){
\r
2552 this.fireEvent('expand', this);
\r
2553 this.runCallback(callback, scope || this, [this]);
\r
2554 if(deep === true){
\r
2555 this.expandChildNodes(true);
\r
2557 }.createDelegate(this));
\r
2561 this.fireEvent('expand', this);
\r
2562 this.runCallback(callback, scope || this, [this]);
\r
2565 this.runCallback(callback, scope || this, [this]);
\r
2567 if(deep === true){
\r
2568 this.expandChildNodes(true);
\r
2572 runCallback : function(cb, scope, args){
\r
2573 if(Ext.isFunction(cb)){
\r
2574 cb.apply(scope, args);
\r
2578 isHiddenRoot : function(){
\r
2579 return this.isRoot && !this.getOwnerTree().rootVisible;
\r
2583 * Collapse this node.
\r
2584 * @param {Boolean} deep (optional) True to collapse all children as well
\r
2585 * @param {Boolean} anim (optional) false to cancel the default animation
\r
2586 * @param {Function} callback (optional) A callback to be called when
\r
2587 * expanding this node completes (does not wait for deep expand to complete).
\r
2588 * Called with 1 parameter, this node.
\r
2589 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
\r
2591 collapse : function(deep, anim, callback, scope){
\r
2592 if(this.expanded && !this.isHiddenRoot()){
\r
2593 if(this.fireEvent('beforecollapse', this, deep, anim) === false){
\r
2596 this.expanded = false;
\r
2597 if((this.getOwnerTree().animate && anim !== false) || anim){
\r
2598 this.ui.animCollapse(function(){
\r
2599 this.fireEvent('collapse', this);
\r
2600 this.runCallback(callback, scope || this, [this]);
\r
2601 if(deep === true){
\r
2602 this.collapseChildNodes(true);
\r
2604 }.createDelegate(this));
\r
2607 this.ui.collapse();
\r
2608 this.fireEvent('collapse', this);
\r
2609 this.runCallback(callback, scope || this, [this]);
\r
2611 }else if(!this.expanded){
\r
2612 this.runCallback(callback, scope || this, [this]);
\r
2614 if(deep === true){
\r
2615 var cs = this.childNodes;
\r
2616 for(var i = 0, len = cs.length; i < len; i++) {
\r
2617 cs[i].collapse(true, false);
\r
2623 delayedExpand : function(delay){
\r
2624 if(!this.expandProcId){
\r
2625 this.expandProcId = this.expand.defer(delay, this);
\r
2630 cancelExpand : function(){
\r
2631 if(this.expandProcId){
\r
2632 clearTimeout(this.expandProcId);
\r
2634 this.expandProcId = false;
\r
2638 * Toggles expanded/collapsed state of the node
\r
2640 toggle : function(){
\r
2641 if(this.expanded){
\r
2649 * Ensures all parent nodes are expanded, and if necessary, scrolls
\r
2650 * the node into view.
\r
2651 * @param {Function} callback (optional) A function to call when the node has been made visible.
\r
2652 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
\r
2654 ensureVisible : function(callback, scope){
\r
2655 var tree = this.getOwnerTree();
\r
2656 tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){
\r
2657 var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime
\r
2658 tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
\r
2659 this.runCallback(callback, scope || this, [this]);
\r
2660 }.createDelegate(this));
\r
2664 * Expand all child nodes
\r
2665 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
\r
2667 expandChildNodes : function(deep){
\r
2668 var cs = this.childNodes;
\r
2669 for(var i = 0, len = cs.length; i < len; i++) {
\r
2670 cs[i].expand(deep);
\r
2675 * Collapse all child nodes
\r
2676 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
\r
2678 collapseChildNodes : function(deep){
\r
2679 var cs = this.childNodes;
\r
2680 for(var i = 0, len = cs.length; i < len; i++) {
\r
2681 cs[i].collapse(deep);
\r
2686 * Disables this node
\r
2688 disable : function(){
\r
2689 this.disabled = true;
\r
2691 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
\r
2692 this.ui.onDisableChange(this, true);
\r
2694 this.fireEvent('disabledchange', this, true);
\r
2698 * Enables this node
\r
2700 enable : function(){
\r
2701 this.disabled = false;
\r
2702 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
\r
2703 this.ui.onDisableChange(this, false);
\r
2705 this.fireEvent('disabledchange', this, false);
\r
2709 renderChildren : function(suppressEvent){
\r
2710 if(suppressEvent !== false){
\r
2711 this.fireEvent('beforechildrenrendered', this);
\r
2713 var cs = this.childNodes;
\r
2714 for(var i = 0, len = cs.length; i < len; i++){
\r
2715 cs[i].render(true);
\r
2717 this.childrenRendered = true;
\r
2721 sort : function(fn, scope){
\r
2722 Ext.tree.TreeNode.superclass.sort.apply(this, arguments);
\r
2723 if(this.childrenRendered){
\r
2724 var cs = this.childNodes;
\r
2725 for(var i = 0, len = cs.length; i < len; i++){
\r
2726 cs[i].render(true);
\r
2732 render : function(bulkRender){
\r
2733 this.ui.render(bulkRender);
\r
2734 if(!this.rendered){
\r
2735 // make sure it is registered
\r
2736 this.getOwnerTree().registerNode(this);
\r
2737 this.rendered = true;
\r
2738 if(this.expanded){
\r
2739 this.expanded = false;
\r
2740 this.expand(false, false);
\r
2746 renderIndent : function(deep, refresh){
\r
2748 this.ui.childIndent = null;
\r
2750 this.ui.renderIndent();
\r
2751 if(deep === true && this.childrenRendered){
\r
2752 var cs = this.childNodes;
\r
2753 for(var i = 0, len = cs.length; i < len; i++){
\r
2754 cs[i].renderIndent(true, refresh);
\r
2759 beginUpdate : function(){
\r
2760 this.childrenRendered = false;
\r
2763 endUpdate : function(){
\r
2764 if(this.expanded && this.rendered){
\r
2765 this.renderChildren();
\r
2769 destroy : function(){
\r
2770 this.unselect(true);
\r
2771 Ext.tree.TreeNode.superclass.destroy.call(this);
\r
2772 Ext.destroy(this.ui, this.loader);
\r
2773 this.ui = this.loader = null;
\r
2777 onIdChange : function(id){
\r
2778 this.ui.onIdChange(id);
\r
2782 Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;/**
\r
2783 * @class Ext.tree.AsyncTreeNode
\r
2784 * @extends Ext.tree.TreeNode
\r
2785 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
\r
2787 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
\r
2789 Ext.tree.AsyncTreeNode = function(config){
\r
2790 this.loaded = config && config.loaded === true;
\r
2791 this.loading = false;
\r
2792 Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
\r
2794 * @event beforeload
\r
2795 * Fires before this node is loaded, return false to cancel
\r
2796 * @param {Node} this This node
\r
2798 this.addEvents('beforeload', 'load');
\r
2801 * Fires when this node is loaded
\r
2802 * @param {Node} this This node
\r
2805 * The loader used by this node (defaults to using the tree's defined loader)
\r
2806 * @type TreeLoader
\r
2807 * @property loader
\r
2810 Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
\r
2811 expand : function(deep, anim, callback, scope){
\r
2812 if(this.loading){ // if an async load is already running, waiting til it's done
\r
2814 var f = function(){
\r
2815 if(!this.loading){ // done loading
\r
2816 clearInterval(timer);
\r
2817 this.expand(deep, anim, callback, scope);
\r
2819 }.createDelegate(this);
\r
2820 timer = setInterval(f, 200);
\r
2824 if(this.fireEvent("beforeload", this) === false){
\r
2827 this.loading = true;
\r
2828 this.ui.beforeLoad(this);
\r
2829 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
\r
2831 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
\r
2835 Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
\r
2839 * Returns true if this node is currently loading
\r
2840 * @return {Boolean}
\r
2842 isLoading : function(){
\r
2843 return this.loading;
\r
2846 loadComplete : function(deep, anim, callback, scope){
\r
2847 this.loading = false;
\r
2848 this.loaded = true;
\r
2849 this.ui.afterLoad(this);
\r
2850 this.fireEvent("load", this);
\r
2851 this.expand(deep, anim, callback, scope);
\r
2855 * Returns true if this node has been loaded
\r
2856 * @return {Boolean}
\r
2858 isLoaded : function(){
\r
2859 return this.loaded;
\r
2862 hasChildNodes : function(){
\r
2863 if(!this.isLeaf() && !this.loaded){
\r
2866 return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
\r
2871 * Trigger a reload for this node
\r
2872 * @param {Function} callback
\r
2873 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Node.
\r
2875 reload : function(callback, scope){
\r
2876 this.collapse(false, false);
\r
2877 while(this.firstChild){
\r
2878 this.removeChild(this.firstChild).destroy();
\r
2880 this.childrenRendered = false;
\r
2881 this.loaded = false;
\r
2882 if(this.isHiddenRoot()){
\r
2883 this.expanded = false;
\r
2885 this.expand(false, false, callback, scope);
\r
2889 Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;/**
\r
2890 * @class Ext.tree.TreeNodeUI
\r
2891 * This class provides the default UI implementation for Ext TreeNodes.
\r
2892 * The TreeNode UI implementation is separate from the
\r
2893 * tree implementation, and allows customizing of the appearance of
\r
2896 * If you are customizing the Tree's user interface, you
\r
2897 * may need to extend this class, but you should never need to instantiate this class.<br>
\r
2899 * This class provides access to the user interface components of an Ext TreeNode, through
\r
2900 * {@link Ext.tree.TreeNode#getUI}
\r
2902 Ext.tree.TreeNodeUI = function(node){
\r
2904 this.rendered = false;
\r
2905 this.animating = false;
\r
2906 this.wasLeaf = true;
\r
2907 this.ecc = 'x-tree-ec-icon x-tree-elbow';
\r
2908 this.emptyIcon = Ext.BLANK_IMAGE_URL;
\r
2911 Ext.tree.TreeNodeUI.prototype = {
\r
2913 removeChild : function(node){
\r
2914 if(this.rendered){
\r
2915 this.ctNode.removeChild(node.ui.getEl());
\r
2920 beforeLoad : function(){
\r
2921 this.addClass("x-tree-node-loading");
\r
2925 afterLoad : function(){
\r
2926 this.removeClass("x-tree-node-loading");
\r
2930 onTextChange : function(node, text, oldText){
\r
2931 if(this.rendered){
\r
2932 this.textNode.innerHTML = text;
\r
2937 onDisableChange : function(node, state){
\r
2938 this.disabled = state;
\r
2939 if (this.checkbox) {
\r
2940 this.checkbox.disabled = state;
\r
2943 this.addClass("x-tree-node-disabled");
\r
2945 this.removeClass("x-tree-node-disabled");
\r
2950 onSelectedChange : function(state){
\r
2953 this.addClass("x-tree-selected");
\r
2956 this.removeClass("x-tree-selected");
\r
2961 onMove : function(tree, node, oldParent, newParent, index, refNode){
\r
2962 this.childIndent = null;
\r
2963 if(this.rendered){
\r
2964 var targetNode = newParent.ui.getContainer();
\r
2965 if(!targetNode){//target not rendered
\r
2966 this.holder = document.createElement("div");
\r
2967 this.holder.appendChild(this.wrap);
\r
2970 var insertBefore = refNode ? refNode.ui.getEl() : null;
\r
2972 targetNode.insertBefore(this.wrap, insertBefore);
\r
2974 targetNode.appendChild(this.wrap);
\r
2976 this.node.renderIndent(true, oldParent != newParent);
\r
2981 * Adds one or more CSS classes to the node's UI element.
\r
2982 * Duplicate classes are automatically filtered out.
\r
2983 * @param {String/Array} className The CSS class to add, or an array of classes
\r
2985 addClass : function(cls){
\r
2987 Ext.fly(this.elNode).addClass(cls);
\r
2992 * Removes one or more CSS classes from the node's UI element.
\r
2993 * @param {String/Array} className The CSS class to remove, or an array of classes
\r
2995 removeClass : function(cls){
\r
2997 Ext.fly(this.elNode).removeClass(cls);
\r
3002 remove : function(){
\r
3003 if(this.rendered){
\r
3004 this.holder = document.createElement("div");
\r
3005 this.holder.appendChild(this.wrap);
\r
3010 fireEvent : function(){
\r
3011 return this.node.fireEvent.apply(this.node, arguments);
\r
3015 initEvents : function(){
\r
3016 this.node.on("move", this.onMove, this);
\r
3018 if(this.node.disabled){
\r
3019 this.onDisableChange(this.node, true);
\r
3021 if(this.node.hidden){
\r
3024 var ot = this.node.getOwnerTree();
\r
3025 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
\r
3026 if(dd && (!this.node.isRoot || ot.rootVisible)){
\r
3027 Ext.dd.Registry.register(this.elNode, {
\r
3029 handles: this.getDDHandles(),
\r
3036 getDDHandles : function(){
\r
3037 return [this.iconNode, this.textNode, this.elNode];
\r
3041 * Hides this node.
\r
3043 hide : function(){
\r
3044 this.node.hidden = true;
\r
3046 this.wrap.style.display = "none";
\r
3051 * Shows this node.
\r
3053 show : function(){
\r
3054 this.node.hidden = false;
\r
3056 this.wrap.style.display = "";
\r
3061 onContextMenu : function(e){
\r
3062 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
\r
3063 e.preventDefault();
\r
3065 this.fireEvent("contextmenu", this.node, e);
\r
3070 onClick : function(e){
\r
3071 if(this.dropping){
\r
3075 if(this.fireEvent("beforeclick", this.node, e) !== false){
\r
3076 var a = e.getTarget('a');
\r
3077 if(!this.disabled && this.node.attributes.href && a){
\r
3078 this.fireEvent("click", this.node, e);
\r
3080 }else if(a && e.ctrlKey){
\r
3083 e.preventDefault();
\r
3084 if(this.disabled){
\r
3088 if(this.node.attributes.singleClickExpand && !this.animating && this.node.isExpandable()){
\r
3089 this.node.toggle();
\r
3092 this.fireEvent("click", this.node, e);
\r
3099 onDblClick : function(e){
\r
3100 e.preventDefault();
\r
3101 if(this.disabled){
\r
3104 if(this.fireEvent("beforedblclick", this.node, e) !== false){
\r
3105 if(this.checkbox){
\r
3106 this.toggleCheck();
\r
3108 if(!this.animating && this.node.isExpandable()){
\r
3109 this.node.toggle();
\r
3111 this.fireEvent("dblclick", this.node, e);
\r
3115 onOver : function(e){
\r
3116 this.addClass('x-tree-node-over');
\r
3119 onOut : function(e){
\r
3120 this.removeClass('x-tree-node-over');
\r
3124 onCheckChange : function(){
\r
3125 var checked = this.checkbox.checked;
\r
3127 this.checkbox.defaultChecked = checked;
\r
3128 this.node.attributes.checked = checked;
\r
3129 this.fireEvent('checkchange', this.node, checked);
\r
3133 ecClick : function(e){
\r
3134 if(!this.animating && this.node.isExpandable()){
\r
3135 this.node.toggle();
\r
3140 startDrop : function(){
\r
3141 this.dropping = true;
\r
3144 // delayed drop so the click event doesn't get fired on a drop
\r
3145 endDrop : function(){
\r
3146 setTimeout(function(){
\r
3147 this.dropping = false;
\r
3148 }.createDelegate(this), 50);
\r
3152 expand : function(){
\r
3153 this.updateExpandIcon();
\r
3154 this.ctNode.style.display = "";
\r
3158 focus : function(){
\r
3159 if(!this.node.preventHScroll){
\r
3160 try{this.anchor.focus();
\r
3164 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
\r
3165 var l = noscroll.scrollLeft;
\r
3166 this.anchor.focus();
\r
3167 noscroll.scrollLeft = l;
\r
3173 * Sets the checked status of the tree node to the passed value, or, if no value was passed,
\r
3174 * toggles the checked status. If the node was rendered with no checkbox, this has no effect.
\r
3175 * @param {Boolean} (optional) The new checked status.
\r
3177 toggleCheck : function(value){
\r
3178 var cb = this.checkbox;
\r
3180 cb.checked = (value === undefined ? !cb.checked : value);
\r
3181 this.onCheckChange();
\r
3186 blur : function(){
\r
3188 this.anchor.blur();
\r
3193 animExpand : function(callback){
\r
3194 var ct = Ext.get(this.ctNode);
\r
3196 if(!this.node.isExpandable()){
\r
3197 this.updateExpandIcon();
\r
3198 this.ctNode.style.display = "";
\r
3199 Ext.callback(callback);
\r
3202 this.animating = true;
\r
3203 this.updateExpandIcon();
\r
3206 callback : function(){
\r
3207 this.animating = false;
\r
3208 Ext.callback(callback);
\r
3211 duration: this.node.ownerTree.duration || .25
\r
3216 highlight : function(){
\r
3217 var tree = this.node.getOwnerTree();
\r
3218 Ext.fly(this.wrap).highlight(
\r
3219 tree.hlColor || "C3DAF9",
\r
3220 {endColor: tree.hlBaseColor}
\r
3225 collapse : function(){
\r
3226 this.updateExpandIcon();
\r
3227 this.ctNode.style.display = "none";
\r
3231 animCollapse : function(callback){
\r
3232 var ct = Ext.get(this.ctNode);
\r
3233 ct.enableDisplayMode('block');
\r
3236 this.animating = true;
\r
3237 this.updateExpandIcon();
\r
3239 ct.slideOut('t', {
\r
3240 callback : function(){
\r
3241 this.animating = false;
\r
3242 Ext.callback(callback);
\r
3245 duration: this.node.ownerTree.duration || .25
\r
3250 getContainer : function(){
\r
3251 return this.ctNode;
\r
3255 * Returns the element which encapsulates this node.
\r
3256 * @return {HtmlElement} The DOM element. The default implementation uses a <code><li></code>.
\r
3258 getEl : function(){
\r
3259 return this.wrap;
\r
3263 appendDDGhost : function(ghostNode){
\r
3264 ghostNode.appendChild(this.elNode.cloneNode(true));
\r
3268 getDDRepairXY : function(){
\r
3269 return Ext.lib.Dom.getXY(this.iconNode);
\r
3273 onRender : function(){
\r
3278 render : function(bulkRender){
\r
3279 var n = this.node, a = n.attributes;
\r
3280 var targetNode = n.parentNode ?
\r
3281 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
\r
3283 if(!this.rendered){
\r
3284 this.rendered = true;
\r
3286 this.renderElements(n, a, targetNode, bulkRender);
\r
3289 if(this.textNode.setAttributeNS){
\r
3290 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
\r
3292 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
\r
3295 this.textNode.setAttribute("ext:qtip", a.qtip);
\r
3297 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
\r
3300 }else if(a.qtipCfg){
\r
3301 a.qtipCfg.target = Ext.id(this.textNode);
\r
3302 Ext.QuickTips.register(a.qtipCfg);
\r
3304 this.initEvents();
\r
3305 if(!this.node.expanded){
\r
3306 this.updateExpandIcon(true);
\r
3309 if(bulkRender === true) {
\r
3310 targetNode.appendChild(this.wrap);
\r
3316 renderElements : function(n, a, targetNode, bulkRender){
\r
3317 // add some indent caching, this helps performance when rendering a large tree
\r
3318 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
\r
3320 var cb = Ext.isBoolean(a.checked),
\r
3322 href = a.href ? a.href : Ext.isGecko ? "" : "#",
\r
3323 buf = ['<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf x-unselectable ', a.cls,'" unselectable="on">',
\r
3324 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
\r
3325 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
\r
3326 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
\r
3327 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',
\r
3328 '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ',
\r
3329 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",
\r
3330 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
\r
3331 "</li>"].join('');
\r
3333 if(bulkRender !== true && n.nextSibling && (nel = n.nextSibling.ui.getEl())){
\r
3334 this.wrap = Ext.DomHelper.insertHtml("beforeBegin", nel, buf);
\r
3336 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf);
\r
3339 this.elNode = this.wrap.childNodes[0];
\r
3340 this.ctNode = this.wrap.childNodes[1];
\r
3341 var cs = this.elNode.childNodes;
\r
3342 this.indentNode = cs[0];
\r
3343 this.ecNode = cs[1];
\r
3344 this.iconNode = cs[2];
\r
3347 this.checkbox = cs[3];
\r
3349 this.checkbox.defaultChecked = this.checkbox.checked;
\r
3352 this.anchor = cs[index];
\r
3353 this.textNode = cs[index].firstChild;
\r
3357 * Returns the <a> element that provides focus for the node's UI.
\r
3358 * @return {HtmlElement} The DOM anchor element.
\r
3360 getAnchor : function(){
\r
3361 return this.anchor;
\r
3365 * Returns the text node.
\r
3366 * @return {HtmlNode} The DOM text node.
\r
3368 getTextEl : function(){
\r
3369 return this.textNode;
\r
3373 * Returns the icon <img> element.
\r
3374 * @return {HtmlElement} The DOM image element.
\r
3376 getIconEl : function(){
\r
3377 return this.iconNode;
\r
3381 * Returns the checked status of the node. If the node was rendered with no
\r
3382 * checkbox, it returns false.
\r
3383 * @return {Boolean} The checked flag.
\r
3385 isChecked : function(){
\r
3386 return this.checkbox ? this.checkbox.checked : false;
\r
3390 updateExpandIcon : function(){
\r
3391 if(this.rendered){
\r
3392 var n = this.node,
\r
3395 cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow",
\r
3396 hasChild = n.hasChildNodes();
\r
3397 if(hasChild || n.attributes.expandable){
\r
3400 c1 = "x-tree-node-collapsed";
\r
3401 c2 = "x-tree-node-expanded";
\r
3404 c1 = "x-tree-node-expanded";
\r
3405 c2 = "x-tree-node-collapsed";
\r
3408 this.removeClass("x-tree-node-leaf");
\r
3409 this.wasLeaf = false;
\r
3411 if(this.c1 != c1 || this.c2 != c2){
\r
3412 Ext.fly(this.elNode).replaceClass(c1, c2);
\r
3413 this.c1 = c1; this.c2 = c2;
\r
3416 if(!this.wasLeaf){
\r
3417 Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
\r
3420 this.wasLeaf = true;
\r
3423 var ecc = "x-tree-ec-icon "+cls;
\r
3424 if(this.ecc != ecc){
\r
3425 this.ecNode.className = ecc;
\r
3432 onIdChange: function(id){
\r
3433 if(this.rendered){
\r
3434 this.elNode.setAttribute('ext:tree-node-id', id);
\r
3439 getChildIndent : function(){
\r
3440 if(!this.childIndent){
\r
3444 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
\r
3446 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
\r
3448 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
\r
3453 this.childIndent = buf.join("");
\r
3455 return this.childIndent;
\r
3459 renderIndent : function(){
\r
3460 if(this.rendered){
\r
3462 p = this.node.parentNode;
\r
3464 indent = p.ui.getChildIndent();
\r
3466 if(this.indentMarkup != indent){ // don't rerender if not required
\r
3467 this.indentNode.innerHTML = indent;
\r
3468 this.indentMarkup = indent;
\r
3470 this.updateExpandIcon();
\r
3474 destroy : function(){
\r
3476 Ext.dd.Registry.unregister(this.elNode.id);
\r
3479 Ext.each(['textnode', 'anchor', 'checkbox', 'indentNode', 'ecNode', 'iconNode', 'elNode', 'ctNode', 'wrap', 'holder'], function(el){
\r
3481 Ext.fly(this[el]).remove();
\r
3490 * @class Ext.tree.RootTreeNodeUI
\r
3491 * This class provides the default UI implementation for <b>root</b> Ext TreeNodes.
\r
3492 * The RootTreeNode UI implementation allows customizing the appearance of the root tree node.<br>
\r
3494 * If you are customizing the Tree's user interface, you
\r
3495 * may need to extend this class, but you should never need to instantiate this class.<br>
\r
3497 Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
\r
3499 render : function(){
\r
3500 if(!this.rendered){
\r
3501 var targetNode = this.node.ownerTree.innerCt.dom;
\r
3502 this.node.expanded = true;
\r
3503 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
\r
3504 this.wrap = this.ctNode = targetNode.firstChild;
\r
3507 collapse : Ext.emptyFn,
\r
3508 expand : Ext.emptyFn
\r
3510 * @class Ext.tree.TreeLoader
\r
3511 * @extends Ext.util.Observable
\r
3512 * A TreeLoader provides for lazy loading of an {@link Ext.tree.TreeNode}'s child
\r
3513 * nodes from a specified URL. The response must be a JavaScript Array definition
\r
3514 * whose elements are node definition objects. e.g.:
\r
3518 text: 'A leaf Node',
\r
3522 text: 'A folder Node',
\r
3525 text: 'A child Node',
\r
3531 * A server request is sent, and child nodes are loaded only when a node is expanded.
\r
3532 * The loading node's id is passed to the server under the parameter name "node" to
\r
3533 * enable the server to produce the correct child nodes.
\r
3535 * To pass extra parameters, an event handler may be attached to the "beforeload"
\r
3536 * event, and the parameters specified in the TreeLoader's baseParams property:
\r
3538 myTreeLoader.on("beforeload", function(treeLoader, node) {
\r
3539 this.baseParams.category = node.attributes.category;
\r
3542 * This would pass an HTTP parameter called "category" to the server containing
\r
3543 * the value of the Node's "category" attribute.
\r
3545 * Creates a new Treeloader.
\r
3546 * @param {Object} config A config object containing config properties.
\r
3548 Ext.tree.TreeLoader = function(config){
\r
3549 this.baseParams = {};
\r
3550 Ext.apply(this, config);
\r
3554 * @event beforeload
\r
3555 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
\r
3556 * @param {Object} This TreeLoader object.
\r
3557 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
\r
3558 * @param {Object} callback The callback function specified in the {@link #load} call.
\r
3563 * Fires when the node has been successfuly loaded.
\r
3564 * @param {Object} This TreeLoader object.
\r
3565 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
\r
3566 * @param {Object} response The response object containing the data from the server.
\r
3570 * @event loadexception
\r
3571 * Fires if the network request failed.
\r
3572 * @param {Object} This TreeLoader object.
\r
3573 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
\r
3574 * @param {Object} response The response object containing the data from the server.
\r
3578 Ext.tree.TreeLoader.superclass.constructor.call(this);
\r
3579 if(Ext.isString(this.paramOrder)){
\r
3580 this.paramOrder = this.paramOrder.split(/[\s,|]/);
\r
3584 Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, {
\r
3586 * @cfg {String} dataUrl The URL from which to request a Json string which
\r
3587 * specifies an array of node definition objects representing the child nodes
\r
3591 * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
\r
3594 * @cfg {String} url Equivalent to {@link #dataUrl}.
\r
3597 * @cfg {Boolean} preloadChildren If set to true, the loader recursively loads "children" attributes when doing the first load on nodes.
\r
3600 * @cfg {Object} baseParams (optional) An object containing properties which
\r
3601 * specify HTTP parameters to be passed to each request for child nodes.
\r
3604 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
\r
3605 * created by this loader. If the attributes sent by the server have an attribute in this object,
\r
3606 * they take priority.
\r
3609 * @cfg {Object} uiProviders (optional) An object containing properties which
\r
3610 * specify custom {@link Ext.tree.TreeNodeUI} implementations. If the optional
\r
3611 * <i>uiProvider</i> attribute of a returned child node is a string rather
\r
3612 * than a reference to a TreeNodeUI implementation, then that string value
\r
3613 * is used as a property name in the uiProviders object.
\r
3618 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
\r
3619 * child nodes before loading.
\r
3621 clearOnLoad : true,
\r
3624 * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. Only used when using directFn.
\r
3625 * A list of params to be executed
\r
3626 * server side. Specify the params in the order in which they must be executed on the server-side
\r
3627 * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
\r
3628 * comma, or pipe. For example,
\r
3629 * any of the following would be acceptable:<pre><code>
\r
3630 paramOrder: ['param1','param2','param3']
\r
3631 paramOrder: 'param1 param2 param3'
\r
3632 paramOrder: 'param1,param2,param3'
\r
3633 paramOrder: 'param1|param2|param'
\r
3636 paramOrder: undefined,
\r
3639 * @cfg {Boolean} paramsAsHash Only used when using directFn.
\r
3640 * Send parameters as a collection of named arguments (defaults to <tt>false</tt>). Providing a
\r
3641 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
\r
3643 paramsAsHash: false,
\r
3646 * @cfg {String} nodeParameter The name of the parameter sent to the server which contains
\r
3647 * the identifier of the node. Defaults to <tt>'node'</tt>.
\r
3649 nodeParameter: 'node',
\r
3652 * @cfg {Function} directFn
\r
3653 * Function to call when executing a request.
\r
3655 directFn : undefined,
\r
3658 * Load an {@link Ext.tree.TreeNode} from the URL specified in the constructor.
\r
3659 * This is called automatically when a node is expanded, but may be used to reload
\r
3660 * a node (or append new children if the {@link #clearOnLoad} option is false.)
\r
3661 * @param {Ext.tree.TreeNode} node
\r
3662 * @param {Function} callback Function to call after the node has been loaded. The
\r
3663 * function is passed the TreeNode which was requested to be loaded.
\r
3664 * @param (Object) scope The cope (<code>this</code> reference) in which the callback is executed.
\r
3665 * defaults to the loaded TreeNode.
\r
3667 load : function(node, callback, scope){
\r
3668 if(this.clearOnLoad){
\r
3669 while(node.firstChild){
\r
3670 node.removeChild(node.firstChild);
\r
3673 if(this.doPreload(node)){ // preloaded json children
\r
3674 this.runCallback(callback, scope || node, [node]);
\r
3675 }else if(this.directFn || this.dataUrl || this.url){
\r
3676 this.requestData(node, callback, scope || node);
\r
3680 doPreload : function(node){
\r
3681 if(node.attributes.children){
\r
3682 if(node.childNodes.length < 1){ // preloaded?
\r
3683 var cs = node.attributes.children;
\r
3684 node.beginUpdate();
\r
3685 for(var i = 0, len = cs.length; i < len; i++){
\r
3686 var cn = node.appendChild(this.createNode(cs[i]));
\r
3687 if(this.preloadChildren){
\r
3688 this.doPreload(cn);
\r
3698 getParams: function(node){
\r
3699 var buf = [], bp = this.baseParams;
\r
3700 if(this.directFn){
\r
3701 buf.push(node.id);
\r
3703 if(this.paramOrder){
\r
3704 for(var i = 0, len = this.paramOrder.length; i < len; i++){
\r
3705 buf.push(bp[this.paramOrder[i]]);
\r
3707 }else if(this.paramsAsHash){
\r
3713 var o = Ext.apply({}, bp);
\r
3714 o[this.nodeParameter] = node.id;
\r
3719 requestData : function(node, callback, scope){
\r
3720 if(this.fireEvent("beforeload", this, node, callback) !== false){
\r
3721 if(this.directFn){
\r
3722 var args = this.getParams(node);
\r
3723 args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));
\r
3724 this.directFn.apply(window, args);
\r
3726 this.transId = Ext.Ajax.request({
\r
3727 method:this.requestMethod,
\r
3728 url: this.dataUrl||this.url,
\r
3729 success: this.handleResponse,
\r
3730 failure: this.handleFailure,
\r
3732 argument: {callback: callback, node: node, scope: scope},
\r
3733 params: this.getParams(node)
\r
3737 // if the load is cancelled, make sure we notify
\r
3738 // the node that we are done
\r
3739 this.runCallback(callback, scope || node, []);
\r
3743 processDirectResponse: function(result, response, args){
\r
3744 if(response.status){
\r
3745 this.handleResponse({
\r
3746 responseData: Ext.isArray(result) ? result : null,
\r
3747 responseText: result,
\r
3751 this.handleFailure({
\r
3758 runCallback: function(cb, scope, args){
\r
3759 if(Ext.isFunction(cb)){
\r
3760 cb.apply(scope, args);
\r
3764 isLoading : function(){
\r
3765 return !!this.transId;
\r
3768 abort : function(){
\r
3769 if(this.isLoading()){
\r
3770 Ext.Ajax.abort(this.transId);
\r
3775 * <p>Override this function for custom TreeNode node implementation, or to
\r
3776 * modify the attributes at creation time.</p>
\r
3777 * Example:<pre><code>
\r
3778 new Ext.tree.TreePanel({
\r
3780 loader: new Ext.tree.TreeLoader({
\r
3782 createNode: function(attr) {
\r
3783 // Allow consolidation consignments to have
\r
3784 // consignments dropped into them.
\r
3785 if (attr.isConsolidation) {
\r
3786 attr.iconCls = 'x-consol',
\r
3787 attr.allowDrop = true;
\r
3789 return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
\r
3795 * @param attr {Object} The attributes from which to create the new node.
\r
3797 createNode : function(attr){
\r
3798 // apply baseAttrs, nice idea Corey!
\r
3799 if(this.baseAttrs){
\r
3800 Ext.applyIf(attr, this.baseAttrs);
\r
3802 if(this.applyLoader !== false && !attr.loader){
\r
3803 attr.loader = this;
\r
3805 if(Ext.isString(attr.uiProvider)){
\r
3806 attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
\r
3808 if(attr.nodeType){
\r
3809 return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
\r
3811 return attr.leaf ?
\r
3812 new Ext.tree.TreeNode(attr) :
\r
3813 new Ext.tree.AsyncTreeNode(attr);
\r
3817 processResponse : function(response, node, callback, scope){
\r
3818 var json = response.responseText;
\r
3820 var o = response.responseData || Ext.decode(json);
\r
3821 node.beginUpdate();
\r
3822 for(var i = 0, len = o.length; i < len; i++){
\r
3823 var n = this.createNode(o[i]);
\r
3825 node.appendChild(n);
\r
3829 this.runCallback(callback, scope || node, [node]);
\r
3831 this.handleFailure(response);
\r
3835 handleResponse : function(response){
\r
3836 this.transId = false;
\r
3837 var a = response.argument;
\r
3838 this.processResponse(response, a.node, a.callback, a.scope);
\r
3839 this.fireEvent("load", this, a.node, response);
\r
3842 handleFailure : function(response){
\r
3843 this.transId = false;
\r
3844 var a = response.argument;
\r
3845 this.fireEvent("loadexception", this, a.node, response);
\r
3846 this.runCallback(a.callback, a.scope || a.node, [a.node]);
\r
3849 destroy : function(){
\r
3850 this.purgeListeners();
\r
3853 * @class Ext.tree.TreeFilter
3854 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
3855 * @param {TreePanel} tree
3856 * @param {Object} config (optional)
3858 Ext.tree.TreeFilter = function(tree, config){
3861 Ext.apply(this, config);
3864 Ext.tree.TreeFilter.prototype = {
3871 * Filter the data by a specific attribute.
3872 * @param {String/RegExp} value Either string that the attribute value
3873 * should start with or a RegExp to test against the attribute
3874 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
3875 * @param {TreeNode} startNode (optional) The node to start the filter at.
3877 filter : function(value, attr, startNode){
3878 attr = attr || "text";
3880 if(typeof value == "string"){
3881 var vlen = value.length;
3882 // auto clear empty filter
3883 if(vlen == 0 && this.clearBlank){
3887 value = value.toLowerCase();
3889 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
3891 }else if(value.exec){ // regex?
3893 return value.test(n.attributes[attr]);
3896 throw 'Illegal filter type, must be string or regex';
3898 this.filterBy(f, null, startNode);
3902 * Filter by a function. The passed function will be called with each
3903 * node in the tree (or from the startNode). If the function returns true, the node is kept
3904 * otherwise it is filtered. If a node is filtered, its children are also filtered.
3905 * @param {Function} fn The filter function
3906 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
3908 filterBy : function(fn, scope, startNode){
3909 startNode = startNode || this.tree.root;
3913 var af = this.filtered, rv = this.reverse;
3914 var f = function(n){
3921 var m = fn.call(scope || n, n);
3929 startNode.cascade(f);
3932 if(typeof id != "function"){
3934 if(n && n.parentNode){
3935 n.parentNode.removeChild(n);
3943 * Clears the current filter. Note: with the "remove" option
3944 * set a filter cannot be cleared.
3948 var af = this.filtered;
3950 if(typeof id != "function"){
3961 * @class Ext.tree.TreeSorter
\r
3962 * Provides sorting of nodes in a {@link Ext.tree.TreePanel}. The TreeSorter automatically monitors events on the
\r
3963 * associated TreePanel that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
\r
3964 * Example usage:<br />
\r
3966 new Ext.tree.TreeSorter(myTree, {
\r
3969 sortType: function(node) {
\r
3970 // sort by a custom, typed attribute:
\r
3971 return parseInt(node.id, 10);
\r
3976 * @param {TreePanel} tree
\r
3977 * @param {Object} config
\r
3979 Ext.tree.TreeSorter = function(tree, config){
\r
3981 * @cfg {Boolean} folderSort True to sort leaf nodes under non-leaf nodes (defaults to false)
\r
3984 * @cfg {String} property The named attribute on the node to sort by (defaults to "text"). Note that this
\r
3985 * property is only used if no {@link #sortType} function is specified, otherwise it is ignored.
\r
3988 * @cfg {String} dir The direction to sort ("asc" or "desc," case-insensitive, defaults to "asc")
\r
3991 * @cfg {String} leafAttr The attribute used to determine leaf nodes when {@link #folderSort} = true (defaults to "leaf")
\r
3994 * @cfg {Boolean} caseSensitive true for case-sensitive sort (defaults to false)
\r
3997 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting. The function
\r
3998 * will be called with a single parameter (the {@link Ext.tree.TreeNode} being evaluated) and is expected to return
\r
3999 * the node's sort value cast to the specific data type required for sorting. This could be used, for example, when
\r
4000 * a node's text (or other attribute) should be sorted as a date or numeric value. See the class description for
\r
4001 * example usage. Note that if a sortType is specified, any {@link #property} config will be ignored.
\r
4004 Ext.apply(this, config);
\r
4005 tree.on("beforechildrenrendered", this.doSort, this);
\r
4006 tree.on("append", this.updateSort, this);
\r
4007 tree.on("insert", this.updateSort, this);
\r
4008 tree.on("textchange", this.updateSortParent, this);
\r
4010 var dsc = this.dir && this.dir.toLowerCase() == "desc";
\r
4011 var p = this.property || "text";
\r
4012 var sortType = this.sortType;
\r
4013 var fs = this.folderSort;
\r
4014 var cs = this.caseSensitive === true;
\r
4015 var leafAttr = this.leafAttr || 'leaf';
\r
4017 this.sortFn = function(n1, n2){
\r
4019 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
\r
4022 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
\r
4026 var v1 = sortType ? sortType(n1.attributes[p]) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
\r
4027 var v2 = sortType ? sortType(n2.attributes[p]) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
\r
4029 return dsc ? +1 : -1;
\r
4030 }else if(v1 > v2){
\r
4031 return dsc ? -1 : +1;
\r
4038 Ext.tree.TreeSorter.prototype = {
\r
4039 doSort : function(node){
\r
4040 node.sort(this.sortFn);
\r
4043 compareNodes : function(n1, n2){
\r
4044 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
\r
4047 updateSort : function(tree, node){
\r
4048 if(node.childrenRendered){
\r
4049 this.doSort.defer(1, this, [node]);
\r
4053 updateSortParent : function(node){
\r
4054 var p = node.parentNode;
\r
4055 if(p && p.childrenRendered){
\r
4056 this.doSort.defer(1, this, [p]);
\r
4060 * @class Ext.tree.TreeDropZone
\r
4061 * @extends Ext.dd.DropZone
\r
4063 * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dropping
\r
4064 * @param {Object} config
\r
4066 if(Ext.dd.DropZone){
\r
4068 Ext.tree.TreeDropZone = function(tree, config){
\r
4070 * @cfg {Boolean} allowParentInsert
\r
4071 * Allow inserting a dragged node between an expanded parent node and its first child that will become a
\r
4072 * sibling of the parent when dropped (defaults to false)
\r
4074 this.allowParentInsert = config.allowParentInsert || false;
\r
4076 * @cfg {String} allowContainerDrop
\r
4077 * True if drops on the tree container (outside of a specific tree node) are allowed (defaults to false)
\r
4079 this.allowContainerDrop = config.allowContainerDrop || false;
\r
4081 * @cfg {String} appendOnly
\r
4082 * True if the tree should only allow append drops (use for trees which are sorted, defaults to false)
\r
4084 this.appendOnly = config.appendOnly || false;
\r
4086 Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.getTreeEl(), config);
\r
4088 * The TreePanel for this drop zone
\r
4089 * @type Ext.tree.TreePanel
\r
4094 * Arbitrary data that can be associated with this tree and will be included in the event object that gets
\r
4095 * passed to any nodedragover event handler (defaults to {})
\r
4096 * @type Ext.tree.TreePanel
\r
4099 this.dragOverData = {};
\r
4101 this.lastInsertClass = "x-tree-no-status";
\r
4104 Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, {
\r
4106 * @cfg {String} ddGroup
\r
4107 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
\r
4108 * interact with other drag drop objects in the same group (defaults to 'TreeDD').
\r
4110 ddGroup : "TreeDD",
\r
4113 * @cfg {String} expandDelay
\r
4114 * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node
\r
4115 * over the target (defaults to 1000)
\r
4117 expandDelay : 1000,
\r
4120 expandNode : function(node){
\r
4121 if(node.hasChildNodes() && !node.isExpanded()){
\r
4122 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
\r
4127 queueExpand : function(node){
\r
4128 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
\r
4132 cancelExpand : function(){
\r
4133 if(this.expandProcId){
\r
4134 clearTimeout(this.expandProcId);
\r
4135 this.expandProcId = false;
\r
4140 isValidDropPoint : function(n, pt, dd, e, data){
\r
4141 if(!n || !data){ return false; }
\r
4142 var targetNode = n.node;
\r
4143 var dropNode = data.node;
\r
4144 // default drop rules
\r
4145 if(!(targetNode && targetNode.isTarget && pt)){
\r
4148 if(pt == "append" && targetNode.allowChildren === false){
\r
4151 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
\r
4154 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
\r
4157 // reuse the object
\r
4158 var overEvent = this.dragOverData;
\r
4159 overEvent.tree = this.tree;
\r
4160 overEvent.target = targetNode;
\r
4161 overEvent.data = data;
\r
4162 overEvent.point = pt;
\r
4163 overEvent.source = dd;
\r
4164 overEvent.rawEvent = e;
\r
4165 overEvent.dropNode = dropNode;
\r
4166 overEvent.cancel = false;
\r
4167 var result = this.tree.fireEvent("nodedragover", overEvent);
\r
4168 return overEvent.cancel === false && result !== false;
\r
4172 getDropPoint : function(e, n, dd){
\r
4175 return tn.allowChildren !== false ? "append" : false; // always append for root
\r
4177 var dragEl = n.ddel;
\r
4178 var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
\r
4179 var y = Ext.lib.Event.getPageY(e);
\r
4180 var noAppend = tn.allowChildren === false || tn.isLeaf();
\r
4181 if(this.appendOnly || tn.parentNode.allowChildren === false){
\r
4182 return noAppend ? false : "append";
\r
4184 var noBelow = false;
\r
4185 if(!this.allowParentInsert){
\r
4186 noBelow = tn.hasChildNodes() && tn.isExpanded();
\r
4188 var q = (b - t) / (noAppend ? 2 : 3);
\r
4189 if(y >= t && y < (t + q)){
\r
4191 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
\r
4199 onNodeEnter : function(n, dd, e, data){
\r
4200 this.cancelExpand();
\r
4203 onContainerOver : function(dd, e, data) {
\r
4204 if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
\r
4205 return this.dropAllowed;
\r
4207 return this.dropNotAllowed;
\r
4211 onNodeOver : function(n, dd, e, data){
\r
4212 var pt = this.getDropPoint(e, n, dd);
\r
4213 var node = n.node;
\r
4215 // auto node expand check
\r
4216 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
\r
4217 this.queueExpand(node);
\r
4218 }else if(pt != "append"){
\r
4219 this.cancelExpand();
\r
4222 // set the insert point style on the target node
\r
4223 var returnCls = this.dropNotAllowed;
\r
4224 if(this.isValidDropPoint(n, pt, dd, e, data)){
\r
4228 if(pt == "above"){
\r
4229 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
\r
4230 cls = "x-tree-drag-insert-above";
\r
4231 }else if(pt == "below"){
\r
4232 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
\r
4233 cls = "x-tree-drag-insert-below";
\r
4235 returnCls = "x-tree-drop-ok-append";
\r
4236 cls = "x-tree-drag-append";
\r
4238 if(this.lastInsertClass != cls){
\r
4239 Ext.fly(el).replaceClass(this.lastInsertClass, cls);
\r
4240 this.lastInsertClass = cls;
\r
4248 onNodeOut : function(n, dd, e, data){
\r
4249 this.cancelExpand();
\r
4250 this.removeDropIndicators(n);
\r
4254 onNodeDrop : function(n, dd, e, data){
\r
4255 var point = this.getDropPoint(e, n, dd);
\r
4256 var targetNode = n.node;
\r
4257 targetNode.ui.startDrop();
\r
4258 if(!this.isValidDropPoint(n, point, dd, e, data)){
\r
4259 targetNode.ui.endDrop();
\r
4262 // first try to find the drop node
\r
4263 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
\r
4264 return this.processDrop(targetNode, data, point, dd, e, dropNode);
\r
4267 onContainerDrop : function(dd, e, data){
\r
4268 if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
\r
4269 var targetNode = this.tree.getRootNode();
\r
4270 targetNode.ui.startDrop();
\r
4271 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, 'append', e) : null);
\r
4272 return this.processDrop(targetNode, data, 'append', dd, e, dropNode);
\r
4278 processDrop: function(target, data, point, dd, e, dropNode){
\r
4286 dropNode: dropNode,
\r
4287 cancel: !dropNode,
\r
4290 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
\r
4291 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
\r
4292 target.ui.endDrop();
\r
4293 return dropEvent.dropStatus;
\r
4296 target = dropEvent.target;
\r
4297 if(point == 'append' && !target.isExpanded()){
\r
4298 target.expand(false, null, function(){
\r
4299 this.completeDrop(dropEvent);
\r
4300 }.createDelegate(this));
\r
4302 this.completeDrop(dropEvent);
\r
4308 completeDrop : function(de){
\r
4309 var ns = de.dropNode, p = de.point, t = de.target;
\r
4310 if(!Ext.isArray(ns)){
\r
4314 for(var i = 0, len = ns.length; i < len; i++){
\r
4317 t.parentNode.insertBefore(n, t);
\r
4318 }else if(p == "below"){
\r
4319 t.parentNode.insertBefore(n, t.nextSibling);
\r
4325 if(Ext.enableFx && this.tree.hlDrop){
\r
4329 this.tree.fireEvent("nodedrop", de);
\r
4333 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
\r
4334 if(Ext.enableFx && this.tree.hlDrop){
\r
4335 dropNode.ui.focus();
\r
4336 dropNode.ui.highlight();
\r
4338 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
\r
4342 getTree : function(){
\r
4347 removeDropIndicators : function(n){
\r
4350 Ext.fly(el).removeClass([
\r
4351 "x-tree-drag-insert-above",
\r
4352 "x-tree-drag-insert-below",
\r
4353 "x-tree-drag-append"]);
\r
4354 this.lastInsertClass = "_noclass";
\r
4359 beforeDragDrop : function(target, e, id){
\r
4360 this.cancelExpand();
\r
4365 afterRepair : function(data){
\r
4366 if(data && Ext.enableFx){
\r
4367 data.node.ui.highlight();
\r
4374 * @class Ext.tree.TreeDragZone
\r
4375 * @extends Ext.dd.DragZone
\r
4377 * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dragging
\r
4378 * @param {Object} config
\r
4380 if(Ext.dd.DragZone){
\r
4381 Ext.tree.TreeDragZone = function(tree, config){
\r
4382 Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.innerCt, config);
\r
4384 * The TreePanel for this drag zone
\r
4385 * @type Ext.tree.TreePanel
\r
4391 Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, {
\r
4393 * @cfg {String} ddGroup
\r
4394 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
\r
4395 * interact with other drag drop objects in the same group (defaults to 'TreeDD').
\r
4397 ddGroup : "TreeDD",
\r
4400 onBeforeDrag : function(data, e){
\r
4401 var n = data.node;
\r
4402 return n && n.draggable && !n.disabled;
\r
4406 onInitDrag : function(e){
\r
4407 var data = this.dragData;
\r
4408 this.tree.getSelectionModel().select(data.node);
\r
4409 this.tree.eventModel.disable();
\r
4410 this.proxy.update("");
\r
4411 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
\r
4412 this.tree.fireEvent("startdrag", this.tree, data.node, e);
\r
4416 getRepairXY : function(e, data){
\r
4417 return data.node.ui.getDDRepairXY();
\r
4421 onEndDrag : function(data, e){
\r
4422 this.tree.eventModel.enable.defer(100, this.tree.eventModel);
\r
4423 this.tree.fireEvent("enddrag", this.tree, data.node, e);
\r
4427 onValidDrop : function(dd, e, id){
\r
4428 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
\r
4433 beforeInvalidDrop : function(e, id){
\r
4434 // this scrolls the original position back into view
\r
4435 var sm = this.tree.getSelectionModel();
\r
4436 sm.clearSelections();
\r
4437 sm.select(this.dragData.node);
\r
4441 afterRepair : function(){
\r
4442 if (Ext.enableFx && this.tree.hlDrop) {
\r
4443 Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
\r
4445 this.dragging = false;
\r
4449 * @class Ext.tree.TreeEditor
4450 * @extends Ext.Editor
4451 * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
4452 * as the editor field.
4454 * @param {TreePanel} tree
4455 * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
4456 * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
4457 * @param {Object} config (optional) A TreeEditor config object
4459 Ext.tree.TreeEditor = function(tree, fc, config){
4461 var field = fc.events ? fc : new Ext.form.TextField(fc);
4462 Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
4467 tree.on('render', this.initEditor, this);
4469 this.initEditor(tree);
4473 Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
4475 * @cfg {String} alignment
4476 * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "l-l").
4482 * @cfg {Boolean} hideEl
4483 * True to hide the bound element while the editor is displayed (defaults to false)
4488 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
4490 cls: "x-small-editor x-tree-editor",
4492 * @cfg {Boolean} shim
4493 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
4499 * @cfg {Number} maxWidth
4500 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
4501 * the containing tree element's size, it will be automatically limited for you to the container width, taking
4502 * scroll and client offsets into account prior to each edit.
4506 * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
4507 * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
4508 * the editor for the node will display, otherwise it will be processed as a regular click.
4512 initEditor : function(tree){
4515 beforeclick: this.beforeNodeClick,
4516 dblclick: this.onNodeDblClick
4520 complete: this.updateNode,
4521 beforestartedit: this.fitToTree,
4522 specialkey: this.onSpecialKey
4524 this.on('startedit', this.bindScroll, this, {delay:10});
4528 fitToTree : function(ed, el){
4529 var td = this.tree.getTreeEl().dom, nd = el.dom;
4530 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
4531 td.scrollLeft = nd.offsetLeft;
4535 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
4536 this.setSize(w, '');
4540 * Edit the text of the passed {@link Ext.tree.TreeNode TreeNode}.
4541 * @param node {Ext.tree.TreeNode} The TreeNode to edit. The TreeNode must be {@link Ext.tree.TreeNode#editable editable}.
4543 triggerEdit : function(node, defer){
4544 this.completeEdit();
4545 if(node.attributes.editable !== false){
4547 * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
4548 * @type Ext.tree.TreeNode
4549 * @property editNode
4551 this.editNode = node;
4552 if(this.tree.autoScroll){
4553 Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
4555 var value = node.text || '';
4556 if (!Ext.isGecko && Ext.isEmpty(node.text)){
4557 node.setText(' ');
4559 this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
4565 bindScroll : function(){
4566 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
4570 beforeNodeClick : function(node, e){
4571 clearTimeout(this.autoEditTimer);
4572 if(this.tree.getSelectionModel().isSelected(node)){
4574 return this.triggerEdit(node);
4578 onNodeDblClick : function(node, e){
4579 clearTimeout(this.autoEditTimer);
4583 updateNode : function(ed, value){
4584 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
4585 this.editNode.setText(value);
4589 onHide : function(){
4590 Ext.tree.TreeEditor.superclass.onHide.call(this);
4592 this.editNode.ui.focus.defer(50, this.editNode.ui);
4597 onSpecialKey : function(field, e){
4602 }else if(k == e.ENTER && !e.hasModifier()){
4604 this.completeEdit();
4608 onDestroy : function(){
4609 clearTimeout(this.autoEditTimer);
4610 Ext.tree.TreeEditor.superclass.onDestroy.call(this);
4611 var tree = this.tree;
4612 tree.un('beforeclick', this.beforeNodeClick, this);
4613 tree.un('dblclick', this.onNodeDblClick, this);