-
Notifications
You must be signed in to change notification settings - Fork 0
/
BestSeller.js
299 lines (261 loc) · 11.1 KB
/
BestSeller.js
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
function loadBook(){
let logoutButton = document.getElementById('logoutButton');
let showLoginButton = document.getElementById('showLoginButton');
if(sessionStorage.getItem('name')!=null){
logoutButton.style.display ="block";
showLoginButton.style.display = "none";
}else{
logoutButton.style.display ="none";
showLoginButton.style.display = "block";
}
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
let table = document.getElementById('showTable');
let result = JSON.parse(this.responseText.slice(0,-18));
let head = document.createElement('thead');
let row =document.createElement('tr');
let sort0 = document.createElement('th');
let sort0_text = document.createElement('순위');
sort0.appendChild(sort0_text);
row.appendChild(sort0);
let sort1 = document.createElement('th');
let sort1_text = document.createTextNode('책');
sort1.appendChild(sort1_text);
row.appendChild(sort1);
let sort2 = document.createElement('th');
let sort2_text = document.createTextNode('제목');
sort2.appendChild(sort2_text);
row.appendChild(sort2);
let sort3 = document.createElement('th');
let sort3_text = document.createTextNode('저자');
sort3.appendChild(sort3_text);
row.appendChild(sort3);
let sort4 = document.createElement('th');
let sort4_text = document.createTextNode('출판사');
sort4.appendChild(sort4_text);
row.appendChild(sort4);
let sort5 = document.createElement('th');
let sort5_text = document.createTextNode('가격');
sort5.appendChild(sort5_text);
row.appendChild(sort5);
head.appendChild(row);
table.appendChild(head);
for(let i = 0; i< result["item"].length; i++){
let tr = document.createElement('tr');
let ranktd = document.createElement('td');
let rank = document.createTextNode(result['item'][i]["rank"]);
ranktd.appendChild(rank);
tr.appendChild(ranktd);
let imagetd = document.createElement('td');
let image = document.createElement('img');
let srcatt = document.createAttribute('src');
srcatt.value = result["item"][i]["coverSmallUrl"];
image.setAttributeNode(srcatt);
imagetd.appendChild(image);
tr.appendChild(imagetd);
let titletd = document.createElement('td');
let title = document.createTextNode(result['item'][i]["title"]);
titletd.appendChild(title);
tr.appendChild(titletd);
let authortd = document.createElement('td');
let author = document.createTextNode(result["item"][i]["author"]);
authortd.appendChild(author);
tr.appendChild(authortd);
let publishertd = document.createElement('td');
let publisher = document.createTextNode(result["item"][i]["publisher"]);
publishertd.appendChild(publisher);
tr.appendChild(publishertd);
let pricetd = document.createElement('td');
let price = document.createTextNode(result["item"][i]["priceStandard"]);
pricetd.appendChild(price);
tr.appendChild(pricetd);
table.appendChild(tr);
}
}
};
xhttp.open("POST", "bestSeller.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send();
}
function logoutFunction(){
sessionStorage.removeItem('name');
let showLoginButton = document.getElementById('showLoginButton');
let logoutButton = document.getElementById('logoutButton');
showLoginButton.style.display ="block";
logoutButton.style.display ="none";
}
function showLoginModal(){
let loginFieldSet = document.getElementById('searchModal');
loginFieldSet.style.display = "block";
}
function loginFunction(){
let id = document.getElementById('idElement').value;
let password = document.getElementById('passwordElement').value;
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if(this.responseText=="Success"){
sessionStorage.setItem('name',id);
alert("성공적으로 로그인 하였습니다.");
let loginFieldSet = document.getElementById('searchModal');
loginFieldSet.style.display="none";
let idfield = document.getElementById('idElement');
idfield.value = "";
let passwordField = document.getElementById('passwordElement');
passwordField.value="";
let showLoginButton = document.getElementById('showLoginButton');
showLoginButton.style.display="none";
let logoutButton = document.getElementById('logoutButton');
logoutButton.style.display="block";
}else{
alert(this.responseText);
}
}
};
xhttp.open("POST", "login.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
let sendstr = "id="+id+"&passwd="+password;
xhttp.send(sendstr);
}
function joinFunction(){
let id = document.getElementById('idElement');
let password = document.getElementById('passwordElement');
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert(this.responseText);
let loginFieldSet = document.getElementById('searchModal');
loginFieldSet.style.display = "none";
id.value ="";
password.value = "";
}
};
xhttp.open("POST", "join.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
let sendstr = "id="+id.value+"&passwd="+password.value;
xhttp.send(sendstr);
}
window.onclick = function(event) {//modal박스 밖을 클릭했을 때
let modal = document.getElementById('searchModal');
if (event.target == modal) {
modal.style.display = "none";
}
}
function removeDivChild(){
let table = document.getElementById('showTable');
while(table.childNodes.length!=0){
table.removeChild(table.childNodes[0]);
}
}
function findBook(){
let input = document.getElementById('booktitle').value;
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
removeDivChild();
let result = this.responseText.slice(17);
let parseData = JSON.parse(result);
let table = document.getElementById('showTable');
if(parseData["display"]==0){
let text = document.createTextNode('결과 없음');
table.appendChild(text);
return;
}
let head = document.createElement('thead');
let row =document.createElement('tr');
let sort1 = document.createElement('th');
let sort1_text = document.createTextNode('책');
sort1.appendChild(sort1_text);
row.appendChild(sort1);
let sort2 = document.createElement('th');
let sort2_text = document.createTextNode('제목');
sort2.appendChild(sort2_text);
row.appendChild(sort2);
let sort3 = document.createElement('th');
let sort3_text = document.createTextNode('저자');
sort3.appendChild(sort3_text);
row.appendChild(sort3);
let sort4 = document.createElement('th');
let sort4_text = document.createTextNode('출판사');
sort4.appendChild(sort4_text);
row.appendChild(sort4);
let sort5 = document.createElement('th');
let sort5_text = document.createTextNode('가격');
sort5.appendChild(sort5_text);
row.appendChild(sort5);
head.appendChild(row);
table.appendChild(head);
for(let i = 0; i< parseData["items"].length; i++){
let tr = document.createElement('tr');
let imagetd = document.createElement('td');
let image = document.createElement('img');
let srcatt = document.createAttribute('src');
srcatt.value = parseData["items"][i]["image"];
image.setAttributeNode(srcatt);
imagetd.appendChild(image);
tr.appendChild(imagetd);
let titletd = document.createElement('td');
if(parseData["items"][i]["title"].indexOf("<b>")==-1){
title = document.createTextNode(parseData["items"][i]["title"]);
titletd.appendChild(title);
}else{
let bTag = document.createElement('b');
let startIndex = parseData["items"][i]["title"].indexOf("<b>");
let endIndex = parseData["items"][i]["title"].indexOf("</b>");
let insidebTag = document.createTextNode(parseData["items"][i]["title"].slice(startIndex+3, endIndex));
bTag.appendChild(insidebTag);
let firstTextNode = document.createTextNode(parseData["items"][i]["title"].slice(0, startIndex));
titletd.appendChild(firstTextNode);
titletd.appendChild(bTag);
let lastTextNode =document.createTextNode(parseData["items"][i]["title"].slice(endIndex+4));
titletd.appendChild(lastTextNode);
}
tr.appendChild(titletd);
let authortd = document.createElement('td');
if(parseData["items"][i]["author"].indexOf("<b>")==-1){
author = document.createTextNode(parseData["items"][i]["author"]);
authortd.appendChild(author);
}else{
let bTag = document.createElement('b');
let startIndex = parseData["items"][i]["author"].indexOf("<b>");
let endIndex = parseData["items"][i]["author"].indexOf("</b>");
let insidebTag = document.createTextNode(parseData["items"][i]["author"].slice(startIndex+3, endIndex));
bTag.appendChild(insidebTag);
let firstTextNode = document.createTextNode(parseData["items"][i]["author"].slice(0, startIndex));
authortd.appendChild(firstTextNode);
authortd.appendChild(bTag);
let lastTextNode =document.createTextNode(parseData["items"][i]["author"].slice(endIndex+4));
authortd.appendChild(lastTextNode);
}
tr.appendChild(authortd);
let publishertd = document.createElement('td');
if(parseData["items"][i]["publisher"].indexOf("<b>")==-1){
publisher = document.createTextNode(parseData["items"][i]["publisher"]);
publishertd.appendChild(publisher);
}else{
let bTag = document.createElement('b');
let startIndex = parseData["items"][i]["publisher"].indexOf("<b>");
let endIndex = parseData["items"][i]["publisher"].indexOf("</b>");
let insidebTag = document.createTextNode(parseData["items"][i]["publisher"].slice(startIndex+3, endIndex));
bTag.appendChild(insidebTag);
let firstTextNode = document.createTextNode(parseData["items"][i]["publisher"].slice(0, startIndex));
publishertd.appendChild(firstTextNode);
publishertd.appendChild(bTag);
let lastTextNode =document.createTextNode(parseData["items"][i]["publisher"].slice(endIndex+4));
publishertd.appendChild(lastTextNode);
}
tr.appendChild(publishertd);
let pricetd = document.createElement('td');
let price = document.createTextNode(parseData["items"][i]["price"]);
pricetd.appendChild(price);
tr.appendChild(pricetd);
table.appendChild(tr);
}
}
};
xhttp.open("POST", "searchBook.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
let sendstr = "search="+input;
xhttp.send(sendstr);
}