<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html style="overflow-x:hidden;overflow-y:auto;">
<head>
	<title>角色权限</title>
	<%@include file="/WEB-INF/views/include/head.jsp" %>
	<%@include file="/WEB-INF/views/include/treeview.jsp" %>
	<script type="text/javascript">
		var tree, setting = {
				check:{
					enable:true,
					chkboxType:{"Y":"ps","N":"s"}
				},
				data: {
		            simpleData: {
		                enable: true,
		                idKey: "code",
		                pIdKey: "parentCode",
		            },
		            key:{
		            	checked:"enable"
		            }
		        },
				view:{
					showIcon:false, 
				},
				callback:{
					onCheck:function(ev,id, node){
						if('exam_mark'==node.parentCode&&!node.enable){
							checkChildAllDisable(node.parentCode)
						}
						if('exam_reject_list'==node.parentCode&&!node.enable){
							checkChildAllDisable(node.parentCode)
						}
						if('exam_inspected_info'==node.parentCode&&!node.enable){
							checkChildAllDisable(node.parentCode)
						}
					}
				}
			};
		$(document).ready(function(){
			// 初始化树结构
			tree = $.fn.zTree.init($("#tree"), setting, JSON.parse('${privilegeList}'));
			var nodes = tree.getNodesByParam("level", 0);
			for(var i=0; i<nodes.length; i++) {
				tree.expandNode(nodes[i], true, false, false);
			}
		});
		function checkChildAllDisable(pcode){
			var nodes = tree.getNodesByParam("parentCode", pcode);
			for(var i=0; i<nodes.length; i++) {
				if(nodes[i].enable){
					return;
				}
			}
			var pnode = tree.getNodeByParam("code", pcode);
			tree.checkNode(pnode, false, true, true);
		}
		function save() {
			var checkedNodes = tree.getCheckedNodes();
			if(checkedNodes&&checkedNodes.length>0){
				var codes=[];
				checkedNodes.forEach(e => {
					codes.push(e.code);
				 });
				$("#selectPrivileges").val(codes.join(','));
			}
			
			$("#searchForm").submit();
			return false;
		}
	</script>
</head>
<body>
	<form id="searchForm"  action="${ctx}/admin/basic/role/info/privilege/save" method="post" class="breadcrumb form-search">
		<input type="hidden" id="schoolId" name="schoolId" value="${schoolId}"/>
		<input type="hidden" id="role" name="role" value="${roleCode}"/>
		<input type="hidden" id="selectPrivileges" name="selectPrivileges"/>
		<div>
			<label>角色</label>
			<input type="text" disabled="disabled" name="roleName" value="${roleName}"  maxlength="20" class="input-medium"/>
			&nbsp;
			<input id="btnSubmit" class="btn btn-primary" type="button" value="保存" onclick="save()"/>
			&nbsp;
			<a href="${ctx}/admin/basic/role/info/list?schoolId=${schoolId}" class="btn">返回</a>
		</div>
	</form>
	<div id="tree" class="ztree" style="padding:15px 20px;"></div>
</body>