diff --git a/locales/dev/translation.json b/locales/dev/translation.json
index 25c94f9..de92a6f 100644
--- a/locales/dev/translation.json
+++ b/locales/dev/translation.json
@@ -1,16 +1,18 @@
{
- "bouquins": {
- "homeTitle": "Library",
- "homeGreetings": "Browse library",
- "authors": "Authors",
- "books": "Books",
- "series": "Series",
- "recent": "Last updates",
- "previous": "Previous",
- "next": "Next",
- "empty": "Empty",
- "cols": {
- "booktitle": "Title",
+ "bouquins": {
+ "homeTitle": "Library",
+ "homeGreetings": "Browse library",
+ "authors": "Authors",
+ "books": "Books",
+ "series": "Series",
+ "recent": "Last updates",
+ "search": "Search",
+ "submitsearch": "Search",
+ "previous": "Previous",
+ "next": "Next",
+ "empty": "Empty",
+ "cols": {
+ "booktitle": "Title",
"bookauthors": "Author(s)",
"bookserie": "Serie",
"authorname": "Name",
@@ -18,29 +20,29 @@
"seriename": "Name",
"serieauthors": "Author(s)",
"seriebooks": "Books"
- },
- "nav": {
- "home": "Home",
- "books": "Books",
+ },
+ "nav": {
+ "home": "Home",
+ "books": "Books",
"authors": "Authors",
"series": "Series"
- },
- "book": {
- "download": "Download",
- "authors": "Author(s)",
- "serie": "Serie",
- "language": "Language",
- "tags": "Tag(s)",
- "nocover": "No cover"
- },
+ },
+ "book": {
+ "download": "Download",
+ "authors": "Author(s)",
+ "serie": "Serie",
+ "language": "Language",
+ "tags": "Tag(s)",
+ "nocover": "No cover"
+ },
"author": {
"books": "Books",
"series": "Series",
"coauthors": "Co-Authors"
- },
+ },
"serie": {
"books": "Books",
"authors": "Authors"
}
- }
+ }
}
diff --git a/locales/fr/translation.json b/locales/fr/translation.json
index 0352516..e004d3a 100644
--- a/locales/fr/translation.json
+++ b/locales/fr/translation.json
@@ -5,10 +5,12 @@
"authors": "Auteurs",
"books": "Livres",
"series": "Séries",
+ "search": "Recherche",
+ "submitsearch": "Rechercher",
"recent": "Derniers ajouts",
"previous": "Précédent",
"next": "Suivant",
- "empty": "Vide"
+ "empty": "Vide",
"cols": {
"booktitle": "Titre",
"bookauthors": "Auteur(s)",
diff --git a/public/js/home.js b/public/js/home.js
index 7547baf..0def81a 100644
--- a/public/js/home.js
+++ b/public/js/home.js
@@ -17,13 +17,14 @@ $.extend(ItemsCol.prototype,{
load: function(addparam) {
var self = this;
$.getJSON( this.url, $.extend({}, home.pagination, addparam),
- function( data, textStatus, xhr ) {
- self.data = data;
- home.current = self;
- home.update();
- var linkHeader = xhr.getResponseHeader('link');
- home.updatePager(parse_link_header(linkHeader));
- });
+ function(data, textStatus, xhr) { self.loadData(data, textStatus, xhr) });
+ },
+ loadData: function(data, textStatus, xhr) {
+ this.data = data;
+ home.current = this;
+ home.update();
+ var linkHeader = xhr.getResponseHeader('link');
+ home.updatePager(parse_link_header(linkHeader));
},
renderRow: function(elt) {
var item = "
";
@@ -70,10 +71,7 @@ var HomePage = function() {
},
function(elt) { return elt.count; }
]);
- this.pagination= {
- perpage: 10,
- page: 0,
- };
+ this.pagination = { perpage: 10, page: 0, };
this.table = $('#items');
// bind buttons events
$.each([this.books,this.authors,this.series], function(ind, itemsCol) {
@@ -84,6 +82,19 @@ var HomePage = function() {
home.books.load({sort:'recent'});
toggleActive(this);
});
+ $('#search').click(function() {
+ home.pagination.page=0;
+ $('#searchpanel').toggleClass('hidden');
+ toggleActive(this);
+ });
+ $('#searchform').submit(function(evt) {
+ var formurl = $(this).attr('action');
+ formurl+='?'+$.param(home.pagination);
+ $.post(formurl, $(this).serialize(), function(data, textStatus, xhr) {
+ home.books.loadData(data, textStatus, xhr);
+ }, 'json');
+ return false;
+ });
$(".perpage").click(function() {
home.pagination.perpage = $(this).attr("value");
$('.perpage').removeClass('active');
@@ -149,13 +160,15 @@ $.extend(HomePage.prototype,{
btn.parent().addClass('disabled');
}
btn.unbind();
- btn.click(function() {
- var parsed = $.url(links[elt]);
- var urlp = parsed.param();
- home.pagination.page = urlp.page;
- home.pagination.perpage = urlp.perpage;
- home.current.load();
- });
+ if (links[elt]) {
+ btn.click(function() {
+ var parsed = $.url(links[elt]);
+ var urlp = parsed.param();
+ home.pagination.page = urlp.page;
+ home.pagination.perpage = urlp.perpage;
+ home.current.load();
+ });
+ }
});
},
});
@@ -185,13 +198,13 @@ function toggleActive(btn) {
* http://developer.github.com/v3/#pagination
*/
function parse_link_header(header) {
- if (header.length == 0) {
- throw new Error("input must not be of zero length");
+ var links = {};
+ if (header == null || header.length == 0) {
+ return links;
}
// Split parts by comma
var parts = header.split(',');
- var links = {};
// Parse each part into a named link
$.each(parts, function(i, p) {
var section = p.split(';');
diff --git a/routes/book.js b/routes/book.js
index 90fb737..bc8cf3c 100644
--- a/routes/book.js
+++ b/routes/book.js
@@ -113,6 +113,7 @@ router.post('/', function(req,res) {
qparams.push(id);
});
query+=')';
+ query = pager.appendInitialQuery(query,'books.sort',qparams,false);
return query;
},
function(books) {
diff --git a/routes/home.js b/routes/home.js
index 398b36e..f5f2a0f 100644
--- a/routes/home.js
+++ b/routes/home.js
@@ -3,7 +3,7 @@ var router = express.Router();
/* GET home page. */
router.get('/', function(req, res) {
- res.render('home', { title: 'Bibliothèque' });
+ res.render('home', { title: req.t('bouquins.homeTitle') });
});
module.exports = router;
diff --git a/views/home.jade b/views/home.jade
index d3217fa..28fddca 100644
--- a/views/home.jade
+++ b/views/home.jade
@@ -12,25 +12,42 @@ block content
a#serie.btn.btn-primary.btn-lg(href="#series",role="button")= t('bouquins.series')
a#recent.btn.btn-warning.btn-lg(href="#books",role="button")= t('bouquins.recent')
+
+ a#search.btn.btn-info.btn-lg(href="#",role="button")= t('bouquins.search')
+ div#searchpanel.row.hidden
+ form#searchform(role="form",action="/book",method="post")
+ div.col-md-6(style="margin-bottom:15px")
+ div.panel.panel-info
+ div.panel-body
+ div.input-group
+ input.form-control(type="text",name="q")
+ span.input-group-btn
+ button.btn.btn-info(type="submit",title=t('bouquins.submitsearch'))
+ span.glyphicon.glyphicon-search
div#blkitems.container-fluid.hidden
- a#itemsanchor
- div.btn-group
- - var initials = '0ABCDEFGHIPQRSTUVWXYZ';
- - for (var i=0;i