search UI

This commit is contained in:
Meutel 2014-06-29 17:14:00 +02:00
parent a90653c421
commit 407edb411b
6 changed files with 103 additions and 68 deletions

View File

@ -1,16 +1,18 @@
{ {
"bouquins": { "bouquins": {
"homeTitle": "Library", "homeTitle": "Library",
"homeGreetings": "Browse library", "homeGreetings": "Browse library",
"authors": "Authors", "authors": "Authors",
"books": "Books", "books": "Books",
"series": "Series", "series": "Series",
"recent": "Last updates", "recent": "Last updates",
"previous": "Previous", "search": "Search",
"next": "Next", "submitsearch": "Search",
"empty": "Empty", "previous": "Previous",
"cols": { "next": "Next",
"booktitle": "Title", "empty": "Empty",
"cols": {
"booktitle": "Title",
"bookauthors": "Author(s)", "bookauthors": "Author(s)",
"bookserie": "Serie", "bookserie": "Serie",
"authorname": "Name", "authorname": "Name",
@ -18,29 +20,29 @@
"seriename": "Name", "seriename": "Name",
"serieauthors": "Author(s)", "serieauthors": "Author(s)",
"seriebooks": "Books" "seriebooks": "Books"
}, },
"nav": { "nav": {
"home": "Home", "home": "Home",
"books": "Books", "books": "Books",
"authors": "Authors", "authors": "Authors",
"series": "Series" "series": "Series"
}, },
"book": { "book": {
"download": "Download", "download": "Download",
"authors": "Author(s)", "authors": "Author(s)",
"serie": "Serie", "serie": "Serie",
"language": "Language", "language": "Language",
"tags": "Tag(s)", "tags": "Tag(s)",
"nocover": "No cover" "nocover": "No cover"
}, },
"author": { "author": {
"books": "Books", "books": "Books",
"series": "Series", "series": "Series",
"coauthors": "Co-Authors" "coauthors": "Co-Authors"
}, },
"serie": { "serie": {
"books": "Books", "books": "Books",
"authors": "Authors" "authors": "Authors"
} }
} }
} }

View File

@ -5,10 +5,12 @@
"authors": "Auteurs", "authors": "Auteurs",
"books": "Livres", "books": "Livres",
"series": "Séries", "series": "Séries",
"search": "Recherche",
"submitsearch": "Rechercher",
"recent": "Derniers ajouts", "recent": "Derniers ajouts",
"previous": "Précédent", "previous": "Précédent",
"next": "Suivant", "next": "Suivant",
"empty": "Vide" "empty": "Vide",
"cols": { "cols": {
"booktitle": "Titre", "booktitle": "Titre",
"bookauthors": "Auteur(s)", "bookauthors": "Auteur(s)",

View File

@ -17,13 +17,14 @@ $.extend(ItemsCol.prototype,{
load: function(addparam) { load: function(addparam) {
var self = this; var self = this;
$.getJSON( this.url, $.extend({}, home.pagination, addparam), $.getJSON( this.url, $.extend({}, home.pagination, addparam),
function( data, textStatus, xhr ) { function(data, textStatus, xhr) { self.loadData(data, textStatus, xhr) });
self.data = data; },
home.current = self; loadData: function(data, textStatus, xhr) {
home.update(); this.data = data;
var linkHeader = xhr.getResponseHeader('link'); home.current = this;
home.updatePager(parse_link_header(linkHeader)); home.update();
}); var linkHeader = xhr.getResponseHeader('link');
home.updatePager(parse_link_header(linkHeader));
}, },
renderRow: function(elt) { renderRow: function(elt) {
var item = "<tr id='" + elt.id + "'>"; var item = "<tr id='" + elt.id + "'>";
@ -70,10 +71,7 @@ var HomePage = function() {
}, },
function(elt) { return elt.count; } function(elt) { return elt.count; }
]); ]);
this.pagination= { this.pagination = { perpage: 10, page: 0, };
perpage: 10,
page: 0,
};
this.table = $('#items'); this.table = $('#items');
// bind buttons events // bind buttons events
$.each([this.books,this.authors,this.series], function(ind, itemsCol) { $.each([this.books,this.authors,this.series], function(ind, itemsCol) {
@ -84,6 +82,19 @@ var HomePage = function() {
home.books.load({sort:'recent'}); home.books.load({sort:'recent'});
toggleActive(this); 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() { $(".perpage").click(function() {
home.pagination.perpage = $(this).attr("value"); home.pagination.perpage = $(this).attr("value");
$('.perpage').removeClass('active'); $('.perpage').removeClass('active');
@ -149,13 +160,15 @@ $.extend(HomePage.prototype,{
btn.parent().addClass('disabled'); btn.parent().addClass('disabled');
} }
btn.unbind(); btn.unbind();
btn.click(function() { if (links[elt]) {
var parsed = $.url(links[elt]); btn.click(function() {
var urlp = parsed.param(); var parsed = $.url(links[elt]);
home.pagination.page = urlp.page; var urlp = parsed.param();
home.pagination.perpage = urlp.perpage; home.pagination.page = urlp.page;
home.current.load(); home.pagination.perpage = urlp.perpage;
}); home.current.load();
});
}
}); });
}, },
}); });
@ -185,13 +198,13 @@ function toggleActive(btn) {
* http://developer.github.com/v3/#pagination * http://developer.github.com/v3/#pagination
*/ */
function parse_link_header(header) { function parse_link_header(header) {
if (header.length == 0) { var links = {};
throw new Error("input must not be of zero length"); if (header == null || header.length == 0) {
return links;
} }
// Split parts by comma // Split parts by comma
var parts = header.split(','); var parts = header.split(',');
var links = {};
// Parse each part into a named link // Parse each part into a named link
$.each(parts, function(i, p) { $.each(parts, function(i, p) {
var section = p.split(';'); var section = p.split(';');

View File

@ -113,6 +113,7 @@ router.post('/', function(req,res) {
qparams.push(id); qparams.push(id);
}); });
query+=')'; query+=')';
query = pager.appendInitialQuery(query,'books.sort',qparams,false);
return query; return query;
}, },
function(books) { function(books) {

View File

@ -3,7 +3,7 @@ var router = express.Router();
/* GET home page. */ /* GET home page. */
router.get('/', function(req, res) { router.get('/', function(req, res) {
res.render('home', { title: 'Bibliothèque' }); res.render('home', { title: req.t('bouquins.homeTitle') });
}); });
module.exports = router; module.exports = router;

View File

@ -12,25 +12,42 @@ block content
a#serie.btn.btn-primary.btn-lg(href="#series",role="button")= t('bouquins.series') a#serie.btn.btn-primary.btn-lg(href="#series",role="button")= t('bouquins.series')
&nbsp; &nbsp;
a#recent.btn.btn-warning.btn-lg(href="#books",role="button")= t('bouquins.recent') a#recent.btn.btn-warning.btn-lg(href="#books",role="button")= t('bouquins.recent')
&nbsp;
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 div#blkitems.container-fluid.hidden
a#itemsanchor div.row
div.btn-group a#itemsanchor
- var initials = '0ABCDEFGHIPQRSTUVWXYZ'; div.btn-group
- for (var i=0;i<initials.length;i++) { - var initials = '0ABCDEFGHIPQRSTUVWXYZ';
- var c = initials.charAt(i); - for (var i=0;i<initials.length;i++) {
button.btn.btn-default.initial(type="button",value=c)= c - var c = initials.charAt(i);
- } button.btn.btn-default.initial(type="button",value=c)= c
ul.pager - }
li.previous.disabled: a.prev= t('bouquins.previous') div.row
li.next.disabled: a.next= t('bouquins.next') ul.pager
table#items.table.table-striped li.previous.disabled: a.prev= t('bouquins.previous')
tr: td.disabled= t('bouquins.empty') li.next.disabled: a.next= t('bouquins.next')
ul.pager div.row
li.previous.disabled: a.prev= t('bouquins.previous') table#items.table.table-striped
li.next.disabled: a.next= t('bouquins.next') tr: td.disabled= t('bouquins.empty')
div.btn-group.center-block div.row
each p in [10,20,50,100] ul.pager
button.btn.btn-default.perpage(type="button",value=p)= p li.previous.disabled: a.prev= t('bouquins.previous')
li.next.disabled: a.next= t('bouquins.next')
div.row
div.btn-group.center-block
each p in [10,20,50,100]
button.btn.btn-default.perpage(type="button",value=p)= p
script script
| $(function() { | $(function() {
| $.i18n.init().done(function() { | $.i18n.init().done(function() {