<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<%@page import="com.blueland.bpm.manage.util.*"%>
<%
	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">
<head>
	<script type="text/javascript" src="${ctx_js_plugins}/zTree/js/jquery-1.4.4.min.js"></script>
   	<script type="text/javascript" src="${ctx_js_plugins}/zTree/js/jquery.ztree.core-3.4.js"></script>
   	<script type="text/javascript" src="${ctx_js_plugins}/zTree/js/jquery.ztree.excheck-3.4.js"></script>
	<link rel="stylesheet" href="${ctx_js_plugins}/zTree/css/demo.css" type="text/css">
	<link rel="stylesheet" href="${ctx_js_plugins}/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css"> 
	<script type="text/javascript">
	 var jQuery_1_4_4= $.noConflict(true);
	</script>
	<SCRIPT type="text/javascript">
	
		var inputObj;
		var initParams1="";
		var initParams2="";
		var initParams3="";
		var initParams4=false;
		function createFileSetting(){
			var setting = {
					view: {
						dblClickExpand: false,
						expandSpeed: "slow",
						selectedMulti: false
					},
					data: {  
				        simpleData: {  
				            enable : true,  
				            idKey : "id",  
				            pIdKey : "pId" ,
				            DIY:"isAccessTopMenu"
				        }  
				    },async: {
						enable: true,
						url:"<%=MyContants.BPM_FILE_PATH%>"+"/ebpm-bpa-web/flow/getTreeProcessFile"
					},
					callback: {
						onClick: onFileClick
					}
				};
			return setting;
		}
		function beforeClick(treeId, treeNode) {
			var zTree = jQuery_1_4_4.fn.zTree.getZTreeObj("treeFile");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
		
		function onCheck(e, treeId, treeNode) {
			var zTree = jQuery_1_4_4.fn.zTree.getZTreeObj("treeFile"),
			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<=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=inputObj+"OnDbClick";
				eval(fun+"('"+name +"','"+id+"')");    
			}catch(e){}
		}

		
		function onFileClick(e, treeId, treeNode) {
			if(treeNode.fileId == null){
				return;
			}
			var zTree = jQuery_1_4_4.fn.zTree.getZTreeObj("treeFile"),
			nodes = zTree.getSelectedNodes(),
			name = "",
			fileId="";
			if(nodes==""){
				try{
					var fun=inputObj+"OnDbClick";
					eval(fun+"('','')");    
				}catch(e){}
				hideMenu();
				return ;
			}
			//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<=initParams3)
					return;
				if(nodes[i].pId=="TOP_FLOW_TYPE"){
					continue;
				}
				name += nodes[i].name + ",";
				fileId += nodes[i].fileId + ",";
			}
			
			if (fileId.length > 0 ) {
				fileId = fileId.substring(0, fileId.length-1);
			}else{
				return;
			}
			if (name.length > 0 ) name = name.substring(0, name.length-1);
			try{
				var fun=inputObj+"OnDbClick";
				eval(fun+"('"+name +"','"+fileId+"')");    
			}catch(e){}
			hideMenu();
		}
		
		function showFlowFile(inputName,params1,params2,params3) {
			initParams1=params1;
			initParams2=params2;
			initParams3=params3;
			jQuery_1_4_4.fn.zTree.init(jQuery_1_4_4("#treeFile"), createFileSetting());
			inputObj=inputName;
			var cityObj = jQuery_1_4_4("#"+inputName);
			var cityOffset = cityObj.offset();
			jQuery_1_4_4("#menuFileContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			jQuery_1_4_4("body").bind("mousedown", onBodyDown);
			
		}
		
		function hideMenu() {
			jQuery_1_4_4("#menuFileContent").fadeOut("fast");
			jQuery_1_4_4("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "menuFileContent" || jQuery_1_4_4(event.target).parents("#menuFileContent").length>0)) {
				hideMenu();
			}
		}

		jQuery_1_4_4(document).ready(function(){
			//
		});
	</SCRIPT>
 </head>
<BODY>
<div  id="menuFileContent" class="menuContent" style="z-index:1;display:none; position: absolute;">
	<ul id="treeFile" class="ztree" style="margin-top:0; width:270px;height:150px"></ul>
	
</div>
</BODY>
</HTML>