<%@ 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'){
			        $('#subject-code-div').show();
			    }else{
			        $('#subject-code-div').hide();
			    }
			});
			$('#role-select').trigger('change');
		});
	</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" class="form-horizontal">
		<form:hidden path="id"/>
		<tags:message content="${message}"/>
		<div class="control-group">
            <label class="control-label">登录名</label>
            <div class="controls">
                <form:input path="loginName" htmlEscape="false" maxlength="20" class="required"/>
            </div>
        </div>
		<div class="control-group">
			<label class="control-label">名称</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="20" class="required"/>
			</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="role" id="role-select">
			        <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>
			    </select>
			</div>
		</div>
		<div class="control-group" id="subject-code-div">
            <label class="control-label">绑定科目</label>
            <div class="controls">
                <form:input path="subjectCode" htmlEscape="false" maxlength="10"/>
            </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="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
			&nbsp;
			<a href="${ctx}/admin/user/list" class="btn">返回</a>
		</div>
	</form:form>
</body>
</html>
