<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/include/header2.jsp"%>
<link rel="stylesheet" type="text/css" href="${ctx}/css/newCss/dialog.css">
<title>权限管理</title>
<style>
	/*#queryDiv .a_btn, #queryDiv .b_btn {
		margin-right: 5px;
		float:none;
	}
	.btnDiv span {
	    padding-right: 5px !important;
	}*/
</style>
</head>
<body class="bg1">
	<div class="headCon">
		<%@ include file="/WEB-INF/jsp/top2.jsp"%>
	</div>

	<div class="clear"></div>
	<div class="container_fluid">
		<div class="searchCon left_menu managerLeft">
			<jsp:include page="/include/manageLeft.jsp">
				<jsp:param name="index" value="权限管理" />
			</jsp:include>
		</div>	
		<div class="resultCon" style="margin-left: 255px;position:relative">
			<input type="hidden" id="CSRFToken" value="${csrfToken }"/>
			<!--输入框查询的内容-->	
			<div class="reSearch">
				<div class="p_bar" style="border-bottom: 1px dashed #afb4bb;">您当前的位置：权限管理</div>
				<input type="hidden" id="page" name="page" value="1" />
				<div class="row">
					<div class="col-md-4">
						<div class="search-group">
							<span>
								权限名称：
								<input type="text" class="input_txt" name="authorityName" placeholder="请输入权限名称"/>
							</span>
						</div>
					</div>
					<div class="col-md-8">
						<div class="search-group">	
							<span>
								权限值：
								<input type="text" class="input_txt" name="authorityValue" placeholder="请输入权限值"/>
							</span>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="search-group btnCon">
						<span>
							<button class="btn btn-primary" id="addBtn"><span class="glyphicon glyphicon-plus" aria-hidden="ture"></span>添加</button>
						</span>
						<span>
							<button class="btn btn-primary" id="searchBtn"><span class="glyphicon glyphicon-search" aria-hidden="ture"></span>查询</button>
						</span>
					</div>
				</div>
			</div>
			<div class="clear"></div><!-- 清除浮动 -->
			<div class="resultTable" style="width: 99%;padding: 10px;border-radius: 5px;">
				<table id="tbwrap" class="table table-bordered" style="table-layout:fixed;"></table>
				<div class="page eui-pager-custom" id="j_pager"></div>
			</div>	
		</div>
	</div>
		<script type="text/html" id="tb_template">
		<thead>
			<tr>
				<th>权限名称</th>
				<th>权限值</th>
				<th>描述</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody data-type="body">
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
				!>
				<tr class="gradeA <!=classItem!>">
					<td title="<!=item["authorityName"]!>"><!=item["authorityName"]!></td>
					<td title="<!=item["authorityValue"]!>"><!=item["authorityValue"]!></td>
					<td title="<!=item["remark"]!>"><!=item["remark"]!></td>
					<td>
						<a title="详情" data-value="<!=item["authorityId"]!>" data-name="<!=item["authorityName"]!>" class="detail btn btn-primary btn-xs">
						<span class="glyphicon glyphicon-list" aria-hidden="ture"></span>详情</a>
						<a title="修改" data-value="<!=item["authorityId"]!>" data-name="<!=item["authorityName"]!>" class="edit btn btn-primary btn-xs">
						<span class="glyphicon glyphicon-edit" aria-hidden="ture"></span>修改</a>
						<a title="删除" data-value="<!=item["authorityId"]!>" data-name="<!=item["authorityName"]!>" class="delete btn btn-danger btn-xs">
						<span class="glyphicon glyphicon-trash" aria-hidden="ture"></span>删除</a>
				<! if(item.authorityType == '3'){ !>
						<a title="设置数据" data-value="<!=item["authorityId"]!>" data-name="<!=item["authorityName"]!>" class="setdata btn btn-primary btn-xs">设置数据</a>
				<! } !>
					</td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="4"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
	</script>



		<script type="text/javascript">
		var sysAuthorityDialog;
		$(function() {

			// 1、添加
			$("#addBtn").click(function() {
				seajs.use("component/dialog", function(dialog) {
					sysAuthorityDialog = new dialog({
						"width": 800,
						"height": 500,
						"contentType": "iframe",
						"html": "${ctx}/sysAuthority/toAdd.do",
						// 内容
						"title": "添加角色功能关系信息" //标题
					});
				});
			});
			
			// 2、详细
			$("#tbwrap").delegate(".detail", "click", function() {
				// 2.1 获取主键
				var authorityId = $(this).data("value");
				var authorityName = $(this).data("name");
				// 2.2 弹窗窗口，显示详细信息
				seajs.use("component/dialog", function(dialog) {
					sysAuthorityDialog = new dialog({
						"width" : 800,
						"height" : 600,
						"contentType" : "iframe",
						"html" : "${ctx}/sysAuthority/view.do?authorityId=" + authorityId, // 内容
						"title" : "查看"+authorityName+"详细信息" //标题
					});
				});
			});
			
			// 3、编辑
			$("#tbwrap").delegate(".edit", "click", function() {
				// 3.1 获取主键
				var authorityId = $(this).data("value");
			
				// 3.2 弹窗窗口，显示详细信息
				seajs.use("component/dialog", function(dialog) {
					sysAuthorityDialog = new dialog({
						"width": 800,
						"height": 600,
						"contentType": "iframe",
						"html": "${ctx}/sysAuthority/toEdit.do?authorityId=" + authorityId,
						// 内容
						"title": "编辑详细信息" //标题
					});
				});
			});
			// 4、删除
			$("#tbwrap").delegate(".delete", "click", function() {
				var authorityId = $(this).data("value");
			
				if (confirm('确定删除？')) {
					$.post("${ctx}/sysAuthority/delete.do", { authorityId : authorityId, CSRFToken : $("#CSRFToken").val()}, function(result) {
						if ("succ" == result) {
							alert("操作成功");
							// 刷新列表页面
							top.location.replace("${ctx}/sysAuthority/list.do?ts="+new Date().getTime()); //如果操作成功则跳到列表界面 
							// 关闭弹窗窗口
			    			parent.sysAuthorityDialog.close();
						} else if ("notThroughSecurityCheck" == result["isThroughSecurityCheck"]) { // 如果不通过安全检查
							var mess = result["mess"];
							$.post("${ctx}/common/notThroughSecurityCheck.do?ts=" + new Date().getTime(), mess, function(res) {
								alert(res);
							},"json");
	
						} else {
							alert(result);
						}
					}, "json");
				}
			
			});
			// 5、查询
			$("#searchBtn").click(function() {
				search();
			});
			
			// 页面加载完成调用查询分页
			search();
		});
	</script>

		<script type="text/javascript">
		function search() {
			// 这里放包含查询条件的DIV
			seajs.use([ "component/table" ], function(uiTable) {
				var paramData = {
						page:1,
						authorityName:$("[name='authorityName']").val(),
						authorityValue:$("[name='authorityValue']").val(),
					};
				$.post("${ctx}/sysAuthority/ajaxPage.do",paramData,function(data){
					var table = new uiTable({
						 "con": "#tbwrap",//放table的容器
						 "data": {
							 "list": data.dataList//渲染需要的数据
						 },
						 "template": "tb_template",//渲染的模板
						 "pager": {//翻页
							 "con": "#j_pager",//翻页容器
							 "data": {
								 "currentPage": data.currentPage,//当前页
								 "pageCount": data.pageCount,
								 "rowCount": data.rowCount
							 },
							 //翻页样式
							 template:'<ul class="pagination" style="margin: 0;"><li><a title="首页" class="page_first" data-role="first" href="#">首页</a></li><li><a title="上一页" class="page_prev" href="#" data-role="prev">上一页</a></li><li class="pageNum" data-value="pageNum"><a></a></li><li><a title="下一页" class="page_next" href="#" data-role="next">下一页</a></li><li><a title="尾页" class="page_last" href="#" data-role="last">尾页</a></li></ul><div class="pageGo">共<span data-role="rowCount"></span>条 跳转到 <input  type="text" data-target="input" class="input_txt" style="width:80px;"/><a href="#" data-role="go" class="go">GO</a></div>'
						 }
					 });
					 table.getPager().bind("changePage", function (event, page, hander) {//点击翻页时
						$("#page").val(page);
						var paramData = {
								page:page,
								authorityName:$("[name='authorityName']").val(),
								authorityValue:$("[name='authorityValue']").val(),
							};
						 $.post("${ctx}/sysAuthority/ajaxPage.do",paramData,function(change){
							 table.render({//重新渲染
									list: change.dataList//传入新的渲染数据
								});
								hander({
									"currentPage": change.currentPage,
									"pageCount": change.pageCount,
									"rowCount": change.rowCount
								});
						 });
					 });
				});
			});
		}
	</script>
	<script src="${ctx}/js/lib/perfect-scrollbar.jquery.js"></script>
	<script>
	     $(function () {
		    $(".resultCon").perfectScrollbar();
		    $(".searchCon").perfectScrollbar();
			resize();
            $(window).resize(function(){
				resize();
			});			
	    });
	    function resize(){
			//获取窗口高度
			var windowheight=$(window).height();
			var leftList = windowheight-40;
			$(".searchCon").css({"height":leftList+"px"});
			$(".resultCon").css({"height":leftList-12+"px"});
			//$(".tableMain").css({"height":windowheight-40-42-131+"px"});
			//$(".table_list").css({"height":windowheight-40-42-100-85+"px"});
			$(".searchCon").perfectScrollbar("update");
			$(".resultCon").perfectScrollbar("update");
		}
	</script>
		<%@ include file="/include/footer.jsp"%>
</body>
</html>
