From 8e33b3af111b889548ea4e7b5a6d603f436674e6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 27 Nov 2013 14:36:09 +0100 Subject: [PATCH] Bug 11311: Browse selected authorities In the same way as the feature "Browse selected biblios", this one adds the same browse feature for authorities. After launching an authority search, some people would like to browse some results from several pages. This patch adds, at the OPAC, a link "Browse selected authorities >>" when at least one authority is checked. You can choose authorities from several page, not only 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 authotiries. Test plan: - Launch an authority search at the OPAC - Check some authorities - Go on another page - Check some authorities - Come back to the first page and check that already checked authorities is automatically checked. - Click on the "Browse selected authorities >>" link - Check that you are able to browse results you had checked. --- C4/Auth.pm | 4 ++ .../bootstrap/en/modules/opac-auth-detail.tt | 38 ++++++++++++++-- .../en/modules/opac-authoritiessearchresultlist.tt | 51 +++++++++++++++++++--- koha-tmpl/opac-tmpl/bootstrap/js/commons.js | 47 ++++++++++++++++++-- opac/opac-authorities-home.pl | 20 +++++++-- opac/opac-authoritiesdetail.pl | 19 +++++++- 6 files changed, 163 insertions(+), 16 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index ef0c585..1455aa0 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -447,6 +447,10 @@ sub get_template_and_user { my $sessionSearch = get_session( $sessionID || $in->{'query'}->cookie("CGISESSID") ); $sessionSearch->clear( ["busc"] ) if ( $sessionSearch->param("busc") ); } + unless ( $pagename =~ /^auth-detail$/ ) { + my $sessionSearch = get_session($sessionID || $in->{'query'}->cookie("CGISESSID")); + $sessionSearch->clear(["busc_auth"]) if ($sessionSearch->param("busc_auth")); + } } # variables passed from CGI: opac_css_override and opac_search_limits. diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt index 1032eee..3e0004d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt @@ -23,10 +23,17 @@ [% INCLUDE 'navigation.inc' %] -
- [% ELSE %] -
[% END %] + + [% content_width = 12 %] + [% IF (OpacNav || OpacNavBottom) %] + [% content_width = content_width - 2 %] + [% END %] + [% IF Koha.Preference('OpacBrowseResults') && (previous || next) %] + [% content_width = content_width - 3 %] + [% END %] + +
@@ -121,6 +128,31 @@
+ + [% IF Koha.Preference('OpacBrowseResults') && ( previous || next ) %] +
+ +
+ [% END %] +
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-authoritiessearchresultlist.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-authoritiessearchresultlist.tt index 4ebaac6..e443070 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-authoritiessearchresultlist.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-authoritiessearchresultlist.tt @@ -6,7 +6,7 @@ @@ -55,6 +55,7 @@ [% END %]

Authority search results

+ Browse selected records [% pagination %] @@ -75,6 +76,7 @@ + [% UNLESS ( isEDITORS ) %] @@ -86,7 +88,8 @@ [% FOREACH resul IN result %] - + + [% UNLESS ( resul.isEDITORS ) %]
Authorized headings Type of heading
[% PROCESS authresult summary=resul.summary %][% PROCESS authresult summary=resul.summary %] [% resul.authtype %] @@ -112,4 +115,42 @@ [% INCLUDE 'opac-bottom.inc' %] -[% BLOCK jsinclude %][% END %] +[% BLOCK jsinclude %] + + +[% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/commons.js b/koha-tmpl/opac-tmpl/bootstrap/js/commons.js index c9c724a..c561f9f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/commons.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/commons.js @@ -33,16 +33,32 @@ function addBibToContext( bibnum ) { setContextBiblioNumbers( $.uniqueArray( bibnums ) ); } +function addAuthToContext( authid ) { + var authids = getContextAuthIds(); + authids.push( authid ); + setContextAuthIds( authids ); +} + function delBibToContext( bibnum ) { var bibnums = getContextBiblioNumbers(); removeByValue( bibnums, bibnum ); setContextBiblioNumbers( $.uniqueArray( bibnums ) ); } +function delAuthToContext( authid ) { + var authids = getContextAuthIds(); + removeByValue( authids, authid ); + setContextAuthIds( $.uniqueArray( authids ) ); +} + function setContextBiblioNumbers( bibnums ) { $.cookie('bibs_selected', JSON.stringify( bibnums )); } +function setContextAuthIds( authids ) { + $.cookie('auths_selected', JSON.stringify( authids )); +} + function getContextBiblioNumbers() { var r = $.cookie('bibs_selected'); if ( r ) { @@ -52,21 +68,44 @@ function getContextBiblioNumbers() { return r; } -function resetSearchContext() { +function getContextAuthIds() { + var r = $.cookie('auths_selected'); + if ( r ) { + return JSON.parse(r); + } + r = new Array(); + return r; +} + +function resetBiblioSearchContext() { setContextBiblioNumbers( new Array() ); } +function resetAuthSearchContext() { + setContextAuthIds( new Array() ); +} + $(document).ready(function(){ // forms with action leading to search $("form[action*='opac-search.pl']").submit(function(){ - resetSearchContext(); + resetBiblioSearchContext(); }); // any link to launch a search except navigation links $("[href*='opac-search.pl?']").not(".nav").not('.searchwithcontext').click(function(){ - resetSearchContext(); + resetBiblioSearchContext(); }); // any link to a detail page from the results page. $("#bookbag_form a[href*='opac-detail.pl?']").click(function(){ - resetSearchContext(); + resetBiblioSearchContext(); + }); + + $("form[action*='opac-authorities-home.pl']").submit(function(){ + resetAuthSearchContext(); + }); + $("[href*='opac-authorities-home.pl?']").not(".nav").not('.searchwithcontext').click(function(){ + resetBiblioSearchContext(); + }); + $("#opac-authorities-home.pl a[href*='opac-authorities-home.pl?']").click(function(){ + resetAuthSearchContext(); }); }); diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl index 54c1444..1f1cbca 100755 --- a/opac/opac-authorities-home.pl +++ b/opac/opac-authorities-home.pl @@ -22,7 +22,7 @@ use strict; use warnings; use CGI qw ( -utf8 ); -use C4::Auth; +use C4::Auth qw( get_session ); use C4::Context; use C4::Auth; @@ -66,8 +66,8 @@ if ( $op eq "do_search" ) { my $orderby = $query->param('orderby'); my @value = ($query->param('value') || "",); - $resultsperpage = $query->param('resultsperpage'); - $resultsperpage = 20 if ( !defined $resultsperpage ); + $resultsperpage = $query->param('resultsperpage') // 20; + my @tags; my ( $results, $total, @fields ) = SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator, @@ -161,6 +161,20 @@ if ( $op eq "do_search" ) { } } + if ( C4::Context->preference("OpacBrowseResults") ) { + my $busc_params; + $busc_params .= 'op=do_search&authtypecode='.$authtypecode; + $busc_params .= '&marclist=' . $_ for @marclist; + $busc_params .= '&and_or=' . $_ for @and_or; + $busc_params .= '&excluding=' . $_ for @excluding; + $busc_params .= '&operator=' . $_ for @operator; + $busc_params .= '&orderby=' . $orderby; + $busc_params .= '&value=' . $_ for @value; + $busc_params .= '&resultsperpage=' . $resultsperpage; + my $session = get_session( $query->cookie("CGISESSID") ); + $session->param( busc_auth => $busc_params ); + } + $template->param( result => $results ) if $results; $template->param( FIELDS => \@fields ); $template->param( orderby => $orderby ); diff --git a/opac/opac-authoritiesdetail.pl b/opac/opac-authoritiesdetail.pl index 79c70db..d097558 100755 --- a/opac/opac-authoritiesdetail.pl +++ b/opac/opac-authoritiesdetail.pl @@ -40,13 +40,16 @@ use strict; use warnings; use C4::AuthoritiesMarc; -use C4::Auth; +use C4::Auth qw( :DEFAULT get_session ); use C4::Context; use C4::Output; use CGI qw ( -utf8 ); use MARC::Record; use C4::Koha; +use JSON; +use List::MoreUtils qw( first_index ); + my $query = new CGI; @@ -169,6 +172,20 @@ if ($show_marc) { } $template->param( "Tab0XX" => \@loop_data ); } else { + my $authids = $query->cookie('auths_selected'); + $authids = $authids ? JSON::from_json($authids) : []; + if ( scalar( @$authids ) ) { + my $idx = first_index { $_ == $authid } @$authids; + my $previous = $idx ? $authids->[$idx - 1] : undef; + my $next = ( $idx + 1 < @$authids ) ? $authids->[$idx + 1] : undef; + my $session = get_session($query->cookie("CGISESSID")); + + $template->param( + previous => $previous, + next => $next, + busc_auth => $session->param("busc_auth"), + ); + } my $summary = BuildSummary($record, $authid, $authtypecode); $template->{VARS}->{'summary'} = $summary; } -- 1.9.1