var url; var links; var cols; var headers; var urlp={}; function link(content, href, glyph) { var link=""; if (content) { if (glyph) link+=" "; link += ""; link+=content+""; } return link; } $('#book').click(function() { headers = ['Titre', 'Auteur(s)', 'Serie']; cols = [ function(elt) { return link(elt.title, '/book/'+elt.id, 'glyphicon-book'); }, function(elt) { var links=""; if (Array.isArray(elt.authors)) { $.each(elt.authors, function(ida, author) { links+=link(author.name, '/author/'+author.id,'glyphicon-user'); }); } return links; }, function(elt) { return link(elt.series_name, '/serie/'+elt.id, 'glyphicon-list'); } ]; }); $('#author').click(function() { headers = ['Nom', 'Livres']; cols = [ function(elt){ return link(elt.name, '/author/'+elt.id,'glyphicon-user'); }, function(elt) { return elt.count; } ]; }); $('#serie').click(function() { headers = ['Nom', 'Auteur(s)', 'Livres']; cols = [ function(elt) { return link(elt.name, '/serie/'+elt.id, 'glyphicon-list'); }, function(elt) { var links=""; if (Array.isArray(elt.authors)) { $.each(elt.authors, function(ida, author) { links+=link(author.name, '/author/'+author.id,'glyphicon-user'); }); } return links; }, function(elt) { return elt.count; } ]; }); $.each(['book','author','serie'], function (i, elt) { $('#'+elt).click(function() { url = '/'+elt; loadItems(); }); }); $.each(['prev','next'], function (i, elt) { $('#'+elt).click(function() { var parsed = $.url(links[elt]); url = parsed.attr('path'); urlp = parsed.param(); loadItems(); }); }); $(".perpage").click(function() { urlp.perpage = $(this).attr("value"); urlp.page = 0; loadItems(); }); function loadItems() { $.getJSON( url, urlp, function( data, textStatus, xhr ) { var items = $('#items'); items.empty(); var item = "