pkg-tree-debug.js
资源名称:ext-3.0.0.zip [点击查看]
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:145k
源码类别:
中间件编程
开发平台:
JavaScript
- /*! * Ext JS Library 3.0.0 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license */ /**
- * @class Ext.tree.TreePanel
- * @extends Ext.Panel
- * <p>The TreePanel provides tree-structured UI representation of tree-structured data.</p>
- * <p>{@link Ext.tree.TreeNode TreeNode}s added to the TreePanel may each contain metadata
- * used by your application in their {@link Ext.tree.TreeNode#attributes attributes} property.</p>
- * <p><b>A TreePanel must have a {@link #root} node before it is rendered.</b> This may either be
- * specified using the {@link #root} config option, or using the {@link #setRootNode} method.
- * <p>An example of tree rendered to an existing div:</p><pre><code>
- var tree = new Ext.tree.TreePanel({
- renderTo: 'tree-div',
- useArrows: true,
- autoScroll: true,
- animate: true,
- enableDD: true,
- containerScroll: true,
- border: false,
- // auto create TreeLoader
- dataUrl: 'get-nodes.php',
- root: {
- nodeType: 'async',
- text: 'Ext JS',
- draggable: false,
- id: 'source'
- }
- });
- tree.getRootNode().expand();
- * </code></pre>
- * <p>The example above would work with a data packet similar to this:</p><pre><code>
- [{
- "text": "adapter",
- "id": "source/adapter",
- "cls": "folder"
- }, {
- "text": "dd",
- "id": "source/dd",
- "cls": "folder"
- }, {
- "text": "debug.js",
- "id": "source/debug.js",
- "leaf": true,
- "cls": "file"
- }]
- * </code></pre>
- * <p>An example of tree within a Viewport:</p><pre><code>
- new Ext.Viewport({
- layout: 'border',
- items: [{
- region: 'west',
- collapsible: true,
- title: 'Navigation',
- xtype: 'treepanel',
- width: 200,
- autoScroll: true,
- split: true,
- loader: new Ext.tree.TreeLoader(),
- root: new Ext.tree.AsyncTreeNode({
- expanded: true,
- children: [{
- text: 'Menu Option 1',
- leaf: true
- }, {
- text: 'Menu Option 2',
- leaf: true
- }, {
- text: 'Menu Option 3',
- leaf: true
- }]
- }),
- rootVisible: false,
- listeners: {
- click: function(n) {
- Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
- }
- }
- }, {
- region: 'center',
- xtype: 'tabpanel',
- // remaining code not shown ...
- }]
- });
- </code></pre>
- *
- * @cfg {Ext.tree.TreeNode} root The root node for the tree.
- * @cfg {Boolean} rootVisible <tt>false</tt> to hide the root node (defaults to <tt>true</tt>)
- * @cfg {Boolean} lines <tt>false</tt> to disable tree lines (defaults to <tt>true</tt>)
- * @cfg {Boolean} enableDD <tt>true</tt> to enable drag and drop
- * @cfg {Boolean} enableDrag <tt>true</tt> to enable just drag
- * @cfg {Boolean} enableDrop <tt>true</tt> to enable just drop
- * @cfg {Object} dragConfig Custom config to pass to the {@link Ext.tree.TreeDragZone} instance
- * @cfg {Object} dropConfig Custom config to pass to the {@link Ext.tree.TreeDropZone} instance
- * @cfg {String} ddGroup The DD group this TreePanel belongs to
- * @cfg {Boolean} ddAppendOnly <tt>true</tt> if the tree should only allow append drops (use for trees which are sorted)
- * @cfg {Boolean} ddScroll <tt>true</tt> to enable body scrolling
- * @cfg {Boolean} containerScroll <tt>true</tt> to register this container with ScrollManager
- * @cfg {Boolean} hlDrop <tt>false</tt> to disable node highlight on drop (defaults to the value of {@link Ext#enableFx})
- * @cfg {String} hlColor The color of the node highlight (defaults to <tt>'C3DAF9'</tt>)
- * @cfg {Boolean} animate <tt>true</tt> to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx})
- * @cfg {Boolean} singleExpand <tt>true</tt> if only 1 node per branch may be expanded
- * @cfg {Object} selModel A tree selection model to use with this TreePanel (defaults to an {@link Ext.tree.DefaultSelectionModel})
- * @cfg {Boolean} trackMouseOver <tt>false</tt> to disable mouse over highlighting
- * @cfg {Ext.tree.TreeLoader} loader A {@link Ext.tree.TreeLoader} for use with this TreePanel
- * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to <tt>'/'</tt>)
- * @cfg {Boolean} useArrows <tt>true</tt> to use Vista-style arrows in the tree (defaults to <tt>false</tt>)
- * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
- *
- * @constructor
- * @param {Object} config
- * @xtype treepanel
- */
- Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
- rootVisible : true,
- animate: Ext.enableFx,
- lines : true,
- enableDD : false,
- hlDrop : Ext.enableFx,
- pathSeparator: "/",
- initComponent : function(){
- Ext.tree.TreePanel.superclass.initComponent.call(this);
- if(!this.eventModel){
- this.eventModel = new Ext.tree.TreeEventModel(this);
- }
- // initialize the loader
- var l = this.loader;
- if(!l){
- l = new Ext.tree.TreeLoader({
- dataUrl: this.dataUrl,
- requestMethod: this.requestMethod
- });
- }else if(typeof l == 'object' && !l.load){
- l = new Ext.tree.TreeLoader(l);
- }
- this.loader = l;
- this.nodeHash = {};
- /**
- * The root node of this tree.
- * @type Ext.tree.TreeNode
- * @property root
- */
- if(this.root){
- var r = this.root;
- delete this.root;
- this.setRootNode(r);
- }
- this.addEvents(
- /**
- * @event append
- * Fires when a new child node is appended to a node in this tree.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The newly appended node
- * @param {Number} index The index of the newly appended node
- */
- "append",
- /**
- * @event remove
- * Fires when a child node is removed from a node in this tree.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node removed
- */
- "remove",
- /**
- * @event movenode
- * Fires when a node is moved to a new location in the tree
- * @param {Tree} tree The owner tree
- * @param {Node} node The node moved
- * @param {Node} oldParent The old parent of this node
- * @param {Node} newParent The new parent of this node
- * @param {Number} index The index it was moved to
- */
- "movenode",
- /**
- * @event insert
- * Fires when a new child node is inserted in a node in this tree.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node inserted
- * @param {Node} refNode The child node the node was inserted before
- */
- "insert",
- /**
- * @event beforeappend
- * Fires before a new child is appended to a node in this tree, return false to cancel the append.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node to be appended
- */
- "beforeappend",
- /**
- * @event beforeremove
- * Fires before a child is removed from a node in this tree, return false to cancel the remove.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node to be removed
- */
- "beforeremove",
- /**
- * @event beforemovenode
- * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
- * @param {Tree} tree The owner tree
- * @param {Node} node The node being moved
- * @param {Node} oldParent The parent of the node
- * @param {Node} newParent The new parent the node is moving to
- * @param {Number} index The index it is being moved to
- */
- "beforemovenode",
- /**
- * @event beforeinsert
- * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node to be inserted
- * @param {Node} refNode The child node the node is being inserted before
- */
- "beforeinsert",
- /**
- * @event beforeload
- * Fires before a node is loaded, return false to cancel
- * @param {Node} node The node being loaded
- */
- "beforeload",
- /**
- * @event load
- * Fires when a node is loaded
- * @param {Node} node The node that was loaded
- */
- "load",
- /**
- * @event textchange
- * Fires when the text for a node is changed
- * @param {Node} node The node
- * @param {String} text The new text
- * @param {String} oldText The old text
- */
- "textchange",
- /**
- * @event beforeexpandnode
- * Fires before a node is expanded, return false to cancel.
- * @param {Node} node The node
- * @param {Boolean} deep
- * @param {Boolean} anim
- */
- "beforeexpandnode",
- /**
- * @event beforecollapsenode
- * Fires before a node is collapsed, return false to cancel.
- * @param {Node} node The node
- * @param {Boolean} deep
- * @param {Boolean} anim
- */
- "beforecollapsenode",
- /**
- * @event expandnode
- * Fires when a node is expanded
- * @param {Node} node The node
- */
- "expandnode",
- /**
- * @event disabledchange
- * Fires when the disabled status of a node changes
- * @param {Node} node The node
- * @param {Boolean} disabled
- */
- "disabledchange",
- /**
- * @event collapsenode
- * Fires when a node is collapsed
- * @param {Node} node The node
- */
- "collapsenode",
- /**
- * @event beforeclick
- * Fires before click processing on a node. Return false to cancel the default action.
- * @param {Node} node The node
- * @param {Ext.EventObject} e The event object
- */
- "beforeclick",
- /**
- * @event click
- * Fires when a node is clicked
- * @param {Node} node The node
- * @param {Ext.EventObject} e The event object
- */
- "click",
- /**
- * @event checkchange
- * Fires when a node with a checkbox's checked property changes
- * @param {Node} this This node
- * @param {Boolean} checked
- */
- "checkchange",
- /**
- * @event dblclick
- * Fires when a node is double clicked
- * @param {Node} node The node
- * @param {Ext.EventObject} e The event object
- */
- "dblclick",
- /**
- * @event contextmenu
- * Fires when a node is right clicked. To display a context menu in response to this
- * event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add
- * a handler for this event:<pre><code>
- new Ext.tree.TreePanel({
- title: 'My TreePanel',
- root: new Ext.tree.AsyncTreeNode({
- text: 'The Root',
- children: [
- { text: 'Child node 1', leaf: true },
- { text: 'Child node 2', leaf: true }
- ]
- }),
- contextMenu: new Ext.menu.Menu({
- items: [{
- id: 'delete-node',
- text: 'Delete Node'
- }],
- listeners: {
- itemclick: function(item) {
- switch (item.id) {
- case 'delete-node':
- var n = item.parentMenu.contextNode;
- if (n.parentNode) {
- n.remove();
- }
- break;
- }
- }
- }
- }),
- listeners: {
- contextmenu: function(node, e) {
- // Register the context node with the menu so that a Menu Item's handler function can access
- // it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.
- node.select();
- var c = node.getOwnerTree().contextMenu;
- c.contextNode = node;
- c.showAt(e.getXY());
- }
- }
- });
- </code></pre>
- * @param {Node} node The node
- * @param {Ext.EventObject} e The event object
- */
- "contextmenu",
- /**
- * @event beforechildrenrendered
- * Fires right before the child nodes for a node are rendered
- * @param {Node} node The node
- */
- "beforechildrenrendered",
- /**
- * @event startdrag
- * Fires when a node starts being dragged
- * @param {Ext.tree.TreePanel} this
- * @param {Ext.tree.TreeNode} node
- * @param {event} e The raw browser event
- */
- "startdrag",
- /**
- * @event enddrag
- * Fires when a drag operation is complete
- * @param {Ext.tree.TreePanel} this
- * @param {Ext.tree.TreeNode} node
- * @param {event} e The raw browser event
- */
- "enddrag",
- /**
- * @event dragdrop
- * Fires when a dragged node is dropped on a valid DD target
- * @param {Ext.tree.TreePanel} this
- * @param {Ext.tree.TreeNode} node
- * @param {DD} dd The dd it was dropped on
- * @param {event} e The raw browser event
- */
- "dragdrop",
- /**
- * @event beforenodedrop
- * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
- * passed to handlers has the following properties:<br />
- * <ul style="padding:5px;padding-left:16px;">
- * <li>tree - The TreePanel</li>
- * <li>target - The node being targeted for the drop</li>
- * <li>data - The drag data from the drag source</li>
- * <li>point - The point of the drop - append, above or below</li>
- * <li>source - The drag source</li>
- * <li>rawEvent - Raw mouse event</li>
- * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
- * to be inserted by setting them on this object.</li>
- * <li>cancel - Set this to true to cancel the drop.</li>
- * <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true
- * will prevent the animated "repair" from appearing.</li>
- * </ul>
- * @param {Object} dropEvent
- */
- "beforenodedrop",
- /**
- * @event nodedrop
- * Fires after a DD object is dropped on a node in this tree. The dropEvent
- * passed to handlers has the following properties:<br />
- * <ul style="padding:5px;padding-left:16px;">
- * <li>tree - The TreePanel</li>
- * <li>target - The node being targeted for the drop</li>
- * <li>data - The drag data from the drag source</li>
- * <li>point - The point of the drop - append, above or below</li>
- * <li>source - The drag source</li>
- * <li>rawEvent - Raw mouse event</li>
- * <li>dropNode - Dropped node(s).</li>
- * </ul>
- * @param {Object} dropEvent
- */
- "nodedrop",
- /**
- * @event nodedragover
- * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
- * passed to handlers has the following properties:<br />
- * <ul style="padding:5px;padding-left:16px;">
- * <li>tree - The TreePanel</li>
- * <li>target - The node being targeted for the drop</li>
- * <li>data - The drag data from the drag source</li>
- * <li>point - The point of the drop - append, above or below</li>
- * <li>source - The drag source</li>
- * <li>rawEvent - Raw mouse event</li>
- * <li>dropNode - Drop node(s) provided by the source.</li>
- * <li>cancel - Set this to true to signal drop not allowed.</li>
- * </ul>
- * @param {Object} dragOverEvent
- */
- "nodedragover"
- );
- if(this.singleExpand){
- this.on("beforeexpandnode", this.restrictExpand, this);
- }
- },
- // private
- proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){
- if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){
- ename = ename+'node';
- }
- // args inline for performance while bubbling events
- return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);
- },
- /**
- * Returns this root node for this tree
- * @return {Node}
- */
- getRootNode : function(){
- return this.root;
- },
- /**
- * Sets the root node for this tree. If the TreePanel has already rendered a root node, the
- * previous root node (and all of its descendants) are destroyed before the new root node is rendered.
- * @param {Node} node
- * @return {Node}
- */
- setRootNode : function(node){
- Ext.destroy(this.root);
- if(!node.render){ // attributes passed
- node = this.loader.createNode(node);
- }
- this.root = node;
- node.ownerTree = this;
- node.isRoot = true;
- this.registerNode(node);
- if(!this.rootVisible){
- var uiP = node.attributes.uiProvider;
- node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);
- }
- if (this.innerCt) {
- this.innerCt.update('');
- this.afterRender();
- }
- return node;
- },
- /**
- * Gets a node in this tree by its id
- * @param {String} id
- * @return {Node}
- */
- getNodeById : function(id){
- return this.nodeHash[id];
- },
- // private
- registerNode : function(node){
- this.nodeHash[node.id] = node;
- },
- // private
- unregisterNode : function(node){
- delete this.nodeHash[node.id];
- },
- // private
- toString : function(){
- return "[Tree"+(this.id?" "+this.id:"")+"]";
- },
- // private
- restrictExpand : function(node){
- var p = node.parentNode;
- if(p){
- if(p.expandedChild && p.expandedChild.parentNode == p){
- p.expandedChild.collapse();
- }
- p.expandedChild = node;
- }
- },
- /**
- * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
- * @param {String} attribute (optional) Defaults to null (return the actual nodes)
- * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
- * @return {Array}
- */
- getChecked : function(a, startNode){
- startNode = startNode || this.root;
- var r = [];
- var f = function(){
- if(this.attributes.checked){
- r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
- }
- };
- startNode.cascade(f);
- return r;
- },
- /**
- * Returns the container element for this TreePanel.
- * @return {Element} The container element for this TreePanel.
- */
- getEl : function(){
- return this.el;
- },
- /**
- * Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.
- * @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.
- */
- getLoader : function(){
- return this.loader;
- },
- /**
- * Expand all nodes
- */
- expandAll : function(){
- this.root.expand(true);
- },
- /**
- * Collapse all nodes
- */
- collapseAll : function(){
- this.root.collapse(true);
- },
- /**
- * Returns the selection model used by this TreePanel.
- * @return {TreeSelectionModel} The selection model used by this TreePanel
- */
- getSelectionModel : function(){
- if(!this.selModel){
- this.selModel = new Ext.tree.DefaultSelectionModel();
- }
- return this.selModel;
- },
- /**
- * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
- * @param {String} path
- * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
- * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
- * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
- */
- expandPath : function(path, attr, callback){
- attr = attr || "id";
- var keys = path.split(this.pathSeparator);
- var curNode = this.root;
- if(curNode.attributes[attr] != keys[1]){ // invalid root
- if(callback){
- callback(false, null);
- }
- return;
- }
- var index = 1;
- var f = function(){
- if(++index == keys.length){
- if(callback){
- callback(true, curNode);
- }
- return;
- }
- var c = curNode.findChild(attr, keys[index]);
- if(!c){
- if(callback){
- callback(false, curNode);
- }
- return;
- }
- curNode = c;
- c.expand(false, false, f);
- };
- curNode.expand(false, false, f);
- },
- /**
- * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
- * @param {String} path
- * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
- * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
- * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
- */
- selectPath : function(path, attr, callback){
- attr = attr || "id";
- var keys = path.split(this.pathSeparator);
- var v = keys.pop();
- if(keys.length > 0){
- var f = function(success, node){
- if(success && node){
- var n = node.findChild(attr, v);
- if(n){
- n.select();
- if(callback){
- callback(true, n);
- }
- }else if(callback){
- callback(false, n);
- }
- }else{
- if(callback){
- callback(false, n);
- }
- }
- };
- this.expandPath(keys.join(this.pathSeparator), attr, f);
- }else{
- this.root.select();
- if(callback){
- callback(true, this.root);
- }
- }
- },
- /**
- * Returns the underlying Element for this tree
- * @return {Ext.Element} The Element
- */
- getTreeEl : function(){
- return this.body;
- },
- // private
- onRender : function(ct, position){
- Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
- this.el.addClass('x-tree');
- this.innerCt = this.body.createChild({tag:"ul",
- cls:"x-tree-root-ct " +
- (this.useArrows ? 'x-tree-arrows' : this.lines ? "x-tree-lines" : "x-tree-no-lines")});
- },
- // private
- initEvents : function(){
- Ext.tree.TreePanel.superclass.initEvents.call(this);
- if(this.containerScroll){
- Ext.dd.ScrollManager.register(this.body);
- }
- if((this.enableDD || this.enableDrop) && !this.dropZone){
- /**
- * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
- * @property dropZone
- * @type Ext.tree.TreeDropZone
- */
- this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
- ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
- });
- }
- if((this.enableDD || this.enableDrag) && !this.dragZone){
- /**
- * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
- * @property dragZone
- * @type Ext.tree.TreeDragZone
- */
- this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
- ddGroup: this.ddGroup || "TreeDD",
- scroll: this.ddScroll
- });
- }
- this.getSelectionModel().init(this);
- },
- // private
- afterRender : function(){
- Ext.tree.TreePanel.superclass.afterRender.call(this);
- this.root.render();
- if(!this.rootVisible){
- this.root.renderChildren();
- }
- },
- onDestroy : function(){
- if(this.rendered){
- this.body.removeAllListeners();
- Ext.dd.ScrollManager.unregister(this.body);
- if(this.dropZone){
- this.dropZone.unreg();
- }
- if(this.dragZone){
- this.dragZone.unreg();
- }
- }
- this.root.destroy();
- this.nodeHash = null;
- Ext.tree.TreePanel.superclass.onDestroy.call(this);
- }
- /**
- * @cfg {String/Number} activeItem
- * @hide
- */
- /**
- * @cfg {Boolean} autoDestroy
- * @hide
- */
- /**
- * @cfg {Object/String/Function} autoLoad
- * @hide
- */
- /**
- * @cfg {Boolean} autoWidth
- * @hide
- */
- /**
- * @cfg {Boolean/Number} bufferResize
- * @hide
- */
- /**
- * @cfg {String} defaultType
- * @hide
- */
- /**
- * @cfg {Object} defaults
- * @hide
- */
- /**
- * @cfg {Boolean} hideBorders
- * @hide
- */
- /**
- * @cfg {Mixed} items
- * @hide
- */
- /**
- * @cfg {String} layout
- * @hide
- */
- /**
- * @cfg {Object} layoutConfig
- * @hide
- */
- /**
- * @cfg {Boolean} monitorResize
- * @hide
- */
- /**
- * @property items
- * @hide
- */
- /**
- * @method cascade
- * @hide
- */
- /**
- * @method doLayout
- * @hide
- */
- /**
- * @method find
- * @hide
- */
- /**
- * @method findBy
- * @hide
- */
- /**
- * @method findById
- * @hide
- */
- /**
- * @method findByType
- * @hide
- */
- /**
- * @method getComponent
- * @hide
- */
- /**
- * @method getLayout
- * @hide
- */
- /**
- * @method getUpdater
- * @hide
- */
- /**
- * @method insert
- * @hide
- */
- /**
- * @method load
- * @hide
- */
- /**
- * @method remove
- * @hide
- */
- /**
- * @event add
- * @hide
- */
- /**
- * @method removeAll
- * @hide
- */
- /**
- * @event afterLayout
- * @hide
- */
- /**
- * @event beforeadd
- * @hide
- */
- /**
- * @event beforeremove
- * @hide
- */
- /**
- * @event remove
- * @hide
- */
- /**
- * @cfg {String} allowDomMove @hide
- */
- /**
- * @cfg {String} autoEl @hide
- */
- /**
- * @cfg {String} applyTo @hide
- */
- /**
- * @cfg {String} contentEl @hide
- */
- /**
- * @cfg {String} disabledClass @hide
- */
- /**
- * @cfg {String} elements @hide
- */
- /**
- * @cfg {String} html @hide
- */
- /**
- * @cfg {Boolean} preventBodyReset
- * @hide
- */
- /**
- * @property disabled
- * @hide
- */
- /**
- * @method applyToMarkup
- * @hide
- */
- /**
- * @method enable
- * @hide
- */
- /**
- * @method disable
- * @hide
- */
- /**
- * @method setDisabled
- * @hide
- */
- });
- Ext.tree.TreePanel.nodeTypes = {};
- Ext.reg('treepanel', Ext.tree.TreePanel);Ext.tree.TreeEventModel = function(tree){
- this.tree = tree;
- this.tree.on('render', this.initEvents, this);
- }
- Ext.tree.TreeEventModel.prototype = {
- initEvents : function(){
- var el = this.tree.getTreeEl();
- el.on('click', this.delegateClick, this);
- if(this.tree.trackMouseOver !== false){
- this.tree.innerCt.on('mouseover', this.delegateOver, this);
- this.tree.innerCt.on('mouseout', this.delegateOut, this);
- }
- el.on('dblclick', this.delegateDblClick, this);
- el.on('contextmenu', this.delegateContextMenu, this);
- },
- getNode : function(e){
- var t;
- if(t = e.getTarget('.x-tree-node-el', 10)){
- var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
- if(id){
- return this.tree.getNodeById(id);
- }
- }
- return null;
- },
- getNodeTarget : function(e){
- var t = e.getTarget('.x-tree-node-icon', 1);
- if(!t){
- t = e.getTarget('.x-tree-node-el', 6);
- }
- return t;
- },
- delegateOut : function(e, t){
- if(!this.beforeEvent(e)){
- return;
- }
- if(e.getTarget('.x-tree-ec-icon', 1)){
- var n = this.getNode(e);
- this.onIconOut(e, n);
- if(n == this.lastEcOver){
- delete this.lastEcOver;
- }
- }
- if((t = this.getNodeTarget(e)) && !e.within(t, true)){
- this.onNodeOut(e, this.getNode(e));
- }
- },
- delegateOver : function(e, t){
- if(!this.beforeEvent(e)){
- return;
- }
- if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
- Ext.getBody().on('mouseover', this.trackExit, this);
- this.trackingDoc = true;
- }
- if(this.lastEcOver){ // prevent hung highlight
- this.onIconOut(e, this.lastEcOver);
- delete this.lastEcOver;
- }
- if(e.getTarget('.x-tree-ec-icon', 1)){
- this.lastEcOver = this.getNode(e);
- this.onIconOver(e, this.lastEcOver);
- }
- if(t = this.getNodeTarget(e)){
- this.onNodeOver(e, this.getNode(e));
- }
- },
- trackExit : function(e){
- if(this.lastOverNode && !e.within(this.lastOverNode.ui.getEl())){
- this.onNodeOut(e, this.lastOverNode);
- delete this.lastOverNode;
- Ext.getBody().un('mouseover', this.trackExit, this);
- this.trackingDoc = false;
- }
- },
- delegateClick : function(e, t){
- if(!this.beforeEvent(e)){
- return;
- }
- if(e.getTarget('input[type=checkbox]', 1)){
- this.onCheckboxClick(e, this.getNode(e));
- }
- else if(e.getTarget('.x-tree-ec-icon', 1)){
- this.onIconClick(e, this.getNode(e));
- }
- else if(this.getNodeTarget(e)){
- this.onNodeClick(e, this.getNode(e));
- }
- },
- delegateDblClick : function(e, t){
- if(this.beforeEvent(e) && this.getNodeTarget(e)){
- this.onNodeDblClick(e, this.getNode(e));
- }
- },
- delegateContextMenu : function(e, t){
- if(this.beforeEvent(e) && this.getNodeTarget(e)){
- this.onNodeContextMenu(e, this.getNode(e));
- }
- },
- onNodeClick : function(e, node){
- node.ui.onClick(e);
- },
- onNodeOver : function(e, node){
- this.lastOverNode = node;
- node.ui.onOver(e);
- },
- onNodeOut : function(e, node){
- node.ui.onOut(e);
- },
- onIconOver : function(e, node){
- node.ui.addClass('x-tree-ec-over');
- },
- onIconOut : function(e, node){
- node.ui.removeClass('x-tree-ec-over');
- },
- onIconClick : function(e, node){
- node.ui.ecClick(e);
- },
- onCheckboxClick : function(e, node){
- node.ui.onCheckChange(e);
- },
- onNodeDblClick : function(e, node){
- node.ui.onDblClick(e);
- },
- onNodeContextMenu : function(e, node){
- node.ui.onContextMenu(e);
- },
- beforeEvent : function(e){
- if(this.disabled){
- e.stopEvent();
- return false;
- }
- return true;
- },
- disable: function(){
- this.disabled = true;
- },
- enable: function(){
- this.disabled = false;
- }
- };/**
- * @class Ext.tree.DefaultSelectionModel
- * @extends Ext.util.Observable
- * The default single selection for a TreePanel.
- */
- Ext.tree.DefaultSelectionModel = function(config){
- this.selNode = null;
- this.addEvents(
- /**
- * @event selectionchange
- * Fires when the selected node changes
- * @param {DefaultSelectionModel} this
- * @param {TreeNode} node the new selection
- */
- "selectionchange",
- /**
- * @event beforeselect
- * Fires before the selected node changes, return false to cancel the change
- * @param {DefaultSelectionModel} this
- * @param {TreeNode} node the new selection
- * @param {TreeNode} node the old selection
- */
- "beforeselect"
- );
- Ext.apply(this, config);
- Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
- };
- Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {
- init : function(tree){
- this.tree = tree;
- tree.getTreeEl().on("keydown", this.onKeyDown, this);
- tree.on("click", this.onNodeClick, this);
- },
- onNodeClick : function(node, e){
- this.select(node);
- },
- /**
- * Select a node.
- * @param {TreeNode} node The node to select
- * @return {TreeNode} The selected node
- */
- select : function(node){
- var last = this.selNode;
- if(node == last){
- node.ui.onSelectedChange(true);
- }else if(this.fireEvent('beforeselect', this, node, last) !== false){
- if(last){
- last.ui.onSelectedChange(false);
- }
- this.selNode = node;
- node.ui.onSelectedChange(true);
- this.fireEvent("selectionchange", this, node, last);
- }
- return node;
- },
- /**
- * Deselect a node.
- * @param {TreeNode} node The node to unselect
- */
- unselect : function(node){
- if(this.selNode == node){
- this.clearSelections();
- }
- },
- /**
- * Clear all selections
- */
- clearSelections : function(){
- var n = this.selNode;
- if(n){
- n.ui.onSelectedChange(false);
- this.selNode = null;
- this.fireEvent("selectionchange", this, null);
- }
- return n;
- },
- /**
- * Get the selected node
- * @return {TreeNode} The selected node
- */
- getSelectedNode : function(){
- return this.selNode;
- },
- /**
- * Returns true if the node is selected
- * @param {TreeNode} node The node to check
- * @return {Boolean}
- */
- isSelected : function(node){
- return this.selNode == node;
- },
- /**
- * Selects the node above the selected node in the tree, intelligently walking the nodes
- * @return TreeNode The new selection
- */
- selectPrevious : function(){
- var s = this.selNode || this.lastSelNode;
- if(!s){
- return null;
- }
- var ps = s.previousSibling;
- if(ps){
- if(!ps.isExpanded() || ps.childNodes.length < 1){
- return this.select(ps);
- } else{
- var lc = ps.lastChild;
- while(lc && lc.isExpanded() && lc.childNodes.length > 0){
- lc = lc.lastChild;
- }
- return this.select(lc);
- }
- } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
- return this.select(s.parentNode);
- }
- return null;
- },
- /**
- * Selects the node above the selected node in the tree, intelligently walking the nodes
- * @return TreeNode The new selection
- */
- selectNext : function(){
- var s = this.selNode || this.lastSelNode;
- if(!s){
- return null;
- }
- if(s.firstChild && s.isExpanded()){
- return this.select(s.firstChild);
- }else if(s.nextSibling){
- return this.select(s.nextSibling);
- }else if(s.parentNode){
- var newS = null;
- s.parentNode.bubble(function(){
- if(this.nextSibling){
- newS = this.getOwnerTree().selModel.select(this.nextSibling);
- return false;
- }
- });
- return newS;
- }
- return null;
- },
- onKeyDown : function(e){
- var s = this.selNode || this.lastSelNode;
- // undesirable, but required
- var sm = this;
- if(!s){
- return;
- }
- var k = e.getKey();
- switch(k){
- case e.DOWN:
- e.stopEvent();
- this.selectNext();
- break;
- case e.UP:
- e.stopEvent();
- this.selectPrevious();
- break;
- case e.RIGHT:
- e.preventDefault();
- if(s.hasChildNodes()){
- if(!s.isExpanded()){
- s.expand();
- }else if(s.firstChild){
- this.select(s.firstChild, e);
- }
- }
- break;
- case e.LEFT:
- e.preventDefault();
- if(s.hasChildNodes() && s.isExpanded()){
- s.collapse();
- }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
- this.select(s.parentNode, e);
- }
- break;
- };
- }
- });
- /**
- * @class Ext.tree.MultiSelectionModel
- * @extends Ext.util.Observable
- * Multi selection for a TreePanel.
- */
- Ext.tree.MultiSelectionModel = function(config){
- this.selNodes = [];
- this.selMap = {};
- this.addEvents(
- /**
- * @event selectionchange
- * Fires when the selected nodes change
- * @param {MultiSelectionModel} this
- * @param {Array} nodes Array of the selected nodes
- */
- "selectionchange"
- );
- Ext.apply(this, config);
- Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
- };
- Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {
- init : function(tree){
- this.tree = tree;
- tree.getTreeEl().on("keydown", this.onKeyDown, this);
- tree.on("click", this.onNodeClick, this);
- },
- onNodeClick : function(node, e){
- if(e.ctrlKey && this.isSelected(node)){
- this.unselect(node);
- }else{
- this.select(node, e, e.ctrlKey);
- }
- },
- /**
- * Select a node.
- * @param {TreeNode} node The node to select
- * @param {EventObject} e (optional) An event associated with the selection
- * @param {Boolean} keepExisting True to retain existing selections
- * @return {TreeNode} The selected node
- */
- select : function(node, e, keepExisting){
- if(keepExisting !== true){
- this.clearSelections(true);
- }
- if(this.isSelected(node)){
- this.lastSelNode = node;
- return node;
- }
- this.selNodes.push(node);
- this.selMap[node.id] = node;
- this.lastSelNode = node;
- node.ui.onSelectedChange(true);
- this.fireEvent("selectionchange", this, this.selNodes);
- return node;
- },
- /**
- * Deselect a node.
- * @param {TreeNode} node The node to unselect
- */
- unselect : function(node){
- if(this.selMap[node.id]){
- node.ui.onSelectedChange(false);
- var sn = this.selNodes;
- var index = sn.indexOf(node);
- if(index != -1){
- this.selNodes.splice(index, 1);
- }
- delete this.selMap[node.id];
- this.fireEvent("selectionchange", this, this.selNodes);
- }
- },
- /**
- * Clear all selections
- */
- clearSelections : function(suppressEvent){
- var sn = this.selNodes;
- if(sn.length > 0){
- for(var i = 0, len = sn.length; i < len; i++){
- sn[i].ui.onSelectedChange(false);
- }
- this.selNodes = [];
- this.selMap = {};
- if(suppressEvent !== true){
- this.fireEvent("selectionchange", this, this.selNodes);
- }
- }
- },
- /**
- * Returns true if the node is selected
- * @param {TreeNode} node The node to check
- * @return {Boolean}
- */
- isSelected : function(node){
- return this.selMap[node.id] ? true : false;
- },
- /**
- * Returns an array of the selected nodes
- * @return {Array}
- */
- getSelectedNodes : function(){
- return this.selNodes;
- },
- onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
- selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
- selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
- });/**
- * @class Ext.data.Tree
- * @extends Ext.util.Observable
- * Represents a tree data structure and bubbles all the events for its nodes. The nodes
- * in the tree have most standard DOM functionality.
- * @constructor
- * @param {Node} root (optional) The root node
- */
- Ext.data.Tree = function(root){
- this.nodeHash = {};
- /**
- * The root node for this tree
- * @type Node
- */
- this.root = null;
- if(root){
- this.setRootNode(root);
- }
- this.addEvents(
- /**
- * @event append
- * Fires when a new child node is appended to a node in this tree.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The newly appended node
- * @param {Number} index The index of the newly appended node
- */
- "append",
- /**
- * @event remove
- * Fires when a child node is removed from a node in this tree.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node removed
- */
- "remove",
- /**
- * @event move
- * Fires when a node is moved to a new location in the tree
- * @param {Tree} tree The owner tree
- * @param {Node} node The node moved
- * @param {Node} oldParent The old parent of this node
- * @param {Node} newParent The new parent of this node
- * @param {Number} index The index it was moved to
- */
- "move",
- /**
- * @event insert
- * Fires when a new child node is inserted in a node in this tree.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node inserted
- * @param {Node} refNode The child node the node was inserted before
- */
- "insert",
- /**
- * @event beforeappend
- * Fires before a new child is appended to a node in this tree, return false to cancel the append.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node to be appended
- */
- "beforeappend",
- /**
- * @event beforeremove
- * Fires before a child is removed from a node in this tree, return false to cancel the remove.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node to be removed
- */
- "beforeremove",
- /**
- * @event beforemove
- * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
- * @param {Tree} tree The owner tree
- * @param {Node} node The node being moved
- * @param {Node} oldParent The parent of the node
- * @param {Node} newParent The new parent the node is moving to
- * @param {Number} index The index it is being moved to
- */
- "beforemove",
- /**
- * @event beforeinsert
- * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
- * @param {Tree} tree The owner tree
- * @param {Node} parent The parent node
- * @param {Node} node The child node to be inserted
- * @param {Node} refNode The child node the node is being inserted before
- */
- "beforeinsert"
- );
- Ext.data.Tree.superclass.constructor.call(this);
- };
- Ext.extend(Ext.data.Tree, Ext.util.Observable, {
- /**
- * @cfg {String} pathSeparator
- * The token used to separate paths in node ids (defaults to '/').
- */
- pathSeparator: "/",
- // private
- proxyNodeEvent : function(){
- return this.fireEvent.apply(this, arguments);
- },
- /**
- * Returns the root node for this tree.
- * @return {Node}
- */
- getRootNode : function(){
- return this.root;
- },
- /**
- * Sets the root node for this tree.
- * @param {Node} node
- * @return {Node}
- */
- setRootNode : function(node){
- this.root = node;
- node.ownerTree = this;
- node.isRoot = true;
- this.registerNode(node);
- return node;
- },
- /**
- * Gets a node in this tree by its id.
- * @param {String} id
- * @return {Node}
- */
- getNodeById : function(id){
- return this.nodeHash[id];
- },
- // private
- registerNode : function(node){
- this.nodeHash[node.id] = node;
- },
- // private
- unregisterNode : function(node){
- delete this.nodeHash[node.id];
- },
- toString : function(){
- return "[Tree"+(this.id?" "+this.id:"")+"]";
- }
- });
- /**
- * @class Ext.data.Node
- * @extends Ext.util.Observable
- * @cfg {Boolean} leaf true if this node is a leaf and does not have children
- * @cfg {String} id The id for this node. If one is not specified, one is generated.
- * @constructor
- * @param {Object} attributes The attributes/config for the node
- */
- Ext.data.Node = function(attributes){
- /**
- * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
- * @type {Object}
- */
- this.attributes = attributes || {};
- this.leaf = this.attributes.leaf;
- /**
- * The node id. @type String
- */
- this.id = this.attributes.id;
- if(!this.id){
- this.id = Ext.id(null, "xnode-");
- this.attributes.id = this.id;
- }
- /**
- * All child nodes of this node. @type Array
- */
- this.childNodes = [];
- if(!this.childNodes.indexOf){ // indexOf is a must
- this.childNodes.indexOf = function(o){
- for(var i = 0, len = this.length; i < len; i++){
- if(this[i] == o){
- return i;
- }
- }
- return -1;
- };
- }
- /**
- * The parent node for this node. @type Node
- */
- this.parentNode = null;
- /**
- * The first direct child node of this node, or null if this node has no child nodes. @type Node
- */
- this.firstChild = null;
- /**
- * The last direct child node of this node, or null if this node has no child nodes. @type Node
- */
- this.lastChild = null;
- /**
- * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
- */
- this.previousSibling = null;
- /**
- * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
- */
- this.nextSibling = null;
- this.addEvents({
- /**
- * @event append
- * Fires when a new child node is appended
- * @param {Tree} tree The owner tree
- * @param {Node} this This node
- * @param {Node} node The newly appended node
- * @param {Number} index The index of the newly appended node
- */
- "append" : true,
- /**
- * @event remove
- * Fires when a child node is removed
- * @param {Tree} tree The owner tree
- * @param {Node} this This node
- * @param {Node} node The removed node
- */
- "remove" : true,
- /**
- * @event move
- * Fires when this node is moved to a new location in the tree
- * @param {Tree} tree The owner tree
- * @param {Node} this This node
- * @param {Node} oldParent The old parent of this node
- * @param {Node} newParent The new parent of this node
- * @param {Number} index The index it was moved to
- */
- "move" : true,
- /**
- * @event insert
- * Fires when a new child node is inserted.
- * @param {Tree} tree The owner tree
- * @param {Node} this This node
- * @param {Node} node The child node inserted
- * @param {Node} refNode The child node the node was inserted before
- */
- "insert" : true,
- /**
- * @event beforeappend
- * Fires before a new child is appended, return false to cancel the append.
- * @param {Tree} tree The owner tree
- * @param {Node} this This node
- * @param {Node} node The child node to be appended
- */
- "beforeappend" : true,
- /**
- * @event beforeremove
- * Fires before a child is removed, return false to cancel the remove.
- * @param {Tree} tree The owner tree
- * @param {Node} this This node
- * @param {Node} node The child node to be removed
- */
- "beforeremove" : true,
- /**
- * @event beforemove
- * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
- * @param {Tree} tree The owner tree
- * @param {Node} this This node
- * @param {Node} oldParent The parent of this node
- * @param {Node} newParent The new parent this node is moving to
- * @param {Number} index The index it is being moved to
- */
- "beforemove" : true,
- /**
- * @event beforeinsert
- * Fires before a new child is inserted, return false to cancel the insert.
- * @param {Tree} tree The owner tree
- * @param {Node} this This node
- * @param {Node} node The child node to be inserted
- * @param {Node} refNode The child node the node is being inserted before
- */
- "beforeinsert" : true
- });
- this.listeners = this.attributes.listeners;
- Ext.data.Node.superclass.constructor.call(this);
- };
- Ext.extend(Ext.data.Node, Ext.util.Observable, {
- // private
- fireEvent : function(evtName){
- // first do standard event for this node
- if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){
- return false;
- }
- // then bubble it up to the tree if the event wasn't cancelled
- var ot = this.getOwnerTree();
- if(ot){
- if(ot.proxyNodeEvent.apply(ot, arguments) === false){
- return false;
- }
- }
- return true;
- },
- /**
- * Returns true if this node is a leaf
- * @return {Boolean}
- */
- isLeaf : function(){
- return this.leaf === true;
- },
- // private
- setFirstChild : function(node){
- this.firstChild = node;
- },
- //private
- setLastChild : function(node){
- this.lastChild = node;
- },
- /**
- * Returns true if this node is the last child of its parent
- * @return {Boolean}
- */
- isLast : function(){
- return (!this.parentNode ? true : this.parentNode.lastChild == this);
- },
- /**
- * Returns true if this node is the first child of its parent
- * @return {Boolean}
- */
- isFirst : function(){
- return (!this.parentNode ? true : this.parentNode.firstChild == this);
- },
- /**
- * Returns true if this node has one or more child nodes, else false.
- * @return {Boolean}
- */
- hasChildNodes : function(){
- return !this.isLeaf() && this.childNodes.length > 0;
- },
- /**
- * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>
- * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
- * @return {Boolean}
- */
- isExpandable : function(){
- return this.attributes.expandable || this.hasChildNodes();
- },
- /**
- * Insert node(s) as the last child node of this node.
- * @param {Node/Array} node The node or Array of nodes to append
- * @return {Node} The appended node if single append, or null if an array was passed
- */
- appendChild : function(node){
- var multi = false;
- if(Ext.isArray(node)){
- multi = node;
- }else if(arguments.length > 1){
- multi = arguments;
- }
- // if passed an array or multiple args do them one by one
- if(multi){
- for(var i = 0, len = multi.length; i < len; i++) {
- this.appendChild(multi[i]);
- }
- }else{
- if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
- return false;
- }
- var index = this.childNodes.length;
- var oldParent = node.parentNode;
- // it's a move, make sure we move it cleanly
- if(oldParent){
- if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
- return false;
- }
- oldParent.removeChild(node);
- }
- index = this.childNodes.length;
- if(index === 0){
- this.setFirstChild(node);
- }
- this.childNodes.push(node);
- node.parentNode = this;
- var ps = this.childNodes[index-1];
- if(ps){
- node.previousSibling = ps;
- ps.nextSibling = node;
- }else{
- node.previousSibling = null;
- }
- node.nextSibling = null;
- this.setLastChild(node);
- node.setOwnerTree(this.getOwnerTree());
- this.fireEvent("append", this.ownerTree, this, node, index);
- if(oldParent){
- node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
- }
- return node;
- }
- },
- /**
- * Removes a child node from this node.
- * @param {Node} node The node to remove
- * @return {Node} The removed node
- */
- removeChild : function(node){
- var index = this.childNodes.indexOf(node);
- if(index == -1){
- return false;
- }
- if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
- return false;
- }
- // remove it from childNodes collection
- this.childNodes.splice(index, 1);
- // update siblings
- if(node.previousSibling){
- node.previousSibling.nextSibling = node.nextSibling;
- }
- if(node.nextSibling){
- node.nextSibling.previousSibling = node.previousSibling;
- }
- // update child refs
- if(this.firstChild == node){
- this.setFirstChild(node.nextSibling);
- }
- if(this.lastChild == node){
- this.setLastChild(node.previousSibling);
- }
- node.setOwnerTree(null);
- // clear any references from the node
- node.parentNode = null;
- node.previousSibling = null;
- node.nextSibling = null;
- this.fireEvent("remove", this.ownerTree, this, node);
- return node;
- },
- /**
- * Inserts the first node before the second node in this nodes childNodes collection.
- * @param {Node} node The node to insert
- * @param {Node} refNode The node to insert before (if null the node is appended)
- * @return {Node} The inserted node
- */
- insertBefore : function(node, refNode){
- if(!refNode){ // like standard Dom, refNode can be null for append
- return this.appendChild(node);
- }
- // nothing to do
- if(node == refNode){
- return false;
- }
- if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
- return false;
- }
- var index = this.childNodes.indexOf(refNode);
- var oldParent = node.parentNode;
- var refIndex = index;
- // when moving internally, indexes will change after remove
- if(oldParent == this && this.childNodes.indexOf(node) < index){
- refIndex--;
- }
- // it's a move, make sure we move it cleanly
- if(oldParent){
- if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
- return false;
- }
- oldParent.removeChild(node);
- }
- if(refIndex === 0){
- this.setFirstChild(node);
- }
- this.childNodes.splice(refIndex, 0, node);
- node.parentNode = this;
- var ps = this.childNodes[refIndex-1];
- if(ps){
- node.previousSibling = ps;
- ps.nextSibling = node;
- }else{
- node.previousSibling = null;
- }
- node.nextSibling = refNode;
- refNode.previousSibling = node;
- node.setOwnerTree(this.getOwnerTree());
- this.fireEvent("insert", this.ownerTree, this, node, refNode);
- if(oldParent){
- node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
- }
- return node;
- },
- /**
- * Removes this node from its parent
- * @return {Node} this
- */
- remove : function(){
- this.parentNode.removeChild(this);
- return this;
- },
- /**
- * Returns the child node at the specified index.
- * @param {Number} index
- * @return {Node}
- */
- item : function(index){
- return this.childNodes[index];
- },
- /**
- * Replaces one child node in this node with another.
- * @param {Node} newChild The replacement node
- * @param {Node} oldChild The node to replace
- * @return {Node} The replaced node
- */
- replaceChild : function(newChild, oldChild){
- var s = oldChild ? oldChild.nextSibling : null;
- this.removeChild(oldChild);
- this.insertBefore(newChild, s);
- return oldChild;
- },
- /**
- * Returns the index of a child node
- * @param {Node} node
- * @return {Number} The index of the node or -1 if it was not found
- */
- indexOf : function(child){
- return this.childNodes.indexOf(child);
- },
- /**
- * Returns the tree this node is in.
- * @return {Tree}
- */
- getOwnerTree : function(){
- // if it doesn't have one, look for one
- if(!this.ownerTree){
- var p = this;
- while(p){
- if(p.ownerTree){
- this.ownerTree = p.ownerTree;
- break;
- }
- p = p.parentNode;
- }
- }
- return this.ownerTree;
- },
- /**
- * Returns depth of this node (the root node has a depth of 0)
- * @return {Number}
- */
- getDepth : function(){
- var depth = 0;
- var p = this;
- while(p.parentNode){
- ++depth;
- p = p.parentNode;
- }
- return depth;
- },
- // private
- setOwnerTree : function(tree){
- // if it is a move, we need to update everyone
- if(tree != this.ownerTree){
- if(this.ownerTree){
- this.ownerTree.unregisterNode(this);
- }
- this.ownerTree = tree;
- var cs = this.childNodes;
- for(var i = 0, len = cs.length; i < len; i++) {
- cs[i].setOwnerTree(tree);
- }
- if(tree){
- tree.registerNode(this);
- }
- }
- },
- /**
- * Changes the id of this node.
- * @param {String} id The new id for the node.
- */
- setId: function(id){
- if(id !== this.id){
- var t = this.ownerTree;
- if(t){
- t.unregisterNode(this);
- }
- this.id = id;
- if(t){
- t.registerNode(this);
- }
- this.onIdChange(id);
- }
- },
- // private
- onIdChange: Ext.emptyFn,
- /**
- * Returns the path for this node. The path can be used to expand or select this node programmatically.
- * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
- * @return {String} The path
- */
- getPath : function(attr){
- attr = attr || "id";
- var p = this.parentNode;
- var b = [this.attributes[attr]];
- while(p){
- b.unshift(p.attributes[attr]);
- p = p.parentNode;
- }
- var sep = this.getOwnerTree().pathSeparator;
- return sep + b.join(sep);
- },
- /**
- * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
- * function call will be the scope provided or the current node. The arguments to the function
- * will be the args provided or the current node. If the function returns false at any point,
- * the bubble is stopped.
- * @param {Function} fn The function to call
- * @param {Object} scope (optional) The scope of the function (defaults to current node)
- * @param {Array} args (optional) The args to call the function with (default to passing the current node)
- */
- bubble : function(fn, scope, args){
- var p = this;
- while(p){
- if(fn.apply(scope || p, args || [p]) === false){
- break;
- }
- p = p.parentNode;
- }
- },
- /**
- * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
- * function call will be the scope provided or the current node. The arguments to the function
- * will be the args provided or the current node. If the function returns false at any point,
- * the cascade is stopped on that branch.
- * @param {Function} fn The function to call
- * @param {Object} scope (optional) The scope of the function (defaults to current node)
- * @param {Array} args (optional) The args to call the function with (default to passing the current node)
- */
- cascade : function(fn, scope, args){
- if(fn.apply(scope || this, args || [this]) !== false){
- var cs = this.childNodes;
- for(var i = 0, len = cs.length; i < len; i++) {
- cs[i].cascade(fn, scope, args);
- }
- }
- },
- /**
- * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
- * function call will be the scope provided or the current node. The arguments to the function
- * will be the args provided or the current node. If the function returns false at any point,
- * the iteration stops.
- * @param {Function} fn The function to call
- * @param {Object} scope (optional) The scope of the function (defaults to current node)
- * @param {Array} args (optional) The args to call the function with (default to passing the current node)
- */
- eachChild : function(fn, scope, args){
- var cs = this.childNodes;
- for(var i = 0, len = cs.length; i < len; i++) {
- if(fn.apply(scope || this, args || [cs[i]]) === false){
- break;
- }
- }
- },
- /**
- * Finds the first child that has the attribute with the specified value.
- * @param {String} attribute The attribute name
- * @param {Mixed} value The value to search for
- * @return {Node} The found child or null if none was found
- */
- findChild : function(attribute, value){
- var cs = this.childNodes;
- for(var i = 0, len = cs.length; i < len; i++) {
- if(cs[i].attributes[attribute] == value){
- return cs[i];
- }
- }
- return null;
- },
- /**
- * Finds the first child by a custom function. The child matches if the function passed
- * returns true.
- * @param {Function} fn
- * @param {Object} scope (optional)
- * @return {Node} The found child or null if none was found
- */
- findChildBy : function(fn, scope){
- var cs = this.childNodes;
- for(var i = 0, len = cs.length; i < len; i++) {
- if(fn.call(scope||cs[i], cs[i]) === true){
- return cs[i];
- }
- }
- return null;
- },
- /**
- * Sorts this nodes children using the supplied sort function
- * @param {Function} fn
- * @param {Object} scope (optional)
- */
- sort : function(fn, scope){
- var cs = this.childNodes;
- var len = cs.length;
- if(len > 0){
- var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
- cs.sort(sortFn);
- for(var i = 0; i < len; i++){
- var n = cs[i];
- n.previousSibling = cs[i-1];
- n.nextSibling = cs[i+1];
- if(i === 0){
- this.setFirstChild(n);
- }
- if(i == len-1){
- this.setLastChild(n);
- }
- }