<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>私塾家</title>
<script th:include="sys/common/metaCSS" th:remove="tag"></script> 
<script th:include="sys/common/metaJS" th:remove="tag"></script> 
<script src="sys/js/jquery.validate.min.js" th:src="@{/static/sys/js/jquery.validate.min.js}"></script>
<script src="sys/js/jquery-validation/messages_zh.js" th:src="@{/static/sys/js/jquery-validation/messages_zh.js}"></script>
 <style>
    	.clearfix:after {
			visibility: hidden;
			display: block;
			font-size: 0;
			content: " ";
			clear: both;
			height: 0;
		}
		.clearfix { display: inline-table; }
		* html .clearfix { height: 1%; }
		.clearfix { display: block; }
		.fl{display:inline;float:left}
		clearfix >control-label-error{display:inline;float:left;marign-left:10px}
		 label.control-label-error {
  				color: Red;
             }
    </style>
</head>

<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    	<li><a href="#">系统管理</a></li>
    	<li><a href="#">角色管理</a></li>
    </ul>
</div>
<div class="formbody">
	<div class="formtitle"><span>角色信息</span></div>
	<form id="roleFrom"   method="post" class="form-horizontal form-validate">
		<input  type="hidden" id="id" th:if="${role}" th:value="${role.id}" name="id">
		<ul class="forminfo">
			<li class="clearfix">
				<label class="fl">角色名称<b>*</b></label>
				  <input  type="text" id="name"  th:value="${role.name}" class="dfinput fl"  name="name">
			</li>
			<li class="clearfix">
				<label class="fl">角色说明<b>*</b></label>
				<input type="text"   th:value="${role.memo}"   class="dfinput fl"  name="memo">
			</li>
			<li>
				<label>&nbsp;</label>
				<button type="submit" class="btn">保存</button>
				<button type="button" class="btn" onclick="window.history.go(-1);">取消</button>
			</li>
		</ul>
	</form>
</div>
</body>
<script type="text/javascript">

$(function(){
	$("#roleFrom").validate({
		rules : {
			name : {
				required : true,
				remote:{
		               type:"POST",
		               url:'[[${sysUrl}]]/sys/role/validateRole',            
		               data:{
		            	   name:function(){return $("#name").val();},
		            	   id:function(){return $("#id").val();},
		               } 
		              } 
			},
			memo : {
				required : true
			}
		},
		messages: {
			name : {
				required : "请输入角色名",
				 remote:"角色名已存在!"  
			},
			memo : {
				required : "请输入角色说明"
			}
			
		},
		errorPlacement : function(error, element) {
				error.appendTo(element.parent()); 
		},
		submitHandler : function(form) {
			roleFrom();
		}
	});
	
});
function roleFrom(){
	var url="[[${sysUrl}]]/sys/role/save";
	var params = $("#roleFrom").serialize();
	$.post(url,params,function(data){
		if(data != null){
				if(data.meta.success){
					layer.msg("操作成功!",{icon:1});
			    	setTimeout(function(){
			    		window.location.href ='[[${sysUrl}]]/sys/role/rolelist.html';
					},1000);
				}else{
					layer.msg(data.meta.message,{icon:11});
				}
		}
		
	});
}


</script>
</html>