<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>私塾家</title>
<link href="sys/css/sort/bootstrap.min.css" th:href="@{/static/sys/css/sort/bootstrap.min.css}" rel="stylesheet"/>
<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">
#bg{ 
	display: block; 
	position: absolute; 
	top: 0%; 
	left: 0%; 
	width: 100%; 
	height: 100%; 
	background-color: black; 
	z-index:1001; 
	-moz-opacity: 0.7; 
	opacity:.20; 
	filter: alpha(opacity=70);
}
label.control-label-error {
  				color: Red;
             }
</style>
</head>
<body>
	<div id="bg"></div>
	
	<h3 class="header-dividing" style="padding-left:10px;">分类操作</h3>
	
	<div class="container" style="margin-top: 10px;">
	 	<form name="typeForm" id="typeForm" class="form-horizontal form-validate" method="post" th:action="@{sys/sort/saveSort}">
							<input  type="hidden" th:value="${sort.id}" th:if="${sort.id}" name="id" id="id">
							<input  type="hidden" th:value="${parent.id}" name="pid" id="pid">
							<input  type="hidden" th:value="${sort.sort}" name="sort" >
							<input  type="hidden" th:value="${sort.level}" name="level" >
	 		
	 		<div class="dialog-panel-body">
		 		<div class="form-group">
		 			<label class="text-right col-xs-2 control-label">上级名称</label>
		            <div class="col-xs-9">
		               <input  class="form-control"  disabled="disabled" th:value="${parent.name}"  />
		            </div>
		 		</div>
		 		
		 		<div class="form-group">
		 			<label class="text-right col-xs-2 control-label required">分类名称</label>
		            <div class="col-xs-9">
		               <input  class="form-control"  id="name" name="name" data-rule-required="true" required="required" th:value="${sort.name}"  />
		            </div>
		 		</div>
		 		<div class="form-group">
		 			<label class="text-right col-xs-2 control-label required">分类编码</label>
		            <div class="col-xs-9">
		               <input  class="form-control"  id="code" name="code" data-rule-required="true" required="required"  th:value="${sort.code}"  />
		            </div>
		 		</div>
		 		<div class="form-group">
		 			<label class="text-right col-xs-2 control-label required">别名</label>
		            <div class="col-xs-9">
		               <input  class="form-control"   name="aliases" data-rule-required="true" required="required"  th:value="${sort.aliases}"  />
		            </div>
		 		</div>
		 		<div class="form-group">
		 			<label class="text-right col-xs-2 control-label required">是否热门</label>
		            <div class="col-xs-9">
		               	是：<input type="radio" name="ishot"  th:checked="${sort.ishot ==null || sort.ishot==1}" value="1" />
		               	否：<input type="radio" name="ishot"  th:checked="${sort.ishot==0}" value="0" />
		            </div>
		 		</div>
	 		</div>
	  	
			<div class="form-group text-center dialog-panel-footer">
				<button type="submit" class="btn btn-primary"><i class="icon icon-save"></i>保 存</button>
			</div>
	 	</form>
	</div>
	
<script type="text/javascript">
	var edit='[[${edit}]]';
	$(function(){
		if(edit==1){
			$("#bg").hide();
		}
		 $("#typeForm").validate({
			submitHandler : function(form) {
				submitFrom();
			}
		});
	});

	function submitFrom(){
		var url="[[${sysUrl}]]/sys/sort/saveSort";
		var params = $("#typeForm").serialize();
		$.post(url,params,function(data){
			if(data != null){
					if(data.meta.success){
						parent.parent.layer.msg("保存成功!",{icon:1});
						var name = $("#name").val();
						if($("#id")!=undefined){ //新增
						    var pid = $("#pid").val();
							var newNodes = [{id:data.data.id, name:name, pid:pid, open:"true"}];
							parent.addNode(newNodes);
						}else{ //修改
							parent.updateCurrentNode(name);
						}
						parent.refreshFrame();
					}else{
						parent.parent.layer.msg(data.meta.message,{icon:11});
					}
			}
			
		});
	}
	
</script>
</body>
</html>