// Licensed Materials - Property of IBM // // IBM Cognos Products: pps // // (C) Copyright IBM Corp. 2005, 2017 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. /******************************************************* Dimension Tree A dimension tree can be created within any HTML container. The data for the dimension tree is taken from the dimCache (which will load the data if it is not there) The steps to creating a dimension tree are as follows: - Create a dimTree instance and pass in a reference to the HTML container. - Set the behaviours of the dimtree wich include: - Multi Select/Single Select: Allow only 1 selection or allow many - Wide Select/ Narrow Select: Select box style selection or windows explorer style selection - Must select (On/Off): Sets whether or not no selection is allowed. - Drag and Drop (On/Off): Sets whether categories can be dragged from the tree to other areas of the display. - Hiearchy Roots Selectable (On/Off): Sets whether hierarchy (Alternate Hierarchies, Custom Subsets) roots are selectable. - Measure Placeholders Disabled (On/Off): Sets whether the measure placeholders appear disabled and are not selectable. - Leaves Selectable (On/Off): Sets whether leaves can be selected. - Show Alternate Hierarchies (On/Off): Sets whether alternate hierarchies appear in the tree or not. - Show Custom subsets (On/Off): Sets whether custom subsets appear in the tree or not. - Tree selection type (can be changed while tree is displayed): Sets the selection display type - TREE_SELECTION_ITEM_ONLY: Only the selected item is highlighted, in dark blue. - TREE_SELECTION_CHILDREN: The selected item is highlighted in dark blue, and the immediate children are highlighted in light blue. - TREE_SELECTION_ALL_DESCENDANTS: The selected item is highlighted in dark blue, and all descendents are highlighted in light blue. - TREE_SELECTION_DESCENDENT_LEAVES: The selected item is highlighted in dark blue, and all leaves under the selected item are highlighted in light blue. - top item closable: Does the top item have a +/- control. - Call an initalization method to draw the tree. Initialization methods include: initCubeDimTree(): Creates a cube tree. The root of the tree is the cube, and the dimensions are children of the cube. The cube node is unselectable. initDimTree(dimIdx,isTopNodeActive): Creates a dimension tree where the top nod is the root of a particular dimension specified by dimIdx. isTopNodeActive specifies whether the dimension root is selectable. initDimSubTree(dimIdx, catCode, isTopNodeActive): Creates a dimension tree with the specified category with code catCode, as the root of the tree. The tree will be created with the following HTML structure: Each node in the tree has the following structure:
// ... // Pre images for indenting and vertical lines // // Joint image (+,-) // Data type image (Folder, File) text Node //Text
//child div
Directly following each node's div is another div that contains all of the child nodes of this node, as well as their child divs. (Even leaves have child divs, which are empty, therefore node divs are always the even numbered children of a containing div and their child divs are always the odd numbered divs. Like so: node div child div niode div child div ... node div child div The only exception to this rule are temporary nodes (Loading..., More...) which have no child divs but always appear as the last child of the container. *******************************************************/ var images = new Array(); var dimCache = topparent.getGlobal("dimCache"); var dimTrees = new Array(); //Constants var IMAGE_BLANK = 0; var IMAGE_T = 1; var IMAGE_T_MINUS = 2; var IMAGE_T_PLUS = 3; var IMAGE_L = 4; var IMAGE_L_MINUS = 5; var IMAGE_L_PLUS = 6; var IMAGE_I = 7; var IMAGE_FOLDER = 8; var IMAGE_FOLDER_OPEN = 9; var IMAGE_FOLDER_DISABLED = 10; var IMAGE_FOLDER_DISABLED_OPEN = 11; var IMAGE_ALT_FOLDER = 12; var IMAGE_ALT_FOLDER_OPEN = 13; var IMAGE_ALT_FOLDER_DISABLED = 14; var IMAGE_ALT_FOLDER_DISABLED_OPEN = 15; var IMAGE_FILE = 16; var IMAGE_FILE_DISABLED = 17; var IMAGE_CALCULATED_FILE = 18; var IMAGE_CALCULATED_FILE_DISABLED = 19; var IMAGE_NONSEL_FOLDER = 20; var IMAGE_NONSEL_FOLDER_OPEN = 21; var IMAGE_NONSEL_FOLDER_DISABLED = 22; var IMAGE_NONSEL_FOLDER_DISABLED_OPEN = 23; var IMAGE_CS_FOLDER = 24; var IMAGE_CS_FOLDER_OPEN = 25; var IMAGE_CS_FOLDER_DISABLED = 26; var IMAGE_CS_FOLDER_DISABLED_OPEN = 27; var IMAGE_ALT_NONSEL_FOLDER = 28; var IMAGE_ALT_NONSEL_FOLDER_OPEN = 29; var IMAGE_ALT_NONSEL_FOLDER_DISABLED = 30; var IMAGE_ALT_NONSEL_FOLDER_DISABLED_OPEN = 31; var IMAGE_SEARCH_FOLDER = 32; var IMAGE_SEARCH_FOLDER_DISABLED = 33; var IMAGE_SEARCH_ALT_FOLDER = 34; var IMAGE_SEARCH_ALT_FOLDER_DISABLED = 35; var IMAGE_SEARCH_FILE = 36; var IMAGE_SEARCH_FILE_DISABLED = 37; var IMAGE_SEARCH_CALCULATED_FILE = 38; var IMAGE_SEARCH_CALCULATED_FILE_DISABLED = 39; var IMAGE_SEARCH_NONSEL_FOLDER = 40; var IMAGE_SEARCH_NONSEL_FOLDER_DISABLED = 41; var IMAGE_SEARCH_ALT_NONSEL_FOLDER = 42; var IMAGE_SEARCH_ALT_NONSEL_FOLDER_DIABLED = 43; var IMAGE_PACKAGE = 44; var IMAGE_LOADING = 45; var JOINT_T = 0; var JOINT_L = 1; var EXPAND_NONE = 0; var EXPAND_CLOSED = 2; var EXPAND_OPEN = 1; var FILE_REGULAR = 0; var FILE_CALCULATED = 1; var PARENT_TOP = 2; var PARENT_MAIN = 3; var PARENT_ALT = 4; var PARENT_NONSEL = 5; var PARENT_CS = 6; var PARENT_ALT_NONSEL = 7; var LOAD_ICON = 8; var DIMTREE_LOAD_DELAY = 100; var TREE_SELECTION_ITEM_ONLY = 0; var TREE_SELECTION_CHILDREN = 1; var TREE_SELECTION_ALL_DESCENDANTS = 2; var TREE_SELECTION_DESCENDENT_LEAVES = 3; var TREE_SELECTION_DESCENDENT_NON_LEAVES = 4; var SUBTREE_EMPTY = 0; var SUBTREE_LOADING = 1; var SUBTREE_NOT_EMPTY = 2; function initDimtree() { dTree = new dimTree(document.getElementById("dimTreeContainer")); dTree.setTreeDragAndDrop(true); dTree.initCubeDimTree(); } function cleanupDimTree() { if (dTree) dTree.clearTreeContainer(); } function deselectAll() { for (var i = 0; i < dimTrees.length;i++) { dimTrees[i].deselectAll(); } } function preloadImages() { var path = topparent.getGlobal("sharedImgPath"); images[IMAGE_BLANK] = new Image(); images[IMAGE_BLANK].src = path + "blank.png"; images[IMAGE_T] = new Image(); images[IMAGE_T].src = path + "T.png"; images[IMAGE_T_MINUS] = new Image(); images[IMAGE_T_MINUS].src = path + "Tminus.png"; images[IMAGE_T_PLUS] = new Image(); images[IMAGE_T_PLUS].src = path + "Tplus.png"; images[IMAGE_L] = new Image(); images[IMAGE_L].src = path + "L.png"; images[IMAGE_L_MINUS] = new Image(); images[IMAGE_L_MINUS].src = path + "Lminus.png"; images[IMAGE_L_PLUS] = new Image(); images[IMAGE_L_PLUS].src = path + "Lplus.png"; images[IMAGE_I] = new Image(); images[IMAGE_I].src = path + "I.png"; images[IMAGE_FOLDER] = new Image(); images[IMAGE_FOLDER].src = path + "foldericon.png"; images[IMAGE_FOLDER_OPEN] = new Image(); images[IMAGE_FOLDER_OPEN].src = path + "openfoldericon.png"; images[IMAGE_FOLDER_DISABLED] = new Image(); images[IMAGE_FOLDER_DISABLED].src = path + "foldericon_no.png"; images[IMAGE_FOLDER_DISABLED_OPEN] = new Image(); images[IMAGE_FOLDER_DISABLED_OPEN].src = path + "openfoldericon_no.png"; images[IMAGE_ALT_FOLDER] = new Image(); images[IMAGE_ALT_FOLDER].src = path + "alternate_drill.png"; images[IMAGE_ALT_FOLDER_OPEN] = new Image(); images[IMAGE_ALT_FOLDER_OPEN].src = path + "alternate_drill_open.png"; images[IMAGE_ALT_FOLDER_DISABLED] = new Image(); images[IMAGE_ALT_FOLDER_DISABLED].src = path + "alternate_drill_no.png"; images[IMAGE_ALT_FOLDER_DISABLED_OPEN] = new Image(); images[IMAGE_ALT_FOLDER_DISABLED_OPEN].src = path + "alternate_drill_open_no.png"; images[IMAGE_FILE] = new Image(); images[IMAGE_FILE].src = path + "file.png"; images[IMAGE_FILE_DISABLED] = new Image(); images[IMAGE_FILE_DISABLED].src = path + "file_no.png"; images[IMAGE_CALCULATED_FILE] = new Image(); images[IMAGE_CALCULATED_FILE].src = path + "calculated.gif"; images[IMAGE_CALCULATED_FILE_DISABLED] = new Image(); images[IMAGE_CALCULATED_FILE_DISABLED].src = path + "calculate_no.gif"; images[IMAGE_NONSEL_FOLDER] = new Image(); images[IMAGE_NONSEL_FOLDER].src = path + "scenario.gif"; images[IMAGE_NONSEL_FOLDER_OPEN] = new Image(); images[IMAGE_NONSEL_FOLDER_OPEN].src = path + "scenario_open.gif"; images[IMAGE_NONSEL_FOLDER_DISABLED] = new Image(); images[IMAGE_NONSEL_FOLDER_DISABLED].src = path + "scenario_no.gif"; images[IMAGE_NONSEL_FOLDER_DISABLED_OPEN] = new Image(); images[IMAGE_NONSEL_FOLDER_DISABLED_OPEN].src = path + "scenario_open_no.gif"; images[IMAGE_CS_FOLDER] = new Image(); images[IMAGE_CS_FOLDER].src = path + "custom_subset_folder.gif"; images[IMAGE_CS_FOLDER_OPEN] = new Image(); images[IMAGE_CS_FOLDER_OPEN].src = path + "custom_subset_folder_open.gif"; images[IMAGE_CS_FOLDER_DISABLED] = new Image(); images[IMAGE_CS_FOLDER_DISABLED].src = path + "custom_subset_folder_no.gif"; images[IMAGE_CS_FOLDER_DISABLED_OPEN] = new Image(); images[IMAGE_CS_FOLDER_DISABLED_OPEN].src = path + "custom_subset_folder_open_no.gif"; images[IMAGE_ALT_NONSEL_FOLDER] = new Image(); images[IMAGE_ALT_NONSEL_FOLDER].src = path + "alternate_scenario.gif"; images[IMAGE_ALT_NONSEL_FOLDER_OPEN] = new Image(); images[IMAGE_ALT_NONSEL_FOLDER_OPEN].src = path + "alternate_scenario_open.gif"; images[IMAGE_ALT_NONSEL_FOLDER_DISABLED] = new Image(); images[IMAGE_ALT_NONSEL_FOLDER_DISABLED].src = path + "alternate_scenario_dis.gif"; images[IMAGE_ALT_NONSEL_FOLDER_DISABLED_OPEN] = new Image(); images[IMAGE_ALT_NONSEL_FOLDER_DISABLED_OPEN].src = path + "alternate_scenario_open_dis.gif"; images[IMAGE_SEARCH_FOLDER] = new Image(); images[IMAGE_SEARCH_FOLDER].src = path + "search_folder.gif"; images[IMAGE_SEARCH_FOLDER_DISABLED] = new Image(); images[IMAGE_SEARCH_FOLDER_DISABLED].src = path + "search_folder_no.gif"; // images[IMAGE_SEARCH_ALT_FOLDER] = new Image(); // images[IMAGE_SEARCH_ALT_FOLDER].src = path + "search_alternate_drill.gif"; // images[IMAGE_SEARCH_ALT_FOLDER_DISABLED] = new Image(); // images[IMAGE_SEARCH_ALT_FOLDER_DISABLED].src = path + "search_alternate_drill_no.gif"; images[IMAGE_SEARCH_FILE] = new Image(); images[IMAGE_SEARCH_FILE].src = path + "search_categories.gif"; images[IMAGE_SEARCH_FILE_DISABLED] = new Image(); images[IMAGE_SEARCH_FILE_DISABLED].src = path + "search_categories_no.gif"; images[IMAGE_SEARCH_CALCULATED_FILE] = new Image(); images[IMAGE_SEARCH_CALCULATED_FILE].src = path + "search_calculated.gif"; images[IMAGE_SEARCH_CALCULATED_FILE_DISABLED] = new Image(); images[IMAGE_SEARCH_CALCULATED_FILE_DISABLED].src = path + "search_calculated_no.gif"; images[IMAGE_SEARCH_NONSEL_FOLDER] = new Image(); images[IMAGE_SEARCH_NONSEL_FOLDER].src = path + "search_scenario.gif"; images[IMAGE_SEARCH_NONSEL_FOLDER_DISABLED] = new Image(); images[IMAGE_SEARCH_NONSEL_FOLDER_DISABLED].src = path + "search_scenario_no.gif"; // images[IMAGE_SEARCH_ALT_NONSEL_FOLDER] = new Image(); // images[IMAGE_SEARCH_ALT_NONSEL_FOLDER].src = path + "alternate_scenario_search.gif"; // images[IMAGE_SEARCH_ALT_NONSEL_FOLDER_DIABLED] = new Image(); // images[IMAGE_SEARCH_ALT_NONSEL_FOLDER_DIABLED].src = path + "alternate_scenario_search_dis.gif"; images[IMAGE_PACKAGE] = new Image(); images[IMAGE_PACKAGE].src = path + "package.gif"; images[IMAGE_LOADING] = new Image(); images[IMAGE_LOADING].src = path + "tree_loading.gif"; } //Dimtree Class function dimTree(treeContainer) { preloadImages(); var topNodeActive = false; var enabledRootPath = null; //Options var treemultiSelect = false; this.setTreeMultiSelect = function(val) { treemultiSelect = val; } this.getTreeMultiSelect = function() { return treemultiSelect; } var treeWideSelect = false; this.setTreeWideSelect = function(val) { treeWideSelect = val; } this.getTreeWideSelect = function() { return treeWideSelect; } var treeMustSelect = false; this.setTreeMustSelect = function(val) { treeMustSelect = val; } this.getTreeMustSelect = function() { return treeMustSelect; } var treeDragAndDrop = false; this.setTreeDragAndDrop = function(val) { treeDragAndDrop = val; } this.getTreeDragAndDrop = function() { return treeDragAndDrop; } var treeHierRootsSelectable = true; this.setTreeHierRootsSelectable = function(val) { treeHierRootsSelectable = val; } this.getTreeHierRootsSelectable = function() { return treeHierRootsSelectable; } var treeMeasurePlaceholdersGrayText = false; this.setMeasurePlaceholdersGrayText = function(val) { treeMeasurePlaceholdersGrayText = val; } this.getMeasurePlaceholdersGrayText = function() { return treeMeasurePlaceholdersGrayText; } var leavesSelectable = true; this.setLeavesSelectable = function(val) { leavesSelectable = val; } this.getLeavesSelectable = function() { return leavesSelectable; } var treeShowAlternateHierarchies = true; this.setTreeShowAlternateHierarchies = function(val) { treeShowAlternateHierarchies = val; } this.getTreeShowAlternateHierarchies = function() { return treeShowAlternateHierarchies; } var treeShowCustomSubsets = true; this.setTreeShowCustomSubsets = function(val) { treeShowCustomSubsets = val; } this.getTreeShowCustomSubsets = function() { return treeShowCustomSubsets; } var treeSelectionType = TREE_SELECTION_ITEM_ONLY; this.setTreeSelectionType = function(val) { treeSelectionType = val; updateTreeSelection(); } this.getTreeSelectionType = function() { return treeSelectionType; } var topItemClosable = false; this.setTopItemClosable = function(val) { topItemClosable = val; } this.getTopItemClosable = function() { return topItemClosable; } //Private Variables var timers = new Array(); var loadingContainers = new Array(); var itemCache = new Array(); var numSubtreesLoading = 0; var selectedItems = new Array(); var numSelected = 0; var treeContainer = treeContainer; var treeNum = 0; //Constructor*** //add this as an entry in the dimTrees array, and record its index treeNum = dimTrees.length; dimTrees[treeNum] = this; //*** //Methods function initCubeDimTree() { var childBox = createCubeNodeContent(treeContainer,cubeName); for (var i = 0; i < topparent.getGlobal("gDimensionInfo").length; i++) { createNodeContent(childBox,dimCache.getDimTopNode(i).getCode(),i,(i == (topparent.getGlobal("gDimensionInfo").length - 1)),true,true); } treeContainer.firstChild.setAttribute("topNode","true"); } this.initCubeDimTree = initCubeDimTree; function initDimTree(dimIdx,isTopNodeActive) { topNodeActive = isTopNodeActive; createNodeContent(treeContainer,dimCache.getDimTopNode(dimIdx).getCode(),dimIdx,true,topNodeActive,true); expandItem(treeContainer.firstChild.firstChild); treeContainer.firstChild.setAttribute("topNode","true"); } this.initDimTree = initDimTree; function initDimSubTree(dimIdx, catCode, isTopNodeActive) { //Assumes that the catCode given exists in the dimcache. topNodeActive = isTopNodeActive; createNodeContent(treeContainer,catCode,dimIdx,true,topNodeActive,true); expandItem(treeContainer.firstChild.firstChild); treeContainer.firstChild.setAttribute("topNode","true"); } this.initDimSubTree = initDimSubTree; function clearTreeContainer() { //This method can be used to clean out the container to display a new tree. //Or, it can and should be used to destruct the tree and prevent IE memory leaks. deselectAll(); while(treeContainer.childNodes.length) { clearEventHandlers(treeContainer.childNodes[treeContainer.childNodes.length - 1]); treeContainer.removeChild(treeContainer.childNodes[treeContainer.childNodes.length - 1]); } } this.clearTreeContainer = clearTreeContainer; function clearEventHandlers(domNode) { if (domNode.ondragstart) domNode.ondragstart = null; if (domNode.onclick) domNode.onclick = null; if (domNode.onmouseover) domNode.onmouseover = null; if (domNode.onmouseout) domNode.onmouseout = null; if (domNode.oncontextmenu) domNode.oncontextmenu = null; for (var i = 0; i < domNode.childNodes.length; i++) clearEventHandlers(domNode.childNodes[i]); } /*****************************/ /* Node creation Functions */ function createCubeNodeContent(container,cubeName) { var div = document.createElement("DIV"); div.className = "dimtree_item_div"; //In IE, we need to force the DIV to 0 height to compress the white space if (document.all) { div.style.height = 0; } if (topItemClosable) { div.appendChild(createJoint(JOINT_L, EXPAND_OPEN)); } div.appendChild(createIcon(PARENT_TOP, EXPAND_OPEN, true)); div.appendChild(createTextNode(cubeName),true); div.setAttribute("expand",EXPAND_OPEN); container.appendChild(div); var childPreString = ""; if (topItemClosable) childPreString = "0"; var childBox = createChildrenBox(childPreString); childBox.className = "dimtree_content_div"; childBox.setAttribute("subtree",SUBTREE_NOT_EMPTY); container.appendChild(childBox); return childBox; } function createNodeContent(parentDiv, code, dimIdx, last, active, enabled) { var catNode = dimCache.getCategory(dimIdx, code); var measurePlaceholder = (treeMeasurePlaceholdersGrayText && catNode.isMeasurePlaceholder()); var div = document.createElement("DIV"); if (treeSelectionType == TREE_SELECTION_ITEM_ONLY || !catNode.isAlternateParent()) div.className = "dimtree_item_div"; else div.className = "dimtree_item_div_notTransparent"; //In IE, we need to force the DIV to 0 height to compress the white space if (document.all) { div.style.height = 0; } div.setAttribute("code",code); div.setAttribute("dimIdx",dimIdx); div.setAttribute("ppdsId",catNode.getPPDSID()); div.setAttribute("level",1); div.setAttribute("page",0); div.setAttribute("type","cm"); if (catNode.isAlternateParent()) div.setAttribute("isHierRoot","true"); else div.setAttribute("isHierRoot","false"); if (catNode.isCustomSubset()) div.setAttribute("customSubset","true"); else div.setAttribute("customSubset","false"); if (catNode.isMeasurePlaceholder()) div.setAttribute("measurePlaceholder","true"); else div.setAttribute("measurePlaceholder","false"); if (enabled) div.setAttribute("tndisabled","false"); else div.setAttribute("tndisabled","true"); var selectable = (active && !measurePlaceholder); if (!treeHierRootsSelectable && (catNode.isTopNode() || catNode.isAlternateParent())) selectable = false; if (!leavesSelectable && (catNode.isLeaf())) selectable = false; if (selectable) div.setAttribute("selectable","true"); else div.setAttribute("selectable","false"); var prevCode = ""; if (parentDiv.getAttribute("prevCode") != null) prevCode = parentDiv.getAttribute("prevCode"); addNodePreImages(prevCode, div); var expand = catNode.isLeaf()? EXPAND_NONE : EXPAND_CLOSED; div.setAttribute("expand",expand); var joint = last? JOINT_L : JOINT_T; var itemtype; if (catNode.isCustomSubset()) itemtype = PARENT_CS; else if (catNode.isLeaf()) if (catNode.isCalculated()) itemtype = FILE_CALCULATED; else itemtype = FILE_REGULAR; else if (catNode.isAlternateParent()) { if (catNode.isNonSelectable()) itemtype = PARENT_ALT_NONSEL else itemtype = PARENT_ALT; } else { if (catNode.isNonSelectable()) itemtype = PARENT_NONSEL; else itemtype = PARENT_MAIN; } div.appendChild(createJoint(joint, expand)); var showenabled = enabled || catNode.isTopNode() || catNode.isAlternateParent(); var icon = createIcon(itemtype, expand, showenabled); if (active && treeDragAndDrop) { icon.ondragstart = function(event) { dragStart(event, this, treeNum); } icon.onclick = function(event) { click(event, this.nextSibling, treeNum); } } if (selectable && !treeWideSelect) { icon.onmouseover = function() { return mouseover(this.nextSibling, treeNum); } icon.onmouseout = function() { return mouseout(this.nextSibling, treeNum); } if ( !topparent.getGlobal("safari") ) { icon.oncontextmenu = function(event) { contextmenu(event, this.nextSibling, treeNum); } } else { if ( icon.onclick != null ) icon.onclick = function(event) { ctrlclickPlusClick(event, this.nextSibling, treeNum); } else icon.onclick = function(event) { ctrlclickNOclick(event, this.nextSibling, treeNum); } } } div.appendChild(icon); var hiddenForm; if (topparent.getXtabFrame()) hiddenForm = topparent.getXtabFrame().document.fhidden; var nodeText = catNode.getLabel(); if( hiddenForm && hiddenForm.SHN != "undefined" && hiddenForm.SHN != null && hiddenForm.SHN.value == 1) nodeText = catNode.getFullName(); var textNode = createTextNode(nodeText,(showenabled && !measurePlaceholder)); if (selectable && !treeWideSelect) { textNode.onmouseover = function() { return mouseover(this, treeNum); } textNode.onmouseout = function() { return mouseout(this, treeNum); } textNode.onclick = function(event) { click(event, this, treeNum); } } if (active && treeDragAndDrop) { textNode.ondragstart = function(event) { dragStart(event, this, treeNum); } if ( !topparent.getGlobal("safari") ) { textNode.oncontextmenu = function(event) { contextmenu(event, this, treeNum); } } else { if ( icon.onclick != null ) textNode.onclick = function(event) { ctrlclickPlusClick(event, this, treeNum); } else textNode.onclick = function(event) { ctrlclickNOclick(event, this, treeNum); } } } if (selectable && treeWideSelect) { div.onmouseover = function() { return mouseover(this, treeNum); } div.onmouseout = function() { return mouseout(this, treeNum); } div.onclick = function(event) { click(event, this, treeNum); } } div.appendChild(textNode); parentDiv.appendChild(div); prevCode += last? "0" : "1"; parentDiv.appendChild(createChildrenBox(prevCode, dimIdx)); } function createLoadNode(parentDiv) { var div = document.createElement("DIV"); div.className = "dimtree_item_div_notTransparent"; addNodePreImages(parentDiv.getAttribute("prevCode"), div); div.appendChild(createJoint(JOINT_L, EXPAND_NONE)); div.appendChild(createIcon(LOAD_ICON, EXPAND_NONE, true)); div.appendChild(createTextNode(topparent.getGlobal("gLoadingText"),true)); div.setAttribute("textNode","true"); parentDiv.appendChild(div); } function createMoreNode(parentDiv, dimIdx, code, nextItem) { var div = document.createElement("DIV"); div.className = "dimtree_item_div_notTransparent"; div.setAttribute("nextItem",nextItem); div.setAttribute("code",code); div.setAttribute("dimIdx",dimIdx); div.setAttribute("more","true"); div.setAttribute("textNode","true"); addNodePreImages(parentDiv.getAttribute("prevCode"), div); div.appendChild(createJoint(JOINT_L, EXPAND_CLOSED)); div.appendChild(createTextNode(topparent.getGlobal("gMoreText"),true)); parentDiv.appendChild(div); } function addNodePreImages(prevCode, div) { //Adds either blank images or I nodes before the content according to the prevCode (0 = blank, 1 = I node). var pCode = prevCode; for (var i = 0; i < pCode.length; i++) { var imgSrc = images[IMAGE_BLANK].src; if (pCode.charAt(i) == "1") imgSrc = images[IMAGE_I].src; insertIMGNode(div, imgSrc, "dimtree_icon", []); } } function createIcon(type, expand, enabled) { var span = document.createElement("SPAN"); span.setAttribute("iconType",type); span.setAttribute("enabled",(enabled)? "true" :"false"); if (type == PARENT_TOP) insertIMGNode(span, images[getIconImageIdx(type, expand, enabled)].src, "dimtree_package_item", []); else insertIMGNode(span, images[getIconImageIdx(type, expand, enabled)].src, "dimtree_folder_icon", []); return span; } function getIconImageIdx(type, expand, enabled) { var imgIdx; switch (type) { case FILE_REGULAR: imgIdx = IMAGE_FILE; break; case FILE_CALCULATED: imgIdx = IMAGE_CALCULATED_FILE; break; case PARENT_TOP: imgIdx = IMAGE_PACKAGE; break; case PARENT_MAIN: imgIdx = IMAGE_FOLDER; break; case PARENT_ALT: imgIdx = IMAGE_ALT_FOLDER; break; case PARENT_CS: imgIdx = IMAGE_CS_FOLDER; break; case PARENT_NONSEL: imgIdx = IMAGE_NONSEL_FOLDER; break; case PARENT_ALT_NONSEL: imgIdx = IMAGE_ALT_NONSEL_FOLDER; break; case LOAD_ICON: imgIdx = IMAGE_LOADING; break; } if ((type == PARENT_MAIN || type == PARENT_ALT || type == PARENT_CS|| type == PARENT_NONSEL || type == PARENT_ALT_NONSEL) && expand == EXPAND_OPEN) imgIdx++; if (!enabled) if (type == FILE_REGULAR || type == FILE_CALCULATED) imgIdx++; else imgIdx += 2; return imgIdx; } function createJoint(type, expand) { var span = document.createElement("SPAN"); span.setAttribute("jointType",type); if (expand == EXPAND_OPEN) span.onclick = function(event) { colapseNode(event, treeNum); } if (expand == EXPAND_CLOSED) span.onclick = function(event) { expandNode(event, treeNum); } insertIMGNode(span, images[getJointImageIdx(type, expand)].src, "dimtree_icon", []); return span; } function getJointImageIdx(type, expand) { var imgIdx = (type == JOINT_T)? IMAGE_T: IMAGE_L; imgIdx += expand; return imgIdx; } function createTextNode(text,enabled) { var link = document.createElement("A"); if (enabled != false) link.className = "dimtree_text"; else link.className = "dimtree_text_disabled"; link.href = "#"; link.appendChild(document.createTextNode(text)); return link; } function createChildrenBox(prevCode, dimIdx) { var div = document.createElement("DIV"); div.className = "dimtree_content_div_hidden"; //In IE, we need to force the DIV to 0 height to compress the white space if (document.all) { div.style.height = 0; } div.setAttribute("prevCode",prevCode); div.setAttribute("subtree",SUBTREE_EMPTY); return div; } /*****************************/ /* Node Action Functions */ function expandItem(item) { var hasMore = (item.parentNode.getAttribute("more") == "true"); if (hasMore) { loadItemChildren(item); } else { loadChildren(item); setJointType(item); setFolderIcon(item); setJointActions(item); setChildClass(item); } } this.expandItem = expandItem; function loadChildren(item) { var childDiv = getChildDiv(item); if (parseInt(childDiv.getAttribute("subtree")) == SUBTREE_EMPTY) { loadTreeChildren(item, childDiv, parseInt(item.parentNode.getAttribute("dimIdx")), item.parentNode.getAttribute("code"), 0); } } function setChildClass(item) { var childDiv = getChildDiv(item); if (childDiv.children.length > 0) { if (notSelectAllDescendents() || notSelected(item)) { if ( selectItemsOnly() || parentIsNotHierarchyRoot(item)) { childDiv.className = "dimtree_content_div"; } else { childDiv.className = "dimtree_content_div_notTransparent"; } } else { childDiv.className = "dimtree_content_div_childselect"; } } else { childDiv.className = "dimtree_content_div_hidden"; } } function parentIsNotHierarchyRoot(item) { return (item.parentNode.getAttribute("isHierRoot") != "true"); } function selectItemsOnly() { return (treeSelectionType == TREE_SELECTION_ITEM_ONLY); } function notSelected(item) { return (item.parentNode.getAttribute("selected") != "true"); } function notSelectAllDescendents() { return (treeSelectionType != TREE_SELECTION_ALL_DESCENDANTS); } function getChildDiv(item) { return item.parentNode.nextSibling; } function loadItemChildren(item) { var moreDiv = item.parentNode; var moreDivParent = moreDiv.parentNode; var dimIdx = moreDiv.getAttribute("dimIdx"); var code = moreDiv.getAttribute("code"); var nextItem = moreDiv.getAttribute("nextItem"); loadTreeChildren( item, moreDivParent, parseInt(dimIdx), code, parseInt(nextItem)); } function setJointType(item) { var childDiv = getChildDiv(item); var jointImgIdx; if (childDiv.children.length > 0) { jointImgIdx = getJointImageIdx(parseInt(item.getAttribute("jointType")),EXPAND_OPEN); } else { jointImgIdx = getJointImageIdx(parseInt(item.getAttribute("jointType")),EXPAND_NONE); // No children = nothing to expand! } var theSrc = images[jointImgIdx].src; if (item.firstChild.src) { item.firstChild.src = theSrc; } else { item.firstChild.setAttribute("theSrc", theSrc); } } function setFolderIcon(item) { var nextObj = item.nextSibling; var iconType = nextObj.getAttribute("iconType"); var isEnabled = (nextObj.getAttribute("enabled") == "true"); var iconImageIdx = getIconImageIdx(parseInt(iconType),EXPAND_OPEN, isEnabled); var theSrc = images[iconImageIdx].src; if (nextObj.firstChild.src) { nextObj.firstChild.src = theSrc; } else { nextObj.firstChild.setAttribute("theSrc", theSrc); } } function setJointActions(item) { var childDiv = getChildDiv(item); if (childDiv.children.length > 0) { item.onclick = function(event) { colapseNode(event, treeNum); } item.parentNode.setAttribute("expand", EXPAND_OPEN); } else { item.onclick = function(event) {} item.parentNode.setAttribute("expand", EXPAND_NONE); } } function colapseItem(item) { nextObj = item.nextSibling; item.parentNode.setAttribute("expand",EXPAND_CLOSED); item.firstChild.src = images[getJointImageIdx(parseInt(item.getAttribute("jointType")),EXPAND_CLOSED)].src; nextObj.firstChild.src = images[getIconImageIdx(parseInt(nextObj.getAttribute("iconType")),EXPAND_CLOSED,nextObj.getAttribute("enabled") == "true")].src; item.onclick = function(event) { expandNode(event, treeNum); } var childDiv = item.parentNode.nextSibling; childDiv.className = "dimtree_content_div_hidden"; } this.colapseItem = colapseItem; function loadTreeChildren(item, div, dimIdx, code, firstItem) { var catNode = dimCache.getCategory(dimIdx, code); if (firstItem) { //remove the more... removeLastText(div); var node = div.childNodes[div.childNodes.length - 2]; changeJointType(node, JOINT_T, node.getAttribute("expand")); } itemCache[code] = item; if (catNode.childrenLoaded(firstItem)) { populateTreeChildren(div, dimIdx, code, firstItem); } else { div.setAttribute("subtree",SUBTREE_LOADING); createLoadNode(div); loadingContainers[code] = div; timers[code] = setInterval("dimTrees[" + treeNum + "].checkTreeLoaded(" + dimIdx + ",'" + code + "'," + firstItem + ")",DIMTREE_LOAD_DELAY); numSubtreesLoading++; catNode.loadChildren(); } } function populateTreeChildren(div, dimIdx, code, firstItem) { var catNode = dimCache.getCategory(dimIdx, code); var more; if (treeShowCustomSubsets) more = (catNode.getNumChildrenLoaded() > firstItem + parseInt(topparent.getGlobal("childLimit")) || !catNode.allChildrenLoaded()); else more = (catNode.getNumChildrenLoaded() > firstItem + parseInt(topparent.getGlobal("childLimit")) || !catNode.allNonCustomSubsetsLoaded()); var catNodes = catNode.getChildren(); if (catNodes.length > 0) { for (var i = firstItem; i < (firstItem + parseInt(topparent.getGlobal("childLimit"))) && i < catNodes.length; i++) { if ((treeShowAlternateHierarchies || !dimCache.getCategory(dimIdx, catNodes[i]).isAlternateParent()) && (treeShowCustomSubsets || !dimCache.getCategory(dimIdx, catNodes[i]).isCustomSubset())) { //Check to see if the parent is enabled or is the root of the enabled hierarchy var enabled = ((enabledRootPath == null) || matchPaths(createPath(div.previousSibling),enabledRootPath) || (div.previousSibling.getAttribute("tndisabled") == "false")); createNodeContent(div,catNodes[i],dimIdx,((i == catNodes.length - 1) && !more),true,enabled); } else if ((i == catNodes.length - 1) && !more && div.childNodes.length) { //we don't show this one, so we have to update the last shown node's joint type to an L. var node = div.childNodes[div.childNodes.length - 2]; changeJointType(node, JOINT_L, node.getAttribute("expand")); } } div.setAttribute("subtree",SUBTREE_NOT_EMPTY); updateTreeSelection(); if (more) { createMoreNode(div, dimIdx, code, firstItem + parseInt(topparent.getGlobal("childLimit"))); } } else { var item = itemCache[code]; setJointType(item); setFolderIcon(item); setJointActions(item); setChildClass(item); itemCache[code] = null; } } function checkTreeLoaded(dimIdx, code, firstItem) { if (dimCache.getCategory(dimIdx, code).childrenLoaded(firstItem)) { clearInterval(timers[code]); if (loadingContainers[code]) { removeLastText(loadingContainers[code]); populateTreeChildren(loadingContainers[code], dimIdx, code, firstItem); loadingContainers[code] = null; numSubtreesLoading--; } } } this.checkTreeLoaded = checkTreeLoaded; function removeLastText(container) { if (container.lastChild.getAttribute("textNode") == "true") container.removeChild(container.lastChild); } function selectItem(item, ctrlPressed) { if (item.parentNode.getAttribute("selected") == "true" && ctrlPressed && (!treeMustSelect || numSelected > 1)) { setItemUnselected(item); if (treeDragAndDrop) topparent.getGlobal("dndManager").cancelDrag(); } else { if ((!treemultiSelect || !ctrlPressed) && numSelected) deselectAll(); setItemSelected(item); if (treeDragAndDrop) topparent.getGlobal("dndManager").setCarry(item.parentNode); } } this.selectItem = selectItem; function setItemOnlySelected(item) { if (treeWideSelect) item.parentNode.className = "dimtree_item_div_selected"; else if (item.className == "dimtree_text dimtree_text_rollover") item.className = "dimtree_text_selected dimtree_text_rollover"; else item.className = "dimtree_text_selected"; } function setItemOnlyUnselected(item) { if (treeWideSelect) item.parentNode.className = "dimtree_item_div"; else if (item.className == "dimtree_text_selected dimtree_text_rollover") item.className = "dimtree_text dimtree_text_rollover"; else item.className = "dimtree_text"; } function setItemChildrenSelected(item) { setItemOnlySelected(item); if (item.parentNode.nextSibling.className != "dimtree_content_div_hidden") item.parentNode.nextSibling.className = "dimtree_content_div"; //Assume that this option is only on when there is wide selection. var childDiv = item.parentNode.nextSibling; for (var i = 0; i < childDiv.childNodes.length; i += 2) { if (childDiv.childNodes[i].getAttribute("textNode") != "true") { if (childDiv.childNodes[i].getAttribute("selected") == "true") childDiv.childNodes[i].className = "dimtree_item_div_selected"; else if (childDiv.childNodes[i].getAttribute("isHierRoot") != "true") { childDiv.childNodes[i].className = "dimtree_item_div_childselect"; } else childDiv.childNodes[i].className = "dimtree_item_div_notTransparent"; } } } function setItemChildrenUnselected(item) { setItemOnlyUnselected(item); //Assume that this option is only on when there is wide selection. var childDiv = item.parentNode.nextSibling; for (var i = 0; i < childDiv.childNodes.length; i += 2) { if (childDiv.childNodes[i].getAttribute("textNode") != "true") { if (childDiv.childNodes[i].getAttribute("selected") == "true") childDiv.childNodes[i].className = "dimtree_item_div_selected"; else if (childDiv.childNodes[i].getAttribute("isHierRoot") != "true") childDiv.childNodes[i].className = "dimtree_item_div"; else childDiv.childNodes[i].className = "dimtree_item_div_notTransparent"; } } unselectChildDiv(item); } function setItemLeavesSelected(item) { setItemOnlySelected(item); if (item.parentNode.nextSibling.className != "dimtree_content_div_hidden") item.parentNode.nextSibling.className = "dimtree_content_div"; //Assume that this option is only on when there is wide selection. setItemLeavesSelection(item.parentNode,true,false); } function setItemLeavesUnselected(item) { setItemOnlyUnselected(item); //Assume that this option is only on when there is wide selection. unselectChildDiv(item); setItemLeavesSelection(item.parentNode,false,false); } function setItemLeavesSelection(item, select, blankout) { var childDiv = item.nextSibling; for (var i = 0; i < childDiv.childNodes.length; i += 2) { if (childDiv.childNodes[i].getAttribute("textNode") != "true") { if (childDiv.childNodes[i].getAttribute("selected") == "true") childDiv.childNodes[i].className = "dimtree_item_div_selected"; else if (childDiv.childNodes[i].getAttribute("isHierRoot") != "true") { if (childDiv.childNodes[i].getAttribute("expand") != EXPAND_NONE) { //Not a leaf if (parseInt(childDiv.childNodes[i + 1].getAttribute("subtree")) == SUBTREE_NOT_EMPTY) //There are children loaded setItemLeavesSelection(childDiv.childNodes[i], select, blankout); } else if (select) { if (blankout) childDiv.childNodes[i].className = "dimtree_item_div_notTransparent"; else childDiv.childNodes[i].className = "dimtree_item_div_childselect"; } else { childDiv.childNodes[i].className = "dimtree_item_div"; } } } } } function setItemNonLeavesSelected(item) { setItemOnlySelected(item); if (item.parentNode.nextSibling.className != "dimtree_content_div_hidden") item.parentNode.nextSibling.className = "dimtree_content_div_childselect"; setItemLeavesSelection(item.parentNode,true,true); } function setItemNonLeavesUnselected(item) { setItemOnlyUnselected(item); unselectChildDiv(item); setItemLeavesSelection(item.parentNode,false,true); } function setItemAllDescendentsSelected(item) { setItemOnlySelected(item); if (item.parentNode.nextSibling.className != "dimtree_content_div_hidden") item.parentNode.nextSibling.className = "dimtree_content_div_childselect"; } function setItemAllDescendentsUnselected(item) { setItemOnlyUnselected(item); unselectChildDiv(item); } function unselectChildDiv(item) { if (item.parentNode.nextSibling.className != "dimtree_content_div_hidden") { if (item.parentNode.getAttribute("isHierRoot") != "true") item.parentNode.nextSibling.className = "dimtree_content_div"; else { item.parentNode.nextSibling.className = "dimtree_content_div_notTransparent"; } } } function removeItemFromSelectionList(item) { var found = false; for (var i = 0; i < numSelected; i++) { if (!found && selectedItems[i] == item) found = true; if (found) { if (i == numSelected - 1) { numSelected--; } else selectedItems[i] = selectedItems[i + 1]; } } } function deselectAll() { for (var i = numSelected - 1; i >= 0; i--) { setItemUnselected(selectedItems[i]); } if (topparent.getGlobal("dndManager") && topparent.getGlobal("dndManager").isCarrying) topparent.getGlobal("dndManager").cancelDrag(); } this.deselectAll = deselectAll; this.numTreeItemsSelected = function() { return numSelected; } this.getTreeSelectedItem = function(idx) { if (idx == null) return selectedItems[0]; else if (idx >= 0 && idx < numSelected) return selectedItems[idx]; else return null; } function updateTreeSelection() { for (var i = 0; i < numSelected; i++) { setItemSelected(selectedItems[i]); } } function setItemSelected(item) { //if the item is not selected, add it to the array. if (item.parentNode.getAttribute("selected") != "true") { item.parentNode.setAttribute("selected","true"); selectedItems[numSelected] = item; numSelected++; } var needUpdate = (parseInt(item.parentNode.getAttribute("selectionType")) != treeSelectionType); if (needUpdate) { switch (parseInt(item.parentNode.getAttribute("selectionType"))) { case TREE_SELECTION_ITEM_ONLY: setItemOnlyUnselected(item); break; case TREE_SELECTION_CHILDREN: setItemChildrenUnselected(item); break; case TREE_SELECTION_ALL_DESCENDANTS: setItemAllDescendentsUnselected(item); break; case TREE_SELECTION_DESCENDENT_LEAVES: setItemLeavesUnselected(item); break; case TREE_SELECTION_DESCENDENT_NON_LEAVES: setItemNonLeavesUnselected(item); break; } } switch (treeSelectionType) { case TREE_SELECTION_ITEM_ONLY: setItemOnlySelected(item); break; case TREE_SELECTION_CHILDREN: setItemChildrenSelected(item); break; case TREE_SELECTION_ALL_DESCENDANTS: setItemAllDescendentsSelected(item); break; case TREE_SELECTION_DESCENDENT_LEAVES: setItemLeavesSelected(item); break; case TREE_SELECTION_DESCENDENT_NON_LEAVES: setItemNonLeavesSelected(item); break; } item.parentNode.setAttribute("selectionType",treeSelectionType); } function setItemUnselected(item) { if (item.parentNode.getAttribute("selected") == "true") { item.parentNode.setAttribute("selected","false"); removeItemFromSelectionList(item); } switch (parseInt(item.parentNode.getAttribute("selectionType"))) { case TREE_SELECTION_ITEM_ONLY: setItemOnlyUnselected(item); break; case TREE_SELECTION_CHILDREN: setItemChildrenUnselected(item); break; case TREE_SELECTION_ALL_DESCENDANTS: setItemAllDescendentsUnselected(item); break; case TREE_SELECTION_DESCENDENT_LEAVES: setItemLeavesUnselected(item); break; case TREE_SELECTION_DESCENDENT_NON_LEAVES: setItemNonLeavesUnselected(item); break; } item.parentNode.setAttribute("selectionType",-1); } function resetTreeToTop() { deselectAll(); var dimIdx = treeContainer.firstChild.getAttribute("dimIdx"); clearTreeContainer(); if (dimIdx == null) { initCubeDimTree(); } else { initDimTree(dimIdx,topNodeActive); } } this.resetTreeToTop = resetTreeToTop; function resetTree() { deselectAll(); var dimIdx = treeContainer.firstChild.getAttribute("dimIdx"); var code = treeContainer.firstChild.getAttribute("code"); clearTreeContainer(); if (dimIdx == null) { initCubeDimTree(); } else { initDimSubTree(dimIdx,code,topNodeActive); } } this.resetTree = resetTree; this.setTreeToCat = function(dimIdx, catCode) { //First Construct the path back to the root of the tree using the dimcache. //The path will be constructed as a list of codes working backwards from the selected node. //if the dimcache is currently loading, then we will wait until it is done if (dimCache.isLoading() || numSubtreesLoading) { setTimeout("dimTrees[" + treeNum + "].setTreeToCat(" + dimIdx + ",\"" + catCode + "\");",DIMTREE_LOAD_DELAY); return; } //Assumes that this category is in the cache var cat = dimCache.getCategory(dimIdx ,catCode); deselectAll(); var path = new Array(); var parent; var siblings; var idx; while (!cat.isTopNode() && cat.getCode() != treeContainer.firstChild.getAttribute("code")) { path[path.length] = cat.getCode(); cat = dimCache.getCategory(dimIdx ,cat.getParent()); } //Start at the root and loop var div = treeContainer.firstChild; if (div.getAttribute("dimIdx") == null) { //Cube node so find the next node, it will be the dimension node that matches the last node in the path var dims = div.nextSibling.childNodes; for (var i = 0; i < dims.length; i += 2) { if (dims[i].getAttribute("dimIdx") == dimIdx) div = dims[i]; } } var ctr = path.length - 1; //Loop through the path and expand the node at each step. while (ctr != -1) { expandItem(div.childNodes[div.childNodes.length - 3]); var dims = div.nextSibling.childNodes; for (var i = 0; i < dims.length; i += 2) { if (dims[i].getAttribute("code") == path[ctr]) div = dims[i]; } ctr--; } //Select the last one. selectItem(div.childNodes[div.childNodes.length - 1],null); } this.selectFirstChildOfRoot = function() { var RETRY_TIMEOUT = 100; var topNode = treeContainer.firstChild; if (parseInt(topNode.nextSibling.getAttribute("subtree")) != SUBTREE_NOT_EMPTY) { setTimeout("dimTrees[" + treeNum + "].selectFirstChildOfRoot();", RETRY_TIMEOUT); return; } selectItem(topNode.nextSibling.firstChild.childNodes[3],false); } this.selectRoot = function() { selectItem(treeContainer.firstChild.childNodes[2],false); } this.selectionInSameHierarchy = function() { if (selectedItems.length) { var path = getHierarchyRootsPath(selectedItems[0].parentNode); for (var i = 1; i < numSelected; i++) { if (!matchPaths(path,getHierarchyRootsPath(selectedItems[i].parentNode))) return false; } } return true; } function getHierarchyRootsPath(node) { while (!dimCache.getCategory(parseInt(node.getAttribute("dimIdx")),node.getAttribute("code")).isAlternateParent() && !dimCache.getCategory(parseInt(node.getAttribute("dimIdx")),node.getAttribute("code")).isTopNode()) { node = node.parentNode.previousSibling; } return createPath(node); } this.getHierarchyRootsPath = getHierarchyRootsPath; function createPath(node) { var path = new Array(); while (node.getAttribute("topNode") != "true") { path[path.length] = node.getAttribute("code"); node = node.parentNode.previousSibling; } path[path.length] = node.getAttribute("code"); return path; } function matchPaths(path1,path2) { if (path1.length != path2.length) return false; for (var i = 0; i < path1.length; i++) { if (path1[i] != path2[i]) return false; } return true; } //Used to enable the child categories of only 1 hierarchy in the tree. this.setEnabledRootNode = function(path) { enabledRootPath = path; if (path == null) enableAllTreeNodes(); //Work backwards down the path to find the node var enabledRootNode = treeContainer.firstChild; for (var i = path.length - 2; i >= 0; i--) { //Find the child of the previous node with the correct code var child = enabledRootNode.nextSibling.firstChild; if (!child) return; while (child.getAttribute("code") != path[i]) { if (!child.nextSibling || !child.nextSibling.nextSibling) return; child = child.nextSibling.nextSibling; } enabledRootNode = child; } refreshTreeNodeEnabling(treeContainer.firstChild,treeContainer.firstChild == enabledRootNode); } function enableAllTreeNodes() { enabledRootPath = null; refreshTreeNodeEnabling(treeContainer.firstChild,true); } this.enableAllTreeNodes = enableAllTreeNodes; function refreshTreeNodeEnabling(node,enabled) { if (node.getAttribute("textNode") == "true") //Could be a loading or more node. return; var cat = dimCache.getCategory(parseInt(node.getAttribute("dimIdx")),node.getAttribute("code")); var childrenEnabled = enabled; if (cat.isTopNode() || cat.isAlternateParent()) { //We have a hierarchy parent setEnabled(node,(enabledRootPath == null || cat.isTopNode())); if (enabledRootPath == null || matchPaths(createPath(node),enabledRootPath)) { //all children are enabled childrenEnabled = true; } else { childrenEnabled = false; } } else { setEnabled(node,enabled); } var dims = node.nextSibling.childNodes; for (var i = 0;i < dims.length; i += 2) { refreshTreeNodeEnabling(dims[i],childrenEnabled); } } function setEnabled(node,enabled) { var icon = node.childNodes[node.childNodes.length - 2]; if (enabled) node.setAttribute("tndisabled","false"); else node.setAttribute("tndisabled","true"); if (enabled || node.getAttribute("isHierRoot") == "true") { node.childNodes[node.childNodes.length - 1].className = "dimtree_text"; icon.setAttribute("enabled","true"); } else { node.childNodes[node.childNodes.length - 1].className = "dimtree_text_disabled"; icon.setAttribute("enabled","false"); } icon.firstChild.src = images[getIconImageIdx(parseInt(icon.getAttribute("iconType")),parseInt(icon.parentNode.getAttribute("expand")),(enabled || node.getAttribute("isHierRoot") == "true"))].src; } //Should only be used on cube trees. this.loadNewDimensionChildren = function(dimIdx) { var node = treeContainer.childNodes[1].childNodes[parseInt(dimIdx) * 2]; //Get the dimension root node var dimTopCatNode = dimCache.getDimTopNode(parseInt(dimIdx)); //Only if all the children have been loaded and are in the tree, do we load the new children. if (node.nextSibling.childNodes.length && node.nextSibling.lastChild.getAttribute("more") != "true") { loadTreeChildren(treeContainer.firstChild.firstChild,node.nextSibling,parseInt(dimIdx),dimTopCatNode.getCode(),dimTopCatNode.getNumChildrenLoaded()); } } //Should only be used on cube trees. //Assume that existing items can only be deleted, or renamed. this.updateDimensionChildren = function(dimIdx) { var nodesChildren = treeContainer.childNodes[1].childNodes[parseInt(dimIdx) * 2 + 1]; //Get the dimension root node var dimTopCatNode = dimCache.getDimTopNode(parseInt(dimIdx)); var treeChildrenIdx = 0; var dimCacheChildrenIdx = 0; while (nodesChildren.childNodes.length > (treeChildrenIdx * 2)) { //(treeChildrenIdx * 2) because there are two divs for each child //The first for the actual child, and the second for its children. if (nodesChildren.childNodes[treeChildrenIdx * 2].getAttribute("code") == dimTopCatNode.getChildren()[dimCacheChildrenIdx]) { var node = nodesChildren.childNodes[treeChildrenIdx * 2]; var cat = dimCache.getCategory(dimIdx, dimTopCatNode.getChildren()[dimCacheChildrenIdx]); //Check if the name has changed if (node.childNodes[node.childNodes.length - 1].firstChild.nodeValue != cat.getLabel()) { node.childNodes[node.childNodes.length - 1].firstChild.nodeValue = cat.getLabel(); } //Check if the children have changed (we can do this the easy way, as we only have 1 tree that stays around). //Easy Way: check if we have no children in the dimcache, if so then repopulate the kids. var childDiv = node.nextSibling; if (!cat.getNumChildrenLoaded()) { if (!cat.isLeaf()) { //Ensure that the node has the correct joint type if (parseInt(node.getAttribute("expand")) == EXPAND_NONE) changeJointType(node, getJointType(node), EXPAND_CLOSED); //clear the nodes children clearChildDiv(node); //If the node is expanded, reload the children if (node.getAttribute("expand") == EXPAND_OPEN) { loadTreeChildren(treeContainer.firstChild.firstChild,childDiv,parseInt(node.getAttribute("dimIdx")),node.getAttribute("code"),0); } } else { //Ensure that the node has the correct joint type if (parseInt(node.getAttribute("expand")) != EXPAND_NONE) changeJointType(node, getJointType(node), EXPAND_NONE); //clear the nodes children clearChildDiv(node); node.nextSibling.className = "dimtree_content_div_hidden"; } } dimCacheChildrenIdx++; treeChildrenIdx++; } else { //Node deleted var node = nodesChildren.childNodes[treeChildrenIdx * 2]; var childDiv = nodesChildren.childNodes[(treeChildrenIdx * 2) + 1]; nodesChildren.removeChild(node); nodesChildren.removeChild(childDiv); //Update the joints in the tree. if (treeChildrenIdx * 2 == nodesChildren.childNodes.length) { var prevNode = nodesChildren.childNodes[(treeChildrenIdx - 1) * 2]; changeJointType(prevNode, JOINT_L, prevNode.getAttribute("expand")); } } } } function changeJointType(node, jointType, expand) { var joint = node.childNodes[node.childNodes.length - 3]; node.setAttribute("expand", expand); joint.firstChild.src = images[getJointImageIdx(jointType, parseInt(expand))].src; joint.setAttribute("jointType",jointType); if (parseInt(expand) == EXPAND_OPEN) { joint.onclick = function(event) { colapseNode(event, treeNum); } } else if (parseInt(expand) == EXPAND_CLOSED) { joint.onclick = function(event) { expandNode(event, treeNum); } } else { joint.onclick = ""; } changePrevCodeBit(node, parseInt(node.childNodes.length - 3), (jointType == JOINT_T)? 1 : 0); } function clearChildDiv(node) { var childDiv = node.nextSibling; while(childDiv.childNodes.length) { childDiv.removeChild(childDiv.lastChild); } childDiv.setAttribute("subtree",SUBTREE_EMPTY); } function getJointType(node) { return node.childNodes[node.childNodes.length - 3].getAttribute("jointType"); } function changePrevCodeBit(node, pos, bit) { var childDiv = node.nextSibling; var prevCode = childDiv.getAttribute("prevCode"); var newPrevCode = prevCode; if (prevCode.length > pos) { newPrevCode = prevCode.substr(0,pos) + bit + prevCode.substr(pos + 1); } if (prevCode.length - 1 > pos) { node.childNodes[pos].src = images[(bit? IMAGE_I : IMAGE_BLANK)].src; } childDiv.setAttribute("prevCode",newPrevCode); for (var i = 0; i < childDiv.childNodes.length; i += 2) { changePrevCodeBit(childDiv.childNodes[i], pos, bit); } } } //********************* //Event handlers function dragStart(event, item, treeNum) { if (item.getAttribute("tndisabled") == "true") return; var rs = "@"; var parentId = 0; var parentNode = item.parentNode.parentNode.previousSibling; if (parentNode.getAttribute("dimIdx") == item.parentNode.getAttribute("dimIdx")) parentId = parentNode.getAttribute("ppdsId"); topparent.getGlobal("dndManager").setDrag("dim" + rs + item.parentNode.getAttribute("dimIdx") + rs + "level" + rs + "1" + rs + "ppds_id" + rs + item.parentNode.getAttribute("ppdsId") + rs + "code" + rs + item.parentNode.getAttribute("code") + rs + "parentId" + rs + parentId); //Get the hierarchy root of the dragged category var catNode = dimCache.getCategory(item.parentNode.getAttribute("dimIdx"),item.parentNode.getAttribute("code")); catNode = dimCache.getCategory(item.parentNode.getAttribute("dimIdx"),catNode.findHierarchyRoot()); topparent.getGlobal("dndManager").setHierRootOfDraggedCategory(catNode.getPPDSID()); event = event || window.event; var eventM = new eventManager(event); eventM.theEvent.dataTransfer.effectAllowed="all"; } function mouseover(item, treeNum) { if (item.getAttribute("tndisabled") == "true") return; if (!dimTrees[treeNum].getTreeWideSelect()) { if (item.className == "dimtree_text_selected") item.className = "dimtree_text_selected dimtree_text_rollover"; else item.className = "dimtree_text dimtree_text_rollover"; setStatus(item.parentNode); } return true; } function mouseout(item, treeNum) { if (item.getAttribute("tndisabled") == "true") return; if (!dimTrees[treeNum].getTreeWideSelect()) { if (item.className == "dimtree_text_selected dimtree_text_rollover") item.className = "dimtree_text_selected"; else item.className = "dimtree_text"; window.status = ""; } return true; } function contextmenu(event, item, treeNum) { if (item.getAttribute("tndisabled") == "true") return; var eventM = new eventManager(event); eventM.preventDefault(); contextMenu(event, item); } function ctrlclickPlusClick(event, item, treeNum) { if ( event != null && event["altKey"] ) { contextmenu(event, item, treeNum); } click(event, item, treeNum); } function ctrlclickNOclick(event, item, treeNum) { if ( event != null && event["altKey"] ) { contextmenu(event, item, treeNum); } } function click(event, item, treeNum) { if (item.getAttribute("tndisabled") == "true") return; var eventM = new eventManager(event); eventM.cancelBubble(); topparent.executeCrossFrameFunction ( 'hidePopupMenu', '', true); if (dimTrees[treeNum].getTreeWideSelect()) dimTrees[treeNum].selectItem(item.childNodes[item.childNodes.length - 1],(topparent.getGlobal("MacGecko"))? eventM.theEvent.altKey : eventM.theEvent.ctrlKey); else dimTrees[treeNum].selectItem(item,(topparent.getGlobal("MacGecko"))? eventM.theEvent.altKey : eventM.theEvent.ctrlKey); } function expandNode(event, treeNum) { //change the icons var eventM = new eventManager(event); eventM.cancelBubble(); topparent.executeCrossFrameFunction ( 'hidePopupMenu', '', true); var sourceObj = eventM.getSrc().parentNode; if (topparent.getXtabFrame()) dimTrees[treeNum].expandItem(sourceObj) } function colapseNode(event, treeNum) { //change the icons var eventM = new eventManager(event); eventM.cancelBubble(); topparent.executeCrossFrameFunction ( 'hidePopupMenu', '', true); var sourceObj = eventM.getSrc().parentNode; dimTrees[treeNum].colapseItem(sourceObj); } function setStatus(item) { var hiddenForm; if (topparent.getXtabFrame()) hiddenForm = topparent.getXtabFrame().document.fhidden; if( hiddenForm && hiddenForm.SHN != "undefined" && hiddenForm.SHN != null && hiddenForm.SHN.value == 1) window.status = dimCache.getCategory(item.getAttribute("dimIdx"), item.getAttribute("code")).getFullName(); else window.status = dimCache.getCategory(item.getAttribute("dimIdx"), item.getAttribute("code")).getLabel(); return true; } function toggleNames(useShortName) { //get all nodes var nodes = document.getElementsByTagName("a"); for (var i = 0; i < nodes.length; i++){ //we care only about nodes that contain ppdsId attribute, //since those are ones with category info if(nodes[i].parentNode.getAttribute("ppdsId") != null && nodes[i].parentNode.getAttribute("ppdsId") != "undefined"){ nodes[i].removeChild(nodes[i].firstChild); if (useShortName) { nodes[i].appendChild(document.createTextNode(dimCache.getCategory(parseInt(nodes[i].parentNode.getAttribute("dimIdx")),nodes[i].parentNode.getAttribute("code")).getFullName())); } else { nodes[i].appendChild(document.createTextNode(dimCache.getCategory(parseInt(nodes[i].parentNode.getAttribute("dimIdx")),nodes[i].parentNode.getAttribute("code")).getLabel())); } } } }