search UI
This commit is contained in:
parent
a90653c421
commit
407edb411b
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)",
|
||||
|
@ -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 = "<tr id='" + elt.id + "'>";
|
||||
@ -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(';');
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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<initials.length;i++) {
|
||||
- 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')
|
||||
li.next.disabled: a.next= t('bouquins.next')
|
||||
table#items.table.table-striped
|
||||
tr: td.disabled= t('bouquins.empty')
|
||||
ul.pager
|
||||
li.previous.disabled: a.prev= t('bouquins.previous')
|
||||
li.next.disabled: a.next= t('bouquins.next')
|
||||
div.btn-group.center-block
|
||||
each p in [10,20,50,100]
|
||||
button.btn.btn-default.perpage(type="button",value=p)= p
|
||||
div.row
|
||||
a#itemsanchor
|
||||
div.btn-group
|
||||
- var initials = '0ABCDEFGHIPQRSTUVWXYZ';
|
||||
- for (var i=0;i<initials.length;i++) {
|
||||
- var c = initials.charAt(i);
|
||||
button.btn.btn-default.initial(type="button",value=c)= c
|
||||
- }
|
||||
div.row
|
||||
ul.pager
|
||||
li.previous.disabled: a.prev= t('bouquins.previous')
|
||||
li.next.disabled: a.next= t('bouquins.next')
|
||||
div.row
|
||||
table#items.table.table-striped
|
||||
tr: td.disabled= t('bouquins.empty')
|
||||
div.row
|
||||
ul.pager
|
||||
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
|
||||
| $(function() {
|
||||
| $.i18n.init().done(function() {
|
||||
|
Loading…
Reference in New Issue
Block a user