search UI
This commit is contained in:
parent
a90653c421
commit
407edb411b
@ -6,6 +6,8 @@
|
|||||||
"books": "Books",
|
"books": "Books",
|
||||||
"series": "Series",
|
"series": "Series",
|
||||||
"recent": "Last updates",
|
"recent": "Last updates",
|
||||||
|
"search": "Search",
|
||||||
|
"submitsearch": "Search",
|
||||||
"previous": "Previous",
|
"previous": "Previous",
|
||||||
"next": "Next",
|
"next": "Next",
|
||||||
"empty": "Empty",
|
"empty": "Empty",
|
||||||
|
@ -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)",
|
||||||
|
@ -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) {
|
||||||
|
this.data = data;
|
||||||
|
home.current = this;
|
||||||
home.update();
|
home.update();
|
||||||
var linkHeader = xhr.getResponseHeader('link');
|
var linkHeader = xhr.getResponseHeader('link');
|
||||||
home.updatePager(parse_link_header(linkHeader));
|
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,6 +160,7 @@ $.extend(HomePage.prototype,{
|
|||||||
btn.parent().addClass('disabled');
|
btn.parent().addClass('disabled');
|
||||||
}
|
}
|
||||||
btn.unbind();
|
btn.unbind();
|
||||||
|
if (links[elt]) {
|
||||||
btn.click(function() {
|
btn.click(function() {
|
||||||
var parsed = $.url(links[elt]);
|
var parsed = $.url(links[elt]);
|
||||||
var urlp = parsed.param();
|
var urlp = parsed.param();
|
||||||
@ -156,6 +168,7 @@ $.extend(HomePage.prototype,{
|
|||||||
home.pagination.perpage = urlp.perpage;
|
home.pagination.perpage = urlp.perpage;
|
||||||
home.current.load();
|
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(';');
|
||||||
|
@ -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) {
|
||||||
|
@ -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;
|
||||||
|
@ -12,7 +12,20 @@ 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')
|
||||||
|
|
||||||
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')
|
||||||
|
|
||||||
|
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
|
||||||
|
div.row
|
||||||
a#itemsanchor
|
a#itemsanchor
|
||||||
div.btn-group
|
div.btn-group
|
||||||
- var initials = '0ABCDEFGHIPQRSTUVWXYZ';
|
- var initials = '0ABCDEFGHIPQRSTUVWXYZ';
|
||||||
@ -20,14 +33,18 @@ block content
|
|||||||
- var c = initials.charAt(i);
|
- var c = initials.charAt(i);
|
||||||
button.btn.btn-default.initial(type="button",value=c)= c
|
button.btn.btn-default.initial(type="button",value=c)= c
|
||||||
- }
|
- }
|
||||||
|
div.row
|
||||||
ul.pager
|
ul.pager
|
||||||
li.previous.disabled: a.prev= t('bouquins.previous')
|
li.previous.disabled: a.prev= t('bouquins.previous')
|
||||||
li.next.disabled: a.next= t('bouquins.next')
|
li.next.disabled: a.next= t('bouquins.next')
|
||||||
|
div.row
|
||||||
table#items.table.table-striped
|
table#items.table.table-striped
|
||||||
tr: td.disabled= t('bouquins.empty')
|
tr: td.disabled= t('bouquins.empty')
|
||||||
|
div.row
|
||||||
ul.pager
|
ul.pager
|
||||||
li.previous.disabled: a.prev= t('bouquins.previous')
|
li.previous.disabled: a.prev= t('bouquins.previous')
|
||||||
li.next.disabled: a.next= t('bouquins.next')
|
li.next.disabled: a.next= t('bouquins.next')
|
||||||
|
div.row
|
||||||
div.btn-group.center-block
|
div.btn-group.center-block
|
||||||
each p in [10,20,50,100]
|
each p in [10,20,50,100]
|
||||||
button.btn.btn-default.perpage(type="button",value=p)= p
|
button.btn.btn-default.perpage(type="button",value=p)= p
|
||||||
|
Loading…
Reference in New Issue
Block a user