<%@ 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" %>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#loginName").focus();
            $("#inputForm").validate({
                submitHandler: function (form) {
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
            $('#role-select').change(function () {
                var role = $('#role-select').val();
                if (role == '4' || role == '8' || role == '6') {
                    $('#subject-code-div').show();
                } else {
                    $('#subject-code-div').hide();
                }
                if (role == '10') {
                    $('#college-div').show();
                } else {
                    $('#college-div').hide();
                }
                if (role == '6') {
                    $('#exam-id-div').show();
                    $('#student-div').show();
                } else {
                    $('#exam-id-div').hide();
                    $('#student-div').hide();
                }
            });
            $('#role-select').trigger('change');
            $("#studentFile").change(function(e) {
                var selectedFile = e.target.files[0];
            	$("#studentFileNameDiv").show();
            	$("#studentFileName").html(selectedFile.name);
              });
        });
        function studentFileClear() {
        	$("#studentFile").val('');
        	$("#studentFileNameDiv").hide();
        	$("#studentFileName").html('');
        }
        function studentFileSelect() {
        	$("#studentFile").click();
        }
        function studentClear() {
        	if (!confirm('确定清空？')) {
	            return;
	        }
            $("#inputForm").attr("action", "${ctx}/admin/user/student/clear");
            $("#inputForm").submit();
        }
        
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li><a href="${ctx}/admin/user/list">用户列表</a></li>
    <li class="active"><a href="##">用户编辑</a></li>
</ul>
<form:form id="inputForm" modelAttribute="user" action="${ctx}/admin/user/save" method="post" 
enctype="multipart/form-data" class="form-horizontal">
    <form:hidden path="id"/>
    <tags:message content="${message}"/>
    <input id="studentFile" name="studentFile" type="file" accept=".xls, .xlsx" style="display:none;"/>
    <input type="hidden"  name="pageNumber" value="${query.pageNumber }"/>
	 <input type="hidden"  name="querSource" value="${query.source.value }"/>
	 <input type="hidden"  name="queryRole" value="${query.role.value }"/>
	 <input type="hidden"  name="queryName" value="${query.name }"/>
	 <input type="hidden"  name="queryLoginName" value="${query.loginName }"/>
	 <input type="hidden"  name="queryEnable" value="${query.enable }"/>
    <div class="control-group">
        <label class="control-label">登录名</label>
        <div class="controls">
            <form:input path="loginName" htmlEscape="false" maxlength="32" class="required"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">名称</label>
        <div class="controls">
            <form:input path="name" htmlEscape="false" maxlength="32" class="required"/>
        </div>
    </div>
	<div class="control-group">
        <label class="control-label">工号</label>
        <div class="controls">
            <form:input path="empno" htmlEscape="false" maxlength="32"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">密码</label>
        <div class="controls">
            <form:password path="password" htmlEscape="false" maxlength="20"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">状态</label>
        <div class="controls">
            <select name="enable" id="enable-select">
                <option value="true" <c:if test="${user.enable==true}">selected</c:if>>启用</option>
                <option value="false" <c:if test="${user.enable==false}">selected</c:if>>禁用</option>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">角色</label>
        <div class="controls">
            <select name="role" id="role-select">
                <c:if test="${roleList != null}">
                    <c:forEach items="${roleList}" var="role">
                        <option value="${role.value}"
                                <c:if test="${role.value==user.role.value}">selected</c:if>>${role.name}</option>
                    </c:forEach>
                </c:if>
                <c:if test="${user.role!=null && roleList==null}">
                    <option value="${user.role.value}" selected>${user.role.name}</option>
                </c:if>
            </select>
        </div>
    </div>
    <c:if test="${user.role==null || user.role.value==6}">
        <div class="control-group" id="exam-id-div">
            <label class="control-label">绑定考试ID</label>
            <div class="controls">
            <textarea name="examIdString" rows="4" class="input-xxlarge"
                      >${examIdString}</textarea>
            </div>
        </div>
    </c:if>
    <c:if test="${user.role==null || user.role.value==4|| user.role.value==6|| user.role.value==8}">
        <div class="control-group" id="subject-code-div">
            <label class="control-label">绑定科目代码</label>
            <div class="controls">
            <textarea name="subjectCodeString" rows="4" class="input-xxlarge"
                      >${subjectCodeString}</textarea>
            </div>
        </div>
    </c:if>
    <c:if test="${user.role==null || user.role.value==10}">
        <div class="control-group" id="college-div">
            <label class="control-label">绑定电厂</label>
            <div class="controls">
            <textarea name="description" rows="4" class="input-xxlarge"
                      >${user.description}</textarea>
            </div>
        </div>
     </c:if>
     <c:if test="${user.role==null || user.role.value==6}">
        <div class="control-group" id="student-div">
            <label class="control-label">绑定考生</label>
            <div class="controls">
            <a href="javascript:" onclick="studentFileSelect()"  class="btn">选择文件</a>
            &nbsp;
            <c:if test="${studentCount!=0}">
            <input onclick="studentClear()" class="btn" type="button" value="清空"/>
            </c:if>
            <c:if test="${studentCount==0}">
            <input onclick="studentClear()" class="btn" type="button" disabled="disabled" value="清空"/>
            </c:if>
            &nbsp;
            <a href="${ctx}/admin/user/student/template">下载模板</a>
            &nbsp;
            <c:if test="${user.role!=null && user.role.value==6}">
            <span>绑定考生<span style="color: red;">${studentCount }</span>条</span>
            </c:if>
            </div>
            <br/>
            <div class="controls" id="studentFileNameDiv" hidden="true">
            	<span id="studentFileName"></span>&nbsp;<span><a href="javascript:" onclick="studentFileClear()">删除</a></span>
            </div>
        </div>
     </c:if>
    <div class="form-actions">
        <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
        &nbsp;
        <a href="javascript:" onclick="history.go(-1);"  class="btn">返回</a>
    </div>
</form:form>
</body>
</html>
