-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.jsp
205 lines (186 loc) · 9 KB
/
product.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="uma.taw.ubayspring.dto.products.ProductDTO" %>
<%@ page import="uma.taw.ubayspring.dto.products.index.ListsDTO" %>
<%@ page import="uma.taw.ubayspring.dto.products.ProductClientDTO" %>
<%--
Created by IntelliJ IDEA.
Author: Francisco Javier Hernández
Date: 28/3/22
Time: 22:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<title><spring:message key="product.header.title"/></title>
</head>
<style>
tr {
cursor: pointer
}
th {
cursor: default;
}
tr:hover {
background-color: #F5F5F5;
}
</style>
<body>
<jsp:include page="../components/navbar.jsp"/>
<%
ListsDTO listas = (ListsDTO) request.getAttribute("listas");
Integer pageLimit = (Integer) request.getAttribute("pageLimit");
ProductClientDTO client = (ProductClientDTO) request.getAttribute("client");
%>
<div class="mx-auto" style="width: 1500px;">
<div class="container">
<div class="row">
<div class="col-3">
<h2><spring:message key="product.index.filter.header"/></h2>
<%--@elvariable id="productModel" type="uma.taw.ubayspring.dto.products.index.ParamsDTO"--%>
<form:form
modelAttribute="productModel"
method="get"
action="${pageContext.request.contextPath}/product">
<div class="form col">
<spring:message key="product.index.filter.name"/>
<form:input
type="text"
class="form-control"
maxlength="20"
path="name"/>
<spring:message key="product.index.filter.category"/>
<form:select
class="form-select"
path="category">
<c:choose>
<c:when test="${productModel.category eq 0}">
<form:option selected="true" value="0">--</form:option>
</c:when>
<c:otherwise>
<form:option selected="false" value="0">--</form:option>
</c:otherwise>
</c:choose>
<form:options items="<%=listas.getCategoryList()%>" itemValue="id" itemLabel="name"/>
</form:select>
<c:if test="<%=client != null%>"> <%-- if(logged in) --%>
<form:radiobuttons
path="favOwnedFilter"
items="<%=listas.getFavOwnedFilterOptions()%>"
class="no-wrapper"
itemValue="value"
itemLabel="label"
element="br"
/>
</c:if>
<form:button type="submit" class="btn btn-primary mt-2"><spring:message key="search"/></form:button>
<a class="btn btn-secondary mt-2" href="<%=request.getContextPath()%>/product"><spring:message key="clean"/></a>
</div>
</form:form>
</div>
<div class="col">
<c:if test="<%=client != null%>">
<form:form method="get" action="${pageContext.request.contextPath}/product/new">
<div class="py-3" style="width: max-content; float: left">
<button type="submit" class="btn btn-primary"><spring:message key="product.index.createproduct.label"/></button>
</div>
</form:form>
</c:if>
<table class="table table-bordered text-center">
<thead>
<tr>
<th scope="col"><spring:message key="product.image"/></th>
<th scope="col"><spring:message key="product.title"/></th>
<th scope="col"><spring:message key="product.status.label"/></th>
<th scope="col"><spring:message key="description"/></th>
</tr>
</thead>
<tbody>
<c:forEach items="<%=listas.getProductList()%>" var="p">
<tr onclick="window.location='${pageContext.request.contextPath}/product/item?id=${p.id}'">
<%
ProductDTO p = (ProductDTO) pageContext.getAttribute("p");
String imgSrc = p.getImages() == null ? "" : request.getContextPath() + "/image?id=" + URLEncoder.encode(p.getImages(), StandardCharsets.UTF_8);
%>
<td><img src="<%=imgSrc%>" class="img-thumbnail" alt="${p.title}" style="width: 200px"></td>
<td class="align-middle"><h3>${p.title}</h3></td>
<c:choose>
<c:when test="${p.closeDate eq null}">
<td class="align-middle"><spring:message key="activeStatus"/></td>
</c:when>
<c:otherwise>
<td class="align-middle"><spring:message key="closedStatus"/></td>
</c:otherwise>
</c:choose>
<td class="align-middle">${p.description}</td>
</tr>
</c:forEach>
</tbody>
</table>
<form:form
id="pagination"
method="get"
modelAttribute="productModel"
action="${pageContext.request.contextPath}/product">
<c:if test="${productModel.category ne 0}">
<form:hidden
name="category"
path="category"/>
</c:if>
<c:if test="${productModel.name ne ''}">
<form:hidden
name="name"
path="name"/>
</c:if>
<c:choose>
<c:when test="${productModel.favOwnedFilter eq 'favFilter'}">
<form:hidden
path="favOwnedFilter"/>
</c:when>
<c:when test="${productModel.favOwnedFilter eq 'ownedFilter'}">
<form:hidden
path="favOwnedFilter"/>
</c:when>
</c:choose>
<nav aria-label="Pagination">
<ul class="pagination justify-content-center">
<c:forEach begin="1" end="<%=pageLimit%>" var="pageNum">
<li class="page-item ${(pageNum eq 1 and productModel.page == 0) or (pageNum eq productModel.page) ? 'active' : ''}">
<form:input
type="submit"
class="page-link"
aria-checked="${pageNum eq productModel.page}"
value="${pageNum}"
path="page"
/>
</li>
</c:forEach>
</ul>
</nav>
</form:form>
</div>
</div>
</div>
</div>
</body>
<script>
$('input[type=radio].no-wrapper').on('mousedown', function(e){
var wasChecked = $(this).prop('checked');
this.turnOff = wasChecked;
$(this).prop('checked', !wasChecked);
});
$('input[type=radio].no-wrapper').on('click', function(e){
$(this).prop('checked', !this.turnOff);
this['turning-off'] = !this.turnOff;
});
</script>
</html>