📄 structure.js
字号:
if (document.all) {n=0;ie=1;fShow="visible";fHide="hidden";}
if (document.layers) {n=1;ie=0;fShow="show"; fHide="hide";}
// Node Class Constructor.
/*
* Global Varibles
*/
var rightX, bottomY, leftX, topY; //Rect of floating menu of which id is actionbar
// array to store the node need to adapt position , only when the view mode is "chart", it is useful .
var adaptNodes = new Array();
var adaptImages = new Array();
// array to store the level information.only when the view mode is "chart",it is useful .
var levelNodes = new Array(); //store the viewNodes of each level
var levelMaxHeight = new Array(); //store the maxHeight value of each level
var levelAdaptedCount = new Array(); //store hadAdapted node count of each level
/*
* A organiztion unit node
*/
function Node(oid,code,name,level,open) {
this.oid = oid;
this.code = code;
this.name = name;
this.level = level;
this.open = open;
this.parent = null;
this.viewNode =null;
this.subnode = null;
this.addSubnode = NodeAddSubnode;
this.getSubnode = NodeGetSubnode;
this.createAllNode = NodeCreateAllNodes;
this.createAllNodeH = NodeCreateAllNodesH;
this.createAllNodeV = NodeCreateAllNodesV;
this.createAllNodeT = NodeCreateAllNodesT;
this.createViewNode = NodeCreateViewNode;
this.createViewNodeV = NodeCreateViewNodeV;
this.createViewNodeH = NodeCreateViewNodeH;
this.createViewNodeT = NodeCreateViewNodeT;
}
// Node Class Methods.
function NodeAddSubnode(node) {
if( this.subnode==null )
this.subnode =new Array();
this.subnode[this.subnode.length] = node;
node.parent = this;
}
function NodeGetSubnode(index){
if( this.subnode==null)
return null;
if( index<0 || index>=this.subnode.length )
return null;
return this.subnode[index];
}
// createAllNode-----------------------------------------------------------------------------
function NodeCreateAllNodes(inParentIndex,parentChildCount){
if( mode=="chart" ){
return this.createAllNodeH(inParentIndex,parentChildCount);
}else{
return this.createAllNodeT(inParentIndex,parentChildCount);
}
}
function NodeCreateAllNodesT(inParentIndex,parentChildCount,level,isLast,emptyPrexCount){
//set level value
if( this.parent==null ){
level=0;
isLast = new Array();
emptyPrexCount = new Array();
}
isLast[level] = (inParentIndex+1==parentChildCount);
if( this.parent==null )
emptyPrexCount[level] = 0;
else
emptyPrexCount[level] = this.level - this.parent.level - 1;
//create whole table;
var wholeTable = document.createElement("<table width='100%' height='1' border='0' cellpadding='0' cellspacing='0' >");
var curRow = wholeTable.insertRow();
//create all the prex image
//modify by liudq, to show the level relation
var i,curCell,curImage;
for(i=0;i<level;i++){
for(var j=0;j<emptyPrexCount[i];j++){
curCell = curRow.insertCell();
curCell.width = "1";
curCell.noWrap = true;
curImage = document.createElement( "<img src='' border='0' width='40' height='36' >" );
curCell.appendChild(curImage);
curImage.src = contextPath + "/images/orgtreeempty.gif";
}
curCell = curRow.insertCell();
curCell.width = "1";
curCell.noWrap = true;
curImage = document.createElement( "<img src='' border='0' width='40' height='36' >" );
curCell.appendChild(curImage);
if( i==level-1 ){
if( inParentIndex+1==parentChildCount )
curImage.src = contextPath + "/images/orgtreebottom.gif";
else
curImage.src = contextPath + "/images/orgtreecenter.gif";
}else{
if( isLast[i+1] )
curImage.src = contextPath + "/images/orgtreeempty.gif";
else
curImage.src = contextPath + "/images/orgtreevertical.gif";
}
}
for(var j=0;j<emptyPrexCount[level];j++){
curCell = curRow.insertCell();
curCell.width = "1";
curCell.noWrap = true;
curImage = document.createElement( "<img src='' border='0' width='40' height='36' >" );
curCell.appendChild(curImage);
curImage.src = contextPath + "/images/orgtreehorizontal.gif";
}
//create the open image
curCell = curRow.insertCell();
curCell.width = "1";
curCell.noWrap = true;
if( this.subnode!=null && this.subnode.length>0 ){
curImage = document.createElement( "<img src='' onclick='doOpen(this.viewNode);' style='cursor:hand' border='0' width='40' height='36'>" );
if( this.open ){
if( this.parent==null )
curImage.src = contextPath + "/images/orgtreerootopen.gif";
else
curImage.src = contextPath + "/images/orgtreeopen.gif";
}else{
if( this.parent==null )
curImage.src = contextPath + "/images/orgtreerootclose.gif";
else
curImage.src = contextPath + "/images/orgtreeclose.gif";
}
}else{
curImage = document.createElement( "<img src='' border='0' width='40' height='36'>" );
if( this.parent!=null )
curImage.src = contextPath + "/images/orgtreehorizontal.gif";
else
curImage.src = contextPath + "/images/orgtreeempty.gif";
}
curCell.appendChild(curImage);
//create viewnode
curCell = curRow.insertCell();
curCell.width = "1";
curCell.noWrap = true;
var viewNode = this.createViewNode(this.oid);
curCell.appendChild(viewNode);
viewNode.openImage = curImage;
curImage.viewNode = viewNode;
curCell = curRow.insertCell();
curCell.width = "90%";
//create subnode's row
var subTable,colSpan;
colSpan = curRow.cells.length;
if( this.subnode!=null && this.subnode.length>0 ){
curRow = wholeTable.insertRow();
curRow.style.display = this.open?"block":"none";
curCell = curRow.insertCell();
curCell.colSpan = colSpan;
for( i=0;i<this.subnode.length;i++){
subTable = this.getSubnode(i).createAllNodeT(i, this.subnode.length, level+1, isLast, emptyPrexCount);
curCell.appendChild(subTable);
}
}
return wholeTable;
}
function NodeCreateAllNodesV(inParentIndex,parentChildCount){
//create wholetable and init
var length;
if( this.subnode == null || this.subnode.length==0 )
length=1;
else
length=this.subnode.length;
var wholeTable = document.createElement("<table border='0' cellpadding='0' cellspacing='0' >");
var i,curRow,curCell,j;
for(i=0;i<length;i++){
curRow = wholeTable.insertRow();
curCell = curRow.insertCell();
curCell.width = "20";
curCell.noWrap = true;
curRow.insertCell();
curRow.insertCell();
if( i!=length-1 ){
curRow = wholeTable.insertRow();
curCell = curRow.insertCell();
curCell.width = "20";
curCell.noWrap = true;
curRow.insertCell();
curRow.insertCell();
if( !(length%2==0 && i==length/2-1) )
curCell.height="13";
}
}
for(i=0;i< wholeTable.rows.length;i++){
wholeTable.rows[i].cells[2].align = "left";
}
//create viewNode
var viewNode = this.createViewNode(this.oid);
wholeTable.rows[length-1].cells[1].appendChild(viewNode);
wholeTable.rows[length-1].cells[1].align="center";
wholeTable.rows[length-1].cells[1].vAlign="center";
//create top line
var curImage;
if( this.parent!=null ){
if( inParentIndex==0 ){
if( parentChildCount==1 ){
//insert " | "
curImage = document.createElement("<img src='" +contextPath+ "/images/orghorizontalshort.gif' width='20' height='60'>");
wholeTable.rows[length-1].cells[0].appendChild(curImage);
wholeTable.rows[length-1].cells[0].align="center";
wholeTable.rows[length-1].cells[0].vAlign="center";
}else{
//insert " ┌──"
subTable = document.createElement("<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0'>");
curRow = subTable.insertRow();
curCell = curRow.insertCell();
curCell.height="50%";
curRow = subTable.insertRow();
curCell = curRow.insertCell();
curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticaltop.gif' width='20' height='60'>");
curCell.appendChild(curImage);
curRow = subTable.insertRow();
curCell = curRow.insertCell();
curCell.height="50%";
curCell.background = contextPath + "/images/orgverticallong.gif";
wholeTable.rows[length-1].cells[0].appendChild(subTable);
wholeTable.rows[length-1].cells[0].height="100%";
wholeTable.rows[length-1].cells[0].align="center";
for(i=length;i<length*2-1;i++)
wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";
}
}else if( parentChildCount%2==1 && inParentIndex==(parentChildCount-1)/2 ){
//insert "──┼──"
for(i=0;i<length*2-1;i++){
if( i==length-1 ) {
curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalcross.gif' width='20' height='60'>");
wholeTable.rows[length-1].cells[0].appendChild(curImage);
wholeTable.rows[length-1].cells[0].align="center";
}
wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";
}
}else if( inParentIndex==parentChildCount-1 ){
//insert "──┐"
subTable = document.createElement("<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0'>");
curRow = subTable.insertRow();
curCell = curRow.insertCell();
curCell.height="50%";
curCell.background = contextPath + "/images/orgverticallong.gif";
curRow = subTable.insertRow();
curCell = curRow.insertCell();
curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalbottom.gif' width='20' height='60'>");
curCell.appendChild(curImage);
curRow = subTable.insertRow();
curCell = curRow.insertCell();
curCell.height="50%";
wholeTable.rows[length-1].cells[0].appendChild(subTable);
wholeTable.rows[length-1].cells[0].height="100%";
wholeTable.rows[length-1].cells[0].align="center";
for(i=0;i<length-1;i++)
wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";
}else{
//insert "──┬──"
for(i=0;i<length*2-1;i++){
if( i==length-1 ){
curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalcenter.gif' width='20' height='60'>");
wholeTable.rows[i].cells[0].appendChild(curImage);
wholeTable.rows[i].cells[0].align="center";
}
wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";
}
}
}
//create bottomY line
var subTable;
if( this.subnode!=null && this.subnode.length>0 ){
for(i=0;i<wholeTable.rows.length;i++)
wholeTable.rows[i].cells[2].style.display = this.open?"block":"none";
for(i=0;i<length-1;i++){
if( length%2==0 && i==length/2-1 ){
//insert "──┴──"
subTable = document.createElement("<table height='100%' width='20' border='0' cellspacing='0' cellpadding='0'>");
wholeTable.rows[i*2+1].cells[2].appendChild(subTable);
wholeTable.rows[i*2+1].cells[2].height="100%";
curCell = subTable.insertRow().insertCell();
curCell.width="20";
curCell.height="100%";
curCell.vAlign="center";
curCell.background = contextPath + "/images/orgverticallong.gif";
curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalcenter2.gif' width='20' height='60'>");
curCell.appendChild( curImage );
}else{
//insert "─────"
subTable = document.createElement("<table height='100%' width='20' border='0' cellspacing='0' cellpadding='0'>");
wholeTable.rows[i*2+1].cells[2].appendChild(subTable);
curCell = subTable.insertRow().insertCell();
curCell.width="100%";
curCell.height="100%";
curCell.background = contextPath + "/images/orgverticallong.gif";
}
}
//call the child's createAllNode() method
if( this.open ){
var subViewNode;
for(i=0;i<length;i++){
subViewNode = this.getSubnode(i).createAllNodeV(i,length);
wholeTable.rows[i*2].cells[2].appendChild(subViewNode);
}
}
}
return wholeTable;
}
function adaptPosition(){
var childViewNode ;
for(var i=adaptNodes.length-1;i>=0;i--){
if( adaptNodes[i].treeNode.open){
if (adaptNodes[i].offsetHeight == 0) continue;
adaptNodes[i].parentNode.height = adaptNodes[i].offsetHeight;
adaptNodes[i].parentNode.width = adaptNodes[i].offsetWidth;
adaptNodes[i].style.position = "absolute";
childViewNode = adaptNodes[i].treeNode.subnode[(adaptNodes[i].treeNode.subnode.length-1)/2].viewNode;
if( childViewNode.style.position!="absolute" )
adaptNodes[i].style.left = calculateSumOffset(childViewNode, "offsetLeft");
else
adaptNodes[i].style.left = childViewNode.style.left;
adaptNodes[i].style.top = calculateSumOffset(adaptNodes[i].parentNode, "offsetTop");
if( adaptImages[i]!=null ){
adaptImages[i].parentNode.height = adaptImages[i].offsetHeight;
adaptImages[i].parentNode.width = adaptImages[i].offsetWidth;
adaptImages[i].style.position = "absolute";
adaptImages[i].style.left = parseInt(adaptNodes[i].style.left) + ( parseInt(adaptNodes[i].offsetWidth)-parseInt(adaptImages[i].offsetWidth) )/2;
adaptImages[i].style.top = calculateSumOffset(adaptImages[i].parentNode, "offsetTop" );
}
}else{
adaptNodes[i].style.position = "static";
if( adaptImages[i]!=null )
adaptImages[i].style.position = "static";
}
}
}
function NodeCreateAllNodesH(inParentIndex,parentChildCount){
var needAdapt=false;
if( this.subnode!=null && this.subnode.length!=0 && this.subnode.length%2==1 ){
var child = this.subnode[(this.subnode.length-1)/2];
needAdapt = (child.subnode!=null && child.subnode.length>0) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -