-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathlist.html
178 lines (148 loc) · 7.65 KB
/
list.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Note/List</title>
<link rel="stylesheet" type="text/css" href="/restful/css/style.css"/>
<script type="text/javascript" src="/restful/js/restful.js"></script>
<script type="text/javascript">
// window.onload
window.onload = function() {
var url = location.href;
var params = "";
if (url.indexOf('?') > 0) {
params = (url.substring(url.indexOf('?'), url.length));
}
var endpoint = "/restful/api/note/list" + params;
ajaxCall('GET', endpoint, null, null, function(data) {
var status = data.status;
if (status == 'OK') {
success(data);
}
}, function(data) {
fail(data);
}
);
};
// Success function
function success(data) {
for (str in data.response) {
if (data.response[str] != null && data.response[str] != 0) {
if (str == "query") {
var url = location.href;
if (url.indexOf('?') > 0) {
url = url.substring(0, url.indexOf('?'));
}
var query = data.response.query;
var pn = query.paging.pn;
var maxPaging = query.paging.maxPaging;
var maxResults = query.paging.maxResults;
var totalResults = query.paging.totalResults;
if (totalResults > 0) {
var paging = "";
var current = parseInt((pn - 1) / maxPaging) + 1;
var start = (current - 1) * maxPaging + 1;
var end = (start + maxPaging) - 1;
var total = parseInt(totalResults / maxResults);
if (totalResults % maxResults > 0) {
total = total + 1;
}
if (end > total) {
end = total;
}
if (start > 1) {
paging += "<a href=\""+ url + "?pn=1\"> << </a>";
} else {
paging += " << ";
}
if (start > maxPaging) {
var prev = start - 1;
paging += "<a href=\"" + url + "?pn=" + prev + "\"> < </a>";
} else {
paging += " < ";
}
for (var i = start ; i <= end ; i++) {
if (i == pn) {
paging += "<b> " + i + " </b>";
} else {
paging += "<a href=\"" + url + "?pn=" + i + "\"> " + i + " </a>";
}
}
if (end < total) {
var next = end + 1;
paging += "<a href=\"" + url + "?pn=" + next + "\"> > </a>";
} else {
paging += " > ";
}
if (end < total) {
paging += "<a href=\"" + url + "?pn=" + total + "\"> >> </a>";
} else {
paging += " >> ";
}
document.getElementById('paging').innerHTML = paging;
}
} else if (str == "object") {
var content = "/restful/note/content.html";
var object = data.response.object;
var html = "";
html += "<table width=\"100%\">";
html += "<tr align=\"center\">";
html += "<td>idx</td>";
html += "<td>subject</td>";
html += "<td>access</td>";
html += "<td>createdate</td>";
html += "</tr>";
for (var i = 0 ; i < object.length ; i++) {
var note = object[i];
html += "<tr>";
html += "<td align=\"center\">" + note.idx + "</td>"
html += "<td><a href=\"" + content + "?" + note.idx + "\">" + note.subject + "</a></td>"
html += "<td align=\"right\">" + note.access + "</td>"
html += "<td align=\"right\">" + new Date(note.createdate).toLocaleDateString() + "</td>"
html += "</tr>";
}
html += "</table>";
document.getElementById('note').innerHTML = html;
}
}
}
}
// Fail function
function fail(data) {
var html = data.response;
document.getElementById('note').innerHTML = html;
}
// Search note
function search() {
var url = location.href;
if (url.indexOf('?') > 0) {
url = url.substring(0, url.indexOf('?'));
}
var q = document.getElementById('search').value;
if (q) {
location.href = url + "?q=" + q;
}
}
</script>
</head>
<body>
<p>List</p>
<table style="width: 200px;">
<tr>
<td><div id="note"></div></td>
</tr>
<tr>
<td align="center">
<input type="text" name="search" id="search" tabindex="1" size="10" placeholder=" Search">
<input type="button" value="Search" onClick="search()">
</td>
</tr>
<tr>
<td align="center"><div id="paging"></div></td>
</tr>
<tr>
<td align="left"><a href="create.html">Create</a></td>
</tr>
</table>
</body>
</html>