</head>
<body>
- <table class="header">
- <tr><td class="box"> </td><td class="title">eBook Library</td></tr>
- </table>
-
<form>
<input id="search" onclick="onSearch();" type="button" value="Search"/>
Author: <input id="aut" type="text"/>
Series: <input id="ser" type="text"/>
</form>
- <div class="footer">
- <input id="back" onclick="onPrev();" value="Back" type="button"/>
- <input id="forward" onclick="onNext();" value="Forward" type="button"/>
+ <div class="pager">
+ <input id="back" onclick="onPrev();" value="Back" type="button"/>
+ <input id="forward" onclick="onNext();" value="Forward" type="button"/>
+ <input id="slider" onchange="onSlide(this.value);" min="1" max="1" type="range" value="0"/>
Showing <span id="first">0</span> through <span id="last">0</span> out of <span id="count">0</span> matching books.
</div>
first: 0,
ids: [],
last: (-1),
- pageSize: 100
+ pageSize: 9
+}
+
+function adjustPos(setting) {
+ var value = parseInt(setting)
+
+ if (g_state.first === value) {
+ // No change
+ return;
+ }
+
+ var maxFirst = g_state.count - g_state.pageSize;
+
+ if (value < 0) {
+ g_state.first = 0;
+ } else if (value > maxFirst) {
+ g_state.first = maxFirst;
+ } else {
+ g_state.first = value;
+ }
+
+ g_state.last = g_state.first + g_state.pageSize - 1;
+ if (g_state.last >= g_state.count) {
+ g_state.last = g_state.count - 1;
+ }
+
+ refreshData();
}
function constructSearchUrl() {
function onNext() {
if (g_state.last < (g_state.count - 1)) {
- g_state.first += g_state.pageSize;
- g_state.last += g_state.pageSize;
- if (g_state.last >= g_state.count) {
- g_state.last = g_state.count - 1;
- }
-
- refreshData();
+ adjustPos(g_state.first + g_state.pageSize);
}
}
function onPrev() {
if (g_state.first > 0) {
- g_state.first -= g_state.pageSize;
- if (g_state.first < 0) {
- g_state.first = 0;
- }
- g_state.last = g_state.first + g_state.pageSize;
-
- refreshData();
+ adjustPos(g_state.first - g_state.pageSize);
}
}
+function onSlide(value) {
+ adjustPos(value);
+}
+
function onSearch() {
console.log('onSearch()');
console.log('JSON response: ', jsonValue);
g_state.ids = jsonValue
g_state.count = g_state.ids.length;
- g_state.first = 0
- g_state.last = (g_state.ids.length) - 1;
- if (g_state.last > g_state.pageSize) {
- g_state.last = g_state.pageSize;
- }
- refreshData()
+ g_state.first = (-1)
+
+ var elem = document.getElementById('slider');
+ elem.max = g_state.count;
+ elem.value = '0'
+
+ adjustPos(0);
})
.catch(err => {
var msg = 'Error fetching JSON from URL: ' + url + ': ' + err + ':' + err.stack;
func handleSearch(w http.ResponseWriter, r *http.Request) {
var err error
- fmt.Println("DEBUG: handleSearch(): " + r.URL.Path)
fields := []Field{Author, Title, Series}
paramName := fv.String()
paramValues := r.Form[paramName]
for _, pv := range(paramValues) {
- fmt.Println("DEBUG: handleSearch(): ", paramName, "=", pv)
if count >= len(terms) {
fmt.Printf("WARNING: limit of %d search terms exceeded. One or more terms ignored.", len(terms))
break