From 07d2a419f36711b5dc9b26a081eafa6a96cfdce9 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 7 Jan 2020 13:03:18 +0000 Subject: [PATCH] Bug 13121: Move search results "action" links ("Place hold," "Add tag," etc) into include file This patch moves markup for controls repeated across several OPAC templates into a single include: Place hold, Request article, Add tag, Save to lists, and Add to cart. To test, apply the patch and view the following OPAC pages: - Search results - Shelf contents view - User tags list On each of these pages all the controls should work correctly: - Place hold - Request art - Add tag - Save to lists - Add to cart Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- .../en/includes/title-actions-menu.inc | 61 +++++++++++++++++++ .../bootstrap/en/modules/opac-results.tt | 44 +------------ .../bootstrap/en/modules/opac-shelves.tt | 50 +-------------- .../bootstrap/en/modules/opac-tags.tt | 2 + opac/opac-shelves.pl | 13 ++++ opac/opac-tags.pl | 20 ++++++ 6 files changed, 98 insertions(+), 92 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/title-actions-menu.inc diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/title-actions-menu.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/title-actions-menu.inc new file mode 100644 index 0000000000..0de923f1b7 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/title-actions-menu.inc @@ -0,0 +1,61 @@ +
+ [% IF Koha.Preference( 'RequestOnOpac' ) == 1 %] + [% UNLESS ( items.norequests ) %] + [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] + [% IF ( shelf AND op == 'view' ) # Lists view has more granular checking of hold availability %] + [% IF ( items.allow_onshelf_holds ) %] + Place hold + [% ELSE %] + [% IF ( items.itemsissued ) %] + Place hold + [% END %] + [% END %] + [% ELSE %] + Place hold + [% END %] + [% END # / IF opacuserlogin %] + [% END # / UNLESS items.norequests %] + [% END # / RequestOnOpac %] + + [% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) %] + [% IF items.artreqpossible %] + Request article + [% END %] + [% END %] + + [% IF ( TagsInputEnabled ) %] + [% IF ( loggedinusername ) %] + Add tag + + + [% ELSE %] + Log in to add tags + [% END # IF loggedinusername %] + [% END # if TagsInputEnabled %] + + [% IF ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && loggedinusername && ( Koha.Preference( 'virtualshelves' ) == 1 ) ) %] + [% IF ( shelf AND op == 'view' ) %] + Save to another list + [% IF can_remove_biblios %] + Remove from this list + [% END %] + [% ELSE %] + Save to lists + [% END # /IF ( shelf AND op == 'view' ) %] + [% END # /IF Koha.Preference( 'opacuserlogin' ) %] + + [% IF Koha.Preference( 'opacbookbag' ) == 1 %] + [% IF ( items.incart ) %] + In your cart (remove) + [% ELSE %] + Add to cart + [% END %] + [% END # / IF opacbookbag %] +
\ No newline at end of file diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt index 2ad3ee9d68..52371ee7fe 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -536,50 +536,8 @@ [% END # / IF OpacStarRatings %] -
- [% IF Koha.Preference( 'RequestOnOpac' ) == 1 %] - [% UNLESS ( SEARCH_RESULT.norequests ) %] - [% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) %] - Place hold - [% END # / IF opacuserlogin && holdable %] - [% END # UNLESS SEARCH_RESULT.norequests %] - [% END # IF RequestOnOpac %] - - [% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) %] - [% IF SEARCH_RESULT.artreqpossible %] - Request article - [% END %] - [% END %] - - [% IF ( TagsInputEnabled ) %] - [% IF ( loggedinusername ) %] - Add tag - - - [% ELSE %] - Log in to add tags - [% END # IF loggedinusername %] - [% END # if TagsInputEnabled %] - - [% IF ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && loggedinusername && ( Koha.Preference( 'virtualshelves' ) == 1 ) ) %] - Save to lists - [% END %] + [% INCLUDE 'title-actions-menu.inc' items=SEARCH_RESULT %] - [% IF Koha.Preference( 'opacbookbag' ) == 1 %] - [% IF ( SEARCH_RESULT.incart ) %] - In your cart (remove) - [% ELSE %] - Add to cart - [% END %] - [% END # / IF opacbookbag %] -
[% INCLUDE "openlibrary-readapi.inc" bib = SEARCH_RESULT %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index ec0ffcd483..cc1cfa6d17 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -463,55 +463,7 @@ [% END %] - - - [% IF Koha.Preference( 'RequestOnOpac' ) == 1 %] - [% UNLESS ( itemsloo.norequests ) %] - [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] - [% IF ( itemsloo.allow_onshelf_holds ) %] - Place hold - [% ELSE %] - [% IF ( itemsloo.itemsissued ) %] - Place hold - [% END %] - [% END %] - [% END # / IF opacuserlogin %] - [% END # / UNLESS itemsloo.norequests %] - [% END # / RequestOnOpac %] - - [% IF ( TagsInputEnabled ) %] - [% IF ( loggedinusername ) %] - - - - [% ELSIF ( loop.first ) %] - Log in to add tags. - [% END # / IF loggedinusername %] - [% END # / IF TagsInputEnabled %] - - [% IF ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && loggedinusername && ( Koha.Preference( 'virtualshelves' ) == 1 ) ) %] - Save to another list - [% END %] - - [% IF can_remove_biblios %] - Remove from this list - [% END %] - - [% IF Koha.Preference( 'opacbookbag' ) == 1 %] - [% IF ( itemsloo.incart ) %] - - [% ELSE %] - - [% END %] - [% END # / IF opacbookbag %] - + [% INCLUDE 'title-actions-menu.inc' items=itemsloo %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt index d5938ecfde..5b319cefef 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt @@ -155,6 +155,8 @@ by [% MY_TAG.author | html %] [% END %] [% END # /IF MY_TAG.XSLTBloc %] + + [% INCLUDE 'title-actions-menu.inc' items=MY_TAG %] diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index f671f1f3f1..06875d2dfe 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -267,12 +267,23 @@ if ( $op eq 'view' ) { my $patron = Koha::Patrons->find( $loggedinuser ); + my $categorycode; # needed for may_article_request + if( C4::Context->preference('ArticleRequests') ) { + $categorycode = $patron ? $patron->categorycode : undef; + } + # Lists display falls back to search results configuration my $xslfile = C4::Context->preference('OPACXSLTListsDisplay'); my $lang = $xslfile ? C4::Languages::getlanguage() : undef; my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); + + my $art_req_itypes; + if( C4::Context->preference('ArticleRequests') ) { + $art_req_itypes = Koha::IssuingRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () }); + } + my @items; while ( my $content = $contents->next ) { my $biblionumber = $content->biblionumber; @@ -304,6 +315,8 @@ if ( $op eq 'view' ) { $this_item->{'normalized_ean'} = GetNormalizedEAN( $record, $marcflavour ); $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour ); $this_item->{'normalized_isbn'} = GetNormalizedISBN( undef, $record, $marcflavour ); + # BZ17530: 'Intelligent' guess if result can be article requested + $this_item->{artreqpossible} = ( $art_req_itypes->{ $this_item->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{}; unless ( defined $this_item->{size} ) { diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl index bc5ac8a9e3..44a38355c1 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -236,6 +236,20 @@ if ($loggedinuser) { $should_hide = ( $should_hide =~ /\S/ ) ? 1 : 0; $my_tags = get_tag_rows({borrowernumber=>$loggedinuser}); my $my_approved_tags = get_approval_rows({ approved => 1 }); + + my $art_req_itypes; + if( C4::Context->preference('ArticleRequests') ) { + $art_req_itypes = Koha::IssuingRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () }); + } + + # get biblionumbers stored in the cart + my @cart_list; + + if($query->cookie("bib_list")){ + my $cart_list = $query->cookie("bib_list"); + @cart_list = split(/\//, $cart_list); + } + foreach my $tag (@$my_tags) { $tag->{visible} = 0; my $biblio = Koha::Biblios->find( $tag->{biblionumber} ); @@ -262,6 +276,8 @@ if ($loggedinuser) { $tag->{part_number} = $biblio->part_number; $tag->{part_name} = $biblio->part_name; $tag->{author} = $biblio->author; + # BZ17530: 'Intelligent' guess if result can be article requested + $tag->{artreqpossible} = ( $art_req_itypes->{ $tag->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{}; my $xslfile = C4::Context->preference('OPACXSLTResultsDisplay'); my $lang = $xslfile ? C4::Languages::getlanguage() : undef; @@ -279,6 +295,10 @@ if ($loggedinuser) { $tag->{time_created_display} = $1; $tag->{approved} = ( grep { $_->{term} eq $tag->{term} and $_->{approved} } @$my_approved_tags ); $tag->{visible} = 1; + # while we're checking each line, see if item is in the cart + if ( grep {$_ eq $biblio->biblionumber} @cart_list) { + $tag->{incart} = 1; + } } } -- 2.39.5