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
127 initComponent : function(){
\r
128 Ext.tree.TreePanel.superclass.initComponent.call(this);
\r
130 if(!this.eventModel){
\r
131 this.eventModel = new Ext.tree.TreeEventModel(this);
\r
134 // initialize the loader
\r
135 var l = this.loader;
\r
137 l = new Ext.tree.TreeLoader({
\r
138 dataUrl: this.dataUrl,
\r
139 requestMethod: this.requestMethod
\r
141 }else if(typeof l == 'object' && !l.load){
\r
142 l = new Ext.tree.TreeLoader(l);
\r
146 this.nodeHash = {};
\r
149 * The root node of this tree.
\r
150 * @type Ext.tree.TreeNode
\r
156 this.setRootNode(r);
\r
164 * Fires when a new child node is appended to a node in this tree.
\r
165 * @param {Tree} tree The owner tree
\r
166 * @param {Node} parent The parent node
\r
167 * @param {Node} node The newly appended node
\r
168 * @param {Number} index The index of the newly appended node
\r
173 * Fires when a child node is removed from a node in this tree.
\r
174 * @param {Tree} tree The owner tree
\r
175 * @param {Node} parent The parent node
\r
176 * @param {Node} node The child node removed
\r
181 * Fires when a node is moved to a new location in the tree
\r
182 * @param {Tree} tree The owner tree
\r
183 * @param {Node} node The node moved
\r
184 * @param {Node} oldParent The old parent of this node
\r
185 * @param {Node} newParent The new parent of this node
\r
186 * @param {Number} index The index it was moved to
\r
191 * Fires when a new child node is inserted in a node in this tree.
\r
192 * @param {Tree} tree The owner tree
\r
193 * @param {Node} parent The parent node
\r
194 * @param {Node} node The child node inserted
\r
195 * @param {Node} refNode The child node the node was inserted before
\r
199 * @event beforeappend
\r
200 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
\r
201 * @param {Tree} tree The owner tree
\r
202 * @param {Node} parent The parent node
\r
203 * @param {Node} node The child node to be appended
\r
207 * @event beforeremove
\r
208 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
\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 removed
\r
215 * @event beforemovenode
\r
216 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
\r
217 * @param {Tree} tree The owner tree
\r
218 * @param {Node} node The node being moved
\r
219 * @param {Node} oldParent The parent of the node
\r
220 * @param {Node} newParent The new parent the node is moving to
\r
221 * @param {Number} index The index it is being moved to
\r
225 * @event beforeinsert
\r
226 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
\r
227 * @param {Tree} tree The owner tree
\r
228 * @param {Node} parent The parent node
\r
229 * @param {Node} node The child node to be inserted
\r
230 * @param {Node} refNode The child node the node is being inserted before
\r
235 * @event beforeload
\r
236 * Fires before a node is loaded, return false to cancel
\r
237 * @param {Node} node The node being loaded
\r
242 * Fires when a node is loaded
\r
243 * @param {Node} node The node that was loaded
\r
247 * @event textchange
\r
248 * Fires when the text for a node is changed
\r
249 * @param {Node} node The node
\r
250 * @param {String} text The new text
\r
251 * @param {String} oldText The old text
\r
255 * @event beforeexpandnode
\r
256 * Fires before a node is expanded, return false to cancel.
\r
257 * @param {Node} node The node
\r
258 * @param {Boolean} deep
\r
259 * @param {Boolean} anim
\r
261 "beforeexpandnode",
\r
263 * @event beforecollapsenode
\r
264 * Fires before a node is collapsed, return false to cancel.
\r
265 * @param {Node} node The node
\r
266 * @param {Boolean} deep
\r
267 * @param {Boolean} anim
\r
269 "beforecollapsenode",
\r
271 * @event expandnode
\r
272 * Fires when a node is expanded
\r
273 * @param {Node} node The node
\r
277 * @event disabledchange
\r
278 * Fires when the disabled status of a node changes
\r
279 * @param {Node} node The node
\r
280 * @param {Boolean} disabled
\r
284 * @event collapsenode
\r
285 * Fires when a node is collapsed
\r
286 * @param {Node} node The node
\r
290 * @event beforeclick
\r
291 * Fires before click processing on a node. Return false to cancel the default action.
\r
292 * @param {Node} node The node
\r
293 * @param {Ext.EventObject} e The event object
\r
298 * Fires when a node is clicked
\r
299 * @param {Node} node The node
\r
300 * @param {Ext.EventObject} e The event object
\r
304 * @event checkchange
\r
305 * Fires when a node with a checkbox's checked property changes
\r
306 * @param {Node} this This node
\r
307 * @param {Boolean} checked
\r
312 * Fires when a node is double clicked
\r
313 * @param {Node} node The node
\r
314 * @param {Ext.EventObject} e The event object
\r
318 * @event contextmenu
\r
319 * Fires when a node is right clicked. To display a context menu in response to this
\r
320 * event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add
\r
321 * a handler for this event:<pre><code>
\r
322 new Ext.tree.TreePanel({
\r
323 title: 'My TreePanel',
\r
324 root: new Ext.tree.AsyncTreeNode({
\r
327 { text: 'Child node 1', leaf: true },
\r
328 { text: 'Child node 2', leaf: true }
\r
331 contextMenu: new Ext.menu.Menu({
\r
334 text: 'Delete Node'
\r
337 itemclick: function(item) {
\r
339 case 'delete-node':
\r
340 var n = item.parentMenu.contextNode;
\r
341 if (n.parentNode) {
\r
350 contextmenu: function(node, e) {
\r
351 // Register the context node with the menu so that a Menu Item's handler function can access
\r
352 // it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.
\r
354 var c = node.getOwnerTree().contextMenu;
\r
355 c.contextNode = node;
\r
356 c.showAt(e.getXY());
\r
361 * @param {Node} node The node
\r
362 * @param {Ext.EventObject} e The event object
\r
366 * @event beforechildrenrendered
\r
367 * Fires right before the child nodes for a node are rendered
\r
368 * @param {Node} node The node
\r
370 "beforechildrenrendered",
\r
373 * Fires when a node starts being dragged
\r
374 * @param {Ext.tree.TreePanel} this
\r
375 * @param {Ext.tree.TreeNode} node
\r
376 * @param {event} e The raw browser event
\r
381 * Fires when a drag operation is complete
\r
382 * @param {Ext.tree.TreePanel} this
\r
383 * @param {Ext.tree.TreeNode} node
\r
384 * @param {event} e The raw browser event
\r
389 * Fires when a dragged node is dropped on a valid DD target
\r
390 * @param {Ext.tree.TreePanel} this
\r
391 * @param {Ext.tree.TreeNode} node
\r
392 * @param {DD} dd The dd it was dropped on
\r
393 * @param {event} e The raw browser event
\r
397 * @event beforenodedrop
\r
398 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
\r
399 * passed to handlers has the following properties:<br />
\r
400 * <ul style="padding:5px;padding-left:16px;">
\r
401 * <li>tree - The TreePanel</li>
\r
402 * <li>target - The node being targeted for the drop</li>
\r
403 * <li>data - The drag data from the drag source</li>
\r
404 * <li>point - The point of the drop - append, above or below</li>
\r
405 * <li>source - The drag source</li>
\r
406 * <li>rawEvent - Raw mouse event</li>
\r
407 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
\r
408 * to be inserted by setting them on this object.</li>
\r
409 * <li>cancel - Set this to true to cancel the drop.</li>
\r
410 * <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true
\r
411 * will prevent the animated "repair" from appearing.</li>
\r
413 * @param {Object} dropEvent
\r
418 * Fires after a DD object is dropped on a node in this tree. The dropEvent
\r
419 * passed to handlers has the following properties:<br />
\r
420 * <ul style="padding:5px;padding-left:16px;">
\r
421 * <li>tree - The TreePanel</li>
\r
422 * <li>target - The node being targeted for the drop</li>
\r
423 * <li>data - The drag data from the drag source</li>
\r
424 * <li>point - The point of the drop - append, above or below</li>
\r
425 * <li>source - The drag source</li>
\r
426 * <li>rawEvent - Raw mouse event</li>
\r
427 * <li>dropNode - Dropped node(s).</li>
\r
429 * @param {Object} dropEvent
\r
433 * @event nodedragover
\r
434 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
\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.</li>
\r
444 * <li>cancel - Set this to true to signal drop not allowed.</li>
\r
446 * @param {Object} dragOverEvent
\r
450 if(this.singleExpand){
\r
451 this.on("beforeexpandnode", this.restrictExpand, this);
\r
456 proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){
\r
457 if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){
\r
458 ename = ename+'node';
\r
460 // args inline for performance while bubbling events
\r
461 return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);
\r
466 * Returns this root node for this tree
\r
469 getRootNode : function(){
\r
474 * Sets the root node for this tree. If the TreePanel has already rendered a root node, the
\r
475 * previous root node (and all of its descendants) are destroyed before the new root node is rendered.
\r
476 * @param {Node} node
\r
479 setRootNode : function(node){
\r
480 Ext.destroy(this.root);
\r
481 if(!node.render){ // attributes passed
\r
482 node = this.loader.createNode(node);
\r
485 node.ownerTree = this;
\r
486 node.isRoot = true;
\r
487 this.registerNode(node);
\r
488 if(!this.rootVisible){
\r
489 var uiP = node.attributes.uiProvider;
\r
490 node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);
\r
492 if (this.innerCt) {
\r
493 this.innerCt.update('');
\r
494 this.afterRender();
\r
500 * Gets a node in this tree by its id
\r
501 * @param {String} id
\r
504 getNodeById : function(id){
\r
505 return this.nodeHash[id];
\r
509 registerNode : function(node){
\r
510 this.nodeHash[node.id] = node;
\r
514 unregisterNode : function(node){
\r
515 delete this.nodeHash[node.id];
\r
519 toString : function(){
\r
520 return "[Tree"+(this.id?" "+this.id:"")+"]";
\r
524 restrictExpand : function(node){
\r
525 var p = node.parentNode;
\r
527 if(p.expandedChild && p.expandedChild.parentNode == p){
\r
528 p.expandedChild.collapse();
\r
530 p.expandedChild = node;
\r
535 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
\r
536 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
\r
537 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
\r
540 getChecked : function(a, startNode){
\r
541 startNode = startNode || this.root;
\r
543 var f = function(){
\r
544 if(this.attributes.checked){
\r
545 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
\r
548 startNode.cascade(f);
\r
553 * Returns the container element for this TreePanel.
\r
554 * @return {Element} The container element for this TreePanel.
\r
556 getEl : function(){
\r
561 * Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.
\r
562 * @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.
\r
564 getLoader : function(){
\r
565 return this.loader;
\r
571 expandAll : function(){
\r
572 this.root.expand(true);
\r
576 * Collapse all nodes
\r
578 collapseAll : function(){
\r
579 this.root.collapse(true);
\r
583 * Returns the selection model used by this TreePanel.
\r
584 * @return {TreeSelectionModel} The selection model used by this TreePanel
\r
586 getSelectionModel : function(){
\r
587 if(!this.selModel){
\r
588 this.selModel = new Ext.tree.DefaultSelectionModel();
\r
590 return this.selModel;
\r
594 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
\r
595 * @param {String} path
\r
596 * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
\r
597 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
\r
598 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
\r
600 expandPath : function(path, attr, callback){
\r
601 attr = attr || "id";
\r
602 var keys = path.split(this.pathSeparator);
\r
603 var curNode = this.root;
\r
604 if(curNode.attributes[attr] != keys[1]){ // invalid root
\r
606 callback(false, null);
\r
611 var f = function(){
\r
612 if(++index == keys.length){
\r
614 callback(true, curNode);
\r
618 var c = curNode.findChild(attr, keys[index]);
\r
621 callback(false, curNode);
\r
626 c.expand(false, false, f);
\r
628 curNode.expand(false, false, f);
\r
632 * 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
633 * @param {String} path
\r
634 * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
\r
635 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
\r
636 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
\r
638 selectPath : function(path, attr, callback){
\r
639 attr = attr || "id";
\r
640 var keys = path.split(this.pathSeparator);
\r
641 var v = keys.pop();
\r
642 if(keys.length > 0){
\r
643 var f = function(success, node){
\r
644 if(success && node){
\r
645 var n = node.findChild(attr, v);
\r
651 }else if(callback){
\r
652 callback(false, n);
\r
656 callback(false, n);
\r
660 this.expandPath(keys.join(this.pathSeparator), attr, f);
\r
662 this.root.select();
\r
664 callback(true, this.root);
\r
670 * Returns the underlying Element for this tree
\r
671 * @return {Ext.Element} The Element
\r
673 getTreeEl : function(){
\r
678 onRender : function(ct, position){
\r
679 Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
\r
680 this.el.addClass('x-tree');
\r
681 this.innerCt = this.body.createChild({tag:"ul",
\r
682 cls:"x-tree-root-ct " +
\r
683 (this.useArrows ? 'x-tree-arrows' : this.lines ? "x-tree-lines" : "x-tree-no-lines")});
\r
687 initEvents : function(){
\r
688 Ext.tree.TreePanel.superclass.initEvents.call(this);
\r
690 if(this.containerScroll){
\r
691 Ext.dd.ScrollManager.register(this.body);
\r
693 if((this.enableDD || this.enableDrop) && !this.dropZone){
\r
695 * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
\r
696 * @property dropZone
\r
697 * @type Ext.tree.TreeDropZone
\r
699 this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
\r
700 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
\r
703 if((this.enableDD || this.enableDrag) && !this.dragZone){
\r
705 * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
\r
706 * @property dragZone
\r
707 * @type Ext.tree.TreeDragZone
\r
709 this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
\r
710 ddGroup: this.ddGroup || "TreeDD",
\r
711 scroll: this.ddScroll
\r
714 this.getSelectionModel().init(this);
\r
718 afterRender : function(){
\r
719 Ext.tree.TreePanel.superclass.afterRender.call(this);
\r
720 this.root.render();
\r
721 if(!this.rootVisible){
\r
722 this.root.renderChildren();
\r
726 onDestroy : function(){
\r
728 this.body.removeAllListeners();
\r
729 Ext.dd.ScrollManager.unregister(this.body);
\r
731 this.dropZone.unreg();
\r
734 this.dragZone.unreg();
\r
737 this.root.destroy();
\r
738 this.nodeHash = null;
\r
739 Ext.tree.TreePanel.superclass.onDestroy.call(this);
\r
743 * @cfg {String/Number} activeItem
\r
747 * @cfg {Boolean} autoDestroy
\r
751 * @cfg {Object/String/Function} autoLoad
\r
755 * @cfg {Boolean} autoWidth
\r
759 * @cfg {Boolean/Number} bufferResize
\r
763 * @cfg {String} defaultType
\r
767 * @cfg {Object} defaults
\r
771 * @cfg {Boolean} hideBorders
\r
775 * @cfg {Mixed} items
\r
779 * @cfg {String} layout
\r
783 * @cfg {Object} layoutConfig
\r
787 * @cfg {Boolean} monitorResize
\r
815 * @method findByType
\r
819 * @method getComponent
\r
823 * @method getLayout
\r
827 * @method getUpdater
\r
847 * @method removeAll
\r
851 * @event afterLayout
\r
859 * @event beforeremove
\r
870 * @cfg {String} allowDomMove @hide
\r
873 * @cfg {String} autoEl @hide
\r
876 * @cfg {String} applyTo @hide
\r
879 * @cfg {String} contentEl @hide
\r
882 * @cfg {String} disabledClass @hide
\r
885 * @cfg {String} elements @hide
\r
888 * @cfg {String} html @hide
\r
891 * @cfg {Boolean} preventBodyReset
\r
895 * @property disabled
\r
899 * @method applyToMarkup
\r
911 * @method setDisabled
\r
916 Ext.tree.TreePanel.nodeTypes = {};
\r
918 Ext.reg('treepanel', Ext.tree.TreePanel);Ext.tree.TreeEventModel = function(tree){
\r
920 this.tree.on('render', this.initEvents, this);
\r
923 Ext.tree.TreeEventModel.prototype = {
\r
924 initEvents : function(){
\r
925 var el = this.tree.getTreeEl();
\r
926 el.on('click', this.delegateClick, this);
\r
927 if(this.tree.trackMouseOver !== false){
\r
928 this.tree.innerCt.on('mouseover', this.delegateOver, this);
\r
929 this.tree.innerCt.on('mouseout', this.delegateOut, this);
\r
931 el.on('dblclick', this.delegateDblClick, this);
\r
932 el.on('contextmenu', this.delegateContextMenu, this);
\r
935 getNode : function(e){
\r
937 if(t = e.getTarget('.x-tree-node-el', 10)){
\r
938 var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
\r
940 return this.tree.getNodeById(id);
\r
946 getNodeTarget : function(e){
\r
947 var t = e.getTarget('.x-tree-node-icon', 1);
\r
949 t = e.getTarget('.x-tree-node-el', 6);
\r
954 delegateOut : function(e, t){
\r
955 if(!this.beforeEvent(e)){
\r
958 if(e.getTarget('.x-tree-ec-icon', 1)){
\r
959 var n = this.getNode(e);
\r
960 this.onIconOut(e, n);
\r
961 if(n == this.lastEcOver){
\r
962 delete this.lastEcOver;
\r
965 if((t = this.getNodeTarget(e)) && !e.within(t, true)){
\r
966 this.onNodeOut(e, this.getNode(e));
\r
970 delegateOver : function(e, t){
\r
971 if(!this.beforeEvent(e)){
\r
974 if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
\r
975 Ext.getBody().on('mouseover', this.trackExit, this);
\r
976 this.trackingDoc = true;
\r
978 if(this.lastEcOver){ // prevent hung highlight
\r
979 this.onIconOut(e, this.lastEcOver);
\r
980 delete this.lastEcOver;
\r
982 if(e.getTarget('.x-tree-ec-icon', 1)){
\r
983 this.lastEcOver = this.getNode(e);
\r
984 this.onIconOver(e, this.lastEcOver);
\r
986 if(t = this.getNodeTarget(e)){
\r
987 this.onNodeOver(e, this.getNode(e));
\r
991 trackExit : function(e){
\r
992 if(this.lastOverNode && !e.within(this.lastOverNode.ui.getEl())){
\r
993 this.onNodeOut(e, this.lastOverNode);
\r
994 delete this.lastOverNode;
\r
995 Ext.getBody().un('mouseover', this.trackExit, this);
\r
996 this.trackingDoc = false;
\r
1000 delegateClick : function(e, t){
\r
1001 if(!this.beforeEvent(e)){
\r
1005 if(e.getTarget('input[type=checkbox]', 1)){
\r
1006 this.onCheckboxClick(e, this.getNode(e));
\r
1008 else if(e.getTarget('.x-tree-ec-icon', 1)){
\r
1009 this.onIconClick(e, this.getNode(e));
\r
1011 else if(this.getNodeTarget(e)){
\r
1012 this.onNodeClick(e, this.getNode(e));
\r
1016 delegateDblClick : function(e, t){
\r
1017 if(this.beforeEvent(e) && this.getNodeTarget(e)){
\r
1018 this.onNodeDblClick(e, this.getNode(e));
\r
1022 delegateContextMenu : function(e, t){
\r
1023 if(this.beforeEvent(e) && this.getNodeTarget(e)){
\r
1024 this.onNodeContextMenu(e, this.getNode(e));
\r
1028 onNodeClick : function(e, node){
\r
1029 node.ui.onClick(e);
\r
1032 onNodeOver : function(e, node){
\r
1033 this.lastOverNode = node;
\r
1034 node.ui.onOver(e);
\r
1037 onNodeOut : function(e, node){
\r
1041 onIconOver : function(e, node){
\r
1042 node.ui.addClass('x-tree-ec-over');
\r
1045 onIconOut : function(e, node){
\r
1046 node.ui.removeClass('x-tree-ec-over');
\r
1049 onIconClick : function(e, node){
\r
1050 node.ui.ecClick(e);
\r
1053 onCheckboxClick : function(e, node){
\r
1054 node.ui.onCheckChange(e);
\r
1057 onNodeDblClick : function(e, node){
\r
1058 node.ui.onDblClick(e);
\r
1061 onNodeContextMenu : function(e, node){
\r
1062 node.ui.onContextMenu(e);
\r
1065 beforeEvent : function(e){
\r
1066 if(this.disabled){
\r
1073 disable: function(){
\r
1074 this.disabled = true;
\r
1077 enable: function(){
\r
1078 this.disabled = false;
\r
1081 * @class Ext.tree.DefaultSelectionModel
\r
1082 * @extends Ext.util.Observable
\r
1083 * The default single selection for a TreePanel.
\r
1085 Ext.tree.DefaultSelectionModel = function(config){
\r
1086 this.selNode = null;
\r
1090 * @event selectionchange
\r
1091 * Fires when the selected node changes
\r
1092 * @param {DefaultSelectionModel} this
\r
1093 * @param {TreeNode} node the new selection
\r
1095 "selectionchange",
\r
1098 * @event beforeselect
\r
1099 * Fires before the selected node changes, return false to cancel the change
\r
1100 * @param {DefaultSelectionModel} this
\r
1101 * @param {TreeNode} node the new selection
\r
1102 * @param {TreeNode} node the old selection
\r
1107 Ext.apply(this, config);
\r
1108 Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
\r
1111 Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {
\r
1112 init : function(tree){
\r
1114 tree.getTreeEl().on("keydown", this.onKeyDown, this);
\r
1115 tree.on("click", this.onNodeClick, this);
\r
1118 onNodeClick : function(node, e){
\r
1119 this.select(node);
\r
1124 * @param {TreeNode} node The node to select
\r
1125 * @return {TreeNode} The selected node
\r
1127 select : function(node){
\r
1128 var last = this.selNode;
\r
1130 node.ui.onSelectedChange(true);
\r
1131 }else if(this.fireEvent('beforeselect', this, node, last) !== false){
\r
1133 last.ui.onSelectedChange(false);
\r
1135 this.selNode = node;
\r
1136 node.ui.onSelectedChange(true);
\r
1137 this.fireEvent("selectionchange", this, node, last);
\r
1143 * Deselect a node.
\r
1144 * @param {TreeNode} node The node to unselect
\r
1146 unselect : function(node){
\r
1147 if(this.selNode == node){
\r
1148 this.clearSelections();
\r
1153 * Clear all selections
\r
1155 clearSelections : function(){
\r
1156 var n = this.selNode;
\r
1158 n.ui.onSelectedChange(false);
\r
1159 this.selNode = null;
\r
1160 this.fireEvent("selectionchange", this, null);
\r
1166 * Get the selected node
\r
1167 * @return {TreeNode} The selected node
\r
1169 getSelectedNode : function(){
\r
1170 return this.selNode;
\r
1174 * Returns true if the node is selected
\r
1175 * @param {TreeNode} node The node to check
\r
1176 * @return {Boolean}
\r
1178 isSelected : function(node){
\r
1179 return this.selNode == node;
\r
1183 * Selects the node above the selected node in the tree, intelligently walking the nodes
\r
1184 * @return TreeNode The new selection
\r
1186 selectPrevious : function(){
\r
1187 var s = this.selNode || this.lastSelNode;
\r
1191 var ps = s.previousSibling;
\r
1193 if(!ps.isExpanded() || ps.childNodes.length < 1){
\r
1194 return this.select(ps);
\r
1196 var lc = ps.lastChild;
\r
1197 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
\r
1198 lc = lc.lastChild;
\r
1200 return this.select(lc);
\r
1202 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
\r
1203 return this.select(s.parentNode);
\r
1209 * Selects the node above the selected node in the tree, intelligently walking the nodes
\r
1210 * @return TreeNode The new selection
\r
1212 selectNext : function(){
\r
1213 var s = this.selNode || this.lastSelNode;
\r
1217 if(s.firstChild && s.isExpanded()){
\r
1218 return this.select(s.firstChild);
\r
1219 }else if(s.nextSibling){
\r
1220 return this.select(s.nextSibling);
\r
1221 }else if(s.parentNode){
\r
1223 s.parentNode.bubble(function(){
\r
1224 if(this.nextSibling){
\r
1225 newS = this.getOwnerTree().selModel.select(this.nextSibling);
\r
1234 onKeyDown : function(e){
\r
1235 var s = this.selNode || this.lastSelNode;
\r
1236 // undesirable, but required
\r
1241 var k = e.getKey();
\r
1245 this.selectNext();
\r
1249 this.selectPrevious();
\r
1252 e.preventDefault();
\r
1253 if(s.hasChildNodes()){
\r
1254 if(!s.isExpanded()){
\r
1256 }else if(s.firstChild){
\r
1257 this.select(s.firstChild, e);
\r
1262 e.preventDefault();
\r
1263 if(s.hasChildNodes() && s.isExpanded()){
\r
1265 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
\r
1266 this.select(s.parentNode, e);
\r
1274 * @class Ext.tree.MultiSelectionModel
\r
1275 * @extends Ext.util.Observable
\r
1276 * Multi selection for a TreePanel.
\r
1278 Ext.tree.MultiSelectionModel = function(config){
\r
1279 this.selNodes = [];
\r
1283 * @event selectionchange
\r
1284 * Fires when the selected nodes change
\r
1285 * @param {MultiSelectionModel} this
\r
1286 * @param {Array} nodes Array of the selected nodes
\r
1290 Ext.apply(this, config);
\r
1291 Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
\r
1294 Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {
\r
1295 init : function(tree){
\r
1297 tree.getTreeEl().on("keydown", this.onKeyDown, this);
\r
1298 tree.on("click", this.onNodeClick, this);
\r
1301 onNodeClick : function(node, e){
\r
1302 if(e.ctrlKey && this.isSelected(node)){
\r
1303 this.unselect(node);
\r
1305 this.select(node, e, e.ctrlKey);
\r
1311 * @param {TreeNode} node The node to select
\r
1312 * @param {EventObject} e (optional) An event associated with the selection
\r
1313 * @param {Boolean} keepExisting True to retain existing selections
\r
1314 * @return {TreeNode} The selected node
\r
1316 select : function(node, e, keepExisting){
\r
1317 if(keepExisting !== true){
\r
1318 this.clearSelections(true);
\r
1320 if(this.isSelected(node)){
\r
1321 this.lastSelNode = node;
\r
1324 this.selNodes.push(node);
\r
1325 this.selMap[node.id] = node;
\r
1326 this.lastSelNode = node;
\r
1327 node.ui.onSelectedChange(true);
\r
1328 this.fireEvent("selectionchange", this, this.selNodes);
\r
1333 * Deselect a node.
\r
1334 * @param {TreeNode} node The node to unselect
\r
1336 unselect : function(node){
\r
1337 if(this.selMap[node.id]){
\r
1338 node.ui.onSelectedChange(false);
\r
1339 var sn = this.selNodes;
\r
1340 var index = sn.indexOf(node);
\r
1342 this.selNodes.splice(index, 1);
\r
1344 delete this.selMap[node.id];
\r
1345 this.fireEvent("selectionchange", this, this.selNodes);
\r
1350 * Clear all selections
\r
1352 clearSelections : function(suppressEvent){
\r
1353 var sn = this.selNodes;
\r
1354 if(sn.length > 0){
\r
1355 for(var i = 0, len = sn.length; i < len; i++){
\r
1356 sn[i].ui.onSelectedChange(false);
\r
1358 this.selNodes = [];
\r
1360 if(suppressEvent !== true){
\r
1361 this.fireEvent("selectionchange", this, this.selNodes);
\r
1367 * Returns true if the node is selected
\r
1368 * @param {TreeNode} node The node to check
\r
1369 * @return {Boolean}
\r
1371 isSelected : function(node){
\r
1372 return this.selMap[node.id] ? true : false;
\r
1376 * Returns an array of the selected nodes
\r
1379 getSelectedNodes : function(){
\r
1380 return this.selNodes;
\r
1383 onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
\r
1385 selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
\r
1387 selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
\r
1389 * @class Ext.data.Tree
\r
1390 * @extends Ext.util.Observable
\r
1391 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
\r
1392 * in the tree have most standard DOM functionality.
\r
1394 * @param {Node} root (optional) The root node
\r
1396 Ext.data.Tree = function(root){
\r
1397 this.nodeHash = {};
\r
1399 * The root node for this tree
\r
1404 this.setRootNode(root);
\r
1409 * Fires when a new child node is appended to a node in this tree.
\r
1410 * @param {Tree} tree The owner tree
\r
1411 * @param {Node} parent The parent node
\r
1412 * @param {Node} node The newly appended node
\r
1413 * @param {Number} index The index of the newly appended node
\r
1418 * Fires when a child node is removed from a node in this tree.
\r
1419 * @param {Tree} tree The owner tree
\r
1420 * @param {Node} parent The parent node
\r
1421 * @param {Node} node The child node removed
\r
1426 * Fires when a node is moved to a new location in the tree
\r
1427 * @param {Tree} tree The owner tree
\r
1428 * @param {Node} node The node moved
\r
1429 * @param {Node} oldParent The old parent of this node
\r
1430 * @param {Node} newParent The new parent of this node
\r
1431 * @param {Number} index The index it was moved to
\r
1436 * Fires when a new child node is inserted in a node in this tree.
\r
1437 * @param {Tree} tree The owner tree
\r
1438 * @param {Node} parent The parent node
\r
1439 * @param {Node} node The child node inserted
\r
1440 * @param {Node} refNode The child node the node was inserted before
\r
1444 * @event beforeappend
\r
1445 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
\r
1446 * @param {Tree} tree The owner tree
\r
1447 * @param {Node} parent The parent node
\r
1448 * @param {Node} node The child node to be appended
\r
1452 * @event beforeremove
\r
1453 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
\r
1454 * @param {Tree} tree The owner tree
\r
1455 * @param {Node} parent The parent node
\r
1456 * @param {Node} node The child node to be removed
\r
1460 * @event beforemove
\r
1461 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
\r
1462 * @param {Tree} tree The owner tree
\r
1463 * @param {Node} node The node being moved
\r
1464 * @param {Node} oldParent The parent of the node
\r
1465 * @param {Node} newParent The new parent the node is moving to
\r
1466 * @param {Number} index The index it is being moved to
\r
1470 * @event beforeinsert
\r
1471 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
\r
1472 * @param {Tree} tree The owner tree
\r
1473 * @param {Node} parent The parent node
\r
1474 * @param {Node} node The child node to be inserted
\r
1475 * @param {Node} refNode The child node the node is being inserted before
\r
1480 Ext.data.Tree.superclass.constructor.call(this);
\r
1483 Ext.extend(Ext.data.Tree, Ext.util.Observable, {
\r
1485 * @cfg {String} pathSeparator
\r
1486 * The token used to separate paths in node ids (defaults to '/').
\r
1488 pathSeparator: "/",
\r
1491 proxyNodeEvent : function(){
\r
1492 return this.fireEvent.apply(this, arguments);
\r
1496 * Returns the root node for this tree.
\r
1499 getRootNode : function(){
\r
1504 * Sets the root node for this tree.
\r
1505 * @param {Node} node
\r
1508 setRootNode : function(node){
\r
1510 node.ownerTree = this;
\r
1511 node.isRoot = true;
\r
1512 this.registerNode(node);
\r
1517 * Gets a node in this tree by its id.
\r
1518 * @param {String} id
\r
1521 getNodeById : function(id){
\r
1522 return this.nodeHash[id];
\r
1526 registerNode : function(node){
\r
1527 this.nodeHash[node.id] = node;
\r
1531 unregisterNode : function(node){
\r
1532 delete this.nodeHash[node.id];
\r
1535 toString : function(){
\r
1536 return "[Tree"+(this.id?" "+this.id:"")+"]";
\r
1541 * @class Ext.data.Node
\r
1542 * @extends Ext.util.Observable
\r
1543 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
\r
1544 * @cfg {String} id The id for this node. If one is not specified, one is generated.
\r
1546 * @param {Object} attributes The attributes/config for the node
\r
1548 Ext.data.Node = function(attributes){
\r
1550 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
\r
1553 this.attributes = attributes || {};
\r
1554 this.leaf = this.attributes.leaf;
\r
1556 * The node id. @type String
\r
1558 this.id = this.attributes.id;
\r
1560 this.id = Ext.id(null, "xnode-");
\r
1561 this.attributes.id = this.id;
\r
1564 * All child nodes of this node. @type Array
\r
1566 this.childNodes = [];
\r
1567 if(!this.childNodes.indexOf){ // indexOf is a must
\r
1568 this.childNodes.indexOf = function(o){
\r
1569 for(var i = 0, len = this.length; i < len; i++){
\r
1578 * The parent node for this node. @type Node
\r
1580 this.parentNode = null;
\r
1582 * The first direct child node of this node, or null if this node has no child nodes. @type Node
\r
1584 this.firstChild = null;
\r
1586 * The last direct child node of this node, or null if this node has no child nodes. @type Node
\r
1588 this.lastChild = null;
\r
1590 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
\r
1592 this.previousSibling = null;
\r
1594 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
\r
1596 this.nextSibling = null;
\r
1601 * Fires when a new child node is appended
\r
1602 * @param {Tree} tree The owner tree
\r
1603 * @param {Node} this This node
\r
1604 * @param {Node} node The newly appended node
\r
1605 * @param {Number} index The index of the newly appended node
\r
1610 * Fires when a child node is removed
\r
1611 * @param {Tree} tree The owner tree
\r
1612 * @param {Node} this This node
\r
1613 * @param {Node} node The removed node
\r
1618 * Fires when this node is moved to a new location in the tree
\r
1619 * @param {Tree} tree The owner tree
\r
1620 * @param {Node} this This node
\r
1621 * @param {Node} oldParent The old parent of this node
\r
1622 * @param {Node} newParent The new parent of this node
\r
1623 * @param {Number} index The index it was moved to
\r
1628 * Fires when a new child node is inserted.
\r
1629 * @param {Tree} tree The owner tree
\r
1630 * @param {Node} this This node
\r
1631 * @param {Node} node The child node inserted
\r
1632 * @param {Node} refNode The child node the node was inserted before
\r
1636 * @event beforeappend
\r
1637 * Fires before a new child is appended, return false to cancel the append.
\r
1638 * @param {Tree} tree The owner tree
\r
1639 * @param {Node} this This node
\r
1640 * @param {Node} node The child node to be appended
\r
1642 "beforeappend" : true,
\r
1644 * @event beforeremove
\r
1645 * Fires before a child is removed, return false to cancel the remove.
\r
1646 * @param {Tree} tree The owner tree
\r
1647 * @param {Node} this This node
\r
1648 * @param {Node} node The child node to be removed
\r
1650 "beforeremove" : true,
\r
1652 * @event beforemove
\r
1653 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
\r
1654 * @param {Tree} tree The owner tree
\r
1655 * @param {Node} this This node
\r
1656 * @param {Node} oldParent The parent of this node
\r
1657 * @param {Node} newParent The new parent this node is moving to
\r
1658 * @param {Number} index The index it is being moved to
\r
1660 "beforemove" : true,
\r
1662 * @event beforeinsert
\r
1663 * Fires before a new child is inserted, return false to cancel the insert.
\r
1664 * @param {Tree} tree The owner tree
\r
1665 * @param {Node} this This node
\r
1666 * @param {Node} node The child node to be inserted
\r
1667 * @param {Node} refNode The child node the node is being inserted before
\r
1669 "beforeinsert" : true
\r
1671 this.listeners = this.attributes.listeners;
\r
1672 Ext.data.Node.superclass.constructor.call(this);
\r
1675 Ext.extend(Ext.data.Node, Ext.util.Observable, {
\r
1677 fireEvent : function(evtName){
\r
1678 // first do standard event for this node
\r
1679 if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){
\r
1682 // then bubble it up to the tree if the event wasn't cancelled
\r
1683 var ot = this.getOwnerTree();
\r
1685 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
\r
1693 * Returns true if this node is a leaf
\r
1694 * @return {Boolean}
\r
1696 isLeaf : function(){
\r
1697 return this.leaf === true;
\r
1701 setFirstChild : function(node){
\r
1702 this.firstChild = node;
\r
1706 setLastChild : function(node){
\r
1707 this.lastChild = node;
\r
1712 * Returns true if this node is the last child of its parent
\r
1713 * @return {Boolean}
\r
1715 isLast : function(){
\r
1716 return (!this.parentNode ? true : this.parentNode.lastChild == this);
\r
1720 * Returns true if this node is the first child of its parent
\r
1721 * @return {Boolean}
\r
1723 isFirst : function(){
\r
1724 return (!this.parentNode ? true : this.parentNode.firstChild == this);
\r
1728 * Returns true if this node has one or more child nodes, else false.
\r
1729 * @return {Boolean}
\r
1731 hasChildNodes : function(){
\r
1732 return !this.isLeaf() && this.childNodes.length > 0;
\r
1736 * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>
\r
1737 * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
\r
1738 * @return {Boolean}
\r
1740 isExpandable : function(){
\r
1741 return this.attributes.expandable || this.hasChildNodes();
\r
1745 * Insert node(s) as the last child node of this node.
\r
1746 * @param {Node/Array} node The node or Array of nodes to append
\r
1747 * @return {Node} The appended node if single append, or null if an array was passed
\r
1749 appendChild : function(node){
\r
1750 var multi = false;
\r
1751 if(Ext.isArray(node)){
\r
1753 }else if(arguments.length > 1){
\r
1754 multi = arguments;
\r
1756 // if passed an array or multiple args do them one by one
\r
1758 for(var i = 0, len = multi.length; i < len; i++) {
\r
1759 this.appendChild(multi[i]);
\r
1762 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
\r
1765 var index = this.childNodes.length;
\r
1766 var oldParent = node.parentNode;
\r
1767 // it's a move, make sure we move it cleanly
\r
1769 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
\r
1772 oldParent.removeChild(node);
\r
1774 index = this.childNodes.length;
\r
1776 this.setFirstChild(node);
\r
1778 this.childNodes.push(node);
\r
1779 node.parentNode = this;
\r
1780 var ps = this.childNodes[index-1];
\r
1782 node.previousSibling = ps;
\r
1783 ps.nextSibling = node;
\r
1785 node.previousSibling = null;
\r
1787 node.nextSibling = null;
\r
1788 this.setLastChild(node);
\r
1789 node.setOwnerTree(this.getOwnerTree());
\r
1790 this.fireEvent("append", this.ownerTree, this, node, index);
\r
1792 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
\r
1799 * Removes a child node from this node.
\r
1800 * @param {Node} node The node to remove
\r
1801 * @return {Node} The removed node
\r
1803 removeChild : function(node){
\r
1804 var index = this.childNodes.indexOf(node);
\r
1808 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
\r
1812 // remove it from childNodes collection
\r
1813 this.childNodes.splice(index, 1);
\r
1815 // update siblings
\r
1816 if(node.previousSibling){
\r
1817 node.previousSibling.nextSibling = node.nextSibling;
\r
1819 if(node.nextSibling){
\r
1820 node.nextSibling.previousSibling = node.previousSibling;
\r
1823 // update child refs
\r
1824 if(this.firstChild == node){
\r
1825 this.setFirstChild(node.nextSibling);
\r
1827 if(this.lastChild == node){
\r
1828 this.setLastChild(node.previousSibling);
\r
1831 node.setOwnerTree(null);
\r
1832 // clear any references from the node
\r
1833 node.parentNode = null;
\r
1834 node.previousSibling = null;
\r
1835 node.nextSibling = null;
\r
1836 this.fireEvent("remove", this.ownerTree, this, node);
\r
1841 * Inserts the first node before the second node in this nodes childNodes collection.
\r
1842 * @param {Node} node The node to insert
\r
1843 * @param {Node} refNode The node to insert before (if null the node is appended)
\r
1844 * @return {Node} The inserted node
\r
1846 insertBefore : function(node, refNode){
\r
1847 if(!refNode){ // like standard Dom, refNode can be null for append
\r
1848 return this.appendChild(node);
\r
1851 if(node == refNode){
\r
1855 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
\r
1858 var index = this.childNodes.indexOf(refNode);
\r
1859 var oldParent = node.parentNode;
\r
1860 var refIndex = index;
\r
1862 // when moving internally, indexes will change after remove
\r
1863 if(oldParent == this && this.childNodes.indexOf(node) < index){
\r
1867 // it's a move, make sure we move it cleanly
\r
1869 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
\r
1872 oldParent.removeChild(node);
\r
1874 if(refIndex === 0){
\r
1875 this.setFirstChild(node);
\r
1877 this.childNodes.splice(refIndex, 0, node);
\r
1878 node.parentNode = this;
\r
1879 var ps = this.childNodes[refIndex-1];
\r
1881 node.previousSibling = ps;
\r
1882 ps.nextSibling = node;
\r
1884 node.previousSibling = null;
\r
1886 node.nextSibling = refNode;
\r
1887 refNode.previousSibling = node;
\r
1888 node.setOwnerTree(this.getOwnerTree());
\r
1889 this.fireEvent("insert", this.ownerTree, this, node, refNode);
\r
1891 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
\r
1897 * Removes this node from its parent
\r
1898 * @return {Node} this
\r
1900 remove : function(){
\r
1901 this.parentNode.removeChild(this);
\r
1906 * Returns the child node at the specified index.
\r
1907 * @param {Number} index
\r
1910 item : function(index){
\r
1911 return this.childNodes[index];
\r
1915 * Replaces one child node in this node with another.
\r
1916 * @param {Node} newChild The replacement node
\r
1917 * @param {Node} oldChild The node to replace
\r
1918 * @return {Node} The replaced node
\r
1920 replaceChild : function(newChild, oldChild){
\r
1921 var s = oldChild ? oldChild.nextSibling : null;
\r
1922 this.removeChild(oldChild);
\r
1923 this.insertBefore(newChild, s);
\r
1928 * Returns the index of a child node
\r
1929 * @param {Node} node
\r
1930 * @return {Number} The index of the node or -1 if it was not found
\r
1932 indexOf : function(child){
\r
1933 return this.childNodes.indexOf(child);
\r
1937 * Returns the tree this node is in.
\r
1940 getOwnerTree : function(){
\r
1941 // if it doesn't have one, look for one
\r
1942 if(!this.ownerTree){
\r
1946 this.ownerTree = p.ownerTree;
\r
1952 return this.ownerTree;
\r
1956 * Returns depth of this node (the root node has a depth of 0)
\r
1957 * @return {Number}
\r
1959 getDepth : function(){
\r
1962 while(p.parentNode){
\r
1970 setOwnerTree : function(tree){
\r
1971 // if it is a move, we need to update everyone
\r
1972 if(tree != this.ownerTree){
\r
1973 if(this.ownerTree){
\r
1974 this.ownerTree.unregisterNode(this);
\r
1976 this.ownerTree = tree;
\r
1977 var cs = this.childNodes;
\r
1978 for(var i = 0, len = cs.length; i < len; i++) {
\r
1979 cs[i].setOwnerTree(tree);
\r
1982 tree.registerNode(this);
\r
1988 * Changes the id of this node.
\r
1989 * @param {String} id The new id for the node.
\r
1991 setId: function(id){
\r
1992 if(id !== this.id){
\r
1993 var t = this.ownerTree;
\r
1995 t.unregisterNode(this);
\r
1999 t.registerNode(this);
\r
2001 this.onIdChange(id);
\r
2006 onIdChange: Ext.emptyFn,
\r
2009 * Returns the path for this node. The path can be used to expand or select this node programmatically.
\r
2010 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
\r
2011 * @return {String} The path
\r
2013 getPath : function(attr){
\r
2014 attr = attr || "id";
\r
2015 var p = this.parentNode;
\r
2016 var b = [this.attributes[attr]];
\r
2018 b.unshift(p.attributes[attr]);
\r
2021 var sep = this.getOwnerTree().pathSeparator;
\r
2022 return sep + b.join(sep);
\r
2026 * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
\r
2027 * function call will be the scope provided or the current node. The arguments to the function
\r
2028 * will be the args provided or the current node. If the function returns false at any point,
\r
2029 * the bubble is stopped.
\r
2030 * @param {Function} fn The function to call
\r
2031 * @param {Object} scope (optional) The scope of the function (defaults to current node)
\r
2032 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
\r
2034 bubble : function(fn, scope, args){
\r
2037 if(fn.apply(scope || p, args || [p]) === false){
\r
2045 * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
\r
2046 * function call will be the scope provided or the current node. The arguments to the function
\r
2047 * will be the args provided or the current node. If the function returns false at any point,
\r
2048 * the cascade is stopped on that branch.
\r
2049 * @param {Function} fn The function to call
\r
2050 * @param {Object} scope (optional) The scope of the function (defaults to current node)
\r
2051 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
\r
2053 cascade : function(fn, scope, args){
\r
2054 if(fn.apply(scope || this, args || [this]) !== false){
\r
2055 var cs = this.childNodes;
\r
2056 for(var i = 0, len = cs.length; i < len; i++) {
\r
2057 cs[i].cascade(fn, scope, args);
\r
2063 * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
\r
2064 * function call will be the scope provided or the current node. The arguments to the function
\r
2065 * will be the args provided or the current node. If the function returns false at any point,
\r
2066 * the iteration stops.
\r
2067 * @param {Function} fn The function to call
\r
2068 * @param {Object} scope (optional) The scope of the function (defaults to current node)
\r
2069 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
\r
2071 eachChild : function(fn, scope, args){
\r
2072 var cs = this.childNodes;
\r
2073 for(var i = 0, len = cs.length; i < len; i++) {
\r
2074 if(fn.apply(scope || this, args || [cs[i]]) === false){
\r
2081 * Finds the first child that has the attribute with the specified value.
\r
2082 * @param {String} attribute The attribute name
\r
2083 * @param {Mixed} value The value to search for
\r
2084 * @return {Node} The found child or null if none was found
\r
2086 findChild : function(attribute, value){
\r
2087 var cs = this.childNodes;
\r
2088 for(var i = 0, len = cs.length; i < len; i++) {
\r
2089 if(cs[i].attributes[attribute] == value){
\r
2097 * Finds the first child by a custom function. The child matches if the function passed
\r
2099 * @param {Function} fn
\r
2100 * @param {Object} scope (optional)
\r
2101 * @return {Node} The found child or null if none was found
\r
2103 findChildBy : function(fn, scope){
\r
2104 var cs = this.childNodes;
\r
2105 for(var i = 0, len = cs.length; i < len; i++) {
\r
2106 if(fn.call(scope||cs[i], cs[i]) === true){
\r
2114 * Sorts this nodes children using the supplied sort function
\r
2115 * @param {Function} fn
\r
2116 * @param {Object} scope (optional)
\r
2118 sort : function(fn, scope){
\r
2119 var cs = this.childNodes;
\r
2120 var len = cs.length;
\r
2122 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
\r
2124 for(var i = 0; i < len; i++){
\r
2126 n.previousSibling = cs[i-1];
\r
2127 n.nextSibling = cs[i+1];
\r
2129 this.setFirstChild(n);
\r
2132 this.setLastChild(n);
\r
2139 * Returns true if this node is an ancestor (at any point) of the passed node.
\r
2140 * @param {Node} node
\r
2141 * @return {Boolean}
\r
2143 contains : function(node){
\r
2144 return node.isAncestor(this);
\r
2148 * Returns true if the passed node is an ancestor (at any point) of this node.
\r
2149 * @param {Node} node
\r
2150 * @return {Boolean}
\r
2152 isAncestor : function(node){
\r
2153 var p = this.parentNode;
\r
2163 toString : function(){
\r
2164 return "[Node"+(this.id?" "+this.id:"")+"]";
\r
2167 * @class Ext.tree.TreeNode
\r
2168 * @extends Ext.data.Node
\r
2169 * @cfg {String} text The text for this node
\r
2170 * @cfg {Boolean} expanded true to start the node expanded
\r
2171 * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)
\r
2172 * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)
\r
2173 * @cfg {Boolean} disabled true to start the node disabled
\r
2174 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
\r
2175 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
\r
2176 * @cfg {String} cls A css class to be added to the node
\r
2177 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
\r
2178 * @cfg {String} href URL of the link used for the node (defaults to #)
\r
2179 * @cfg {String} hrefTarget target frame for the link
\r
2180 * @cfg {Boolean} hidden True to render hidden. (Defaults to false).
\r
2181 * @cfg {String} qtip An Ext QuickTip for the node
\r
2182 * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
\r
2183 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
\r
2184 * @cfg {Boolean} singleClickExpand True for single click expand on this node
\r
2185 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)
\r
2186 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
\r
2187 * (defaults to undefined with no checkbox rendered)
\r
2188 * @cfg {Boolean} draggable True to make this node draggable (defaults to false)
\r
2189 * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)
\r
2190 * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)
\r
2191 * @cfg {Boolean} editable False to not allow this node to be edited by an (@link Ext.tree.TreeEditor} (defaults to true)
\r
2193 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
\r
2195 Ext.tree.TreeNode = function(attributes){
\r
2196 attributes = attributes || {};
\r
2197 if(typeof attributes == "string"){
\r
2198 attributes = {text: attributes};
\r
2200 this.childrenRendered = false;
\r
2201 this.rendered = false;
\r
2202 Ext.tree.TreeNode.superclass.constructor.call(this, attributes);
\r
2203 this.expanded = attributes.expanded === true;
\r
2204 this.isTarget = attributes.isTarget !== false;
\r
2205 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
\r
2206 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
\r
2209 * Read-only. The text for this node. To change it use setText().
\r
2212 this.text = attributes.text;
\r
2214 * True if this node is disabled.
\r
2217 this.disabled = attributes.disabled === true;
\r
2219 * True if this node is hidden.
\r
2222 this.hidden = attributes.hidden === true;
\r
2226 * @event textchange
\r
2227 * Fires when the text for this node is changed
\r
2228 * @param {Node} this This node
\r
2229 * @param {String} text The new text
\r
2230 * @param {String} oldText The old text
\r
2234 * @event beforeexpand
\r
2235 * Fires before this node is expanded, return false to cancel.
\r
2236 * @param {Node} this This node
\r
2237 * @param {Boolean} deep
\r
2238 * @param {Boolean} anim
\r
2242 * @event beforecollapse
\r
2243 * Fires before this node is collapsed, return false to cancel.
\r
2244 * @param {Node} this This node
\r
2245 * @param {Boolean} deep
\r
2246 * @param {Boolean} anim
\r
2251 * Fires when this node is expanded
\r
2252 * @param {Node} this This node
\r
2256 * @event disabledchange
\r
2257 * Fires when the disabled status of this node changes
\r
2258 * @param {Node} this This node
\r
2259 * @param {Boolean} disabled
\r
2264 * Fires when this node is collapsed
\r
2265 * @param {Node} this This node
\r
2269 * @event beforeclick
\r
2270 * Fires before click processing. Return false to cancel the default action.
\r
2271 * @param {Node} this This node
\r
2272 * @param {Ext.EventObject} e The event object
\r
2277 * Fires when this node is clicked
\r
2278 * @param {Node} this This node
\r
2279 * @param {Ext.EventObject} e The event object
\r
2283 * @event checkchange
\r
2284 * Fires when a node with a checkbox's checked property changes
\r
2285 * @param {Node} this This node
\r
2286 * @param {Boolean} checked
\r
2291 * Fires when this node is double clicked
\r
2292 * @param {Node} this This node
\r
2293 * @param {Ext.EventObject} e The event object
\r
2297 * @event contextmenu
\r
2298 * Fires when this node is right clicked
\r
2299 * @param {Node} this This node
\r
2300 * @param {Ext.EventObject} e The event object
\r
2304 * @event beforechildrenrendered
\r
2305 * Fires right before the child nodes for this node are rendered
\r
2306 * @param {Node} this This node
\r
2308 "beforechildrenrendered"
\r
2311 var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;
\r
2314 * Read-only. The UI for this node
\r
2315 * @type TreeNodeUI
\r
2317 this.ui = new uiClass(this);
\r
2319 Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
\r
2320 preventHScroll: true,
\r
2322 * Returns true if this node is expanded
\r
2323 * @return {Boolean}
\r
2325 isExpanded : function(){
\r
2326 return this.expanded;
\r
2330 * Returns the UI object for this node.
\r
2331 * @return {TreeNodeUI} The object which is providing the user interface for this tree
\r
2332 * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance
\r
2333 * of {@link Ext.tree.TreeNodeUI}
\r
2335 getUI : function(){
\r
2339 getLoader : function(){
\r
2341 return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : new Ext.tree.TreeLoader());
\r
2344 // private override
\r
2345 setFirstChild : function(node){
\r
2346 var of = this.firstChild;
\r
2347 Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);
\r
2348 if(this.childrenRendered && of && node != of){
\r
2349 of.renderIndent(true, true);
\r
2351 if(this.rendered){
\r
2352 this.renderIndent(true, true);
\r
2356 // private override
\r
2357 setLastChild : function(node){
\r
2358 var ol = this.lastChild;
\r
2359 Ext.tree.TreeNode.superclass.setLastChild.call(this, node);
\r
2360 if(this.childrenRendered && ol && node != ol){
\r
2361 ol.renderIndent(true, true);
\r
2363 if(this.rendered){
\r
2364 this.renderIndent(true, true);
\r
2368 // these methods are overridden to provide lazy rendering support
\r
2369 // private override
\r
2370 appendChild : function(n){
\r
2371 if(!n.render && !Ext.isArray(n)){
\r
2372 n = this.getLoader().createNode(n);
\r
2374 var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);
\r
2375 if(node && this.childrenRendered){
\r
2378 this.ui.updateExpandIcon();
\r
2382 // private override
\r
2383 removeChild : function(node){
\r
2384 this.ownerTree.getSelectionModel().unselect(node);
\r
2385 Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
\r
2386 // if it's been rendered remove dom node
\r
2387 if(this.childrenRendered){
\r
2390 if(this.childNodes.length < 1){
\r
2391 this.collapse(false, false);
\r
2393 this.ui.updateExpandIcon();
\r
2395 if(!this.firstChild && !this.isHiddenRoot()) {
\r
2396 this.childrenRendered = false;
\r
2401 // private override
\r
2402 insertBefore : function(node, refNode){
\r
2403 if(!node.render){
\r
2404 node = this.getLoader().createNode(node);
\r
2406 var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
\r
2407 if(newNode && refNode && this.childrenRendered){
\r
2410 this.ui.updateExpandIcon();
\r
2415 * Sets the text for this node
\r
2416 * @param {String} text
\r
2418 setText : function(text){
\r
2419 var oldText = this.text;
\r
2421 this.attributes.text = text;
\r
2422 if(this.rendered){ // event without subscribing
\r
2423 this.ui.onTextChange(this, text, oldText);
\r
2425 this.fireEvent("textchange", this, text, oldText);
\r
2429 * Triggers selection of this node
\r
2431 select : function(){
\r
2432 this.getOwnerTree().getSelectionModel().select(this);
\r
2436 * Triggers deselection of this node
\r
2438 unselect : function(){
\r
2439 this.getOwnerTree().getSelectionModel().unselect(this);
\r
2443 * Returns true if this node is selected
\r
2444 * @return {Boolean}
\r
2446 isSelected : function(){
\r
2447 return this.getOwnerTree().getSelectionModel().isSelected(this);
\r
2451 * Expand this node.
\r
2452 * @param {Boolean} deep (optional) True to expand all children as well
\r
2453 * @param {Boolean} anim (optional) false to cancel the default animation
\r
2454 * @param {Function} callback (optional) A callback to be called when
\r
2455 * expanding this node completes (does not wait for deep expand to complete).
\r
2456 * Called with 1 parameter, this node.
\r
2457 * @param {Object} scope (optional) The scope in which to execute the callback.
\r
2459 expand : function(deep, anim, callback, scope){
\r
2460 if(!this.expanded){
\r
2461 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
\r
2464 if(!this.childrenRendered){
\r
2465 this.renderChildren();
\r
2467 this.expanded = true;
\r
2468 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
\r
2469 this.ui.animExpand(function(){
\r
2470 this.fireEvent("expand", this);
\r
2471 this.runCallback(callback, scope || this, [this]);
\r
2472 if(deep === true){
\r
2473 this.expandChildNodes(true);
\r
2475 }.createDelegate(this));
\r
2479 this.fireEvent("expand", this);
\r
2480 this.runCallback(callback, scope || this, [this]);
\r
2483 this.runCallback(callback, scope || this, [this]);
\r
2485 if(deep === true){
\r
2486 this.expandChildNodes(true);
\r
2490 runCallback: function(cb, scope, args){
\r
2491 if(Ext.isFunction(cb)){
\r
2492 cb.apply(scope, args);
\r
2496 isHiddenRoot : function(){
\r
2497 return this.isRoot && !this.getOwnerTree().rootVisible;
\r
2501 * Collapse this node.
\r
2502 * @param {Boolean} deep (optional) True to collapse all children as well
\r
2503 * @param {Boolean} anim (optional) false to cancel the default animation
\r
2504 * @param {Function} callback (optional) A callback to be called when
\r
2505 * expanding this node completes (does not wait for deep expand to complete).
\r
2506 * Called with 1 parameter, this node.
\r
2507 * @param {Object} scope (optional) The scope in which to execute the callback.
\r
2509 collapse : function(deep, anim, callback, scope){
\r
2510 if(this.expanded && !this.isHiddenRoot()){
\r
2511 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
\r
2514 this.expanded = false;
\r
2515 if((this.getOwnerTree().animate && anim !== false) || anim){
\r
2516 this.ui.animCollapse(function(){
\r
2517 this.fireEvent("collapse", this);
\r
2518 this.runCallback(callback, scope || this, [this]);
\r
2519 if(deep === true){
\r
2520 this.collapseChildNodes(true);
\r
2522 }.createDelegate(this));
\r
2525 this.ui.collapse();
\r
2526 this.fireEvent("collapse", this);
\r
2527 this.runCallback(callback, scope || this, [this]);
\r
2529 }else if(!this.expanded){
\r
2530 this.runCallback(callback, scope || this, [this]);
\r
2532 if(deep === true){
\r
2533 var cs = this.childNodes;
\r
2534 for(var i = 0, len = cs.length; i < len; i++) {
\r
2535 cs[i].collapse(true, false);
\r
2541 delayedExpand : function(delay){
\r
2542 if(!this.expandProcId){
\r
2543 this.expandProcId = this.expand.defer(delay, this);
\r
2548 cancelExpand : function(){
\r
2549 if(this.expandProcId){
\r
2550 clearTimeout(this.expandProcId);
\r
2552 this.expandProcId = false;
\r
2556 * Toggles expanded/collapsed state of the node
\r
2558 toggle : function(){
\r
2559 if(this.expanded){
\r
2567 * Ensures all parent nodes are expanded, and if necessary, scrolls
\r
2568 * the node into view.
\r
2569 * @param {Function} callback (optional) A function to call when the node has been made visible.
\r
2570 * @param {Object} scope (optional) The scope in which to execute the callback.
\r
2572 ensureVisible : function(callback, scope){
\r
2573 var tree = this.getOwnerTree();
\r
2574 tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){
\r
2575 var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime
\r
2576 tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
\r
2577 this.runCallback(callback, scope || this, [this]);
\r
2578 }.createDelegate(this));
\r
2582 * Expand all child nodes
\r
2583 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
\r
2585 expandChildNodes : function(deep){
\r
2586 var cs = this.childNodes;
\r
2587 for(var i = 0, len = cs.length; i < len; i++) {
\r
2588 cs[i].expand(deep);
\r
2593 * Collapse all child nodes
\r
2594 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
\r
2596 collapseChildNodes : function(deep){
\r
2597 var cs = this.childNodes;
\r
2598 for(var i = 0, len = cs.length; i < len; i++) {
\r
2599 cs[i].collapse(deep);
\r
2604 * Disables this node
\r
2606 disable : function(){
\r
2607 this.disabled = true;
\r
2609 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
\r
2610 this.ui.onDisableChange(this, true);
\r
2612 this.fireEvent("disabledchange", this, true);
\r
2616 * Enables this node
\r
2618 enable : function(){
\r
2619 this.disabled = false;
\r
2620 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
\r
2621 this.ui.onDisableChange(this, false);
\r
2623 this.fireEvent("disabledchange", this, false);
\r
2627 renderChildren : function(suppressEvent){
\r
2628 if(suppressEvent !== false){
\r
2629 this.fireEvent("beforechildrenrendered", this);
\r
2631 var cs = this.childNodes;
\r
2632 for(var i = 0, len = cs.length; i < len; i++){
\r
2633 cs[i].render(true);
\r
2635 this.childrenRendered = true;
\r
2639 sort : function(fn, scope){
\r
2640 Ext.tree.TreeNode.superclass.sort.apply(this, arguments);
\r
2641 if(this.childrenRendered){
\r
2642 var cs = this.childNodes;
\r
2643 for(var i = 0, len = cs.length; i < len; i++){
\r
2644 cs[i].render(true);
\r
2650 render : function(bulkRender){
\r
2651 this.ui.render(bulkRender);
\r
2652 if(!this.rendered){
\r
2653 // make sure it is registered
\r
2654 this.getOwnerTree().registerNode(this);
\r
2655 this.rendered = true;
\r
2656 if(this.expanded){
\r
2657 this.expanded = false;
\r
2658 this.expand(false, false);
\r
2664 renderIndent : function(deep, refresh){
\r
2666 this.ui.childIndent = null;
\r
2668 this.ui.renderIndent();
\r
2669 if(deep === true && this.childrenRendered){
\r
2670 var cs = this.childNodes;
\r
2671 for(var i = 0, len = cs.length; i < len; i++){
\r
2672 cs[i].renderIndent(true, refresh);
\r
2677 beginUpdate : function(){
\r
2678 this.childrenRendered = false;
\r
2681 endUpdate : function(){
\r
2682 if(this.expanded && this.rendered){
\r
2683 this.renderChildren();
\r
2687 destroy : function(){
\r
2688 if(this.childNodes){
\r
2689 for(var i = 0,l = this.childNodes.length; i < l; i++){
\r
2690 this.childNodes[i].destroy();
\r
2692 this.childNodes = null;
\r
2694 if(this.ui.destroy){
\r
2695 this.ui.destroy();
\r
2700 onIdChange: function(id){
\r
2701 this.ui.onIdChange(id);
\r
2705 Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;/**
\r
2706 * @class Ext.tree.AsyncTreeNode
\r
2707 * @extends Ext.tree.TreeNode
\r
2708 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
\r
2710 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
\r
2712 Ext.tree.AsyncTreeNode = function(config){
\r
2713 this.loaded = config && config.loaded === true;
\r
2714 this.loading = false;
\r
2715 Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
\r
2717 * @event beforeload
\r
2718 * Fires before this node is loaded, return false to cancel
\r
2719 * @param {Node} this This node
\r
2721 this.addEvents('beforeload', 'load');
\r
2724 * Fires when this node is loaded
\r
2725 * @param {Node} this This node
\r
2728 * The loader used by this node (defaults to using the tree's defined loader)
\r
2729 * @type TreeLoader
\r
2730 * @property loader
\r
2733 Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
\r
2734 expand : function(deep, anim, callback, scope){
\r
2735 if(this.loading){ // if an async load is already running, waiting til it's done
\r
2737 var f = function(){
\r
2738 if(!this.loading){ // done loading
\r
2739 clearInterval(timer);
\r
2740 this.expand(deep, anim, callback, scope);
\r
2742 }.createDelegate(this);
\r
2743 timer = setInterval(f, 200);
\r
2747 if(this.fireEvent("beforeload", this) === false){
\r
2750 this.loading = true;
\r
2751 this.ui.beforeLoad(this);
\r
2752 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
\r
2754 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
\r
2758 Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
\r
2762 * Returns true if this node is currently loading
\r
2763 * @return {Boolean}
\r
2765 isLoading : function(){
\r
2766 return this.loading;
\r
2769 loadComplete : function(deep, anim, callback, scope){
\r
2770 this.loading = false;
\r
2771 this.loaded = true;
\r
2772 this.ui.afterLoad(this);
\r
2773 this.fireEvent("load", this);
\r
2774 this.expand(deep, anim, callback, scope);
\r
2778 * Returns true if this node has been loaded
\r
2779 * @return {Boolean}
\r
2781 isLoaded : function(){
\r
2782 return this.loaded;
\r
2785 hasChildNodes : function(){
\r
2786 if(!this.isLeaf() && !this.loaded){
\r
2789 return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
\r
2794 * Trigger a reload for this node
\r
2795 * @param {Function} callback
\r
2796 * @param {Object} scope (optional) The scope in which to execute the callback.
\r
2798 reload : function(callback, scope){
\r
2799 this.collapse(false, false);
\r
2800 while(this.firstChild){
\r
2801 this.removeChild(this.firstChild).destroy();
\r
2803 this.childrenRendered = false;
\r
2804 this.loaded = false;
\r
2805 if(this.isHiddenRoot()){
\r
2806 this.expanded = false;
\r
2808 this.expand(false, false, callback, scope);
\r
2812 Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;/**
\r
2813 * @class Ext.tree.TreeNodeUI
\r
2814 * This class provides the default UI implementation for Ext TreeNodes.
\r
2815 * The TreeNode UI implementation is separate from the
\r
2816 * tree implementation, and allows customizing of the appearance of
\r
2819 * If you are customizing the Tree's user interface, you
\r
2820 * may need to extend this class, but you should never need to instantiate this class.<br>
\r
2822 * This class provides access to the user interface components of an Ext TreeNode, through
\r
2823 * {@link Ext.tree.TreeNode#getUI}
\r
2825 Ext.tree.TreeNodeUI = function(node){
\r
2827 this.rendered = false;
\r
2828 this.animating = false;
\r
2829 this.wasLeaf = true;
\r
2830 this.ecc = 'x-tree-ec-icon x-tree-elbow';
\r
2831 this.emptyIcon = Ext.BLANK_IMAGE_URL;
\r
2834 Ext.tree.TreeNodeUI.prototype = {
\r
2836 removeChild : function(node){
\r
2837 if(this.rendered){
\r
2838 this.ctNode.removeChild(node.ui.getEl());
\r
2843 beforeLoad : function(){
\r
2844 this.addClass("x-tree-node-loading");
\r
2848 afterLoad : function(){
\r
2849 this.removeClass("x-tree-node-loading");
\r
2853 onTextChange : function(node, text, oldText){
\r
2854 if(this.rendered){
\r
2855 this.textNode.innerHTML = text;
\r
2860 onDisableChange : function(node, state){
\r
2861 this.disabled = state;
\r
2862 if (this.checkbox) {
\r
2863 this.checkbox.disabled = state;
\r
2866 this.addClass("x-tree-node-disabled");
\r
2868 this.removeClass("x-tree-node-disabled");
\r
2873 onSelectedChange : function(state){
\r
2876 this.addClass("x-tree-selected");
\r
2879 this.removeClass("x-tree-selected");
\r
2884 onMove : function(tree, node, oldParent, newParent, index, refNode){
\r
2885 this.childIndent = null;
\r
2886 if(this.rendered){
\r
2887 var targetNode = newParent.ui.getContainer();
\r
2888 if(!targetNode){//target not rendered
\r
2889 this.holder = document.createElement("div");
\r
2890 this.holder.appendChild(this.wrap);
\r
2893 var insertBefore = refNode ? refNode.ui.getEl() : null;
\r
2895 targetNode.insertBefore(this.wrap, insertBefore);
\r
2897 targetNode.appendChild(this.wrap);
\r
2899 this.node.renderIndent(true, oldParent != newParent);
\r
2904 * Adds one or more CSS classes to the node's UI element.
\r
2905 * Duplicate classes are automatically filtered out.
\r
2906 * @param {String/Array} className The CSS class to add, or an array of classes
\r
2908 addClass : function(cls){
\r
2910 Ext.fly(this.elNode).addClass(cls);
\r
2915 * Removes one or more CSS classes from the node's UI element.
\r
2916 * @param {String/Array} className The CSS class to remove, or an array of classes
\r
2918 removeClass : function(cls){
\r
2920 Ext.fly(this.elNode).removeClass(cls);
\r
2925 remove : function(){
\r
2926 if(this.rendered){
\r
2927 this.holder = document.createElement("div");
\r
2928 this.holder.appendChild(this.wrap);
\r
2933 fireEvent : function(){
\r
2934 return this.node.fireEvent.apply(this.node, arguments);
\r
2938 initEvents : function(){
\r
2939 this.node.on("move", this.onMove, this);
\r
2941 if(this.node.disabled){
\r
2942 this.addClass("x-tree-node-disabled");
\r
2943 if (this.checkbox) {
\r
2944 this.checkbox.disabled = true;
\r
2947 if(this.node.hidden){
\r
2950 var ot = this.node.getOwnerTree();
\r
2951 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
\r
2952 if(dd && (!this.node.isRoot || ot.rootVisible)){
\r
2953 Ext.dd.Registry.register(this.elNode, {
\r
2955 handles: this.getDDHandles(),
\r
2962 getDDHandles : function(){
\r
2963 return [this.iconNode, this.textNode, this.elNode];
\r
2967 * Hides this node.
\r
2969 hide : function(){
\r
2970 this.node.hidden = true;
\r
2972 this.wrap.style.display = "none";
\r
2977 * Shows this node.
\r
2979 show : function(){
\r
2980 this.node.hidden = false;
\r
2982 this.wrap.style.display = "";
\r
2987 onContextMenu : function(e){
\r
2988 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
\r
2989 e.preventDefault();
\r
2991 this.fireEvent("contextmenu", this.node, e);
\r
2996 onClick : function(e){
\r
2997 if(this.dropping){
\r
3001 if(this.fireEvent("beforeclick", this.node, e) !== false){
\r
3002 var a = e.getTarget('a');
\r
3003 if(!this.disabled && this.node.attributes.href && a){
\r
3004 this.fireEvent("click", this.node, e);
\r
3006 }else if(a && e.ctrlKey){
\r
3009 e.preventDefault();
\r
3010 if(this.disabled){
\r
3014 if(this.node.attributes.singleClickExpand && !this.animating && this.node.isExpandable()){
\r
3015 this.node.toggle();
\r
3018 this.fireEvent("click", this.node, e);
\r
3025 onDblClick : function(e){
\r
3026 e.preventDefault();
\r
3027 if(this.disabled){
\r
3030 if(this.checkbox){
\r
3031 this.toggleCheck();
\r
3033 if(!this.animating && this.node.isExpandable()){
\r
3034 this.node.toggle();
\r
3036 this.fireEvent("dblclick", this.node, e);
\r
3039 onOver : function(e){
\r
3040 this.addClass('x-tree-node-over');
\r
3043 onOut : function(e){
\r
3044 this.removeClass('x-tree-node-over');
\r
3048 onCheckChange : function(){
\r
3049 var checked = this.checkbox.checked;
\r
3051 this.checkbox.defaultChecked = checked;
\r
3052 this.node.attributes.checked = checked;
\r
3053 this.fireEvent('checkchange', this.node, checked);
\r
3057 ecClick : function(e){
\r
3058 if(!this.animating && this.node.isExpandable()){
\r
3059 this.node.toggle();
\r
3064 startDrop : function(){
\r
3065 this.dropping = true;
\r
3068 // delayed drop so the click event doesn't get fired on a drop
\r
3069 endDrop : function(){
\r
3070 setTimeout(function(){
\r
3071 this.dropping = false;
\r
3072 }.createDelegate(this), 50);
\r
3076 expand : function(){
\r
3077 this.updateExpandIcon();
\r
3078 this.ctNode.style.display = "";
\r
3082 focus : function(){
\r
3083 if(!this.node.preventHScroll){
\r
3084 try{this.anchor.focus();
\r
3088 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
\r
3089 var l = noscroll.scrollLeft;
\r
3090 this.anchor.focus();
\r
3091 noscroll.scrollLeft = l;
\r
3097 * Sets the checked status of the tree node to the passed value, or, if no value was passed,
\r
3098 * toggles the checked status. If the node was rendered with no checkbox, this has no effect.
\r
3099 * @param {Boolean} (optional) The new checked status.
\r
3101 toggleCheck : function(value){
\r
3102 var cb = this.checkbox;
\r
3104 cb.checked = (value === undefined ? !cb.checked : value);
\r
3105 this.onCheckChange();
\r
3110 blur : function(){
\r
3112 this.anchor.blur();
\r
3117 animExpand : function(callback){
\r
3118 var ct = Ext.get(this.ctNode);
\r
3120 if(!this.node.isExpandable()){
\r
3121 this.updateExpandIcon();
\r
3122 this.ctNode.style.display = "";
\r
3123 Ext.callback(callback);
\r
3126 this.animating = true;
\r
3127 this.updateExpandIcon();
\r
3130 callback : function(){
\r
3131 this.animating = false;
\r
3132 Ext.callback(callback);
\r
3135 duration: this.node.ownerTree.duration || .25
\r
3140 highlight : function(){
\r
3141 var tree = this.node.getOwnerTree();
\r
3142 Ext.fly(this.wrap).highlight(
\r
3143 tree.hlColor || "C3DAF9",
\r
3144 {endColor: tree.hlBaseColor}
\r
3149 collapse : function(){
\r
3150 this.updateExpandIcon();
\r
3151 this.ctNode.style.display = "none";
\r
3155 animCollapse : function(callback){
\r
3156 var ct = Ext.get(this.ctNode);
\r
3157 ct.enableDisplayMode('block');
\r
3160 this.animating = true;
\r
3161 this.updateExpandIcon();
\r
3163 ct.slideOut('t', {
\r
3164 callback : function(){
\r
3165 this.animating = false;
\r
3166 Ext.callback(callback);
\r
3169 duration: this.node.ownerTree.duration || .25
\r
3174 getContainer : function(){
\r
3175 return this.ctNode;
\r
3179 getEl : function(){
\r
3180 return this.wrap;
\r
3184 appendDDGhost : function(ghostNode){
\r
3185 ghostNode.appendChild(this.elNode.cloneNode(true));
\r
3189 getDDRepairXY : function(){
\r
3190 return Ext.lib.Dom.getXY(this.iconNode);
\r
3194 onRender : function(){
\r
3199 render : function(bulkRender){
\r
3200 var n = this.node, a = n.attributes;
\r
3201 var targetNode = n.parentNode ?
\r
3202 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
\r
3204 if(!this.rendered){
\r
3205 this.rendered = true;
\r
3207 this.renderElements(n, a, targetNode, bulkRender);
\r
3210 if(this.textNode.setAttributeNS){
\r
3211 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
\r
3213 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
\r
3216 this.textNode.setAttribute("ext:qtip", a.qtip);
\r
3218 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
\r
3221 }else if(a.qtipCfg){
\r
3222 a.qtipCfg.target = Ext.id(this.textNode);
\r
3223 Ext.QuickTips.register(a.qtipCfg);
\r
3225 this.initEvents();
\r
3226 if(!this.node.expanded){
\r
3227 this.updateExpandIcon(true);
\r
3230 if(bulkRender === true) {
\r
3231 targetNode.appendChild(this.wrap);
\r
3237 renderElements : function(n, a, targetNode, bulkRender){
\r
3238 // add some indent caching, this helps performance when rendering a large tree
\r
3239 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
\r
3241 var cb = typeof a.checked == 'boolean';
\r
3243 var href = a.href ? a.href : Ext.isGecko ? "" : "#";
\r
3244 var buf = ['<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf x-unselectable ', a.cls,'" unselectable="on">',
\r
3245 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
\r
3246 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
\r
3247 '<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
3248 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',
\r
3249 '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ',
\r
3250 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",
\r
3251 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
\r
3252 "</li>"].join('');
\r
3255 if(bulkRender !== true && n.nextSibling && (nel = n.nextSibling.ui.getEl())){
\r
3256 this.wrap = Ext.DomHelper.insertHtml("beforeBegin", nel, buf);
\r
3258 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf);
\r
3261 this.elNode = this.wrap.childNodes[0];
\r
3262 this.ctNode = this.wrap.childNodes[1];
\r
3263 var cs = this.elNode.childNodes;
\r
3264 this.indentNode = cs[0];
\r
3265 this.ecNode = cs[1];
\r
3266 this.iconNode = cs[2];
\r
3269 this.checkbox = cs[3];
\r
3271 this.checkbox.defaultChecked = this.checkbox.checked;
\r
3274 this.anchor = cs[index];
\r
3275 this.textNode = cs[index].firstChild;
\r
3279 * Returns the <a> element that provides focus for the node's UI.
\r
3280 * @return {HtmlElement} The DOM anchor element.
\r
3282 getAnchor : function(){
\r
3283 return this.anchor;
\r
3287 * Returns the text node.
\r
3288 * @return {HtmlNode} The DOM text node.
\r
3290 getTextEl : function(){
\r
3291 return this.textNode;
\r
3295 * Returns the icon <img> element.
\r
3296 * @return {HtmlElement} The DOM image element.
\r
3298 getIconEl : function(){
\r
3299 return this.iconNode;
\r
3303 * Returns the checked status of the node. If the node was rendered with no
\r
3304 * checkbox, it returns false.
\r
3305 * @return {Boolean} The checked flag.
\r
3307 isChecked : function(){
\r
3308 return this.checkbox ? this.checkbox.checked : false;
\r
3312 updateExpandIcon : function(){
\r
3313 if(this.rendered){
\r
3314 var n = this.node, c1, c2;
\r
3315 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
\r
3316 var hasChild = n.hasChildNodes();
\r
3317 if(hasChild || n.attributes.expandable){
\r
3320 c1 = "x-tree-node-collapsed";
\r
3321 c2 = "x-tree-node-expanded";
\r
3324 c1 = "x-tree-node-expanded";
\r
3325 c2 = "x-tree-node-collapsed";
\r
3328 this.removeClass("x-tree-node-leaf");
\r
3329 this.wasLeaf = false;
\r
3331 if(this.c1 != c1 || this.c2 != c2){
\r
3332 Ext.fly(this.elNode).replaceClass(c1, c2);
\r
3333 this.c1 = c1; this.c2 = c2;
\r
3336 if(!this.wasLeaf){
\r
3337 Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
\r
3340 this.wasLeaf = true;
\r
3343 var ecc = "x-tree-ec-icon "+cls;
\r
3344 if(this.ecc != ecc){
\r
3345 this.ecNode.className = ecc;
\r
3352 onIdChange: function(id){
\r
3353 if(this.rendered){
\r
3354 this.elNode.setAttribute('ext:tree-node-id', id);
\r
3359 getChildIndent : function(){
\r
3360 if(!this.childIndent){
\r
3362 var p = this.node;
\r
3364 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
\r
3366 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
\r
3368 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
\r
3373 this.childIndent = buf.join("");
\r
3375 return this.childIndent;
\r
3379 renderIndent : function(){
\r
3380 if(this.rendered){
\r
3382 var p = this.node.parentNode;
\r
3384 indent = p.ui.getChildIndent();
\r
3386 if(this.indentMarkup != indent){ // don't rerender if not required
\r
3387 this.indentNode.innerHTML = indent;
\r
3388 this.indentMarkup = indent;
\r
3390 this.updateExpandIcon();
\r
3394 destroy : function(){
\r
3396 Ext.dd.Registry.unregister(this.elNode.id);
\r
3398 delete this.elNode;
\r
3399 delete this.ctNode;
\r
3400 delete this.indentNode;
\r
3401 delete this.ecNode;
\r
3402 delete this.iconNode;
\r
3403 delete this.checkbox;
\r
3404 delete this.anchor;
\r
3405 delete this.textNode;
\r
3409 Ext.removeNode(this.holder);
\r
3410 delete this.holder;
\r
3412 Ext.removeNode(this.wrap);
\r
3419 * @class Ext.tree.RootTreeNodeUI
\r
3420 * This class provides the default UI implementation for <b>root</b> Ext TreeNodes.
\r
3421 * The RootTreeNode UI implementation allows customizing the appearance of the root tree node.<br>
\r
3423 * If you are customizing the Tree's user interface, you
\r
3424 * may need to extend this class, but you should never need to instantiate this class.<br>
\r
3426 Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
\r
3428 render : function(){
\r
3429 if(!this.rendered){
\r
3430 var targetNode = this.node.ownerTree.innerCt.dom;
\r
3431 this.node.expanded = true;
\r
3432 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
\r
3433 this.wrap = this.ctNode = targetNode.firstChild;
\r
3436 collapse : Ext.emptyFn,
\r
3437 expand : Ext.emptyFn
\r
3439 * @class Ext.tree.TreeLoader
\r
3440 * @extends Ext.util.Observable
\r
3441 * A TreeLoader provides for lazy loading of an {@link Ext.tree.TreeNode}'s child
\r
3442 * nodes from a specified URL. The response must be a JavaScript Array definition
\r
3443 * whose elements are node definition objects. e.g.:
\r
3447 text: 'A leaf Node',
\r
3451 text: 'A folder Node',
\r
3454 text: 'A child Node',
\r
3460 * A server request is sent, and child nodes are loaded only when a node is expanded.
\r
3461 * The loading node's id is passed to the server under the parameter name "node" to
\r
3462 * enable the server to produce the correct child nodes.
\r
3464 * To pass extra parameters, an event handler may be attached to the "beforeload"
\r
3465 * event, and the parameters specified in the TreeLoader's baseParams property:
\r
3467 myTreeLoader.on("beforeload", function(treeLoader, node) {
\r
3468 this.baseParams.category = node.attributes.category;
\r
3471 * This would pass an HTTP parameter called "category" to the server containing
\r
3472 * the value of the Node's "category" attribute.
\r
3474 * Creates a new Treeloader.
\r
3475 * @param {Object} config A config object containing config properties.
\r
3477 Ext.tree.TreeLoader = function(config){
\r
3478 this.baseParams = {};
\r
3479 Ext.apply(this, config);
\r
3483 * @event beforeload
\r
3484 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
\r
3485 * @param {Object} This TreeLoader object.
\r
3486 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
\r
3487 * @param {Object} callback The callback function specified in the {@link #load} call.
\r
3492 * Fires when the node has been successfuly loaded.
\r
3493 * @param {Object} This TreeLoader object.
\r
3494 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
\r
3495 * @param {Object} response The response object containing the data from the server.
\r
3499 * @event loadexception
\r
3500 * Fires if the network request failed.
\r
3501 * @param {Object} This TreeLoader object.
\r
3502 * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
\r
3503 * @param {Object} response The response object containing the data from the server.
\r
3507 Ext.tree.TreeLoader.superclass.constructor.call(this);
\r
3508 if(typeof this.paramOrder == 'string'){
\r
3509 this.paramOrder = this.paramOrder.split(/[\s,|]/);
\r
3513 Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, {
\r
3515 * @cfg {String} dataUrl The URL from which to request a Json string which
\r
3516 * specifies an array of node definition objects representing the child nodes
\r
3520 * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
\r
3523 * @cfg {String} url Equivalent to {@link #dataUrl}.
\r
3526 * @cfg {Boolean} preloadChildren If set to true, the loader recursively loads "children" attributes when doing the first load on nodes.
\r
3529 * @cfg {Object} baseParams (optional) An object containing properties which
\r
3530 * specify HTTP parameters to be passed to each request for child nodes.
\r
3533 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
\r
3534 * created by this loader. If the attributes sent by the server have an attribute in this object,
\r
3535 * they take priority.
\r
3538 * @cfg {Object} uiProviders (optional) An object containing properties which
\r
3539 * specify custom {@link Ext.tree.TreeNodeUI} implementations. If the optional
\r
3540 * <i>uiProvider</i> attribute of a returned child node is a string rather
\r
3541 * than a reference to a TreeNodeUI implementation, then that string value
\r
3542 * is used as a property name in the uiProviders object.
\r
3547 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
\r
3548 * child nodes before loading.
\r
3550 clearOnLoad : true,
\r
3553 * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. Only used when using directFn.
\r
3554 * A list of params to be executed
\r
3555 * server side. Specify the params in the order in which they must be executed on the server-side
\r
3556 * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
\r
3557 * comma, or pipe. For example,
\r
3558 * any of the following would be acceptable:<pre><code>
\r
3559 paramOrder: ['param1','param2','param3']
\r
3560 paramOrder: 'param1 param2 param3'
\r
3561 paramOrder: 'param1,param2,param3'
\r
3562 paramOrder: 'param1|param2|param'
\r
3565 paramOrder: undefined,
\r
3568 * @cfg {Boolean} paramsAsHash Only used when using directFn.
\r
3569 * Send parameters as a collection of named arguments (defaults to <tt>false</tt>). Providing a
\r
3570 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
\r
3572 paramsAsHash: false,
\r
3575 * @cfg {Function} directFn
\r
3576 * Function to call when executing a request.
\r
3578 directFn : undefined,
\r
3581 * Load an {@link Ext.tree.TreeNode} from the URL specified in the constructor.
\r
3582 * This is called automatically when a node is expanded, but may be used to reload
\r
3583 * a node (or append new children if the {@link #clearOnLoad} option is false.)
\r
3584 * @param {Ext.tree.TreeNode} node
\r
3585 * @param {Function} callback
\r
3586 * @param (Object) scope
\r
3588 load : function(node, callback, scope){
\r
3589 if(this.clearOnLoad){
\r
3590 while(node.firstChild){
\r
3591 node.removeChild(node.firstChild);
\r
3594 if(this.doPreload(node)){ // preloaded json children
\r
3595 this.runCallback(callback, scope || node, []);
\r
3596 }else if(this.directFn || this.dataUrl || this.url){
\r
3597 this.requestData(node, callback, scope || node);
\r
3601 doPreload : function(node){
\r
3602 if(node.attributes.children){
\r
3603 if(node.childNodes.length < 1){ // preloaded?
\r
3604 var cs = node.attributes.children;
\r
3605 node.beginUpdate();
\r
3606 for(var i = 0, len = cs.length; i < len; i++){
\r
3607 var cn = node.appendChild(this.createNode(cs[i]));
\r
3608 if(this.preloadChildren){
\r
3609 this.doPreload(cn);
\r
3619 getParams: function(node){
\r
3620 var buf = [], bp = this.baseParams;
\r
3621 if(this.directFn){
\r
3622 buf.push(node.id);
\r
3624 if(this.paramOrder){
\r
3625 for(var i = 0, len = this.paramOrder.length; i < len; i++){
\r
3626 buf.push(bp[this.paramOrder[i]]);
\r
3628 }else if(this.paramsAsHash){
\r
3634 for(var key in bp){
\r
3635 if(!Ext.isFunction(bp[key])){
\r
3636 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
\r
3639 buf.push("node=", encodeURIComponent(node.id));
\r
3640 return buf.join("");
\r
3644 requestData : function(node, callback, scope){
\r
3645 if(this.fireEvent("beforeload", this, node, callback) !== false){
\r
3646 if(this.directFn){
\r
3647 var args = this.getParams(node);
\r
3648 args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));
\r
3649 this.directFn.apply(window, args);
\r
3651 this.transId = Ext.Ajax.request({
\r
3652 method:this.requestMethod,
\r
3653 url: this.dataUrl||this.url,
\r
3654 success: this.handleResponse,
\r
3655 failure: this.handleFailure,
\r
3657 argument: {callback: callback, node: node, scope: scope},
\r
3658 params: this.getParams(node)
\r
3662 // if the load is cancelled, make sure we notify
\r
3663 // the node that we are done
\r
3664 this.runCallback(callback, scope || node, []);
\r
3668 processDirectResponse: function(result, response, args){
\r
3669 if(response.status){
\r
3670 this.handleResponse({
\r
3671 responseData: Ext.isArray(result) ? result : null,
\r
3672 responseText: result,
\r
3676 this.handleFailure({
\r
3683 runCallback: function(cb, scope, args){
\r
3684 if(Ext.isFunction(cb)){
\r
3685 cb.apply(scope, args);
\r
3689 isLoading : function(){
\r
3690 return !!this.transId;
\r
3693 abort : function(){
\r
3694 if(this.isLoading()){
\r
3695 Ext.Ajax.abort(this.transId);
\r
3700 * <p>Override this function for custom TreeNode node implementation, or to
\r
3701 * modify the attributes at creation time.</p>
\r
3702 * Example:<pre><code>
\r
3703 new Ext.tree.TreePanel({
\r
3705 new Ext.tree.TreeLoader({
\r
3707 createNode: function(attr) {
\r
3708 // Allow consolidation consignments to have
\r
3709 // consignments dropped into them.
\r
3710 if (attr.isConsolidation) {
\r
3711 attr.iconCls = 'x-consol',
\r
3712 attr.allowDrop = true;
\r
3714 return Ext.tree.TreeLoader.prototype.call(this, attr);
\r
3720 * @param attr {Object} The attributes from which to create the new node.
\r
3722 createNode : function(attr){
\r
3723 // apply baseAttrs, nice idea Corey!
\r
3724 if(this.baseAttrs){
\r
3725 Ext.applyIf(attr, this.baseAttrs);
\r
3727 if(this.applyLoader !== false){
\r
3728 attr.loader = this;
\r
3730 if(typeof attr.uiProvider == 'string'){
\r
3731 attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
\r
3733 if(attr.nodeType){
\r
3734 return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
\r
3736 return attr.leaf ?
\r
3737 new Ext.tree.TreeNode(attr) :
\r
3738 new Ext.tree.AsyncTreeNode(attr);
\r
3742 processResponse : function(response, node, callback, scope){
\r
3743 var json = response.responseText;
\r
3745 var o = response.responseData || Ext.decode(json);
\r
3746 node.beginUpdate();
\r
3747 for(var i = 0, len = o.length; i < len; i++){
\r
3748 var n = this.createNode(o[i]);
\r
3750 node.appendChild(n);
\r
3754 this.runCallback(callback, scope || node, [node]);
\r
3756 this.handleFailure(response);
\r
3760 handleResponse : function(response){
\r
3761 this.transId = false;
\r
3762 var a = response.argument;
\r
3763 this.processResponse(response, a.node, a.callback, a.scope);
\r
3764 this.fireEvent("load", this, a.node, response);
\r
3767 handleFailure : function(response){
\r
3768 this.transId = false;
\r
3769 var a = response.argument;
\r
3770 this.fireEvent("loadexception", this, a.node, response);
\r
3771 this.runCallback(a.callback, a.scope || a.node, [a.node]);
\r
3774 * @class Ext.tree.TreeFilter
3775 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
3776 * @param {TreePanel} tree
3777 * @param {Object} config (optional)
3779 Ext.tree.TreeFilter = function(tree, config){
3782 Ext.apply(this, config);
3785 Ext.tree.TreeFilter.prototype = {
3792 * Filter the data by a specific attribute.
3793 * @param {String/RegExp} value Either string that the attribute value
3794 * should start with or a RegExp to test against the attribute
3795 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
3796 * @param {TreeNode} startNode (optional) The node to start the filter at.
3798 filter : function(value, attr, startNode){
3799 attr = attr || "text";
3801 if(typeof value == "string"){
3802 var vlen = value.length;
3803 // auto clear empty filter
3804 if(vlen == 0 && this.clearBlank){
3808 value = value.toLowerCase();
3810 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
3812 }else if(value.exec){ // regex?
3814 return value.test(n.attributes[attr]);
3817 throw 'Illegal filter type, must be string or regex';
3819 this.filterBy(f, null, startNode);
3823 * Filter by a function. The passed function will be called with each
3824 * node in the tree (or from the startNode). If the function returns true, the node is kept
3825 * otherwise it is filtered. If a node is filtered, its children are also filtered.
3826 * @param {Function} fn The filter function
3827 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
3829 filterBy : function(fn, scope, startNode){
3830 startNode = startNode || this.tree.root;
3834 var af = this.filtered, rv = this.reverse;
3835 var f = function(n){
3842 var m = fn.call(scope || n, n);
3850 startNode.cascade(f);
3853 if(typeof id != "function"){
3855 if(n && n.parentNode){
3856 n.parentNode.removeChild(n);
3864 * Clears the current filter. Note: with the "remove" option
3865 * set a filter cannot be cleared.
3869 var af = this.filtered;
3871 if(typeof id != "function"){
3882 * @class Ext.tree.TreeSorter
\r
3883 * Provides sorting of nodes in a {@link Ext.tree.TreePanel}. The TreeSorter automatically monitors events on the
\r
3884 * associated TreePanel that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
\r
3885 * Example usage:<br />
\r
3887 new Ext.tree.TreeSorter(myTree, {
\r
3890 sortType: function(node) {
\r
3891 // sort by a custom, typed attribute:
\r
3892 return parseInt(node.id, 10);
\r
3897 * @param {TreePanel} tree
\r
3898 * @param {Object} config
\r
3900 Ext.tree.TreeSorter = function(tree, config){
\r
3902 * @cfg {Boolean} folderSort True to sort leaf nodes under non-leaf nodes (defaults to false)
\r
3905 * @cfg {String} property The named attribute on the node to sort by (defaults to "text"). Note that this
\r
3906 * property is only used if no {@link #sortType} function is specified, otherwise it is ignored.
\r
3909 * @cfg {String} dir The direction to sort ("asc" or "desc," case-insensitive, defaults to "asc")
\r
3912 * @cfg {String} leafAttr The attribute used to determine leaf nodes when {@link #folderSort} = true (defaults to "leaf")
\r
3915 * @cfg {Boolean} caseSensitive true for case-sensitive sort (defaults to false)
\r
3918 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting. The function
\r
3919 * will be called with a single parameter (the {@link Ext.tree.TreeNode} being evaluated) and is expected to return
\r
3920 * the node's sort value cast to the specific data type required for sorting. This could be used, for example, when
\r
3921 * a node's text (or other attribute) should be sorted as a date or numeric value. See the class description for
\r
3922 * example usage. Note that if a sortType is specified, any {@link #property} config will be ignored.
\r
3925 Ext.apply(this, config);
\r
3926 tree.on("beforechildrenrendered", this.doSort, this);
\r
3927 tree.on("append", this.updateSort, this);
\r
3928 tree.on("insert", this.updateSort, this);
\r
3929 tree.on("textchange", this.updateSortParent, this);
\r
3931 var dsc = this.dir && this.dir.toLowerCase() == "desc";
\r
3932 var p = this.property || "text";
\r
3933 var sortType = this.sortType;
\r
3934 var fs = this.folderSort;
\r
3935 var cs = this.caseSensitive === true;
\r
3936 var leafAttr = this.leafAttr || 'leaf';
\r
3938 this.sortFn = function(n1, n2){
\r
3940 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
\r
3943 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
\r
3947 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
\r
3948 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
\r
3950 return dsc ? +1 : -1;
\r
3951 }else if(v1 > v2){
\r
3952 return dsc ? -1 : +1;
\r
3959 Ext.tree.TreeSorter.prototype = {
\r
3960 doSort : function(node){
\r
3961 node.sort(this.sortFn);
\r
3964 compareNodes : function(n1, n2){
\r
3965 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
\r
3968 updateSort : function(tree, node){
\r
3969 if(node.childrenRendered){
\r
3970 this.doSort.defer(1, this, [node]);
\r
3974 updateSortParent : function(node){
\r
3975 var p = node.parentNode;
\r
3976 if(p && p.childrenRendered){
\r
3977 this.doSort.defer(1, this, [p]);
\r
3981 * @class Ext.tree.TreeDropZone
\r
3982 * @extends Ext.dd.DropZone
\r
3984 * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dropping
\r
3985 * @param {Object} config
\r
3987 if(Ext.dd.DropZone){
\r
3989 Ext.tree.TreeDropZone = function(tree, config){
\r
3991 * @cfg {Boolean} allowParentInsert
\r
3992 * Allow inserting a dragged node between an expanded parent node and its first child that will become a
\r
3993 * sibling of the parent when dropped (defaults to false)
\r
3995 this.allowParentInsert = config.allowParentInsert || false;
\r
3997 * @cfg {String} allowContainerDrop
\r
3998 * True if drops on the tree container (outside of a specific tree node) are allowed (defaults to false)
\r
4000 this.allowContainerDrop = config.allowContainerDrop || false;
\r
4002 * @cfg {String} appendOnly
\r
4003 * True if the tree should only allow append drops (use for trees which are sorted, defaults to false)
\r
4005 this.appendOnly = config.appendOnly || false;
\r
4007 Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.getTreeEl(), config);
\r
4009 * The TreePanel for this drop zone
\r
4010 * @type Ext.tree.TreePanel
\r
4015 * Arbitrary data that can be associated with this tree and will be included in the event object that gets
\r
4016 * passed to any nodedragover event handler (defaults to {})
\r
4017 * @type Ext.tree.TreePanel
\r
4020 this.dragOverData = {};
\r
4022 this.lastInsertClass = "x-tree-no-status";
\r
4025 Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, {
\r
4027 * @cfg {String} ddGroup
\r
4028 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
\r
4029 * interact with other drag drop objects in the same group (defaults to 'TreeDD').
\r
4031 ddGroup : "TreeDD",
\r
4034 * @cfg {String} expandDelay
\r
4035 * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node
\r
4036 * over the target (defaults to 1000)
\r
4038 expandDelay : 1000,
\r
4041 expandNode : function(node){
\r
4042 if(node.hasChildNodes() && !node.isExpanded()){
\r
4043 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
\r
4048 queueExpand : function(node){
\r
4049 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
\r
4053 cancelExpand : function(){
\r
4054 if(this.expandProcId){
\r
4055 clearTimeout(this.expandProcId);
\r
4056 this.expandProcId = false;
\r
4061 isValidDropPoint : function(n, pt, dd, e, data){
\r
4062 if(!n || !data){ return false; }
\r
4063 var targetNode = n.node;
\r
4064 var dropNode = data.node;
\r
4065 // default drop rules
\r
4066 if(!(targetNode && targetNode.isTarget && pt)){
\r
4069 if(pt == "append" && targetNode.allowChildren === false){
\r
4072 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
\r
4075 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
\r
4078 // reuse the object
\r
4079 var overEvent = this.dragOverData;
\r
4080 overEvent.tree = this.tree;
\r
4081 overEvent.target = targetNode;
\r
4082 overEvent.data = data;
\r
4083 overEvent.point = pt;
\r
4084 overEvent.source = dd;
\r
4085 overEvent.rawEvent = e;
\r
4086 overEvent.dropNode = dropNode;
\r
4087 overEvent.cancel = false;
\r
4088 var result = this.tree.fireEvent("nodedragover", overEvent);
\r
4089 return overEvent.cancel === false && result !== false;
\r
4093 getDropPoint : function(e, n, dd){
\r
4096 return tn.allowChildren !== false ? "append" : false; // always append for root
\r
4098 var dragEl = n.ddel;
\r
4099 var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
\r
4100 var y = Ext.lib.Event.getPageY(e);
\r
4101 var noAppend = tn.allowChildren === false || tn.isLeaf();
\r
4102 if(this.appendOnly || tn.parentNode.allowChildren === false){
\r
4103 return noAppend ? false : "append";
\r
4105 var noBelow = false;
\r
4106 if(!this.allowParentInsert){
\r
4107 noBelow = tn.hasChildNodes() && tn.isExpanded();
\r
4109 var q = (b - t) / (noAppend ? 2 : 3);
\r
4110 if(y >= t && y < (t + q)){
\r
4112 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
\r
4120 onNodeEnter : function(n, dd, e, data){
\r
4121 this.cancelExpand();
\r
4124 onContainerOver : function(dd, e, data) {
\r
4125 if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
\r
4126 return this.dropAllowed;
\r
4128 return this.dropNotAllowed;
\r
4132 onNodeOver : function(n, dd, e, data){
\r
4133 var pt = this.getDropPoint(e, n, dd);
\r
4134 var node = n.node;
\r
4136 // auto node expand check
\r
4137 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
\r
4138 this.queueExpand(node);
\r
4139 }else if(pt != "append"){
\r
4140 this.cancelExpand();
\r
4143 // set the insert point style on the target node
\r
4144 var returnCls = this.dropNotAllowed;
\r
4145 if(this.isValidDropPoint(n, pt, dd, e, data)){
\r
4149 if(pt == "above"){
\r
4150 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
\r
4151 cls = "x-tree-drag-insert-above";
\r
4152 }else if(pt == "below"){
\r
4153 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
\r
4154 cls = "x-tree-drag-insert-below";
\r
4156 returnCls = "x-tree-drop-ok-append";
\r
4157 cls = "x-tree-drag-append";
\r
4159 if(this.lastInsertClass != cls){
\r
4160 Ext.fly(el).replaceClass(this.lastInsertClass, cls);
\r
4161 this.lastInsertClass = cls;
\r
4169 onNodeOut : function(n, dd, e, data){
\r
4170 this.cancelExpand();
\r
4171 this.removeDropIndicators(n);
\r
4175 onNodeDrop : function(n, dd, e, data){
\r
4176 var point = this.getDropPoint(e, n, dd);
\r
4177 var targetNode = n.node;
\r
4178 targetNode.ui.startDrop();
\r
4179 if(!this.isValidDropPoint(n, point, dd, e, data)){
\r
4180 targetNode.ui.endDrop();
\r
4183 // first try to find the drop node
\r
4184 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
\r
4185 return this.processDrop(targetNode, data, point, dd, e, dropNode);
\r
4188 onContainerDrop : function(dd, e, data){
\r
4189 if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
\r
4190 var targetNode = this.tree.getRootNode();
\r
4191 targetNode.ui.startDrop();
\r
4192 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, 'append', e) : null);
\r
4193 return this.processDrop(targetNode, data, 'append', dd, e, dropNode);
\r
4199 processDrop: function(target, data, point, dd, e, dropNode){
\r
4207 dropNode: dropNode,
\r
4208 cancel: !dropNode,
\r
4211 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
\r
4212 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
\r
4213 target.ui.endDrop();
\r
4214 return dropEvent.dropStatus;
\r
4217 target = dropEvent.target;
\r
4218 if(point == 'append' && !target.isExpanded()){
\r
4219 target.expand(false, null, function(){
\r
4220 this.completeDrop(dropEvent);
\r
4221 }.createDelegate(this));
\r
4223 this.completeDrop(dropEvent);
\r
4229 completeDrop : function(de){
\r
4230 var ns = de.dropNode, p = de.point, t = de.target;
\r
4231 if(!Ext.isArray(ns)){
\r
4235 for(var i = 0, len = ns.length; i < len; i++){
\r
4238 t.parentNode.insertBefore(n, t);
\r
4239 }else if(p == "below"){
\r
4240 t.parentNode.insertBefore(n, t.nextSibling);
\r
4246 if(Ext.enableFx && this.tree.hlDrop){
\r
4250 this.tree.fireEvent("nodedrop", de);
\r
4254 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
\r
4255 if(Ext.enableFx && this.tree.hlDrop){
\r
4256 dropNode.ui.focus();
\r
4257 dropNode.ui.highlight();
\r
4259 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
\r
4263 getTree : function(){
\r
4268 removeDropIndicators : function(n){
\r
4271 Ext.fly(el).removeClass([
\r
4272 "x-tree-drag-insert-above",
\r
4273 "x-tree-drag-insert-below",
\r
4274 "x-tree-drag-append"]);
\r
4275 this.lastInsertClass = "_noclass";
\r
4280 beforeDragDrop : function(target, e, id){
\r
4281 this.cancelExpand();
\r
4286 afterRepair : function(data){
\r
4287 if(data && Ext.enableFx){
\r
4288 data.node.ui.highlight();
\r
4295 * @class Ext.tree.TreeDragZone
\r
4296 * @extends Ext.dd.DragZone
\r
4298 * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dragging
\r
4299 * @param {Object} config
\r
4301 if(Ext.dd.DragZone){
\r
4302 Ext.tree.TreeDragZone = function(tree, config){
\r
4303 Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.innerCt, config);
\r
4305 * The TreePanel for this drag zone
\r
4306 * @type Ext.tree.TreePanel
\r
4312 Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, {
\r
4314 * @cfg {String} ddGroup
\r
4315 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
\r
4316 * interact with other drag drop objects in the same group (defaults to 'TreeDD').
\r
4318 ddGroup : "TreeDD",
\r
4321 onBeforeDrag : function(data, e){
\r
4322 var n = data.node;
\r
4323 return n && n.draggable && !n.disabled;
\r
4327 onInitDrag : function(e){
\r
4328 var data = this.dragData;
\r
4329 this.tree.getSelectionModel().select(data.node);
\r
4330 this.tree.eventModel.disable();
\r
4331 this.proxy.update("");
\r
4332 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
\r
4333 this.tree.fireEvent("startdrag", this.tree, data.node, e);
\r
4337 getRepairXY : function(e, data){
\r
4338 return data.node.ui.getDDRepairXY();
\r
4342 onEndDrag : function(data, e){
\r
4343 this.tree.eventModel.enable.defer(100, this.tree.eventModel);
\r
4344 this.tree.fireEvent("enddrag", this.tree, data.node, e);
\r
4348 onValidDrop : function(dd, e, id){
\r
4349 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
\r
4354 beforeInvalidDrop : function(e, id){
\r
4355 // this scrolls the original position back into view
\r
4356 var sm = this.tree.getSelectionModel();
\r
4357 sm.clearSelections();
\r
4358 sm.select(this.dragData.node);
\r
4362 afterRepair : function(){
\r
4363 if (Ext.enableFx && this.tree.hlDrop) {
\r
4364 Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
\r
4366 this.dragging = false;
\r
4370 * @class Ext.tree.TreeEditor
4371 * @extends Ext.Editor
4372 * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
4373 * as the editor field.
4375 * @param {TreePanel} tree
4376 * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
4377 * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
4378 * @param {Object} config (optional) A TreeEditor config object
4380 Ext.tree.TreeEditor = function(tree, fc, config){
4382 var field = fc.events ? fc : new Ext.form.TextField(fc);
4383 Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
4388 tree.on('render', this.initEditor, this);
4390 this.initEditor(tree);
4394 Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
4396 * @cfg {String} alignment
4397 * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "l-l").
4403 * @cfg {Boolean} hideEl
4404 * True to hide the bound element while the editor is displayed (defaults to false)
4409 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
4411 cls: "x-small-editor x-tree-editor",
4413 * @cfg {Boolean} shim
4414 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
4420 * @cfg {Number} maxWidth
4421 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
4422 * the containing tree element's size, it will be automatically limited for you to the container width, taking
4423 * scroll and client offsets into account prior to each edit.
4427 * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
4428 * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
4429 * the editor for the node will display, otherwise it will be processed as a regular click.
4433 initEditor : function(tree){
4434 tree.on('beforeclick', this.beforeNodeClick, this);
4435 tree.on('dblclick', this.onNodeDblClick, this);
4436 this.on('complete', this.updateNode, this);
4437 this.on('beforestartedit', this.fitToTree, this);
4438 this.on('startedit', this.bindScroll, this, {delay:10});
4439 this.on('specialkey', this.onSpecialKey, this);
4443 fitToTree : function(ed, el){
4444 var td = this.tree.getTreeEl().dom, nd = el.dom;
4445 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
4446 td.scrollLeft = nd.offsetLeft;
4450 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
4451 this.setSize(w, '');
4455 * Edit the text of the passed {@link Ext.tree.TreeNode TreeNode}.
4456 * @param node {Ext.tree.TreeNode} The TreeNode to edit. The TreeNode must be {@link Ext.tree.TreeNode#editable editable}.
4458 triggerEdit : function(node, defer){
4459 this.completeEdit();
4460 if(node.attributes.editable !== false){
4462 * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
4463 * @type Ext.tree.TreeNode
4464 * @property editNode
4466 this.editNode = node;
4467 if(this.tree.autoScroll){
4468 Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
4470 var value = node.text || '';
4471 if (!Ext.isGecko && Ext.isEmpty(node.text)){
4472 node.setText(' ');
4474 this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
4480 bindScroll : function(){
4481 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
4485 beforeNodeClick : function(node, e){
4486 clearTimeout(this.autoEditTimer);
4487 if(this.tree.getSelectionModel().isSelected(node)){
4489 return this.triggerEdit(node);
4493 onNodeDblClick : function(node, e){
4494 clearTimeout(this.autoEditTimer);
4498 updateNode : function(ed, value){
4499 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
4500 this.editNode.setText(value);
4504 onHide : function(){
4505 Ext.tree.TreeEditor.superclass.onHide.call(this);
4507 this.editNode.ui.focus.defer(50, this.editNode.ui);
4512 onSpecialKey : function(field, e){
4517 }else if(k == e.ENTER && !e.hasModifier()){
4519 this.completeEdit();