<%@ 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="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Language" content="zh-cn">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>demo列表</title>
	<link rel="stylesheet"
		  href="${ pageContext.request.contextPath }/css/goodslist.css" />
	<!-- 引入Jquery -->
	<script type="text/javascript"
			src="${ pageContext.request.contextPath }/static/js/jquery-2.1.1.min.js"></script>

	<link href="${pageContext.request.contextPath}/css/Style1.css"
		  rel="stylesheet" type="text/css" />

	<!-- 引入样式 -->
	<link
			href="${ pageContext.request.contextPath }/static/bootstrap-3.3.7-dist/css/bootstrap.min.css"
			rel="stylesheet">
	<script
			src="'${ pageContext.request.contextPath }/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

	<script type="text/javascript">
		var basepath= '${APP_PATH}';

		function refresh(){
			window.location.href = "${pageContext.request.contextPath}/demo/findAllByPage.action?page=1";
		}

		function addDemo(){
			window.location.href = "${pageContext.request.contextPath}/demo/add.action";
		}
		function edit(did) {
			window.location.href = "${pageContext.request.contextPath}/demo/updateById.action?did="+did;
		}
		function deletecs(did) {
			var r=confirm("确定删除吗？");
			if (r==true){
				window.location.href = "${pageContext.request.contextPath}/demo/deleteById.action?did="+did;
			}
			else{
			}
		}
		function look(did) {
			window.location.href = "${pageContext.request.contextPath}/demo/findById.action?did="+did;
		}

		function validate() {
			var condition = document.getElementById("condition").value;
			if (condition == null || condition == '') {
				alert("请输入关键字");
				return false;
			}
			return true;
		}
	</script>

</head>
<body>
<div class="a">
	<div class="b">
		<form method="post"
			  action="${pageContext.request.contextPath}/demo/searchDemoByCondition.action">
			<input id="condition" name="condition" type="text" class="input1"
				   value="请输入关键词" onfocus="this.value = '';"
				   onblur="if (this.value == '') {this.value = '请输入关键词';}">&nbsp;&nbsp;

			<button type="submit"
					class="btn btn-primary btn-sm glyphicon glyphicon-search"
					onclick="validate()"></button>
		</form>
	</div>

	<div align="right" style="padding-right: 30px;">
		<input type="button" value="+添加demo" class="btn btn-primary"
			   onclick="addDemo()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<button type="button" onclick="refresh()"
				class="btn glyphicon glyphicon-refresh"></button>
	</div>
</div>

<div class="d" style="width: 96%; margin-left: 25px;">
	<!-- 显示结果 -->
	<form style="margin-top: 3px;">
		<table width="100%" align="center"
			   class="table table-hover table-striped" id="table"
			   style="border: 1px solid #D0D0D0">
			<thead>
			<tr align="center" bgcolor="#93b6bd" height="33px;">
				<th scope="col" style="text-align: center;">demoID</th>
				<th scope="col" style="text-align: center;">demo名</th>
				<th scope="col" style="text-align: center;">备注</th>
				<th scope="col" style="text-align: center;">操作</th>
			</tr>
			</thead>
			<!-- <tbody></tbody> -->
			<c:forEach items="${allProPageBean.list }" var="d"
					   varStatus="status">
				<tr height="30">
					<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="5%">${d.did}</td>
					<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="15%">${d.dname }</td>
					<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="15%">${d.comment }</td>
					<td>
						<button type="button"
								class="btn btn-primary btn-sm glyphicon glyphicon-pencil"
								onclick="edit(${d.did})"></button>&nbsp;
						<button type="button"
								class="btn btn-success btn-sm glyphicon glyphicon-asterisk"
								onclick="look(${d.did})"></button>
						<button type="button"
								class="btn btn-success btn-sm glyphicon glyphicon-trash"
								onclick="deletecs(${d.did})"></button>
					</td>
				</tr>
			</c:forEach>
		</table>
	</form>
</div>


<!-- 分页 -->
<div align="right"
	 style="padding-right: 40px; margin-bottom: 10px; font-size: 13px;">
	第${allProPageBean.page }/${allProPageBean.totlePage}页
	<c:if test="${allProPageBean.page!= 1}">
		<a style="font-size: 13px;"
		   href="${pageContext.request.contextPath }/demo/findAllByPage.action?page=1">首页</a>|
		<a style="font-size: 13px;"
		   href="${pageContext.request.contextPath }/demo/findAllByPage.action?page=${allProPageBean.page-1}">上一页</a>
	</c:if>

	<c:choose>
		<c:when test="${allProPageBean.totlePage<=6}">
			<c:set var="begin" value="1" />
			<c:set var="end" value="${allProPageBean.totlePage}" />
		</c:when>
		<c:otherwise>
			<c:set var="begin" value="${allProPageBean.page-3}" />
			<c:set var="end" value="${allProPageBean.page+3}" />
			<!-- 头溢出 -->
			<c:if test="${begin<1}">
				<c:set var="begin" value="1" />
				<c:set var="end" value="7" />
			</c:if>
			<!-- 尾溢出 -->
			<c:if test="${end>allProPageBean.totlePage}">
				<c:set var="begin" value="${allProPageBean.totlePage-6}" />
				<c:set var="end" value="${allProPageBean.totlePage}" />
			</c:if>
		</c:otherwise>
	</c:choose>
	<%-- <c:forEach begin="1" end="${allProPageBean.totlePage}" var="i"> --%>
	<c:forEach var="i" begin="${begin}" end="${end}">
		<c:choose>
			<c:when test="${allProPageBean.page!=i}">
				<a style="font-size: 13px;"
				   href="${ pageContext.request.contextPath }/product/findAllByPage.action?page=${i}">${i}</a>
			</c:when>
			<c:otherwise>
				<span class="currentPage">${i}</span>
			</c:otherwise>
		</c:choose>
	</c:forEach>

	<c:if test="${allProPageBean.page!= allProPageBean.totlePage }">
		<a style="font-size: 13px;"
		   href="${pageContext.request.contextPath }/demo/findAllByPage.action?page=${allProPageBean.page+1}">下一页</a> |
		<a style="font-size: 13px;"
		   href="${pageContext.request.contextPath }/demo/findAllByPage.action?page=${allProPageBean.totlePage }">尾页</a>
	</c:if>
</div>

</body>
</html>

