/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.widget.TreeNode");
dojo.require("dojo.event.*");
dojo.require("dojo.io.*");
// make it a tag
dojo.widget.tags.addParseTreeHandler("dojo:TreeNode");
// # //////////
dojo.widget.TreeNode = function() {
dojo.widget.HtmlWidget.call(this);
this.actionsDisabled = [];
}
dojo.inherits(dojo.widget.TreeNode, dojo.widget.HtmlWidget);
dojo.lang.extend(dojo.widget.TreeNode, {
widgetType: "TreeNode",
loadStates: {
UNCHECKED: "UNCHECKED",
LOADING: "LOADING",
LOADED: "LOADED"
},
actions: {
MOVE: "MOVE",
REMOVE: "REMOVE",
EDIT: "EDIT",
ADDCHILD: "ADDCHILD"
},
isContainer: true,
lockLevel: 0, // lock ++ unlock --, so nested locking works fine
templateString: ('
'
+ '
'
+ ' ${this.title} '
+ ' '
+ '
${this.afterLabel} '
+ '
'
+ '
').replace(/(>|<)\s+/g, '$1'), // strip whitespaces between nodes
childIconSrc: "",
childIconFolderSrc: dojo.uri.dojoUri("src/widget/templates/images/Tree/closed.gif"), // for under root parent item child icon,
childIconDocumentSrc: dojo.uri.dojoUri("src/widget/templates/images/Tree/document.gif"), // for under root parent item child icon,
childIcon: null,
isTreeNode: true,
objectId: "", // the widget represents an object
afterLabel: "",
afterLabelNode: null, // node to the left of labelNode
// an icon left from childIcon: imgs[-2].
// if +/- for folders, blank for leaves
expandIcon: null,
title: "",
object: "", // node may have object attached, settable from HTML
isFolder: false,
labelNode: null, // the item label
titleNode: null, // the item title
imgs: null, // an array of icons imgs
expandLevel: "", // expand to level
tree: null,
depth: 0,
isExpanded: false,
state: null, // after creation will change to loadStates: "loaded/loading/unchecked"
domNodeInitialized: false, // domnode is initialized with icons etc
isFirstNode: function() {
return this.getParentIndex() == 0 ? true: false;
},
isLastNode: function() {
return this.getParentIndex() == this.parent.children.length-1 ? true : false;
},
lock: function(){ return this.tree.lock.apply(this, arguments) },
unlock: function(){ return this.tree.unlock.apply(this, arguments) },
isLocked: function(){ return this.tree.isLocked.apply(this, arguments) },
cleanLock: function(){ return this.tree.cleanLock.apply(this, arguments) },
actionIsDisabled: function(action) {
var _this = this;
var disabled = false;
if (this.tree.strictFolders && action == this.actions.ADDCHILD && !this.isFolder) {
disabled = true;
}
if (dojo.lang.inArray(_this.actionsDisabled, action)) {
disabled = true;
}
if (this.isLocked()) {
disabled = true;
}
return disabled;
},
getInfo: function() {
// No title here (title may be widget)
var info = {
widgetId: this.widgetId,
objectId: this.objectId,
index: this.getParentIndex(),
isFolder: this.isFolder
}
return info;
},
initialize: function(args, frag){
//dojo.debug(this.title)
this.state = this.loadStates.UNCHECKED;
for(var i=0; i move right, negative => move left
*/
adjustDepth: function(depthDiff) {
for(var i=0; i0) {
for(var i=0; i= this.imgs.length-2) return;
this.imgs[idx].style.backgroundImage = 'url(' + src + ')';
},
updateIconTree: function(){
this.tree.updateIconTree.call(this);
},
expand: function(){
if (this.isExpanded) return;
if (this.children.length) {
this.showChildren();
}
this.isExpanded = true;
this.updateExpandIcon();
dojo.event.topic.publish(this.tree.eventNames.expand, {source: this} );
},
collapse: function(){
if (!this.isExpanded) return;
this.hideChildren();
this.isExpanded = false;
this.updateExpandIcon();
dojo.event.topic.publish(this.tree.eventNames.collapse, {source: this} );
},
hideChildren: function(){
this.tree.toggleObj.hide(
this.containerNode, this.toggleDuration, this.explodeSrc, dojo.lang.hitch(this, "onHide")
);
/* if dnd is in action, recalculate changed coordinates */
if(dojo.exists(dojo, 'dnd.dragManager.dragObjects') && dojo.dnd.dragManager.dragObjects.length) {
dojo.dnd.dragManager.cacheTargetLocations();
}
},
showChildren: function(){
this.tree.toggleObj.show(
this.containerNode, this.toggleDuration, this.explodeSrc, dojo.lang.hitch(this, "onShow")
);
/* if dnd is in action, recalculate changed coordinates */
if(dojo.exists(dojo, 'dnd.dragManager.dragObjects') && dojo.dnd.dragManager.dragObjects.length) {
dojo.dnd.dragManager.cacheTargetLocations();
}
},
addChild: function(){
return this.tree.addChild.apply(this, arguments);
},
doAddChild: function(){
return this.tree.doAddChild.apply(this, arguments);
},
/* Edit current node : change properties and update contents */
edit: function(props) {
dojo.lang.mixin(this, props);
if (props.title) {
this.titleNode.innerHTML = this.title;
}
if (props.afterLabel) {
this.afterLabelNode.innerHTML = this.afterLabel;
}
if (props.childIconSrc) {
this.buildChildIcon();
}
},
removeNode: function(){ return this.tree.removeNode.apply(this, arguments) },
doRemoveNode: function(){ return this.tree.doRemoveNode.apply(this, arguments) },
toString: function() {
return "["+this.widgetType+" Tree:"+this.tree+" ID:"+this.widgetId+" Title:"+this.title+"]";
}
});