From 047bb75971a70a9e483515f2b37b8c7d2b821f79 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 14 Nov 2012 17:05:45 +0100 Subject: [PATCH] Bug 10858: Browse selected biblios After launching a search, some people would like to browse some results from several pages. This patch adds, at the OPAC, a link "Browse selected biblios >>" when at least one biblio is checked. You can choose biblios from several page, not the current one. In this way, checkboxes already checked become again checked when you come back on this results page. After clicking the link, the "Browse results" block is filled with selected biblios, not (like as the current behavior) with the classic results. Test plan: - Launch a search at the OPAC - Check some biblios - Go on another page - Check some biblios - Come back to the first page and check that already checked biblio is automatically checked. - Click on the "Browse selected biblios >>" link - Check that you are able to browse results you had checked. You can also: - check some biblios from several pages - add them to the cart - add them to a list Signed-off-by: Cedric Vita Signed-off-by: Koha Team Amu Signed-off-by: Kyle M Hall Signed-off-by: Marcel de Rooy --- .../bootstrap/en/includes/opac-bottom.inc | 4 +- .../bootstrap/en/includes/page-numbers.inc | 4 +- .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 64 +++++++++++--------- .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 55 +++++++++++++++-- koha-tmpl/opac-tmpl/bootstrap/js/basket.js | 42 +++++++++---- koha-tmpl/opac-tmpl/bootstrap/js/commons.js | 69 ++++++++++++++++++++++ .../lib/jquery/plugins/jquery.cookie.min.js | 1 + opac/opac-detail.pl | 20 ++++++- 8 files changed, 207 insertions(+), 52 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/js/commons.js create mode 100644 koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.cookie.min.js diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index 0220d26..a351163 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -83,6 +83,8 @@ $.widget.bridge('uitooltip', $.ui.tooltip); + + diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js index 675dc0a..d3a1c9b 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js @@ -157,17 +157,25 @@ function SelectAll(){ } function addMultiple(){ + var bibnums = getContextBiblioNumbers(); var c_value = ""; - if(document.bookbag_form.biblionumber.length > 0) { - for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { - if (document.bookbag_form.biblionumber[i].checked) { - c_value = c_value + document.bookbag_form.biblionumber[i].value + "/"; - } + if ( bibnums.length > 0 ) { + for ( var i = 0 ; i < bibnums.length ; i++ ) { + c_value = c_value + bibnums[i] + "/"; } addSelRecords(c_value); } else { - c_value = c_value + document.bookbag_form.biblionumber.value + "/"; - addSelRecords(c_value); + if(document.bookbag_form.biblionumber.length > 0) { + for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { + if (document.bookbag_form.biblionumber[i].checked) { + c_value = c_value + document.bookbag_form.biblionumber[i].value + "/"; + } + } + addSelRecords(c_value); + } else { + c_value = c_value + document.bookbag_form.biblionumber.value + "/"; + addSelRecords(c_value); + } } } @@ -433,20 +441,28 @@ function addSelToShelf() { /// vShelfAdd() builds url string for multiple-biblio adds. function vShelfAdd() { - bibs= new Array; + var bibnums = getContextBiblioNumbers(); + bibs = new Array; + if ( bibnums.length > 0 ) { + for ( var i = 0 ; i < bibnums.length ; i++ ) { + bibs.push("biblionumber=" + bibnums[i]); + } + return bibs.join("&"); + } else { if(document.bookbag_form.biblionumber.length > 0) { - for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { - if (document.bookbag_form.biblionumber[i].checked) { - bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value); - } + for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { + if (document.bookbag_form.biblionumber[i].checked) { + bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value); } - if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); } + } + if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); } return bibs.join("&"); } else { if (document.bookbag_form.biblionumber.checked) { return "biblionumber=" + document.bookbag_form.biblionumber.value; } } + } } function showCart(){ diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/commons.js b/koha-tmpl/opac-tmpl/bootstrap/js/commons.js new file mode 100644 index 0000000..d0feed6 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/js/commons.js @@ -0,0 +1,69 @@ +// Extends jQuery API +// http://www.wskidmore.com/downloads/jquery-uniqueArray.min.js +jQuery.extend({uniqueArray:function(e){if($.isArray(e)){var c={};var a,b;for(b=0,a=e.length;bparam('busc')) { push @{$arrParamsBusc{$key}}, uri_unescape($value); } } + my $searchAgain = 0; + my ( $offset, $results_per_page ); + + my $bibnums = JSON::from_json( $query->cookie('bibs_selected') || '[]' ); + if ( scalar( @$bibnums ) ) { + $arrParamsBusc{count} = scalar( @$bibnums ); + $arrParamsBusc{listBiblios} = join ',', @$bibnums; + $results_per_page = $arrParamsBusc{count}; + $offset = 0; + } else { + $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0; my $count = C4::Context->preference('OPACnumSearchResults') || 20; - my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count; + $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count; $arrParamsBusc{'count'} = $results_per_page; - my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0; # The value OPACnumSearchResults has changed and the search has to be rebuild if ($count != $results_per_page) { if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) { @@ -308,6 +319,9 @@ if ($session->param('busc')) { @arrBusc = split(/\&(?:amp;)?/, $newbusc); } } + + } # end if cookie bibs_selected exists + my $buscParam = ''; my $j = 0; # Rebuild the query for the button "back to results" @@ -374,7 +388,7 @@ if ($session->param('busc')) { } $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0); } - if ($searchAgain) { + if ($searchAgain and not scalar( @$bibnums )) { my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page); my @newresults = @$newresultsRef; # build the new listBiblios -- 2.1.0