search UI
This commit is contained in:
parent
a90653c421
commit
407edb411b
@ -6,6 +6,8 @@
|
||||
"books": "Books",
|
||||
"series": "Series",
|
||||
"recent": "Last updates",
|
||||
"search": "Search",
|
||||
"submitsearch": "Search",
|
||||
"previous": "Previous",
|
||||
"next": "Next",
|
||||
"empty": "Empty",
|
||||
|
@ -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;
|
||||
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,6 +160,7 @@ $.extend(HomePage.prototype,{
|
||||
btn.parent().addClass('disabled');
|
||||
}
|
||||
btn.unbind();
|
||||
if (links[elt]) {
|
||||
btn.click(function() {
|
||||
var parsed = $.url(links[elt]);
|
||||
var urlp = parsed.param();
|
||||
@ -156,6 +168,7 @@ $.extend(HomePage.prototype,{
|
||||
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,7 +12,20 @@ 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
|
||||
div.row
|
||||
a#itemsanchor
|
||||
div.btn-group
|
||||
- var initials = '0ABCDEFGHIPQRSTUVWXYZ';
|
||||
@ -20,14 +33,18 @@ block content
|
||||
- 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
|
||||
|
Loading…
Reference in New Issue
Block a user