board.ejs
4.75 KB
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
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(function(){ // pagination 현재 페이지 활성화 시킴
var page = location.href.split("page=")[1]; // url에 page 넘버로 구분
var index = page-1; // 0부터 시작이므로 1 빼줌
if(page == null) { // 메인화면에서는 page 쿼리가 없으므로 빈값일 때
$(".pagination a:eq(0)").attr('class', 'current-page');
}
$(".pagination a:eq(" + index + ")").attr('class', 'current-page');
});
function searchContent() {
if($('#searchWord').val == ''){
alert("검색어를 입력해주세요!!!");
} else {
$('#searchAction').submit();
}
}
function submitContents() {
var name = $('#addContentName').val();
var company = $('#addContentCompany').val();
var category = $('#addContentCategory').val();
var price = $('#addContentPrice').val();
// 새 글 등록 시
if(name == '' || company == '' || category == '' || price == '') {
alert("이름, 회사, 카테고리, 가격 모두 있어야합니다.");
return;
} else {
$('#writeAction').submit();
}
}
</script>
</head>
<body>
<div class="main">
<a href="/boards"><h2>게시판</h2></a>
<table class="board_list">
<tr>
<th>Rank</th>
<th>Name</th>
<th>Company</th>
<th>Category</th>
<th>Price</th>
</tr>
<%if(contents.length>0){%>
<%var i = 0;%>
<%contents.forEach(function(item){%>
<%i++;%>
<tr>
<td class="number"><%=(page-1)*10+i%></td>
<td class="name"><a href="/boards/view?id=<%=item._id%>"><%=item.name%> [<%=item.comments.length%>] </a></td>
<td class="company"><%=item.company%></td>
<td class="category"><%=item.category%></td>
<td class="average"><%=item.average%></td>
</tr>
<%})%>
<%} else {%>
<tr>
<td colspan="5">게시물이 없습니다.</td>
</tr>
<%}%>
</table>
<div class="pagination">
<%
if(searchWord != '') {
for(var i=1; i<=pagination; i++){
%>
<a href="/boards/search?searchWord=<%=searchWord%>&page=<%=i%>" class="next-page"><%=i%></a>
<%
}
} else {
for(var i=1; i<=pagination; i++){
%>
<a href="/boards?page=<%=i%>" class="next-page"><%=i%></a>
<%}}%>
</div>
<div class="btn_group">
<div class="search">
<form action="/boards/search" method="get" id="searchAction" name="searchAction">
<input type="text" class="search_word" id="searchWord" name="searchWord">
<input type="radio" name="company" value="CU">CU</input>
<input type="radio" name="company" value="GS25">GS25</input>
<input type="radio" name="company" value="SevenEleven">SevenEleven</input>
<input type="radio" name="company" value="all" style="visibility:hidden" checked="true"></input>
<br>
<input type="radio" name="category" value="주먹밥">주먹밥</input>
<input type="radio" name="category" value="샌드위치">샌드위치</input>
<input type="radio" name="category" value="도시락">도시락</input>
<input type="radio" name="category" value="all" style="visibility:hidden" checked="true"></input>
<a href="#" onclick="searchContent();"><div class="search_btn">검색</div></a>
</form>
</div>
</div>
<!-- new content write form-->
<div class="write_form">
<form id="writeAction" action="/boards?mode=add" method="post">
<input type="text" class="inputName" id="addContentName" name="addContentName" placeholder="name">
<input type="text" class="inputCompany" id="addContentCompany" name="addContentCompany" placeholder="company">
<input type="text" class="inputCategory" id="addContentCategory" name="addContentCategory" placeholder="category">
<input type="text" class="inputPrice" id="addContentPrice" name="addContentPrice" placeholder="price"></textarea>
<div id = "new" class="addBtngroup">
<a onclick="submitContents();"><div>SUBMIT</div></a>
<a onclick="cancelWriteForm('cancel');"><div>CANCEL</div></a>
</div>
</form>
</div>
<!-- write form end-->
</div>
</body>
</html>