kingpub

海内存知己,博客若比邻

 

另一种树型结构的解决方案

在这个解决方案当中,我对原 xg_delayth 的方案 做了一些改进,让首节点也可以通过点击传递数据。其中修改的地方用红字标出。

 

<%@ page contentType = "text/html; charset=gb2312" language = "java" import = "java.sql.*" errorPage = "" %>

<%@ page import = "system.*" %>

<%@ page import = "pub.*" %>

<%

    int x=Check.CheckPage(request, "admin_admindepart_list" );

    String Error= "" ;

    if (x==1){

       Error= "<script>alert(' 你已掉线,需要重新登陆 !');top.location.href='../login.jsp'</script>" ;

    } else {

       if (x==2){

           Error= "<script>alert(' 你无权进入该页面 !');history.back();</script>" ;

       }

    }

%>

<%= Error %>

<%

   if (x!=0){

        return ;

    }

%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >

< html >

< head >

< meta http-equiv = "Content-Type" content = "text/html; charset=gb2312" >

< link href = "../css/putong.css" type = "text/css" rel = "stylesheet" >

< title > 无标题文档 </ title >

</ head >

< script >

    // JavaScript Document

 

//***********************************************************************************************************************

//--- Function: the define of tree's node object

//--- Return:

//--- Parameters:

//---   ANodeID: the nodeID of the treeNode

//---   ANodeInnerHtml: view in the node_div

//---   ANodeParentID: the nodeID of the parentNode,if it is the root node the ANodeParentID is "-1"

//---   ANodeDivID: the id of the node_div

//--- Create time:      2002-08-12       Change time:      2002-08-12

//--- Create Programer:  xg_delayth       Change Programer: xg_delayth

  function xg_TreeNode(ANodeID,ANodeInnerHtml,ANodeParentID,ANodeDivID) {

    this .nodeID=ANodeID;

    this .nodeInnerHtml=ANodeInnerHtml;

    this .nodeParentID=ANodeParentID;

    this .nodeDivID=ANodeDivID;

    //-- if 0 not view the children else if 1 view the children

    this .nodeIsView=0;

  }

//***********************************************************************************************************************

//--- Function: the define of xg_Tree

//--- Return:

//--- Parameters:

//--- Create time:      2002-08-12       Change time:      2002-08-12

//--- Create Programer:  xg_delayth       Change Programer: xg_delayth

  function xg_Tree() {

    var crop=document.all.hiddenCropName.value

    //-- store the information about the tree

    this .xg_TreeArray= new Array();

    //-- create the root node

//this .xg_TreeArray[0]= new xg_TreeNode(0, 部门结构图, -1, "xgDiv0" );

    this.xg_TreeArray[0]=new xg_TreeNode(0,"<a style='cursor:hand; color:#0A52CB' onclick='selnode(0);' >"+crop+"</a>",-1,"xgDiv0");

    //-- store the tree_node number

    this .xg_ArrayCount=1;

 

    this .xg_TreeInsert=xg_TreeInsert;

    this .xg_TreeSearch=xg_TreeSearch;

    this .xg_TreeDelete=xg_TreeDelete;

    this .xg_GetNodeCount=xg_GetNodeCount;

  }

//***********************************************************************************************************************

//--- Function: insert a node into the tree

//--- Return:

//--- Parameters:

//---   ATreeNode: the new node to insert into the tree

//--- Create time:      2002-08-12       Change time:      2002-08-12

//--- Create Programer:  xg_delayth       Change Programer: xg_delayth

  function xg_TreeInsert(ATreeNode) {

    with ( this ) {

      //-- if ATreeNode is null or it's parentid is null or it's id had been in tree return -1;

      if (!ATreeNode || "" ==xg_TreeSearch( this ,ATreeNode.nodeParentID) || "" !=xg_TreeSearch( this ,ATreeNode.nodeID)) {

        return -1;

      }

      xg_TreeArray[xg_ArrayCount]=ATreeNode;

      xg_ArrayCount++;

    }

  }

//***********************************************************************************************************************

//--- Function: search the node by the nodeID inputed

//--- Return:

//--- Parameters:

//---   AXGTree: the object of xg_Tree insert

//---   ANodeID: the nodeID about the searching node

//--- Create time:      2002-08-12       Change time:      2002-08-12

//--- Create Programer:  xg_delayth       Change Programer: xg_delayth

  function xg_TreeSearch(AXGTree,ANodeID) {

    with (AXGTree) {

      

      for ( var i=0;i<xg_TreeArray.length;i++) {

        if (xg_TreeArray[i].nodeID==ANodeID) {

          return xg_TreeArray[i];

        }

      }

      return "" ;

    }

  }

//***********************************************************************************************************************

//--- Function: Get children's count

//--- Return: the count of the number of children

//--- Parameters:

//---   AXGTree: the object of xg_Tree

//---   ANodeID: the parentnode's nodeID

//--- Create time:      2002-08-12       Change time:      2002-08-12

//--- Create Programer:  xg_delayth       Change Programer: xg_delayth

  function xg_GetNodeCount(AXGTree,ANodeID) {

    with (AXGTree) {

      var childCount=0;

      for ( var i=0;i<xg_ArrayCount;i++) {

        if (xg_TreeArray[i].nodeParentID==ANodeID) {

         childCount++;

       }

      }

      return childCount;

    }

  }

//***********************************************************************************************************************

//--- Function: delete the node of the tree and it's children by recursion

//--- Return:

//--- Parameters:

//---   AXGTree: the object of xg_Tree

//---   ANodeID: the node to be deleted

//--- Create time:      2002-08-12       Change time:      2002-08-12

//--- Create Programer:  xg_delayth       Change Programer: xg_delayth

  function xg_TreeDelete(AXGTree,ANodeID) {

    with (AXGTree) {

      while (1==1) {   

        if (0==xg_GetNodeCount(AXGTree,ANodeID)) { //-- if no children be found

          for ( var i=0;i<xg_TreeArray.length;i++) {

           //-- wipe off the delete_node

            if (xg_TreeArray[i].nodeID==ANodeID) {

             for ( var j=i+1;j<xg_TreeArray.length;j++) {

               xg_TreeArray[j-1]=xg_TreeArray[j];

             }

             //-- reduce the length of the array

             xg_TreeArray.pop();

             AXGTree.xg_ArrayCount--;

           }

          } 

         return ;

       } else{ //-- if children be found,delete the children by recursion

         for ( var i=0;i<xg_ArrayCount;i++) {

           if (xg_TreeArray[i].nodeParentID==ANodeID) {

             xg_TreeDelete(AXGTree,xg_TreeArray[i].nodeID);

           }

         }

       }

      } 

    }

  }

//***********************************************************************************************************************

//--- Function: make the show table

//--- Return:

//--- Parameters:

//---   AXGTree: the object of xg_Tree

//--- Create time:      2002-08-12       Change time:      2002-08-12

//--- Create Programer:  xg_delayth       Change Programer: xg_delayth

  function xg_ShowTree(AXGTree) {

    var tmpOut= "" ;

    tmpOut+= "<table align=left>" ;

    tmpOut+= "<tr><td>" ;

    tmpOut+=xg_GetChildren(AXGTree,0,0);

    tmpOut+= "</td></tr>" ;

    tmpOut+= "</table>" ;

    return tmpOut;

  }

//***********************************************************************************************************************

//--- Function: make the show div by recursion

//--- Return:

//--- Parameters:

//---   AXGTree: the object of xg_Tree

//---   ANodeID: the root nodeID

//---   ALevel: the level the div

//--- Create time:      2002-08-12       Change time:      2002-08-12

//--- Create Programer:  xg_delayth       Change Programer: xg_delayth

  function xg_GetChildren(AXGTree,ANodeID,ALevel) {

    var tmpNode=xg_TreeSearch(AXGTree,ANodeID);

    var tmpOut= "" ;

    with (tmpNode) {

      tmpOut+= "<div id='" +nodeDivID+ "' nodeID='" +nodeID+ "' style='display:inline;'>" ;

      tmpOut+= "<br>" ;

      for ( var i=0;i<ALevel;i++) {

        tmpOut+= "&nbsp;&nbsp;&nbsp;" ;

      }

      tmpOut+= "<img id='img" +tmpNode.nodeID+ "' onmouseover='img_onmouseover(this);' onmouseout='img_onmouseout(this);' " ;

      if (0==xg_GetNodeCount(AXGTree,ANodeID)) {

        tmpOut+= "src='../images/file.gif' " ;

      } else{

        tmpOut+= "src='../images/folder.gif' " ;

      }

      tmpOut+= "width='16' height='16' onclick='div_viewOnclick(" +nodeID+ ",this)' style='color:blue;cursor:hand;'>&nbsp;" ; 

 

      tmpOut+=nodeInnerHtml;

        for ( var i=0;i<AXGTree.xg_TreeArray.length;i++) {

        if (ANodeID==AXGTree.xg_TreeArray[i].nodeParentID) {

          tmpOut+=xg_GetChildren(AXGTree,AXGTree.xg_TreeArray[i].nodeID,ALevel+1);

        }

      }

      tmpOut+= "</div>" ;

    }

    return tmpOut;

  } 

//--- Function: control the view of the tree

//--- Return:

//--- Parameters:

//---   ANodeID: the node to be clicked

//---   AImg: the AImg object stand by with the node

//--- Create time:      2002-08-12       Change time:      2002-08-12

//--- Create Programer:  xg_delayth       Change Programer: xg_delayth

  function div_viewOnclick(ANodeID,AImg) {

    with (xgTree) {

      if (0==xg_GetNodeCount(xgTree,ANodeID)) return ;

 

      var tmpNode=xg_TreeSearch(xgTree,ANodeID);

      for ( var i=0;i<xg_TreeArray.length;i++) {

        if (ANodeID==xg_TreeArray[i].nodeParentID) {

          if (0==tmpNode.nodeIsView)

           eval(xg_TreeArray[i].nodeDivID+ ".style.display='inline';" );

         else

           eval(xg_TreeArray[i].nodeDivID+ ".style.display='none';" );

       }

      }

      if (0==tmpNode.nodeIsView) {

        tmpNode.nodeIsView=1;

       AImg.src= '../images/folderopen.gif' ;

      } else{

       tmpNode.nodeIsView=0;

       AImg.src= '../images/folder.gif' ;

      }

    }

  }

//***********************************************************************************************************************

  function img_onmouseover(AImg) {

    AImg.style.filter= 'alpha(opacity=40)' ;

  }

//***********************************************************************************************************************

  function img_onmouseout(AImg) {

    AImg.style.filter= 'alpha(opacity=100)' ;

  }

    function findObj(theObj, theDoc)

    {

      var p, i, foundObj;

     

      if (!theDoc) theDoc = document;

      if ( (p = theObj.indexOf( "?" )) > 0 && parent.frames.length)

      {

       theDoc = parent.frames[theObj.substring(p+1)].document;

       theObj = theObj.substring(0,p);

      }

      if (!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];

      for (i=0; !foundObj && i < theDoc.forms.length; i++)

       foundObj = theDoc.forms[i][theObj];

      for (i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)

       foundObj = findObj(theObj,theDoc.layers[i].document);

      if (!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

     

      return foundObj;

    }

    function setColor(objName,  bg)

    {

      obj = findObj(objName);

      if (obj.style)

      {   

       obj.style.backgroundColor =bg;

      }

    }

    function selnode(key) {

       if (key==0){

        document.all.selected.value=document.all.hiddenCropID.value;

        // var me='123';

            // alert(me);

        }

       else{

           document.all.selected.value=key;

       }

    }

    function selok(key)

    {

       var inputs = document.all.tags( "INPUT" );

         for ( var i=0; i< inputs.length; i++)

         {

           if (inputs[i].type== "checkbox" && inputs[i].checked)

           {

              document.all.selected.value=document.all.selected.value+inputs[i].value+ ',' ;

           }

         }

         if (document.all.selected.value.length>0)

         {

             document.all.selected.value=document.all.selected.value.substring(0,document.all.selected.value.length-1);

         }

       document.FormList.action= "role_fun.jsp?Oper=1&Key=" +key;

       document.FormList.submit();

    }

    function Add()

    {

       if (document.all.selected.value!= "" ) {

            var a=showModalDialog( "admindepart_edit.jsp?Oper=add&Key=0&Parent=" +document.all.selected.value+ "&cropid=" +document.all.selcropid.value, "" , "status:no;resizable:yes;dialogHeight:410px;dialogWidth:460px;unadorne:yes" );

               if ((a==0))

             {     

                document.FormList.submit();

             }

       }else{

           alert( ' 请选择机构 ' );

       }

    }

    function Edit()

    {

       if (document.all.selected.value!= "0" ) {

            var a=showModalDialog( "admindepart_edit.jsp?Oper=add&Key=" +document.all.selected.value+ "&cropid=" +document.all.selcropid.value, "" , "status:no;resizable:yes;dialogHeight:410px;dialogWidth:460px;unadorne:yes" );

               if ((a==0))

             {     

                document.FormList.submit();

             }

       }else{

           alert( ' 请选择机构 ' );

       }

    }

    function Del ()

    {

      if (window.confirm( " 确实要删除吗? " ))

      {

       if (document.all.selected.value!= "0" ) {

            var a=showModalDialog( "admindepart_ctl.jsp?Oper=del&Key=" +document.all.selected.value, "" , "status:no;resizable:yes;dialogHeight:410px;dialogWidth:460px;unadorne:yes" );

               if ((a==0))

             {      

               document.FormList.submit();

             }

       }else{

           alert( ' 请选择机构 ' );

       }

     }

    }

    function onsel() {

       document.FormList.action= "admindepart_list.jsp" ;

       document.FormList.submit();

    }

  </ script >

< body >

< form name = "FormList" action = "admindepart_list.jsp" method = "post" >

< table cellSpacing = "0" cellPadding = "0" width = "100%" bgColor = "#bfcae6" border = "0" background = "../images/subtitle.gif" >

    < tr >

       < td width = "100%" height = "26" >< FONT face = " 宋体 " >

          < DIV align = "left" >< FONT face = " 宋体 " color = "#ffffff" > &nbsp;&nbsp; 当前位置:系统管理 &gt;&gt; 组织机构 &gt;&gt; 部门设置            </ FONT >

           </ DIV >

           </ FONT >

       </ td >

    </ tr >

  </ table >

   <%

    MachineBean corp= new MachineBean();

    String cropid=request.getParameter( "selcropid" );

    String strCropName= "" ;

    String strCropID= "" ;

    if (cropid== null ) {

       cropid= "" +session.getAttribute( "cropid" );

    }

    DataTable dt = new DataTable();

    Conn conn= new Conn ();

    String mSql= "Select MachID,MachName from sys04_Machine  where MachID=" +cropid;

    System.out.println( "mSql:" +mSql);

    if (conn.querySql(mSql,dt)){

       if (dt.getRowCount()>0){

              strCropName = dt.getItemForName(0,"MachName");

              strCropID = dt.getItemForName(0,"MachID");

       }

    }

  %>  

 

  <input type="hidden" name="selected" value="0"> 

  <input type="hidden" name="hiddenCropName" value="<%=strCropName%>" >

  <input type="hidden" name="hiddenCropID" value="<%=strCropID%>" >

  < table border = "0" cellpadding = "0" cellspacing = "0" width = "100%"  background = "../images/ico_14.jpg" >

  < tr >

  < td height = "26" align = "right" background = "../images/ico_14.jpg" >

  选择公司:

  < select name = "selcropid" onChange = "onsel()" ></ select >

  &nbsp;&nbsp;

  < input type = "button" class = "button" value = " 新增子机构 " onclick = "Add();" >

  &nbsp;&nbsp; < input type = "button" class = "button" value = " 编辑 " onclick = "Edit();" >

  &nbsp;&nbsp; < input type = "button" value = " 删除 " class = "button" onClick = "Del();" size = "50" >   </ td >

  </ tr >

  </ table >

  < div style = "overflow-y:scroll ;width:100%; height:458px" >

  < div id = divID ></ div >

  </ div >

  <%

    out.println(PubClass.BindAllCorpList( "document.all.selcropid" ));

    out.println( "<script>document.all.selcropid.value=" +cropid+ ";</script>" );

  %>

  <%= corp.getAllTree( "select * from sys04_Machine where cropid=" +cropid) %>

</ form >

 

< script language = javascript >    

  divID.innerHTML=xg_ShowTree(xgTree);

  eval(xgTree.xg_TreeArray[0].nodeDivID+ ".style.display='inline';" );

</ script >

</ body >

</ html >

posted on 2006-08-22 16:17 xiaofeng 阅读(149) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

收藏夹

搜索

最新评论

阅读排行榜

评论排行榜