<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jspf"%>
<!-- COMPOSE MESSAGE MODAL -->
       <div class="modal-dialog">
		   <form id="form_add_res"  action="system/res/addRes.do" method="post">
	           <div class="modal-content">
	               <div class="modal-header">
	                   <button type="button" class="close" data-dismiss="modal">&times;</button>
	                   <h4 class="modal-title"><i class="fa fa-envelope-o"></i>添加资源</h4>
	               </div>
					<div class="modal-body">
						<div class="container-fluid">
							<div class="row">
								<div class="col-sm-3" style="text-align: right;padding-top: 5px;">
									<label >资源名称</label>
								</div>
								<div id="add_res_name" class="col-sm-9" style="text-align: left;">
									<div class="form-group">
										<input type="text" class="form-control" id="add_resName" name="resName" placeholder="请输入名称" >
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3" style="text-align: right;">
									<label >资源内容</label>
								</div>
								<div id="add_res_content" class="col-sm-9" style="text-align: left;word-break:break-all;">
									<div class="form-group">
										<input type="text" class="form-control" id="add_resContent" name="resContent" placeholder="请输入内容">
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3" style="text-align: right;">
									<label >资源权限标识</label>
								</div>
								<div id="add_res_identity" class="col-sm-9" style="text-align: left;word-break:break-all;">
									<div class="form-group">
										<input type="text" class="form-control" id="add_resIdentity" name="resIdentity" placeholder="请输入权限标识">
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3" style="text-align: right;">
									<label >资源图标</label>
								</div>
								<div id="add_res_icon" class="col-sm-9" style="text-align: left;">
									<div class="form-group">
										<input type="text" class="form-control" id="add_resIcon" name="resIcon" placeholder="请输入图标">
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3" style="text-align: right;">
									<label >资源类型</label>
								</div>
								<div id="add_res_type" class="col-sm-9" style="text-align: left;">
									<div class="form-group">
										<select id="select_res_type" class="form-control" name="resType">
											<c:forEach items="${resTypeMap}" var="map">
										    	<option value="${map.key}">${map.value}</option>
										    </c:forEach>
										</select>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3" style="text-align: right;">
									<label >上级资源</label>
								</div>
								<div id="add_res_parent" class="col-sm-9" style="text-align: left;">
									<div class="form-group" >
										<select id="select_res_parent" class="form-control" name="resParentId">
										    <option value="${resRootId}">根资源</option>
											<c:forEach items="${resList}" var="pRes">
										    	<option value="${pRes.resId}">
										    		<c:forEach begin="0" end="${resMaxLevel}" var="tmp" varStatus="status">
											    		<c:if test="${status.index le pRes.level}">
											    			&nbsp;&nbsp;
											    		</c:if>
										    		</c:forEach>
										    		${pRes.resName}
										    	</option>
										    </c:forEach>
										</select>
									</div>
								</div>
							</div>
							
							<div class="row">
								<div class="col-sm-3" style="text-align: right;">
									<label >资源排序号</label>
								</div>
								<div id="add_res_seq" class="col-sm-9" style="text-align: left;">
									<div class="form-group">
										<input type="text" class="form-control" id="add_resSeq" name="resSeq" placeholder="请输入序号">
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3" style="text-align: right;">
									<label >资源状态</label>
								</div>
								<div id="add_res_status" class="col-sm-9" style="text-align: left;">
									<div class="form-group">
										<select class="form-control" name="resStatus">
											<c:forEach items="${resStatusMap}" var="map">
										    	<option value="${map.key}">${map.value}</option>
										    </c:forEach>
										</select>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3" style="text-align: right;">
									<label >资源描述</label>
								</div>
								<div id="add_res_desc" class="col-sm-9" style="text-align: left;word-break:break-all;">
									<div class="form-group">
										<input type="text" class="form-control" id="add_resDesc" name="resDesc" placeholder="请输入描述">
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="modal-footer clearfix">
					    <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-times"></i>取消</button>
						<button type="submit" class="btn btn-primary pull-left"><i class="fa fa-envelope"></i>确定</button>
					</div>
				</div><!-- /.modal-content -->
			</form>
	   </div><!-- /.modal-dialog -->
	   
	   <script type="text/javascript">
		   jQuery(document).ready(function() {
				var form = $('#form_add_res');
			    var addResForm = form.platformValidate({
			    	rules:{
			    		resName:{
			    			required:true,
			    			maxlength:25
			    		},
			    		resSeq:{
			    			required:true, 
			    			number:true,
			    			maxlength:15
			    		},
			    		resContent:{
			    			maxlength:150
			    		},
			    		resIdentity:{
			    			maxlength:50
			    		},
			    		resDesc:{
			    			maxlength:150
			    		}
			    	},
			    	messages:{
			    		resName:{
			    			required:"资源名称不能为空",
			    			maxlength:"资源名称最大长度为25"
			    		},
			    		resSeq:{
			    			required:"资源排序号不能为空",
			    			number:"资源排序号只能输入数字",
			    			maxlength:"资源排序号最大长度为15"
			    		},
			    		resContent:{
			    			maxlength:"资源内容最大长度为150"
			    		},
			    		resIdentity:{
			    			maxlength:"资源权限标识最大长度为50"
			    		},
			    		resDesc:{
			    			maxlength:"资源描述最大长度为150"
			    		}
			    	}
			    });
			});
		   
		   $("#select_res_type").change( function() {
			   $.ajax({
				   type: "POST",
				   url: "system/res/getParentByType.do",
				   data: {resType:this.value},
				   dataType: "json",
				   success: function(res){
					   	var optionStr = "<option value='0'>根资源</option>";
						for(var i = 0; i < res.length; i++){
							var lever = parseInt(res[i].level,10);
							optionStr+="<option value='"+res[i].resId+"'>"
							for(var j = 0; j <= lever; j++){
								optionStr+="&nbsp;&nbsp;";
							}
							optionStr+=res[i].resName+"</option>";
						}
						$("#select_res_parent").html(optionStr);
				   },
				   error: function(){
					   platformDanger("获得上级资源失败！");
				   }
				});
		   });
	   </script>