Search in navbar

This commit is contained in:
Meutel 2017-08-06 15:41:58 +02:00
parent e2edf6c944
commit f67d3f7aad
3 changed files with 18 additions and 4 deletions

View File

@ -4,8 +4,6 @@ Bouquins in Go
## TODO ## TODO
* search (table results: authors, tags...)
* search in header
* About * About
* translations * translations
* tests * tests

View File

@ -26,7 +26,7 @@ Vue.component('results-list', {
icon: function() { icon: function() {
switch (this.type) { switch (this.type) {
case 'books': case 'books':
return 'icon'; return 'book';
case 'authors': case 'authors':
return 'user'; return 'user';
case 'series': case 'series':
@ -289,6 +289,7 @@ if (document.getElementById("search")) {
new Vue({ new Vue({
el: '#search', el: '#search',
data: { data: {
urlParams: [],
authors: [], authors: [],
books: [], books: [],
series: [], series: [],
@ -376,6 +377,15 @@ if (document.getElementById("search")) {
this.q = this.urlParams.q; this.q = this.urlParams.q;
} }
}, },
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) { sendQuery: function(url, error, success) {
var xmh = new XMLHttpRequest(); var xmh = new XMLHttpRequest();
var v; var v;
@ -403,6 +413,12 @@ if (document.getElementById("search")) {
stdError: function(code, resp) { stdError: function(code, resp) {
console.log('ERROR ' + code + ': ' + resp); console.log('ERROR ' + code + ': ' + resp);
} }
},
created: function() {
this.urlParse();
},
mounted: function() {
this.searchUrl();
} }
}); });
} }

View File

@ -18,7 +18,7 @@
<li><a href="/search">Recherche</a></li> <li><a href="/search">Recherche</a></li>
<li><a href="#">A propos</a></li> <li><a href="#">A propos</a></li>
</ul> </ul>
<form class="navbar-form navbar-right" role="search" method="get" action="search.html"> <form class="navbar-form navbar-right" role="search" method="get" action="/search/">
<div class="form-group"> <div class="form-group">
<input name="q" type="text" class="form-control" placeholder="Recherche"> <input name="q" type="text" class="form-control" placeholder="Recherche">
</div> </div>