<%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.blueland.bpm.manage.util.BaseUser"%>
<%@ include file="/commons/taglibs.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	boolean isEbpmAdmin=BaseUser.isEbpmAdmin(request);
%>
<!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>
	<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-1.4.4.min.js"></script>
	<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" src="${ctx }/resource/js/plugins/zTree/js/jquery.ztree.exedit-3.4.js"></script>

	<script>
		(function() {
			var _skin="blue";
			document.write('<script src="${ctx }/resource/js/plugins/artDialog/jquery.artDialog.js?skin=' + (_skin || 'blue') +'"></sc'+'ript>');
		})();
	</script>
	<script src="${ctx }/resource/js/plugins/artDialog/iframeTools.source.js"></script>
	<script src="${ctx }/resource/js/common/application.js"></script>
	<SCRIPT type="text/javascript">
		var zNodes ;
		var setting = {
			view: {
				<%if(isEbpmAdmin){%>
				addHoverDom: addHoverDom,
				<%}%>
				removeHoverDom: removeHoverDom,
				dblClickExpand : false,
				selectedMulti: false
			},
			edit: {
				enable: <%=isEbpmAdmin%>,
				showRemoveBtn: setRemoveBtn,
				removeTitle: "删除",
				showRenameBtn: setRenameBtn,
				renameTitle: "编辑",
				drag:{isMove:false}
			},
			data: {
				simpleData: {
					enable : true,
					idKey : "id",
					pIdKey : "pId" ,
					DIY:"isAccessTopMenu"
				}
			},async: {
				enable: true,
				url:"${ctx}/sysGlType/geWfTypeTree.do",
				autoParam:["id", "name=n","level=lv"],
				otherParam:{"otherParam":"userTreeAsync"},
				dataFilter: filter
			},callback: {
				beforeEditName: beforeEditName,
				beforeRemove: beforeRemove,
				beforeClick: beforeClick
			}

		};

		function filter(treeId, parentNode, childNodes) {
			//alert(childNodes);
			//默认加载第一个或者根节点
			if(typeof(parentNode)=="undefined"||parentNode==null||parentNode==""){
				//alert(childNodes[2].id);

			}

			return childNodes;
		}
		function beforeClick(treeId, treeNode) {
			//判断是否有权限访问根节点
			if (treeNode.pId==""||treeNode.isAccessTopNode=="false") {
				return false;
			} else {
				parent.document.getElementById("rightFrame").src="${ctx}/sysGlType/show.do?typeId="+treeNode.id+"&processTypeName="+encodeURIComponent(treeNode.name);
			}
			return true;
		}

		function setRemoveBtn(treeId, treeNode) {
			if (treeNode.pId==""||treeNode.isAccessTopNode=="false") {
				return false;
			}
			return true;
		}
		function setRenameBtn(treeId, treeNode) {
			if (treeNode.pId==""||treeNode.isAccessTopNode=="false") {
				return false;
			}
			return true;
		}


		function beforeRemove(treeId, treeNode) {
			if(confirm("您确认删除["+ treeNode.name +"]流程分类吗？")){
				var url="${ctx }/sysGlType/delete.do";
				$.ajax({
					url: url,
					type: "post",
					data: {typeId: treeNode.id},
					success : function(data){
						alert(data);
						parent.document.getElementById("leftFrame").src=parent.document.getElementById("leftFrame").src;
						parent.document.getElementById("rightFrame").src="${ctx}/sysGlType/show.do";
					}
				});
			}
			return false;
		}

		function beforeEditName(treeId, treeNode) {
			var url="${ctx }/sysGlType/edit.do?typeId="+treeNode.id;
			showDiaLog(url, '编辑流程分类', '500px', '400px');
			return false;
		}

		function addHoverDom(treeId, treeNode) {
			//判断是否有权限访问根节点

			//if (treeNode.pId==""||treeNode.isAccessTopNode=="false") {
			//return false;
			//}
			var sObj = $("#" + treeNode.tId + "_span");
			if (treeNode.editNameFlag || $("#addBtn_"+treeNode.id).length>0) return;
			var addStr = "<span class='button add' id='addBtn_" + treeNode.id
					+ "' title='新增流程分类'></span>";
			sObj.after(addStr);
			var btn = $("#addBtn_"+treeNode.id);
			if (btn) btn.bind("click", function(){
				//removeHoverDom(treeId, treeNode);
				var url="${ctx}/sysGlType/create.do?typeParentId="+treeNode.id+"&typeParentName="+treeNode.name;
				showDiaLog(url, '新增流程分类', '500px', '400px');
				return false;
			});
		};

		function removeHoverDom(treeId, treeNode) {
			$("#addBtn_"+treeNode.id).unbind().remove();
		};

		$(document).ready(function(){
			$.fn.zTree.init($("#dataTree"), setting);
		});
	</SCRIPT>
</head>

<body>
<div class="zTreeDemoBackground left">
	<ul id="dataTree" class="ztree"></ul>
</div>

<form  id="queryForm" name="queryForm" action="" method="post" target="myIFrame"></form>
<iframe name="myIFrame" id="myIFrame" style="display:none" src="" width="0"  height="0"></iframe>
</body>
</html>