From 769f934e01f71e60461e49784b2d5825cc267556 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 ++ koha-tmpl/opac-tmpl/prog/en/js/commons.js | 47 ++++++++++++++++-- .../opac-tmpl/prog/en/modules/opac-auth-detail.tt | 32 +++++++++++- .../en/modules/opac-authoritiessearchresultlist.tt | 52 +++++++++++++++++--- opac/opac-authorities-home.pl | 22 +++++++-- opac/opac-authoritiesdetail.pl | 19 ++++++- 6 files changed, 161 insertions(+), 15 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 8b0bebe..d1f1ae2 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -380,6 +380,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. my $opac_search_limit = $ENV{'OPAC_SEARCH_LIMIT'}; diff --git a/koha-tmpl/opac-tmpl/prog/en/js/commons.js b/koha-tmpl/opac-tmpl/prog/en/js/commons.js index 490bfdf..3dbd6d0 100644 --- a/koha-tmpl/opac-tmpl/prog/en/js/commons.js +++ b/koha-tmpl/opac-tmpl/prog/en/js/commons.js @@ -30,17 +30,33 @@ function addBibToContext( bibnum ) { //var store = sessionStorage.getItem( "bibs_selected" ); } +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 ) { //sessionStorage.setItem("bibs_selected", JSON.stringify( bibnums ) ); $.cookie('bibs_selected', JSON.stringify( bibnums )); } +function setContextAuthIds( authids ) { + $.cookie('auths_selected', JSON.stringify( authids )); +} + function getContextBiblioNumbers() { //var r = sessionStorage.getItem("bibs_selected"); var r = $.cookie('bibs_selected'); @@ -51,22 +67,45 @@ 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/koha-tmpl/opac-tmpl/prog/en/modules/opac-auth-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-auth-detail.tt index 78bc5b9..6714b0d 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-auth-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-auth-detail.tt @@ -31,8 +31,10 @@ $(document).ready(function() {
[% INCLUDE 'masthead.inc' %]
-
+
+
+
Normal view MARC view
@@ -105,6 +107,34 @@ $(document).ready(function() {
+[% IF Koha.Preference('OpacBrowseResults') && ( previous || next ) %] +
+
+ +
+
+[% END %] + +
+
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-authoritiessearchresultlist.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-authoritiessearchresultlist.tt index 71ad40e..5936ace 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-authoritiessearchresultlist.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-authoritiessearchresultlist.tt @@ -3,6 +3,43 @@ [% PROCESS 'authorities-search-results.inc' %] [% INCLUDE 'doc-head-open.inc' %][% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › [% IF ( total ) %]Authority search result[% ELSE %]No results found[% END %] [% INCLUDE 'doc-head-close.inc' %] + + [% IF ( OpacNav ) %]
[% ELSE %]
[% END %] @@ -13,9 +50,10 @@

Authority search results

+ Browse selected records
[% IF ( displayprev ) %] - + << [% END %] @@ -23,11 +61,11 @@ [% IF ( number.highlight ) %] [% number.number %] [% ELSE %] - [% number.number %] + [% number.number %] [% END %] [% END %] [% IF ( displaynext ) %] - >> + >> [% END %]
@@ -46,6 +84,7 @@
+ [% UNLESS ( isEDITORS ) %] @@ -59,6 +98,7 @@ [% ELSE %] [% END %] + [% UNLESS ( resul.isEDITORS ) %] @@ -75,15 +115,15 @@
[% IF ( displayprev ) %] - << + << [% END %] [% FOREACH number IN numbers %] [% IF ( number.highlight ) %][% number.number %][% ELSE %] - [% number.number %] + [% number.number %] [% END %] [% END %] [% IF ( displaynext ) %] - >> + >> [% END %]
[% END %] diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl index 115012e..daff9b0 100755 --- a/opac/opac-authorities-home.pl +++ b/opac/opac-authorities-home.pl @@ -22,7 +22,8 @@ use strict; use warnings; use CGI; -use C4::Auth; +use C4::Auth qw( get_session ); + use C4::Context; use C4::Auth; @@ -65,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, @@ -129,6 +130,21 @@ if ( $op eq "do_search" ) { my @usedauths = grep { $_->{used} > 0 } @$results; $results = \@usedauths; } + + 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 3e17cf1..7c0e189 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; 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.7.10.4
Authorized headings Type of heading
[% PROCESS authresult summary=resul.summary link="/cgi-bin/koha/opac-authorities-home.pl?op=do_search&type=opac&operatorc=contains&marclistc=mainentry&and_orc=and&orderby=HeadingAsc&valuec=" %] [% resul.authtype %]