/* * Ext JS Library 1.0.1 * Copyright(c) 2006-2007, Ext JS, LLC. * licensing@extjs.com * * http://www.extjs.com/license */ /** * The TreeNode UI implementation is separate from the * tree implementation. Unless you are customizing the tree UI, * you should never have to use this directly. */ Ext.tree.TreeNodeUI = function(node){ this.node = node; this.rendered = false; this.animating = false; this.emptyIcon = Ext.BLANK_IMAGE_URL; }; Ext.tree.TreeNodeUI.prototype = { removeChild : function(node){ if(this.rendered){ this.ctNode.removeChild(node.ui.getEl()); } }, beforeLoad : function(){ this.addClass("x-tree-node-loading"); }, afterLoad : function(){ this.removeClass("x-tree-node-loading"); }, onTextChange : function(node, text, oldText){ if(this.rendered){ this.textNode.innerHTML = text; } }, onDisableChange : function(node, state){ this.disabled = state; if(state){ this.addClass("x-tree-node-disabled"); }else{ this.removeClass("x-tree-node-disabled"); } }, onSelectedChange : function(state){ if(state){ this.focus(); this.addClass("x-tree-selected"); }else{ //this.blur(); this.removeClass("x-tree-selected"); } }, onMove : function(tree, node, oldParent, newParent, index, refNode){ this.childIndent = null; if(this.rendered){ var targetNode = newParent.ui.getContainer(); if(!targetNode){//target not rendered this.holder = document.createElement("div"); this.holder.appendChild(this.wrap); return; } var insertBefore = refNode ? refNode.ui.getEl() : null; if(insertBefore){ targetNode.insertBefore(this.wrap, insertBefore); }else{ targetNode.appendChild(this.wrap); } this.node.renderIndent(true); } }, addClass : function(cls){ if(this.elNode){ Ext.fly(this.elNode).addClass(cls); } }, removeClass : function(cls){ if(this.elNode){ Ext.fly(this.elNode).removeClass(cls); } }, remove : function(){ if(this.rendered){ this.holder = document.createElement("div"); this.holder.appendChild(this.wrap); } }, fireEvent : function(){ return this.node.fireEvent.apply(this.node, arguments); }, initEvents : function(){ this.node.on("move", this.onMove, this); var E = Ext.EventManager; var a = this.anchor; var el = Ext.fly(a); if(Ext.isOpera){ // opera render bug ignores the CSS el.setStyle("text-decoration", "none"); } el.on("click", this.onClick, this); el.on("dblclick", this.onDblClick, this); el.on("contextmenu", this.onContextMenu, this); var icon = Ext.fly(this.iconNode); icon.on("click", this.onClick, this); icon.on("dblclick", this.onDblClick, this); icon.on("contextmenu", this.onContextMenu, this); E.on(this.ecNode, "click", this.ecClick, this, true); if(this.node.disabled){ this.addClass("x-tree-node-disabled"); } if(this.node.hidden){ this.addClass("x-tree-node-disabled"); } var ot = this.node.getOwnerTree(); var dd = ot.enableDD || ot.enableDrag || ot.enableDrop; if(dd && (!this.node.isRoot || ot.rootVisible)){ Ext.dd.Registry.register(this.elNode, { node: this.node, handles: [this.iconNode, this.textNode], isHandle: false }); } }, hide : function(){ if(this.rendered){ this.wrap.style.display = "none"; } }, show : function(){ if(this.rendered){ this.wrap.style.display = ""; } }, onContextMenu : function(e){ e.preventDefault(); this.focus(); this.fireEvent("contextmenu", this.node, e); }, onClick : function(e){ if(this.dropping){ return; } if(this.fireEvent("beforeclick", this.node, e) !== false){ if(!this.disabled && this.node.attributes.href){ this.fireEvent("click", this.node, e); return; } e.preventDefault(); if(this.disabled){ return; } if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){ this.node.toggle(); } this.fireEvent("click", this.node, e); }else{ e.stopEvent(); } }, onDblClick : function(e){ e.preventDefault(); if(this.disabled){ return; } if(!this.animating && this.node.hasChildNodes()){ this.node.toggle(); } this.fireEvent("dblclick", this.node, e); }, ecClick : function(e){ if(!this.animating && this.node.hasChildNodes()){ this.node.toggle(); } }, startDrop : function(){ this.dropping = true; }, // delayed drop so the click event doesn't get fired on a drop endDrop : function(){ setTimeout(function(){ this.dropping = false; }.createDelegate(this), 50); }, expand : function(){ this.updateExpandIcon(); this.ctNode.style.display = ""; }, focus : function(){ if(!this.node.preventHScroll){ try{this.anchor.focus(); }catch(e){} }else if(!Ext.isIE){ try{ var noscroll = this.node.getOwnerTree().el.dom; var l = noscroll.scrollLeft; this.anchor.focus(); noscroll.scrollLeft = l; }catch(e){} } }, blur : function(){ try{ this.anchor.blur(); }catch(e){} }, animExpand : function(callback){ var ct = Ext.get(this.ctNode); ct.stopFx(); if(!this.node.hasChildNodes()){ this.updateExpandIcon(); this.ctNode.style.display = ""; Ext.callback(callback); return; } this.animating = true; this.updateExpandIcon(); ct.slideIn('t', { callback : function(){ this.animating = false; Ext.callback(callback); }, scope: this, duration: this.node.ownerTree.duration || .25 }); }, highlight : function(){ var tree = this.node.getOwnerTree(); Ext.fly(this.wrap).highlight( tree.hlColor || "C3DAF9", {endColor: tree.hlBaseColor} ); }, collapse : function(){ this.updateExpandIcon(); this.ctNode.style.display = "none"; }, animCollapse : function(callback){ var ct = Ext.get(this.ctNode); ct.enableDisplayMode('block'); ct.stopFx(); this.animating = true; this.updateExpandIcon(); ct.slideOut('t', { callback : function(){ this.animating = false; Ext.callback(callback); }, scope: this, duration: this.node.ownerTree.duration || .25 }); }, getContainer : function(){ return this.ctNode; }, getEl : function(){ return this.wrap; }, appendDDGhost : function(ghostNode){ ghostNode.appendChild(this.elNode.cloneNode(true)); }, getDDRepairXY : function(){ return Ext.lib.Dom.getXY(this.iconNode); }, onRender : function(){ this.render(); }, render : function(bulkRender){ var n = this.node; var targetNode = n.parentNode ? n.parentNode.ui.getContainer() : n.ownerTree.container.dom; if(!this.rendered){ this.rendered = true; var a = n.attributes; // add some indent caching, this helps performance when rendering a large tree this.indentMarkup = ""; if(n.parentNode){ this.indentMarkup = n.parentNode.ui.getChildIndent(); } var buf = ['