<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jspf"%>
<!-- COMPOSE MESSAGE MODAL -->
		<div class="modal-dialog" style="width: 860px;">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title"><i class="fa fa-envelope-o"></i>查看角色</h4>
				</div>
				<div class="modal-body">
					<div class="row form-group">
						<div class="col-sm-2">
		  					<span class="span">角色标识：</span>
						</div>
						<div class="col-sm-4">
		 					${role.roleIdentity}
						</div>
						<div class="col-sm-2">
		  					<span class="span">角色名称：</span>
						</div>
						<div class="col-sm-4">
		 					${role.roleName}
						</div>
					</div>
					<div class="row form-group">
						<div class="col-sm-2">
		  					<span class="span">角色状态：</span>
						</div>
						<div class="col-sm-4">
							<c:forEach items="${roleStatusMap}" var="map">
					    		<c:if test="${map.key eq role.roleStatus}">
					    			${map.value}
					    		</c:if>
						    </c:forEach>
						</div>
						<div class="col-sm-2">
		  					<span class="span">角色描述：</span>
						</div>
						<div class="col-sm-4">
		 					${role.roleDesc}
						</div>
					</div>
					<div class="row form-group">
						<div class="col-sm-12" id="tree_div">
							
						</div>
					</div>
				</div>
				<div class="modal-footer">
				    <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-times"></i>取消</button>
				</div>
			</div>
		</div>
    
		<script type="text/javascript">
			$(function(){
				//取得角色对应的权限列表
				$.post("system/role/getRoleResourcePrmsList.do", {roleId:"${role.roleId}"},function(data){
					if (typeof(data.resType) == "undefined") { 
						return;
					}
					
					//取得所有的权限列表
					$.post("system/role/getResList.do",{resType:data.resType},function(result){
						var treeArys=[];
						treeArys.push("<div class='box'>");
						treeArys.push("<div class='box-body table-responsive'>");
						treeArys.push("<h4>"+data.resTypeStr+"</h4>");
						treeArys.push("<table class='table tree table-bordered table-striped table-condensed'>");
						treeArys.push("<tr class='treegrid-0'><td><input type='checkbox' id='allResIds' value='0' />所有资源</td><td></td></tr>");
						$.each(result.data,function(index,res){
							var arys = [];
							var parentClass="";
							var chkChildStr="";
							var chkStr="<input type='checkbox' name='resId' value='"+res.resId+"' />";
							
							if(parseInt(res.resParentId)>0){
								parentClass="treegrid-parent-"+res.resParentId;
							}
							if(res.leaf){
								<c:forEach items="${prmsList}" var="prms">
						    		arys.push("<input type='checkbox' name='prmsId' value='${prms.prmsId}' /> ${prms.prmsName}");
						    	</c:forEach>
						    	chkChildStr=arys.join("&nbsp;&nbsp;&nbsp;&nbsp;");
							}
							treeArys.push("<tr class='treegrid-"+res.resId+" "+parentClass+"'><td>"+chkStr+res.resName+"</td><td>"+chkChildStr+"</td></tr>");
						});
						treeArys.push("</table>");
						treeArys.push("</div>");
						treeArys.push("</div>");
						$("#tree_div").html(treeArys.join(""));
						$('.tree').treegrid({
		                    expanderExpandedClass: 'glyphicon glyphicon-minus',
		                    expanderCollapsedClass: 'glyphicon glyphicon-plus'
		                });
						
						//标记角色包含的资源和权限
						var nodes = $("input[name='resId']");
						for ( var i = 0; i < nodes.length; i++) {
							var node = $(nodes[i]);
							if(data.data["RES-"+node.val()]){
								node.attr("checked",true);
								$.each(data.data["RES-"+node.val()],function(j,p){
									$(node.parent().next().children("input[value='"+p+"']")).attr("checked",true);
								});
							}
						}
						
						//禁用checkbox
						var checkbox = $("#tree_div").find("input:checkbox");
						checkbox.each(function(){
							$(this).attr("disabled","disabled");
						});
					});
				});
			});
		</script>