<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/taglib/c.tld" prefix="c"%>
<%@ include file="../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="../common/top.jsp"%>
</head>
<body class="easyui-layout">
	<%@ include file="../common/header.jsp"%>
	<%@ include file="../leftMenu/exam-admin.jsp"%>
	<div data-options="region:'center',title:'首页 -【考试管理】- 添加分析用户'">
		<div class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'north',border:false" class="domain"><a href="${ctx}/admin/analysis/user"><button class="btn fr" type="button"><i class="icon-hand-left"></i> 返回</button></a></div>
		<div class="border" data-options="region:'center'">
        <form id="edit-form" class="form-horizontal" action="${ctx}/admin/analysis/user/save" method="post">
          <input type="hidden" name="saveType" value="isEdit">
          <input type="hidden" name="id" value="${editUser.id}">
          <div class="control-group <c:if test="${loginNameError==true}">error</c:if>">
            <label class="control-label" for="">登录名</label>
            <div class="controls">
             <input type="text" name="loginName" value="${editUser.loginName}">
             <c:if test="${loginNameError==true}">
				<span class="help-inline">该登录名已存在</span>
			 </c:if>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="">姓名</label>
            <div class="controls">
             <input type="text" name="name" value="${editUser.name}">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="">密码</label>
            <div class="controls">
             <input id="pd1" type="password" name="password">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="">重复密码</label>
            <div class="controls">
             <input id="pd2" type="password" onblur="checkPassword()">
             <div id="passwordError" style="display:none">
				<span class="help-inline">两次密码输入不一致！</span>
             </div>
            </div>  
          </div>
          <div class="control-group">
            <label class="control-label" for="">角色</label>
            <div id="roleList">
	            <c:forEach items="${roles}" var="role">
		            <label class="checkbox inline">
			            <input type="checkbox" id="inlineCheckbox1" 
				            <c:forEach items="${editUser.roleMap}" var="map">
				              <c:if test="${map.key eq role.name}">checked="checked"</c:if> 
				            </c:forEach>
			  			value="${role.name}">${role.display}
		            </label>
	            </c:forEach>
            </div>
            <input id="roles" type="hidden" name="roleNames">
          </div>
          <div class="controls">
            <button class="btn btn-primary" type="button" onclick="save()">保存</button>
            <button class="btn" type="reset">清空</button>
          </div>
        </form>
        </div>
        </div>
	</div>
</body>
<script type="text/javascript">
	$(document).ready(function() {
		$("#top-ks").addClass("active");
		$("#top-jc").removeClass("active");
	});
	
	function save(){
		var roles='';
		$('#roles').val('');
		$('#roleList').find('input[type=checkbox]:checked').each(function(){
			var role=$(this).val();
			roles=roles+role+',';
		});
		var len=roles.length;
		roles=roles.substr(0,len-1);
		$('#roles').val(roles);
		$("#edit-form").submit();
	}
	
	function checkPassword(){
		var pd1=$('#pd1').val();
		var pd2=$('#pd2').val();
		if(pd2!=pd1){
			$('#passwordError').css('display','block');
		}else{
			$('#passwordError').css('display','none');
		}
	}
</script>
</html>
