<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta name="description" content="Xenon Boostrap Admin Panel" />
	<meta name="author" content="" />
	<title>系统菜单管理</title>
</head>
<body class="page-body">
	<div class="page-container">
		<%@ include file="../../common/menu.jsp"%>
		<div class="main-content">
			<%@ include file="../../common/header.jsp"%>
			<div class="page-title">
				<div class="title-env">
					<h1 class="title">修改系统菜单</h1>
				</div>
				<div class="breadcrumb-env">
					<ol class="breadcrumb bc-1">
						<li>
							<a href="#"><i class="fa-home"></i>系统管理</a>
						</li>
						<li class="active">
							<strong>修改系统菜单</strong>
						</li>
					</ol>
				</div>
			</div>
			<!-- Removing search and results count filter -->
			<div class="row">
				<div class="col-sm-12">
					<div class="panel panel-default">
						<div class="panel-body">
							<form role="form" id="editUserForm" class="form-horizontal" >
								<input type="hidden" name="id" id="id" value="${menu.id}"/>
								<div class="form-group">
									<label class="col-sm-2 control-label" for="field-1">用户名</label>
									<div class="col-sm-4">
										<input type="text" class="form-control" id="name" name="name" value="${menu.name}" >
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label" for="description">描述</label>
									<div class="col-sm-4">
										<input type="text" class="form-control" id="description" name="description" value="${menu.description}"  />
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label" for="url">路径</label>
									<div class="col-sm-4">
										<input type="text" class="form-control" id="url" name="url" value="${menu.url}" />
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label" for="order_by">排序</label>
									<div class="col-sm-4">
										<input type="text" class="form-control" name="order_by" id="order_by" value="${menu.order_by }">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label" >父菜单</label>
									<div class="col-sm-4">
										<select class="form-control" id="parent_id" name="parent_id">
											<option value="0">无</option>
											<c:forEach var="r" items="${parent_menu }" >
											    <option value="${r.id }" <c:if test="${menu.parent_id == r.id }">selected="selected"</c:if> >${r.name }</option>
											</c:forEach>
										</select>		
									</div>
								</div>
								<div class="form-group-separator"></div>
								<div class="form-group">
									<div class="col-sm-6" style="text-align: center;">
										<button type="button" id="btn_save" class="btn btn-info" >保存</button>
										<button type="button" id="btn_cancel" class="btn btn-white" >返回</button>
										<input id="token" type="hidden" name="token" value="${SESSION_TOKEN }"/>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
			<%@ include file="../../common/footer.jsp"%>
		</div>
	</div>
	
	<script type="text/javascript">
		$(function() {
			
			$("#btn_save").click(function(){
				var name = $("#name").val();
				var url = $("#url").val();
				var order_by = $("#order_by").val();
				if(!checkStr(name)){
					toastr.error("菜单名不能为空", null, opts);
					return false;
				}
				if(!checkStr(url)){
					toastr.error("url不能为空", null, opts);
					return false;
				}
				if(!isNull(order_by) && !isPositiveNumber(order_by)){
					toastr.error("排序请输入正整数", null, opts);
					return false;
				}
				$("#btn_save").attr("disabled","disabled");
				$("#editUserForm").ajaxSubmit({  
		                type:'post',  
		                dataType: "json",
		                url : "${ROOT_PATH}/sysMenu/save.do",
		                success:function(data){  
		                	window.setTimeout("enableBtn('#btn_save');",Constants.reloadTime);
		                	if (data.result == '01') {
		                		toastr.success("修改成功", null, opts);
		                		window.location.href = '${ROOT_PATH}/sysMenu';
		                	}
		                	else
		                	{
		                		toastr.error(data.msg, null, opts);
		                	}
		                },  
		                error:function(XmlHttpRequest,textStatus,errorThrown){  
		                	window.setTimeout("enableBtn('#btn_save');",Constants.reloadTime);
		                	toastr.error(Constants.netError, null, opts);
		                }  
		            }); 
			});
	
			$("#btn_cancel").click(function(){
				history.back(-1);
			});
		});
		</script>
</body>
</html>