dtree 显示右键菜单

由于本人水平有限,欢迎提出宝贵意见。


<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page language="java"
import="ldap.util.jspBean.*,com.opensymphony.xwork2.ActionContext,java.util.*"%>
<%@page import="ldap.domain.User"%>
<%@page import="ldap.util.UserStatics"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page isELIgnored="false"%>

<% 

  response.setHeader("Cache-Control","no-cache"); 
  response.setHeader("Pragma","no-cache"); 
  response.setDateHeader("Expires",0); 
  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
<title></title>
<link href="${pageContext.request.contextPath }/css/common.css"
rel="StyleSheet" type="text/css" />

<link rel="StyleSheet"
href="${pageContext.request.contextPath }/dtree/dtree.css"
type="text/css" />
<script type="text/javascript"
src="${pageContext.request.contextPath }/dtree/dtree.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath }/dtree/jquery-1.1.3.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath }/dtree/jquery.contextmenu.js"></script>


<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/ext-3.2.0/resources/css/ext-all.css" />
<script type="text/javascript"
src="${pageContext.request.contextPath}/ext-3.2.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/ext-3.2.0/ext-all.js"></script>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/css/forms.css" />


<script language="JavaScript1.2" type="text/javascript">
<%
  //System.out.println("dd:"+request.getSession(false));
 
  if(request.getSession(true).getAttribute(UserStatics.USRKEY)==null){
 
 
  %>
  alert('用户已经退出!');
  window.top.location.href="/userMSys/login.jsp";
  <%}%> 
 
 

      function opTab(){

        var mnu = document.getElementById("menubar")

        var arrdiv = document.getElementById("arrow")

        var arrtxt = document.getElementById("arr")

        if((mnu.style.display != "block") || (mnu.style.display == "")){

          mnu.style.display = "block"
         
          window.parent.document.getElementById("cnt").cols="250,*";
         
          arrdiv.style.pixelLeft = mnu.style.width.substring(0 , mnu.style.width.length - 2)

          arrtxt.innerText = "3";

        } else
        {
          window.parent.document.getElementById("cnt").cols="20,*";
          mnu.style.display = "none"
          arrtxt.innerText = "4";
          arrdiv.style.pixelLeft =0;
        }

        event.cancelBubble = true;

      }

    </script>

<style type="text/css">
#menubar {
position: absolute;
top: 0px;
left: 0px;
display: none;
font-family: Verdana, Helvetica, Arial;
font-weight: 700;
font-size: 10px;
cursor: hand;
z-index: 5;
background-image: url();
background-repeat: repeat-y;
filter: progid :   DXImageTransform.Microsoft.gradient (   enabled = 
'true', gradientType =   '1', startColorstr =   '#FFFFFF', endColorstr
=   '#FFFFFF' );
}

.pulltab {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 12px;
padding-left: 1px;
cursor: hand;
color: #000000;
font-family: Webdings;
font-weight: bold;
font-size: 10px;
z-index: 10;
background-image: url();
background-repeat: repeat-y;
filter: progid :   DXImageTransform.Microsoft.gradient (   enabled = 
'true', gradientType =   '1', startColorstr =   '#DDDDDD', endColorstr
=   '#AAAAAA' );
}

.inner {
height: 100%;
width: 100%;
}
</style>







<script>  
function ScreenSaver(settings){  
    this.settings = settings;  
 
    this.nTimeout = this.settings.timeout;  
              
    document.body.screenSaver = this;  
    // link in to body events  
    document.body.onmousemove = ScreenSaver.prototype.onevent;  
    document.body.onmousedown = ScreenSaver.prototype.onevent;  
    document.body.onkeydown = ScreenSaver.prototype.onevent;  
    document.body.onkeypress = ScreenSaver.prototype.onevent;  
      
    var pThis = this;  
    var f = function(){pThis.timeout();}  
    this.timerID = window.setTimeout(f, this.nTimeout);  
}  
ScreenSaver.prototype.timeout = function(){  
    if ( !this.saver ){  
    //超时后的操作
    alert("操作超时 !");
        window.parent.location.href = '/userMSys/login.jsp';
    }  
}  
ScreenSaver.prototype.signal = function(){  
    if ( this.saver ){  
        this.saver.stop();  
    }  
      
    window.clearTimeout(this.timerID);  
      
    var pThis = this;  
    var f = function(){pThis.timeout();}  
    this.timerID = window.setTimeout(f, this.nTimeout);  
}  
 
ScreenSaver.prototype.onevent = function(e){  
    this.screenSaver.signal();  
}  
 
 
var saver;  
function initScreenSaver(){  
    //blort;  
    saver = new ScreenSaver({timeout:1500000});   //超时时间:1s = 1000, 25min = 1500000
    //如果25分钟内不操作,则超时退出登录
}  
function window.onload(){  
   initScreenSaver();  
}
 
</script> 



<script type="text/javascript"><!--

  var pid;
  var id;
  var op;

    dTree.prototype.isParentNode = function(nodeID) {
    var isParentNode = false;
var n=0;

    pid=this.aNodes[nodeID].pid+"";
    id=this.aNodes[nodeID].id+"";


    isParentNode = true;
    if(id==2||id==3){
    return false

    }


//    if(id.length >= 7)//用户菜单显
////    {

        //           document.getElementById("add").style.visibility='hidden';
                   /*
                   document.getElementById("edit").style.visibility='hidden';
                   document.getElementById("delete").style.visibility='visible'; 
                   document.getElementById("refresh").style.visibility='hidden';
                   document.getElementById("gp").style.visibility='hidden';
                   document.getElementById("usr").style.visibility='visible';
                   */
                 
        //           isParentNode = false;  
  
//    }else{
    document.getElementById("add").style.visibility='visible';
                  
                   document.getElementById("edit").style.visibility='visible';
                   document.getElementById("delete").style.visibility='visible'; 
                   document.getElementById("refresh").style.visibility='visible';
                   document.getElementById("gp").style.visibility='visible';
                   document.getElementById("usr").style.visibility='visible';
                   document.getElementById("usrALL").style.visibility='visible';
   
//   }


            /*
    if(id.length==8)//用户菜单显
    {

   
                   document.getElementById("add").style.visibility='hidden';
                   document.getElementById("edit").style.visibility='hidden';
                   document.getElementById("delete").style.visibility='visible'; 
                   document.getElementById("refresh").style.visibility='hidden';
                   document.getElementById("gp").style.visibility='hidden';
                   document.getElementById("usr").style.visibility='visible';
                   document.getElementById("editUserGp").style.visibility='visible';
                 
                   document.getElementById("jqueryDtreeMenu").height ="10px;";
                  
                  
                    op = 1;
  
    }
     else  if(id.length<8&&parseInt(id)%1000==0)//显示右键ou
    {

                
                   document.getElementById("add").style.visibility='visible';
                   document.getElementById("edit").style.visibility='visible';
                   document.getElementById("delete").style.visibility='visible'; 
                   document.getElementById("refresh").style.visibility='visible';
                   document.getElementById("gp").style.visibility='hidden';
                    document.getElementById("usr").style.visibility='hidden';
                     document.getElementById("editUserGp").style.visibility='hidden';
                    op = 2;
  
    }
    else if(id.trim()=="1"||id.trim()==1) //右键example
{ //增加ou


           document.getElementById("add").style.visibility='visible';
                   document.getElementById("edit").style.visibility='visible';
                   document.getElementById("delete").style.visibility='visible'; 
                   document.getElementById("refresh").style.visibility='visible';
                   document.getElementById("gp").style.visibility='hidden';
                   document.getElementById("usr").style.visibility='hidden';
                   document.getElementById("editUserGp").style.visibility='hidden';
   
         op = 4;
   
    }
    else  {    //右键组
              
          document.getElementById("add").style.visibility='visible';
                 document.getElementById("edit").style.visibility='visible';
                 document.getElementById("delete").style.visibility='visible'; 
                 document.getElementById("refresh").style.visibility='visible';
                 document.getElementById("gp").style.visibility='visible';
                 document.getElementById("usr").style.visibility='hidden';
          document.getElementById("editUserGp").style.visibility='hidden';
       op = 3;
   
    }


*/
//if (pid=="1"||pid=="0")
//{


//}else
//{

//}

return  true;//isParentNode;
};
var jqueryDtree = new dTree('jqueryDtree');
jqueryDtree.config.target = "mainFrame";
jqueryDtree.config.folderLinks=true;
jqueryDtree.add(0,-1,' ');
jqueryDtree.add(1,0,'loccaldomain','/userMSys/message.jsp','','','/userMSys/dtree/img/GenericDirectory_small.png','/userMSys/dtree/img/GenericDirectory_small.png');
<%User user=(User)session.getAttribute(UserStatics.USRKEY);
if(user!=null){
int rigth=user.getRight();
if(rigth==1){
%>
jqueryDtree.add(2,0,"<s:text name='password.policy'/>",'/userMSys/policy/form.action','','','/userMSys/dtree/img/GenericDirectory_small.png','/userMSys/dtree/img/GenericDirectory_small.png');
jqueryDtree.add(3,0,"<s:text name='system'/>",'/userMSys/appAction.action','','','/userMSys/dtree/img/GenericDirectory_small.png','/userMSys/dtree/img/GenericDirectory_small.png');

<%
}

}
%>



<%//start
List<JspBean> beanList = (List<JspBean>)
    ActionContext.getContext().getValueStack().findValue("topOu");
%>
<%
if(null != beanList && beanList.size() > 0){
for(JspBean bean : beanList){
%>
jqueryDtree.add(<%=bean.getId() %>,<%=bean.getPid() %>,'<%=bean.getName() %>',
'showChildren.action?ouId=<%=bean.getId() %>',
'','','/userMSys/dtree/img/folder.gif','/userMSys/dtree/img/folderopen.gif');
<%
}
}
%>
    $().ready(function() {

      $('a').contextMenu('jqueryDtreeMenu', {
onContextMenu: function(e) {
  var nodeId = $(e.target).attr('id').substr(jqueryDtree.obj.length+1);
 
// alert("nodeId:"+ $(e.target).attr('id'));
// alert(this.aNodes[nodeId].pid)
 
          if(jqueryDtree.isParentNode(nodeId))
  {
  return true;
  }else return false;
        },
        bindings: {

          'add': function(t) {
        
          if(pid==0){
parent.frames["mainFrame"].location="/userMSys/create_ou.action";
}else{
parent.frames["mainFrame"].location="/userMSys/create_childou.action?id="+id;
}
          },
          'edit': function(t) {

parent.frames["mainFrame"].location="/userMSys/getOuAction.action?id="+id;

   },        
          'delete': function(t) {

            Ext.onReady(function(){
  Ext.Msg.confirm("","<s:text name='menu_tip'/>",function(btn){  
                    if(btn=='yes'){  
                        //发送删除请求  
                      /* Ext.lib.Ajax.request('get','/userMSys/de11lAction.action?id='+id,{  
                               success:function(form,action){   
                                parent.frames["leftFrame"].location="/userMSys/list/doMain.action"
                                alert(action.result);
                                var t = action.result.msg;
                                    alert(t);
                               },
                               failure:function(form,action){
                                    Ext.Msg.alert('错误','无法删除信息,请检查是否有内容!');  
                               }  
                            } 
                           
                        ); */ 
                       
                         Ext.Ajax.request({   
url:'/userMSys/delAction.action?id='+id+'&pid='+pid,   
scope:this,   
sync:true,
success:function(response,options){
var json= Ext.util.JSON.decode(response.responseText);
                                 var res=json.success;
                            
                             if(res){
                             parent.frames["leftFrame"].location="/userMSys/list/doMain.action";
                             }else{
                             Ext.Msg.alert("<s:text name='menu_error'/>", "<s:text name='menu_info'/>");
                             }
},
failure: function(resp,opts) {
                           var respText = Ext.util.JSON.decode(resp.responseText)
                         
}
});
                    }  
                }) 
               
              
               
});
           

          },    
   
          'gp': function(t) {
parent.frames["mainFrame"].location="/userMSys/cnjsp.action?id="+id+"&pid="+pid;
          },
          'usr': function(t) {
        //alert("增加用户");
          parent.frames["mainFrame"].location="/userMSys/nuser/createUserForm.action?ouId="+id;
          },
          'usrALL': function(t) {
            //  批量增加
             
            if(pid==0){
  parent.frames["mainFrame"].location="/userMSys/jsp/user2/addByFile.jsp?ouId="+id;
  }else{
  parent.frames["mainFrame"].location="/userMSys/user/interFileUpload.action?ouId="+id;

 
  }
            },
         
          'refresh': function(t) {
            parent.frames["leftFrame"].location="/userMSys/list/doMain.action";
          }
 
        }

      });
 
    });

  --></script>


</head>

<body bgcolor="#F0FFFF" >
<!--<div id="arrow" class="pulltab" onclick="opTab()">
<table class="inner">
<tr> onload="initScreenSaver()"
<td id="arr" valign="middle">
4
</td>
</tr>
</table>
</div>

<div id="menubar"
style="HEIGHT: expression(document.body.offsetHeight); WIDTH: 223px">   -->
<div class="dtree">

<!--<p>
<a href="javascript: jqueryDtree.openAll();">
<font color="blue">open
all</font> </a> |
<a href="javascript: jqueryDtree.closeAll();">
<font color="blue">close all</font> </a>
</p>
--><script type="text/javascript">
document.write(jqueryDtree);
</script>
</div>

<div class="contextMenu" id="jqueryDtreeMenu">


<ul>

<li id="add" class="comm">
<img src="${pageContext.request.contextPath }/dtree/create.gif" />
<s:text name='menu_create'/>
</li>
<li id="edit" class="comm">
<img src="${pageContext.request.contextPath }/dtree/edit.gif" />
<s:text name='menu_edit'/>
</li>
<li id="delete" class="comm">
<img src="${pageContext.request.contextPath }/dtree/delete.gif" />
<s:text name='menu_del'/>
</li>
<li id="gp" class="comm">
<img src="${pageContext.request.contextPath }/dtree/groupACL.png" />
<s:text name='menu_group'/>
</li>
<li id="usr" class="comm">
<img src="${pageContext.request.contextPath }/dtree/userACL.png" />
<s:text name='menu_user'/>
</li>
<li id="usrALL" class="comm">
<img src="${pageContext.request.contextPath }/dtree/userACL.png" />
<s:text name='menu_users'/>
</li>
<li id="refresh" class="comm">
<img
src="${pageContext.request.contextPath }/dtree/updateentry.gif" />
<s:text name='menu_load'/>
</li>
</ul>

</div>



<!--</div>-->

</body>
<script type="text/javascript">
function dos()
{

  var mnu = document.getElementById("menubar")

        var arrdiv = document.getElementById("arrow")

        var arrtxt = document.getElementById("arr")


          mnu.style.display = "block"
         
        //  window.parent.document.getElementById("cnt").cols="250,*";
         
          arrdiv.style.pixelLeft = mnu.style.width.substring(0 , mnu.style.width.length - 2)

          arrtxt.innerText = "3";

  
}

//dos();
</script>
</html>

你可能感兴趣的:(Ajax,json,bean,ext,prototype)