<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 type="text/css">
    body{min-width:280px;}
    </style>
</head>


<body>
<div class="formbody">
	<div class="formtitle"><span>基本信息</span></div>
	<form id="submitFrom" method="post" class="form-horizontal form-validate">
		<input type="hidden" name="id" th:if="${org.id}" th:value="${org.id}" />
		<input type="hidden" name="parentId" th:value="${org.parentId}" />
		<input type="hidden" name="subCount" th:value="${org.subCount}" />
		<ul class="forminfo">
			<li>
				<label>名称<b>*</b></label>
				<input type="text" name="menuName" th:value="${org.menuName}" class="dfinput" />
			</li>
			<li>
				<label>目录URL</label>
				<input type="text" name="menuUrl" th:value="${org.menuUrl}" class="dfinput" />
			</li>
			<li>
				<label>排序号</label>
				<input type="number" name="MenuOrder" th:value="${org.MenuOrder}" class="dfinput" />
			</li>
			
			<li>
				<label>&nbsp;</label>
				<button type="submit" class="btn">保存</button>
				<button type="button" class="btn" onclick="closeWin();">取消</button>
			</li>
		</ul>
	</form>
</div>
<script type="text/javascript">

$(function(){
	
	
	$(function(){
		$("#submitFrom").validate({
			rules : {
				
				menuName : {
					required : true,
					maxlength: 300
				},
				menuUrl : {
					required : true,
					maxlength: 300
				},
				MenuOrder : {
					digits:true
				}
			},
			messages: {
				menuName : {
					required : "名称不能为空",
					maxlength : "最多300个字符"
				},
				menuUrl : {
					required : "目录URL为空",
					maxlength : "最多300个字符"
				},
				MenuOrder : {
					digits:"必须输入整数"
				}
				
			},
			errorPlacement : function(error, element) {
					error.appendTo(element.parent()); 
			},
			submitHandler : function(form) {
				roleFrom();
			}
		});
		
	});
	function roleFrom(){
		var url="[[${sysUrl}]]/sys/menu/save";
		var params = $("#submitFrom").serialize();
		var id="";
		if($("#submitFrom").find("input[name='id']").val() != undefined){
			id = $("#submitFrom").find("input[name='id']").val();
		}
		var parentid = $("#submitFrom").find("input[name='parentId']").val();
		var menuName =$("#submitFrom").find("input[name='menuName']").val();
		$.post(url,params,function(data){
			if(data != null){
					if(data.meta.success){
						parent.layer.msg('操作成功',{icon:1});
						refreshTree(id, parentid, menuName);
				    	setTimeout(function(){
				    		parent.refreshList();
							closeWin();
						},1000);
					}else{
						layer.msg(data.meta.message,{icon:11});
					}
			}
			
		});
	}
});

function refreshTree(id, parentid, menuName){
	parent.refreshNode(id, parentid, menuName);
}

function closeWin(){
	parent.layer.close(parent.layer.getFrameIndex(window.name));
}
</script>
</body>
</html>