// ident "@(#)tree.js 1.19 04/09/02 SMI"
//
// Copyright 2004 by Sun Microsystems, Inc. All rights reserved.
// Use is subject to license terms.
//
// This javascript file defines various javascript objects used by the client
// side tree component
/*****************************************************************************/
/* Define a tree node base class */
/*****************************************************************************/
// every node will be assigned a unique index in the tree list of elements
this.id = -1;
// every node has a label
// the node's target
// every node has status text
// every node has an associated url
// width of this node's icon
// every node has an icon
// every node is represented by an html "layer"
this.layer = null;
// every node has a unique yoke to key
// every node can have a parent
this.parent = null;
// whether or not this is a "root" node (for display purposes)
this.isRoot = false;
// the tree this node is part of
this.tree = null;
// save onclick
}
// This OO function maps to CCAbstractTreeNode::createIndex()
//
// It will be called when an item is created in order to add it to the tree's
// array of items / assign this node an id
}
// This OO function maps to CCAbstractTreeNode::display()
//
// It will be called to display an item
if (!this.isVisible()) {
return;
}
if (is_nav4up) {
// also show any sub layers
// show the selected / bold label sub layer
} else {
// show the non selected / bold label sub layer
}
} else if (is_ie4up) {
// test if this node is selected
}
}
}
// This OO function maps to CCAbstractTreeNode::doHide()
//
// It will be called to hide an item
// hide the table / layer containing this node
if (is_nav4up) {
// also hide the nested label layers
}
} else if (is_ie4up) {
}
}
// This OO function maps to CCAbstractTreeNode::isTopNode()
//
// Returns true if this node is at the top of its tree
if (!this.tree) {
// this node is not part of any tree yet
return false;
}
// test if this node is the first root level node of its tree
return true;
}
return false;
}
// This OO function maps to CCAbstractTreeNode::isVisible()
//
// Returns true if this node is currently visible, false otherwise
var p = this.parent;
if (p == null) {
// node has no parent, it's visible
return true;
}
if (!pOpen) {
// parent is closed, can't be visible
return false;
} else {
// parent is open, might be visible so check next ancestor
return p.isVisible();
}
}
// This OO function maps to CCAbstractTreeNode::getOpenAnchor()
//
// This method outputs the html necessary for this nodes link
var customJs = "";
if (this.onClick != null) {
}
anchor += " = ''; return true;\" onblur=\"window.status = ''; ";
if (setId) {
}
return anchor;
}
// This OO function maps to CCAbstractTreeNode::getTableStart(bgColor)
//
// This method outputs the table start tag for a node with the given bgColor
var tableStart = "";
if (is_nav4up) {
// use the layer tag in ns4 - create one for the node's table
tableStart += "\" visibility=\"show\">";
}
// each node goes into a table
tableStart += "\n<table width=\"100%\" ";
if (is_ie4up) {
// ie and other newer browsers allow dhtml for any tag
}
if (bgColor != null) {
}
tableStart += "border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
tableStart += "<tr";
if (is_ie4up) {
}
if (rowHeight != null) {
}
if (this.isRoot) {
}
tableStart += "height=\"22\" alt=\"\"></img>";
return tableStart;
}
/*****************************************************************************/
/* Define a container node class that extends the abstract node class */
/*****************************************************************************/
// this class extends AbstractTreeNode
this.base = CCAbstractTreeNode;
// call the super constructor
// flag indiciating if this is a last sibling
this.isLastSibling = false;
// pointer to the img element for the container's turner
this.turnerImgObj = null;
// whether or not this container is currently open
this.isOpen = true;
// this containers children
this.children = new Array;
// the number of children this container has
this.numChildren = 0;
}
// CCContainerNode extends CCAbstractTreeNode
// This OO function maps to CCContainerNode::addChild(childNode)
//
// This method adds the given child to this container node
// add the child node to the child array and increment our child count
}
// This OO function maps to CCContainerNode::collapseAll()
//
// This method closes this container as well as any descendant containers
var i;
this.children[i].collapseAll();
}
}
this.setOpen(false);
}
// This OO function maps to CCContainerNode::display()
//
// This method displays this node
if (!this.isVisible()) {
// this node isn't currently visible
return;
}
var i = 0;
var showParentOfSelection = false;
this.doDisplay();
if (this.isOpen) {
// this container is open, display all children too
}
// this container is closed and some descendant is selected
showParentOfSelection = true;
}
// show parent of selection style if necessary
if (showParentOfSelection && !this.isRoot) {
if (is_nav4up) {
p = this.parent;
while (p != null && p.layer != null) {
p = p.parent;
}
} else {
p = this.parent;
while (p != null && p.layer != null) {
p = p.parent;
}
}
}
}
// This OO function maps to CCContainerNode::getHeightOfChildren()
//
// This method is used in netscape 4 to determine the total height of a
// container node and any descendant container nodes it may have
var i;
var height = 0;
if (this.isOpen) {
}
}
}
return height;
}
// This OO function maps to CCContainerNode:getTurnerHtml(turnerSrc, turnerAlt)
//
// This method will return the html necessary to display this node's clickable
// turner using the image src passed in
// no image src was specified
return "";
}
return "<a onmouseover=\"window.status='" + this.statusTxt +
"'; return true;\" onmouseout=\"window.status = ''; return true;\" " +
"onblur=\"window.status = ''; return true;\" class=\"" +
"\" width=\"16\" height=\"22\" border=\"0\" alt=\"" + turnerAlt +
}
// This OO function maps to CCContainerNode:hasDescendant(nodeId)
//
// This method will return true if a node with the given id is a descendant of
// this node
return true;
}
var i = 0;
var found = false;
for (i = 0; i < this.numChildren; i++) {
found = true;
break;
}
if (found) {
break;
}
}
}
return found;
}
// This OO function maps to CCContainerNode:hide()
//
// This method will hide the container as well as any children
this.doHide();
var i = 0;
// also hide all children
}
}
// This OO function maps to CCContainerNode:init(depth, lastSibling, lhsHtml)
//
// This method is called to initialize and display a container node
var i = 0;
var turnerHtml;
this.createIndex();
if (depth > 0) {
if (lastSibling) {
// render this as the last sibling in the children array
if (this.isTopNode()) {
// top & non-root node
} else {
}
// add a blank space imager to the left hand side html
// store the fact that we're the last sibling
this.isLastSibling = true;
} else {
// render this node as a middle sibling
if (this.isTopNode()) {
// top & non-root node
} else {
}
// add a tree hierarchy line to the left hand side html
// store the fact that we're not the last sibling
this.isLastSibling = false;
}
} else {
// we're at the root node level
}
// now display any child nodes
if (this.numChildren > 0) {
// increment the curent depth
depth++;
// loop thru all child nodes
for (i = 0; i < this.numChildren; i++) {
if (i == this.numChildren - 1) {
// this is the last of the children
} else {
// not the last child node
}
}
}
if (is_nav4up) {
} else {
}
// set the turner image object
} else {
// set the turner image object in other browsers
}
}
// This OO function maps to CCContainerNode:setOpen(isOpen)
//
// It will open or close a container based on the given argument
var i;
var totalHeight;
// no change in open state
return;
}
// handle netscape 4
totalHeight = 0;
// total up the height of all children
for (i = 0; i < this.numChildren; i++) {
}
}
if (this.isOpen) {
// this node is closing
}
// move the next visible node up or down
}
}
this.tree.updateDisplay(this);
}
// This OO function maps to CCContainerNode:render(lhsHtml, depth)
//
// This method outputs the html necessary to display this node. It prepends
// this output with the given left hand side html
// define left hand pixel margin for ns4
if (this.iconWidth < CCTREE_NODE_IMG_WIDTH) {
// width of node image is less than default
} else if (this.iconWidth > CCTREE_NODE_IMG_WIDTH) {
// node image is wider than default
}
if (this.isRoot) {
} else {
}
if (lhsHtml != "") {
// output the left hand side html we were given
}
// write out the td for the node image
// test if this node is clickable
if (linkNode) {
// output the link for this nodes image
}
// output the image for this node
if (linkNode) {
// close the image link
}
if (!is_nav4up) {
// append a spacer
} else {
// netscape 4 has limited dhtml suport so we need to jump thru some
// hoops to support the desired UI effects. We'll output 3 layers, each
// containing the nodes label but with a different appearance. Layer
// label is the default non selected style, pLabel is the selection
// parent highlight (just bold) and sLabel is the selected node style
// (bold and black)
}
if (linkNode) {
var openAnchor = this.getOpenAnchor(true);
// write out the label as a link
}
if (linkNode) {
// close the anchor
}
if (is_nav4up) {
if (linkNode) {
// append the hidden style layers
}
}
// close the label td, tr and table
if (is_nav4up) {
// close the layer containing this node's table
// set the dhtml element for this node to be the layer
// adjust the document's vertical position
} else {
// set the dhtml element for this to be the table we created
}
}
// This OO function maps to CCContainerNode::getNumDescendants()
//
// Returns the number of descendants this node has
var numDescendants = this.numChildren;
var i = 0;
// loop thru each child
for (i = 0; i < this.numChildren; i++){
// test if child is a container node
// it is so add it's children to sub entries
}
}
return numDescendants;
}
/*****************************************************************************/
/* Define an ojbect class that extends the abstract tree node class */
/*****************************************************************************/
this.base = CCAbstractTreeNode;
}
// CCObjectNode extends CCAbstractTreeNode
// This OO function maps to CCObjectNode:display()
//
// This method will show the object
this.doDisplay();
}
// This OO function maps to CCObjectNode:hide()
//
// This method will hide the object
this.doHide();
}
// This OO function maps to CCObjectNode:init()
//
// This method is called to initialize the node
this.createIndex();
if (depth > 0) {
// there is only one node in the tree
} else if (this.isTopNode()) {
// the top node is a leaf node
} else if (lastNode) {
// the last sibling in the children array
} else {
// not the last sibling, use middle line
}
} else {
}
}
// This OO function maps to CCObjectNode::render(lhsHtml. depth)
//
// This method will output the html necessary to display this object node. It
// prepends the given left hand side html to this output
// define left hand pixel margin for ns4
if (this.iconWidth < CCTREE_NODE_IMG_WIDTH) {
// width of node image is less than default
} else if (this.iconWidth > CCTREE_NODE_IMG_WIDTH) {
// node image is wider than default
}
// test if this node is clickable
if (linkNode) {
// write the anchor for it
}
if (linkNode) {
}
if (!is_nav4up) {
// append a spacer
} else {
}
if (linkNode) {
var openAnchor = this.getOpenAnchor(true);
}
if (linkNode) {
}
if (is_nav4up) {
if (linkNode) {
// node is linked, write hidden style layers
}
}
// close the label td, tr and table
if (is_nav4up) {
// close the layer containing this node's table
} else if (is_ie4up) {
}
}
/*****************************************************************************/
/* Define a tree object class */
/*****************************************************************************/
// the distinct name of this tree
// an array containing the top or root level nodes
this.rootLevelNodes = new Array;
// an array containing all the nodes in this tree
this.nodes = new Array;
// the html layer of the selected item
this.selectedLayer = null;
// the id of the selected item
this.selectedId = -1;
// the selected node
this.selectedNode = null;
// whether or not this tree should save state via a cookie
this.isPersistent = false;
// the target to open links for this tree in
this.target = null;
}
// This OO function maps to CCTree::addChild(node)
//
// This method will called to add a top / root level node to a tree.
if (node == null) {
return;
}
}
// This OO function maps to CCTree::createIndex(node)
//
// This method will called to create an index for the given node in this tree's
// array of nodes
}
// This OO function maps to CCTree::getNode(targetId)
//
// This method will return the node with the given id, or null if no such node
// was found in this tree
if (this.nodes == null) {
// no nodes, return null
return null;
}
var targetNode = null;
// loop through all the nodes in this tree checking id's
return this.nodes[i];
}
}
return targetNode;
}
// This OO function maps to CCTree::init(openContainers)
//
// This method will init the tree at load time
var i;
if (is_nav6up) {
// Use ie4 implementation for Netscape 6
is_nav4up = 0;
is_ie4up = 1;
}
var n = this.rootLevelNodes[i];
} else {
}
n.display();
}
} else {
// display the node
}
if (is_nav4up) {
}
// close the whole tree
// collapse any / all the containers in the tree
if (this.rootLevelNodes[i].isOpen != null) {
// is a container node
this.rootLevelNodes[i].collapseAll()
if (this.rootLevelNodes[i].isRoot) {
// expand any root nodes
this.rootLevelNodes[i].setOpen(true);
}
}
}
if (is_nav4up) {
// loop thru all seleced label layers and hide them
if (sLayer != null) {
}
}
}
}
if (this.isPersistent) {
// restore the selected item and open containers
this.restoreState(cookie);
this.saveState();
}
}
// This OO function maps to CCTree::openOrClose(id)
//
// This method will called to open or close the container with the given id
var container;
var state;
if (this.isPersistent) {
// save the state via cookie
this.saveState();
}
}
// This OO function maps to CCTree::updateDisplay(container)
//
// This method will called when a container node in this tree is opened or
// closed. It will perform the necessary DHTML to render the new tree state.
var i = 0;
var child;
var layer;
var p;
// container opened
if (container.turnerImgObj) {
if (container.isLastSibling) {
// top node with no more siblings
} else {
// last sibling, use handle open last image
}
} else {
// top node but not last sibling
} else {
// not last sibling, use handle open middle
}
}
}
var selectionNowVisible = false;
// loop thru and display all children
selectionNowVisible = true;
}
}
// the selected node may now be visible
if (selectionNowVisible) {
// selected node is now visible
// remove the selection parent highlight
if (is_nav4up) {
layer =
layer =
} else {
"";
}
}
} else {
// container closed
if (container.turnerImgObj) {
if (container.isLastSibling) {
// top node with no siblings
} else {
// last sibling
}
} else {
// top node with more siblings
} else {
// last sibling
}
}
}
// loop thru and hide all the children of this node
}
// the selected node may now be hidden
// either this node is selected or the selected node is now hidden
// so give this node the selection parent highlight
if (is_nav4up) {
layer =
layer =
} else {
"bold";
}
}
}
if (this.isPersistent == true) {
this.saveState();
}
}
// This OO function maps to CCTree::doSelection(id)
//
// This method will perform the necessary DHTML to show the node with the given
// id as being selcted
var parentNode = null;
var selectedLabel = null;
var layer = null;
if (this.selectedLayer != null) {
// remove prior selection
if (is_nav4up) {
if (this.selectedNode.isVisible()) {
}
// also remove prior selection parent highlight
if (parentNode.isVisible()) {
}
if (layer != null) {
}
}
} else {
if (!this.selectedNode.isRoot) {
// remove selected row stle from non-root nodes
}
while (parentNode != null) {
if (layer != null) {
}
}
}
}
// update the current selection id and get the selected node object
this.selectedId = id;
if (is_nav4up) {
if (!this.selectedNode.isRoot) {
// only update row color for non-root nodes
}
if (pLayer != null) {
if (layer != null) {
}
if (layer != null) {
}
}
}
} else if (is_ie4up) {
if (!this.selectedNode.isRoot) {
// only update row color for non-root nodes
}
if (layer != null) {
}
}
}
if (this.isPersistent) {
// save the state via cookie
this.saveState();
}
}
// This OO function maps to CCTree::yokeTo(key)
//
// This method will set the node with the given key to be the selected node. It
// will also ensure that the node is visible. It will however NOT open the url
// associated with the node (use yokeToAndLoad(key) for that)
var i;
var found = false;
}
}
}
// This OO function maps to CCTree::yokeToAndLoad(key)
//
// This method will set the node with the given key to be the selected node. It
// will also ensure that the node is visible and open the url associated with
// this node in the target frame
var i;
var found = false;
}
}
}
// This OO function maps to CCTree::doYoke(node, key, loadUrl)
//
// This method will set the node with the given key to be the selected node. It
// will also ensure that the node is visible. Depending on the value specified
// for loadUrl, it will load (or not) the url associated with the yoke to node
// in the target frame
var i;
var found = false;
// open all parent containers to ensure yoke to node is visible
while (p != null) {
p.setOpen(true);
p = p.parent;
}
// see if the we should open the url associated with this node
if (loadUrl) {
}
// the given node is the yoke to node
return true;
}
// this node is not the yoke to node, check any children
}
}
// return whether the yoke succeeded
return found;
}
// This OO function maps to CCTree::saveState()
//
// This method will save the state of the tree in a client side browser cookie
var i;
// create a cookie containing the id of the selection and open containers
}
// store the cookie
}
// This OO function maps to CCTree::saveNodeState(node)
//
// This method is used by saveState to store the state of the tree
var i;
var cookie = "";
// container node
// its open, save its key in the cookie
}
// also save the state of any child containers
}
}
return cookie;
}
// This OO function maps to CCTree::restoreState(cookie)
//
// This method will attempt to restore the tree state from the given cookie
if (cookie != null) {
if (pos >= 0) {
// there is a state cookie, restore it
// determine the selected node id
// if we got one, yoke to the node with sId
}
// the rest of the cookie contains a list of open container ids
var keys = new Array;
var key = cookie_keys[i];
}
// loop thru and restore the state of all container nodes
// before restoring open containers, close all of them since
// some initially open nodes may not be after page reload
if (this.rootLevelNodes[i].children) {
// has a children array, must be a container so close it
this.rootLevelNodes[i].collapseAll();
}
// recursively restore the state of this node & its descendants
}
}
}
}
// This OO function maps to CCTree::restoreNodeState(node, keys)
//
// This method will restore the state of the given node according to the given
// list of open container ids (the keys param)
var cookie = "";
// this node is open
}
var i;
}
}
return cookie;
}
// Global convience variables