<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/head.jsp" %>
	<style type="text/css">.sort{color:#0663A2;cursor:pointer;}</style>
</head>
<body>
    <ul class="nav nav-tabs">
        <li class="active"><a href="##">用户列表</a></li>
        <c:if test="${web_user.schoolAdmin==true}">
        <li><a href="${ctx}/admin/user/add">创建用户</a></li>
        </c:if>
    </ul>
	<form id="searchForm"  action="${ctx}/admin/user/list" method="post" class="breadcrumb form-search">
		<input type="hidden" id="pageNumber" name="pageNumber" value="${query.pageNumber}"/>
		<input type="hidden" id="pageSize" name="pageSize" value="${query.pageSize}"/>
		<div>
			<label>登录名</label>
			<input type="text" name="loginName" value="${query.name}"  maxlength="20" class="input-medium"/>
			&nbsp;
			<label>角色</label>
            <select class="input-medium" name="role" id="role-select">
                <option value="">不限</option>
                <c:forEach items="${roleList}" var="role">
                <option value="${role.value}" <c:if test="${role.value==query.role.value}">selected</c:if>>${role.name}</option>
                </c:forEach>
            </select>
            &nbsp;
            <label>状态</label>
            <select class="input-medium" name="enable" id="enable-select">
                <option value="">不限</option>
                <option value="true" <c:if test="${query.enable!=null && query.enable==true}">selected</c:if>>启用</option>
                <option value="false" <c:if test="${query.enable!=null && query.enable==false}">selected</c:if>>禁用</option>
            </select>
            &nbsp;
			<input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
			<c:if test="${web_user.schoolAdmin==true}">
			&nbsp;
			<a href="${ctx}/admin/user/add" class="btn">新建</a>
			</c:if>
		</div>
	</form>
	<tags:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>登录名</th>
				<th>名称</th>
				<th>角色</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${query.result}" var="user">
			<tr>
			    <td>${user.loginName}</td>
				<td>${user.name}</td>
				<td>${user.role.name}</td>
				<td>
				    <c:if test="${user.enable==true}">
				    启用
				    </c:if>
				    <c:if test="${user.enable==false}">
				    禁用
                    </c:if>
				</td>
				<td>
				    <c:if test="${web_user.id!=user.id && web_user.schoolAdmin==true && user.role.value!= 6}">
					<a href="${ctx}/admin/user/edit?id=${user.id}">修改</a>
					&nbsp;
					<a href="${ctx}/admin/user/delete?id=${user.id}" data-name="${user.loginName}" class="delete-link">删除</a>
					</c:if>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${query}</div>
<script type="text/javascript">
$('.delete-link').click(function(){
    return confirm('确定要删除用户'+$(this).attr('data-name')+'吗？');
});
function page(n,s){
	$("#pageNumber").val(n);
	$("#pageSize").val(s);
	$("#searchForm").submit();
	return false;
}
function goSearch(){
	$("#pageNumber").val(1);
	$("#pageSize").val('${query.pageSize}');
	$("#searchForm").submit();
	return false;
}
</script>	
</body>
</html>