<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/skin/default/skin.css" rel="stylesheet" type="text/css" id="skin" />
<link href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="row-fluid">
			<div class="page-header">
				<h3>编辑二级管理员权限  <small></small></h3>
			</div>
			<form class="form-horizontal" id="horizontalPermissions">
			<table class="table table-striped table-bordered table-condensed" style="font-size: 10px;width: 100%">
				<thead>
					<tr>
						<th>您要修改的管理员为:${adminchildinfo.adminLoginName }<input value="10" name="id" type="hidden"></th>
						<th>一级权限</th>
						<th>二级权限（选中表示拥有）</th>
					</tr>
				</thead>
				<tbody>
				<!-- 遍历所有权限(包括一级权限) -->
				<c:if test="${! (empty menuInfos) }">
				<%-- <c:forEach var="i" begin="1" end="${fn:length(menuInfos)}"> --%>
					<c:forEach items="${menuInfos }" var="menu">
					<tr class="list-users">
						<td></td>
						<!-- 显示一级权限名称 -->
						<td>
							<label><input name="pid" id="checkInput${menu.permissionsId}" value="${menu.permissionsId}" onclick="selected(this)" class="allSelect"  var="permission"  type="checkbox">${menu.permissionsName }</label>
						</td>
						<td>
							<table>
								<tbody>
								<c:forEach items="${menu.menus }" var="info">
									<tr>															
										<td>
										<input class="pSelect${menu.permissionsId}" onclick="selectedTwo(this)" id="checkInput${menu.permissionsId}_${menu.permissionsId }" 
											<c:forEach items="${adminChildHavePermission }" var="Permission">
											${Permission.permissionId==info.ermissionsId?'checked="checked"':''}
											</c:forEach> name="eid" value="${info.ermissionsId }" type="checkbox">${info.ermissionsName }
										</td>
									</tr>
								</c:forEach>
								</tbody>
							</table>
						</td>
					</tr>
					</c:forEach>
					<%-- </c:forEach> --%>
				</c:if>
				</tbody>
			</table>
			<div class="form-actions text-c">
				<input type="hidden" name="adminChildId" value = "${adminchildinfo.adminId }" >
				<input class="btn btn-success btn-large" value="确认修改" type="button" onclick="admin_updateAllPermissions()">
			</div>	
		  </form>
		  </div>
		  <script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
	<script type="text/javascript">
		//勾选一级权限则选中全部二级权限
		function selected(_this){
			   obj = $(_this);
			   if (obj.prop("checked")==false){
	                 obj.parents('td:first').next().find('input[type=checkbox]').prop("checked", false); 
	           }else{                  
	                obj.parents('td:first').next().find('input[type=checkbox]').prop("checked", true);     
	           }
		}
		//勾选二级权限则取消一级权限选中
		function selectedTwo(_this){
			   // 当前选中的个数
			   var count = 0;
			   var $class = $("." + $(_this).attr("class"));
			   for(var i = 0; i < $class.length; i++) {
				   if ($($class[i])[0].checked) {
					   count = count + 1;
				   }
			   }
			   
			   if (count == $class.length) {
				   $("#checkInput" + $(_this).attr("id").split("_")[1]).attr("checked", true);
			   } else {
				   $("#checkInput" + $(_this).attr("id").split("_")[1]).attr("checked", false);
			   }
		}
	/*管理员权限-修改*/
	function admin_updateAllPermissions(){
			  $.ajax({
	              url: '${pageContext.request.contextPath }/admin/admin/updateAllPermissions',
	              type: "POST",
	              dataType: "json",
	              data: $("#horizontalPermissions").serialize(),
	              success:  function(data){
	            	  layer.msg(data.status,{icon: 1,time:3000},function(){
	            		  layer_close();
	            		   window.location.href = '${pageContext.request.contextPath }/admin/admin/listUI'; 
	            	  });
	            	  
	              },
	              error:function(data){
	            	  layer.msg(data.status,{icon: 5,time:3000});
	              }
	          });
	}
	</script>
</body>
</html>