<%@ 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>
    <div id="importBox" class="hide">
        <form id="importForm" action="${ctx}/admin/user/subject/import" method="post" enctype="multipart/form-data"
              style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
            <input name="isHeader" type="hidden" value="true"/>
            <input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
            <input id="btnImportSubmit" class="btn btn-primary" type="submit" value="  导    入  "/>
            <a href="${ctx}/admin/user/subject/template?isHeader=true">下载模板</a>
        </form>
    </div>
        <div id="importInspectorBox" class="hide">
        <form id="importForm" action="${ctx}/admin/user/subject/import" method="post" enctype="multipart/form-data"
              style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
            <input name="isHeader" type="hidden" value="false"/>
            <input id="uploadInspectorFile" name="file" type="file" style="width:330px"/><br/><br/>　　
            <input id="btnImportInspectorSubmit" class="btn btn-primary" type="submit" value="  导    入  "/>
            <a href="${ctx}/admin/user/subject/template?isHeader=false">下载模板</a>
        </form>
    </div>
    <div id="importClassBox" class="hide">
        <form id="importClassForm" action="${ctx}/admin/user/class/import" method="post" enctype="multipart/form-data"
              style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
            <input id="uploadClassFile" name="file" type="file" style="width:330px"/><br/><br/>　　
            <input id="btnImportClassSubmit" class="btn btn-primary" type="submit" value="  导    入  "/>
            <a href="${ctx}/admin/user/class/template">下载模板</a>
        </form>
    </div>
<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.loginName}" maxlength="20" class="input-small"/>
        &nbsp;
        <label>姓名</label>
        <input type="text" name="name" value="${query.name}" maxlength="20" class="input-small"/>
        &nbsp;
        <label>来源</label>
        <select class="input-small" name="source" id="source-select">
            <option value="">不限</option>
            <c:forEach items="${sourceList}" var="source">
                <option value="${source.value}"
                        <c:if test="${source.value==query.source.value}">selected</c:if>>${source.name}</option>
            </c:forEach>
        </select>
        &nbsp;
        <label>角色</label>
        <select class="input-small" 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-small" 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>
            &nbsp;
            <div class="btn-group">
                <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                    导入<span class="caret"></span>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="##" id="btnImport">评卷组长</a></li>
                    <li><a href="##" id="btnImportInspector">复核员</a></li>
                </ul>
            </div>
            &nbsp;
            <input id="btnImportClass" class="btn" type="button" value="导入评卷员机组"/>
            &nbsp;
            <div class="btn-group">
				<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
					导出<span class="caret"></span>
				</a>
				<ul class="dropdown-menu">
					<li><a href="##" onclick="goExport()">导出</a></li>
					<li><a href="##" onclick="goExportExam()">按考试导出</a></li>
				</ul>
			</div>
			 &nbsp;
            <a href="${ctx}/admin/user/batchAdd" class="btn">批量创建</a>
            &nbsp;
            <input id="btnEnable" class="btn" type="button" value="启用" onclick="goEnable(true)"/>
            &nbsp;
            <input id="btnEnable" class="btn" type="button" value="禁用" onclick="goEnable(false)"/>
            &nbsp;
            <input id="btnReset" class="btn" type="button" value="重置密码" onclick="goReset()"/>
        </c:if>
    </div>
</form>
<form id="exportForm" action="${ctx}/admin/user/export" method="post" class="breadcrumb form-search hide">
        <input type="text" name="loginName" value="${query.loginName}" maxlength="20" class="input-small"/>
        <input type="text" name="name" value="${query.name}" maxlength="20" class="input-small"/>
        <input type="text" name="source" value="${query.source.value}" maxlength="20" class="input-small"/>
         <input type="text" name="role" id="roleId" value="${query.role.value}" maxlength="20" class="input-small"/>
         <input type="text" name="enable" value="${query.enable}" maxlength="20" class="input-small"/>
</form>
<tags:message content="${message}"/>
<form id="checkForm" action="${ctx}/admin/user/toggle" method="post" class="breadcrumb form-search">
<input type="hidden" id="enable" name="enable" value=""/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th><input type="checkbox" id="ids">登录名</th>
        <th>名称</th>
        <th>来源</th>
        <th>角色</th>
        <th>状态</th>
        <th>关联账号</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${query.result}" var="user">
        <tr>
            <td><input type="checkbox" class="ids" name="ids" value="${user.id}">${user.loginName}</td>
            <td>${user.name}</td>
            <td>${user.source.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>${user.relatedAccount}</td>
            <td>
                <c:if test="${web_user.schoolAdmin==true && user.source.value==1}">
                    <a href="${ctx}/admin/user/edit?id=${user.id}&pageNumber=${query.pageNumber}&name=${query.name}&loginName=${query.loginName}&source=${query.source.value}&role=${query.role.value}&enable=${query.enable}">修改</a>
                    <a href="javascript:void(0)" class="reSetPassword-button" data-id="${user.id}"
                       onclick="reSetPassword('${user.id}');">重置密码</a>
                </c:if>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="reSetPasswordWin" style="display:none">
    <div class="password-header">
        <p class="title">重置密码</p>
        <p class="image-close password-close"><img src="${ctxStatic}/mark-new/images/images-close.png"/></p></div>
    <div class="password-content"><input type="text" class="password-value" placeholder="请输入新的密码"/><i class="passwordWrong"></i></div>
    <a href="#" class="btn btn-small btn-info password-btn">确定</a>
</div>
</form>
<div class="pagination">${query}</div>
<style type="text/css">
        .sort {
            color: #0663A2;
            cursor: pointer;
        }
        
        .taskWindow, .reSetPasswordWin {
            width: 400px;
            min-height: 150px;
            background: #fff;
            font-family: "微软雅黑", Fixedsys;
            border: #5d6d7d solid 1px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin: -150px 0 0 -200px;
            text-align: center;
            z-index: 99999;
        }
        
        .task-header, .password-header {
            width: 100%;
            height: 46px;
            background: #5d6d7d;
            color: #fff;
        }
        
        .task-content, .password-content {
            font-size: 18px;
            color: #005277;
            text-align: left;
            padding: 15px;
            line-height: 30px;
            word-wrap: break-word;
        }
        
        .image-close {
            margin-top: 15px;
            margin-right: 15px;
            cursor: pointer;
            float: right;
        }
        
        .title {
            font-size: 22px;
            font-weight: bold;
            color: #fff;
            margin: 0px;
            padding: 13px 0 0 13px;
            float: left;
        }

        .task-count, .password-value {
            width: 150px;
        }

        .btn-info {
            height: 25px;
            margin-left: 320px;
            margin-bottom: 20px;
        }
        
        .wrong, .passwordWrong {
            font-size: 12px;
            color: #f00;
            line-height: 30px;
            padding-left: 20px;
        }
        
        #cover {
            position: fixed;
            z-index: 9999;
            top: 0px;
            left: 0px;
            display: none;
            width: 100%;
            height: 100%;
            opacity: 0.5;
            background: #000 none repeat scroll 0% 0%;
        }
    </style>
<script type="text/javascript">
    function page(n, s) {
        $("#pageNumber").val(n);
        $("#pageSize").val(s);
        $("#searchForm").attr("action", "${ctx}/admin/user/list");
        $("#searchForm").submit();
        return false;
    }

    function goSearch() {
        $("#pageNumber").val(1);
        $("#pageSize").val('${query.pageSize}');
        $("#searchForm").attr("action", "${ctx}/admin/user/list");
        $("#searchForm").submit();
        return false;
    }
    $("#btnImport").click(function(){
    	  $.jBox($("#importBox").html(), {title:"导入评卷组长", buttons:{"关闭":true},
    	    bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
    });
    $("#btnImportInspector").click(function(){
  	  $.jBox($("#importInspectorBox").html(), {title:"导入复核员", buttons:{"关闭":true},
  	    bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
  });
    $("#btnImportClass").click(function(){
  	  $.jBox($("#importClassBox").html(), {title:"导入评卷员机组", buttons:{"关闭":true},
  	    bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
  });
    function goExport() {
        $("#exportForm").attr("action", "${ctx}/admin/user/export");
        $("#exportForm").submit();
    }
    function goExportExam() {
    	var roleId= $('#roleId').val();
    	if(roleId!="4" && roleId!="5" && roleId!="8"){
    		alert("请选择角色，查询后导出");
    		return false;
    	}
        $("#exportForm").attr("action", "${ctx}/admin/user/exportExam");
        $("#exportForm").submit();
    }
    $("#ids").change(function () {
        if ($("#ids").is(':checked')) {
            $(".ids").attr("checked", true);
        } else {
        	$(".ids").attr("checked", false);
        }
    });
    
    $(".ids").change(function () {
    	var all = true;
    	$("input[name='ids']").each(function(){
    		if(!$(this).is(':checked')){
    			all = false;
    		}
    	})
		 $("#ids").attr("checked", all);
    });
    function goEnable(enable) {
    	var check_list = []
    	$("input[name='ids']:checked").each(function(){
    		check_list.push($(this).val())
    	})
        if(check_list.length==0) {
            alert('请选择');
            return false;
        }
    	$("#enable").attr("value", enable);
        $("#checkForm").submit();
        return false;
    }
    
    var check_list;
    function reSetPassword(obj) {
        $('.passwordWrong').html('');
        $('.password-value').val('');
        $('.reSetPasswordWin').show();
        $('#cover').show();
        check_list = [];
        check_list.push(obj);
    }
    $('.password-close').click(function () {
        $('.reSetPasswordWin').hide();
        $('#cover').hide();
    });
    $('.password-btn').click(function () {
        var password = $('.password-value').val();
        var wrongMessage = $('.passwordWrong');
        password = password.replace(/(^\s*)|(\s*$)/g, "");
        if (password.length == 0) {
            wrongMessage.html('密码不能为空！');
            return false;
        } else if (password.length > 12 || password.length < 6) {
            wrongMessage.html('密码至少6位，不能大于12位');
            return false;
        }
        $.ajax({
        	url:"${ctx}/admin/user/resetPassword",
        	data:{ids: check_list, password: password},
        	traditional:true,
        	type:"post",
        	success:function (result) {
                if (result.success == true) {
                    alert('修改成功');
                    $("#searchForm").submit();
                } else {
                    alert(result.message);
                }
                $('.reSetPasswordWin').hide();
        	}
        });
    });
    function goReset() {
    	check_list = [];
    	$("input[name='ids']:checked").each(function(){
    		check_list.push($(this).val())
    	})
        if(check_list.length==0) {
            alert('请选择');
            return false;
        }
    	$('.passwordWrong').html('');
        $('.password-value').val('');
        $('.reSetPasswordWin').show();
        $('#cover').show();
        return false;
    }
</script>
</body>
</html>