<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户管理</title>
<%@ include file="../../common/top.jsp"%>
<link rel='stylesheet' href='${ctx}/resources/css/themes/default/easyui.css' type='text/css'/>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<style>
.myInput{
	width: 140px;height: 20px;margin: 10px;
}
</style>
<script type="text/javascript">
	function hideAllLab(){
		$("#oldLab").hide();
		$("#newLab").hide();
		$("#confirmLab").hide();
	}

	function changePassword(){
		hideAllLab();
		$("#oldPassword").val($.trim($("#oldPassword").val()));
		if($("#oldPassword").val()==""){
			$("#oldLab").text("*请输入原密码");
			$("#oldLab").show();
			$("#oldPassword").focus();
			return;
		}

		$("#newPassword").val($.trim($("#newPassword").val()));
		if($("#newPassword").val()==""){
			$("#newLab").text("*请输入新密码");
			$("#newLab").show();
			$("#newPassword").focus();
			return;
		}

		$("#againPassword").val($.trim($("#againPassword").val()));
		if($("#againPassword").val()==""){
			$("#confirmLab").text("*请输入确认密码");
			$("#confirmLab").show();
			$("#againPassword").focus();
			return;
		}
		
			if($("#newPassword").val()!=$("#againPassword").val()){
				$("#confirmLab").text("*两次输入密码不一致");
				$("#confirmLab").show();
				$("#againPassword").select();
				return;
			}
			
			if($("#againPassword").val().length>16||$("#newPassword").val().length>16){
				$("#confirmLab").text("*新密码长度不能大于16");
				$("#confirmLab").show();
				$("#againPassword").select();
				return;
			}else{
				var obj={
						"id" : $("#userId").val(),
						"password" : $("#oldPassword").val()
				};
				var User = JSON.stringify(obj);
				
				
				$.ajax({
					type : "POST",
					url : "${ctx}/user/validateOldPassword",
					data : User,
					contentType : "application/json; charset=utf-8",
					dataType : "json",
					success : function(callback) {
						callback = eval(callback);
						if(callback.type=="success"){
							var obj={
									"id" : $("#userId").val(),
									"password" : $("#newPassword").val()
							};
							var User = JSON.stringify(obj);
							$.ajax({
								type : "POST",
								url : "${ctx}/user/changePassword",
								data : User,
								contentType : "application/json; charset=utf-8",
								dataType : "json",
								success : function(callback) {
									callback = eval(callback);
									if(callback.type=="success"){
										$.messager.alert('提示','修改密码成功!');
										$('#w').window('close');
									}else{
										$.messager.alert('提示','修改密码失败!');
										$('#w').window('close');
									}
								}
							});
						}else{
							$("#oldLab").text("*请输入正确的原密码");
							$("#oldLab").show();
						}
					}
				});
			}
	}
	
	function setValue(id){
		$("#userId").val(id);
	}
</script>
</head>
<body>
<div class="container-fluid">
	<%@ include file="../../common/header.jsp"%>
	<div class="row-fluid">
		<%@ include file="../../common/sub_menu.jsp"%>
		
		<div class="span10" id="page" >
			<ul class="breadcrumb">
	            <li class="active">个人信息</li>
            </ul>
            
			<div class="Personal-information">
				<div class="img"></div>
				<div class="font">
                  <h1>姓名：${user.name}</h1>
                  <p>性别：</p>
                  <p>职称：</p>
                  <p>单位：</p>
                  <p>院系：</p>
                  <p>电话：</p>
                  <p>Email：</p>
                  <p>上次登录时间：<fmt:formatDate value="${lastLoginDate}" pattern="HH:mm:ss MM/dd/yyyy"/></p>
                  <h1>权限信息</h1>
                  <p>角色：${role.name } </p>
                  <!-- 
                  <p>课程：语文</p>
                   -->
                  <a href="#" type="submit" class="btn btn-large btn-info" onclick="$('#w').window('open');setValue('${user.id}')">修改密码</a>
              	</div>
              </div>
			</div>   
		</div>
	</div>
<div id="footer">版权所有：武汉启明泰和软件服务有限公司</div>
		
		<div id="w" class="easyui-window" title="修改密码" data-options="modal:true,closed:true,iconCls:'icon-save',collapsible:true" style="width:430px;height:260px;">
			<div style="margin-top: 20px;"align="center">
				<input type="hidden" id="userId" value="" />
				<div>
						<table width="410px;">
							<tr>
								<td style="width: 110px;" align="right">原密码:</td>
								<td><input type="password" id="oldPassword" class="myInput" maxlength="20"/><label style="display: none;color: red;" id="oldLab" >*原密码不正确</label></td>
							</tr>
							<tr>
								<td align="right">新密码:</td>
								<td><input type="password" id="newPassword" class="myInput" maxlength="20"/><label style="display: none;color: red;" id="newLab" >*两次输入密码不一致</label></td>
							</tr>
							<tr>
								<td align="right">确认密码:</td>
								<td><input type="password" id="againPassword" class="myInput" maxlength="20"/><label style="display: none;color: red;" id="confirmLab" >*两次输入密码不一致</label></td>
							</tr>
							<tr align="center">
								<td colspan="2" ><input type="button" value="提交" class="btn" onclick="changePassword()"/></td>
							</tr>
						</table>
				</div>
			</div>
		</div>
		
</body>
</html>