<%@ 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>
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />

<link rel="stylesheet" href="${ctx}/resources/js/multiselect/jquery.multiselect.css" type="text/css" />
<%@ include file="../../common/top.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/multiselect/jquery-ui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/multiselect/jquery.multiselect.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/jquery.checktable.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<%@ include file="../../common/validation.jsp"%>

<title>新增用户</title>

<script type="text/javascript">
function editUser(){
	var f=true;
	var loginName=$("#loginName").val();
	
	var name=$("#name").val();
	if(name==""){
		f=false;
		$("#nameLab").show();
	}
	var roleId=$("input[name='role']").val();
	if(roleId==""){
		f=false;
		$("#roleLab").show();
	}
	if(f){
		var obj={
			"id" : $("#userId").val(),
			"name" : name,
			"loginName" : loginName
		};
		var User = JSON.stringify(obj);
		var arrRole = new Array();
		$('*[name="role"]').each(function(){
			arrRole.push($(this).val());
		});
		
		$.ajax({
			type : "POST",
			url : "${ctx}/user/editUserInfo",
			data : "{User:" + User + ",arrRole:" + "[" + arrRole + "]"+"}",
			contentType : "application/json; charset=utf-8",
			dataType : "json",
			success : function(callback) {
				callback = eval(callback);
				if(callback.type=="success"){
					$.messager.alert('提示','编辑用户成功!');
				}else{
					$.messager.alert('提示','编辑用户失败!');
				}
			}
		});
	}
}
function check(){
	var name=$("#name").val();
	if(name!=""){
		$("#nameLab").hide();
	}
	var roleId=$('.combo-value').val();
	if(roleId!=""){
		$("#roleLab").hide();
	}
}
</script>
</head>
<body >
    <%@ include file="../../common/header.jsp"%>
    <div id="content" class="content">
        <%@ include file="../../common/sub_menu.jsp"%>
        <div class="page" id="page" >
        <div class="page-header" >编辑用户</div>
        <div class="page-body" align="center" onmouseover="check()">
            <div>
                <form id="search-form" method="post" >
                	<input type="hidden" id="userId" value="${user.id}"/>
                    <table class="label-table" border="0">
                        <tr>
                            <td class="label-table-label"><label>登录名：</label></td>
                            <td class="qBox label-table-content" colspan="2" style="width: 250px;"><input id="loginName" value="${user.loginName}" disabled="disabled"/></td>
                        </tr>
                        <tr>
                            <td class="label-table-label"><label>用户姓名：</label></td>
                            <td class="qBox label-table-content" colspan="2" style="width: 250px;"><input name="name" id="name" value="${user.name}"/><label style="display: none;color: red;" id="nameLab" >*请输入用户姓名</label></td>
                        </tr>
                        <tr>
                            <td class="label-table-label"><label>角色：</label></td>
                            <td class="qBox label-table-content" colspan="2">
                            	<input id="role" name="role" class="easyui-combobox" style="width:450px;"  data-options="url:'${ctx}/user/getSelectRole/${user.id}',
                            																							method:'get',
                            																							valueField:'id',
																														textField:'text',
																														multiple:true,
																							   							panelHeight:'auto',
																														editable:false,
																														required:true "/>
                            	<label style="display: none;color: red;" id="roleLab" >*请选择角色</label>
                            </td>
                        </tr>
                        <tr>
                        	<td colspan="3" align="center">
                        		<input type="button" value="编辑保存" class="btn" onclick="editUser()"/>    		
                        	</td>
                        </tr>
                    </table>                 
                </form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>