<%@ page language="java" contentType="text/html;charset=UTF-8" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 
<%@ page isELIgnored="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>咨询列表</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<link rel="stylesheet" href="<%=request.getContextPath() %>/js/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="<%=request.getContextPath() %>/js/bootstrap/css/bootstrap-theme.min.css">
    <script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/jquery/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/jquery/Jquery.Query.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/jquery.twbsPagination/jquery.twbsPagination.js"></script>
	<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/layer/layer.js"> </script>
    <script type="text/javascript">
    var typeList1 = [{ 'contentTypeId': '', 'name': '全部', 'level': 1 }, 
	<c:forEach var="type" items="${contentTypeList1}">
		{ 'contentTypeId': '${type.id}', 'name': '${type.name}', 'level': ${type.level} },
	</c:forEach>
	];
	var typeList2 = [{ 'contentTypeId': '', 'name': '全部', 'level': 2 },
	<c:forEach var="type" items="${contentTypeList2}">
		{ 'contentTypeId': '${type.id}', 'name': '${type.name}', 'level': ${type.level}, 'parentTypeId': '${type.parentTypeId}' },
	</c:forEach>
	];
	var typeList3 = [{ 'contentTypeId': '', 'name': '全部', 'level': 3 },
	<c:forEach var="type" items="${contentTypeList3}">
		{ 'contentTypeId': '${type.id}', 'name': '${type.name}', 'level': ${type.level}, 'parentTypeId': '${type.parentTypeId}' },
	</c:forEach>
	];
	var sel1, sel2, sel3;
	var contentType1 = '${param.contentType1}';
	var contentType2 = '${param.contentType2}';
	var contentType3 = '${param.contentType3}';
	function build_option_htm(type, selected)
	{
		var htm = "<option value='" + type.contentTypeId + "'";
		if (selected)
		{
			htm += " selected='selected'";
		}
		htm += ">" + type.name + "</option>";
		return htm;
	}
	function build_select(){
		sel1 = $("#sel1");
		sel2 = $("#sel2");
		sel3 = $("#sel3");
		for(var i=0;i<typeList1.length;i++){
			var type1 = typeList1[i];
			var html1 = build_option_htm(type1,type1.contentTypeId==contentType1);
			sel1.append(html1);
		}
		for(var j=0;j<typeList2.length;j++){
			var type2 = typeList2[j];
			if(type2.parentTypeId==contentType1 || type2.contentTypeId==''){
				var html2 = build_option_htm(type2,type2.contentTypeId==contentType2);
				sel2.append(html2);
			}
		}
		for(var x=0;x<typeList3.length;x++){
			var type3 = typeList3[x];
			if(type3.parentTypeId==contentType2 || type3.contentTypeId==''){
				var html3 = build_option_htm(type3,type3.contentTypeId==contentType3);
				sel3.append(html3);
			}
		}
		sel1.change(function(){
			searchType2(sel1.val());
		});
		sel2.change(function(){
			searchType3(sel2.val());
		})
	}
		function searchType2(type){
			sel2.empty();
			sel3.empty();
			for(var j=0;j<typeList2.length;j++){
				var type2 = typeList2[j];
				if(type2.parentTypeId==type || type2.contentTypeId==''){
					var html2 = build_option_htm(type2,type2.contentTypeId=='');
					sel2.append(html2);
				}
			}
		}
		function searchType3(type){
			sel3.empty();
			for(var x=0;x<typeList3.length;x++){
				var type3 = typeList3[x];
				if(type3.parentTypeId==type || type3.contentTypeId==''){
					var html3 = build_option_htm(type3,type3.contentTypeId=='');
					sel3.append(html3);
				}
			}
		}
    </script>
</head>
<body>
<div class="container">
	<form class="form-horizontal" action="<%=request.getContextPath() %>/publish/getListModal.do" method="get">

		<div class="panel panel-default">
			<div class="panel-body">
				<div class="form-group-sm">
					<label class="control-label col-md-1">标题:</label>
					<div class="col-md-3">
						<input type="title" class="form-control" value="${param.title}" name="title" placeholder="标题">
					</div>
				</div>

				<div class="form-group-sm">
					<label class="control-label col-md-1">分类:</label>
					<div class="col-md-3">
						<select id="sel1" name="contentType1" class="form-control">
						</select>
						<select id="sel2" name="contentType2" class="form-control">
						</select>
						<select id="sel3" name="contentType3" class="form-control">
						</select>
					</div>
				</div>
			</div>
		</div>

		<div class="form-group-sm text-center padding10" >
			<button type="button" onclick="tijiao()" class="btn btn-default">提交</button>
			<a type="button" href="<%=request.getContextPath() %>/publish/list.do" class="btn btn-default">重置/刷新</a>
			<a class="btn btn-success" style="margin-right: 10px;" href="<%=request.getContextPath() %>/publish/view.do">添加</a>
		</div>

		<div class="panel panel-default">
			<table class="table table-striped table-hover">
		      <thead>
		        <tr>
		          <th>主标题</th>
		          <th>分类</th>
		          <th>操作</th>
		        </tr>
		      </thead>
		      <tbody>
		<c:forEach var="item" items="${contentList.list}">
		        <tr>
		          <td>${item.title}</td>
		          <td >
		          ${item.showContentTypeName}
		          </td>
		          <td>
					  <a class="btn btn-primary" onclick="addParent(${item.id})">选择</a>
		          </td>
		        </tr>
		</c:forEach>
		      </tbody>
		    </table>
		</div>
			<input type="hidden" id="pageval" name="page" class="form-control" value="${param.page==null?1:param.page}">
			<input type="hidden" name="limit" class="form-control" value="10">
		<div class="row" id="pageShow" style="text-align: center;">
			  <nav id="pagination_box"><ul class="pagination" id="pagercontent"></ul></nav>
		</div>
</form>
</div>
<script>
build_select();
$(function(){
	initVal();
})
function selectVal(type){
	var val = $("#"+type+"Sel").val();
	$("#"+type+"Hidden").val(val);
}
function initVal(){
	var isFirst = $("#isFirstHidden").val();
	if(isFirst=='all'){
		$("#isFirst0").attr("selected","selected");
	}else if(isFirst=='yes'){
		$("#isFirst1").attr("selected","selected");
	}else{
		$("#isFirst2").attr("selected","selected");
	}
	var isTop = $("#isTopHidden").val();
	if(isTop=='all'){
		$("#isTop0").attr("selected","selected");
	}else if(isTop=='yes'){
		$("#isTop1").attr("selected","selected");
	}else{
		$("#isTop2").attr("selected","selected");
	}
	var isCreate = $("#isCreateHidden").val();
	if(isCreate=='all'){
		$("#isCreate0").attr("selected","selected");
	}else if(isCreate=='yes'){
		$("#isCreate1").attr("selected","selected");
	}else{
		$("#isCreate2").attr("selected","selected");
	}
}
function tijiao(){
	$('#pageval').val(1);
	$("form").submit();
}
$('#pagercontent').twbsPagination({
	  startPage: ${param.page==null?1:param.page},
	  initiateStartPageClick: false,
	  totalPages: ${contentList.totalCount}==0?1:Math.ceil(${contentList.totalCount}/10),
	  onPageClick: function (event, page) {
	    $('#pageval').val(page);
	    $("form").submit();
	  }
	});
function addParent(contentId){
	console.log(parent);
	parent.$('#addMatchId').val(contentId);
	parent.layer.closeAll();
}
</script>
</body>
</html>