<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<hred>
<%@ include file="/commons/meta.jsp" %>
	<link rel="stylesheet" href="${ctx}/resource/js/plugins/zTree/css/demo.css" type="text/css">
	<link rel="stylesheet" href="${ctx}/resource/js/plugins/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">  
   <script type="text/javascript" src="${ctx}/resource/js/plugins/zTree/js/jquery.ztree.core-3.4.js"></script>
   	<script type="text/javascript" src="${ctx}/resource/js/plugins/zTree/js/jquery.ztree.excheck-3.4.js"></script>
	<SCRIPT type="text/javascript">
	
		var p_inputObj;
		var p_initParams1="";
		var p_initParams2="";
		var p_initParams3="";
		var p_initParams4=false;
		function createSetting(){
			var setting = {
					view: {
						dblClickExpand: false,
						expandSpeed: "slow",
						selectedMulti: false
					},
					data: {  
				        simpleData: {  
				            enable : true,  
				            idKey : "id",  
				            pIdKey : "pId" ,
				            DIY:"isAccessTopMenu"
				        }  
				    },async: {
						enable: true,
						url:"${ctx}/procDefMgr/getProcDefTree.do",
						autoParam:["id", "name=n","level=lv"],
				    	otherParam:{"assignTreeId":p_initParams1,"treeLevel":p_initParams2}
					},
					callback: {
						onDblClick: onDblClick
					}
				};
			return setting;
		}
		
		function createSettingCheck(){
			var setting = {
					check: {
						enable: true,
						chkboxType: {"Y":"", "N":""}
					},
					view: {
						dblClickExpand: false,
						expandSpeed: "slow"
					},
					data: {  
				        simpleData: {  
				            enable : true,  
				            idKey : "id",  
				            pIdKey : "pId" ,
				            DIY:"isAccessTopMenu"
				        }  
				    },async: {
						enable: true,
						url:"${ctx}/procDefMgr/getProcDefTree.do",
						autoParam:["id", "name=n","level=lv"],
				    	otherParam:{"assignTreeId":p_initParams1,"treeLevel":p_initParams2}
					},
					callback: {
						beforeClick: beforeClick,
						onCheck: onCheck
					}

				};
			return setting;
		}

		function beforeClick(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("p_treeDept");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
		
		function onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("p_treeDept"),
			nodes = zTree.getCheckedNodes(true),
			name = "",
			id="";
			
			//nodes.sort(function compare(a,b){return a.id-b.id;});
			for (var i=0, l=nodes.length; i<l; i++) {
				if(nodes[i].level<=0||nodes[i].level<=p_initParams3)
					continue;
				name += nodes[i].name + ",";
				id += nodes[i].id + ",";
			}
			
			if (id.length > 0 ) id = id.substring(0, id.length-1);
			if (name.length > 0 ) name = name.substring(0, name.length-1);
			try{
				var fun=p_inputObj+"OnDbClick";
				eval(fun+"('"+name +"','"+id+"')");    
			}catch(e){}
		}

		
		function onDblClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("p_treeDept"),
			nodes = zTree.getSelectedNodes(),
			name = "",
			id="";
			
			//nodes.sort(function compare(a,b){return a.id-b.id;});
			for (var i=0, l=nodes.length; i<l; i++) {
				if(nodes[i].level<=0||nodes[i].level<=p_initParams3)
					return;
				name += nodes[i].name + ",";
				id += nodes[i].id + ",";
			}
			
			if (id.length > 0 ) id = id.substring(0, id.length-1);
			if (name.length > 0 ) name = name.substring(0, name.length-1);
			try{
				var fun=p_inputObj+"OnDbClick";
				eval(fun+"('"+name +"','"+id+"')");    
			}catch(e){}
			hideMenu();
		}
		
		function showMenu(inputName,params1,params2,params3) {
			//alert(params2);
			p_initParams1=params1;
			p_initParams2=params2;
			p_initParams3=params3;
			$.fn.zTree.init($("#p_treeDept"), createSetting());
			p_inputObj=inputName;
			var cityObj = $("#"+inputName);
			var cityOffset = cityObj.offset();
			$("#p_menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			$("body").bind("mousedown", onBodyDown);
			
		}
		
		function showMenu1(inputName,params1,params2,params3) {
			//alert(params2);
			p_initParams1=params1;
			p_initParams2=params2;
			p_initParams3=params3;
			$.fn.zTree.init($("#p_treeDept"), createSettingCheck());
			p_inputObj=inputName;
			var cityObj = $("#"+inputName);
			var cityOffset = cityObj.offset();
			$("#p_menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			$("body").bind("mousedown", onBodyDown);
			
		}
		
		function hideMenu() {
			$("#p_menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {		
			
			if (!(event.target.id == "p_menuBtn" || event.target.id == "p_menuContent" || $(event.target).parents("#p_menuContent").length>0)) {
				hideMenu();
			}
		}

		$(document).ready(function(){
			//
		});
	</SCRIPT>
 </HEAD>
<BODY>
<div  id="p_menuContent" class="menuContent" style="z-index:1;display:none; position: absolute;">
	<ul id="p_treeDept" class="ztree" style="margin-top:0; width:230px;height: auto;max-height: 300px;"></ul>
	
</div>
</BODY>
</HTML>