From fce863d8f7a5d9f8eedfb7c6c0abf9e19d6fb6b4 Mon Sep 17 00:00:00 2001 From: Meutel Date: Sat, 14 Jan 2017 17:38:40 +0100 Subject: [PATCH] Search books --- Makefile | 4 +-- index.html | 14 +++++++++ search.html | 45 +++++++++++++++++++++++++++ search.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 search.html create mode 100644 search.js diff --git a/Makefile b/Makefile index ce7ae34..5ef77a3 100644 --- a/Makefile +++ b/Makefile @@ -60,8 +60,8 @@ sinclude GNUmakefile.local DATABASE = metadata.db OBJS = db.o db_author.o db_book.o db_series.o json.o main.o -HTMLS = index.html book.html author.html series.html -JSMINS = index.min.js book.min.js author.min.js series.min.js +HTMLS = index.html book.html author.html series.html search.html +JSMINS = index.min.js book.min.js author.min.js series.min.js search.min.js EXTJS = externals/vue.min.js CSS = externals/bootstrap.min.css FONTS = externals/fonts/* diff --git a/index.html b/index.html index 4821ee4..9f60dac 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,20 @@ +

Bouquins

diff --git a/search.html b/search.html new file mode 100644 index 0000000..ac3dbf8 --- /dev/null +++ b/search.html @@ -0,0 +1,45 @@ + + + + Bouquins + + + + + + + + + + +
+
+

Recherche

+
+
+

Livres

+ +
+
+ + + + diff --git a/search.js b/search.js new file mode 100644 index 0000000..90c4a30 --- /dev/null +++ b/search.js @@ -0,0 +1,90 @@ +var app = new Vue({ + el: '#app', + data: { + urlParams: {}, + authors: [], + series: [], + books: [] + }, + methods: { + urlParse: function() { + var match, + pl = /\+/g, // Regex for replacing addition symbol with a space + search = /([^&=]+)=?([^&]*)/g, + decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, + query = window.location.search.substring(1); + while (match = search.exec(query)) + this.urlParams[decode(match[1])] = decode(match[2]); + }, + sendQuery: function(url, error, success) { + var xmh = new XMLHttpRequest(); + var v; + + xmh.onreadystatechange = function() { + v = xmh.responseText; + if (xmh.readyState === 4 && xmh.status === 200) { + var res; + try { + res = JSON.parse(v); + } catch (err) { + if (null !== error) + error(err.name, err.message); + } + if (null !== success) + success(res); + } else if (xmh.readyState === 4) { + if (null !== error) + error(xmh.status, v); + } + }; + + xmh.open('GET', url, true); + xmh.send(null); + }, + stdError: function(code, resp) { + console.log('ERROR ' + code + ': ' + resp); + }, + searchParams: function(url) { + var res = url; + var first = true; + for (var i=0; i