From d8a4c4b777d270cada1bd42cf7e846657ea939b3 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 3 Aug 2022 12:13:20 +0000 Subject: [PATCH] Bug 29144: Show html opac_info on opac-detail page Note: This patch disables the API call (which is not really needed), and still needs attention in a following patch. Test plan: Add opac_info for two libraries and a branchurl for one of the two. Select a biblio with an item having these two libraries as either home or holding branch. Toggle OpacLocationBranchToDisplay and check items table on opac detail. Click on the library name. Signed-off-by: Marcel de Rooy Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize --- .../bootstrap/en/modules/opac-detail.tt | 89 +++++++++++-------- opac/opac-detail.pl | 13 ++- 2 files changed, 66 insertions(+), 36 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 9eea246bad..90f10d0488 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -1246,16 +1246,19 @@ - [% IF ( ITEM_RESULT.holding_branch.opac_info ) %] - - [% ITEM_RESULT.holding_branch.branchname | html %] + [%# Show opac_info or branchurl from holding library %] + [% SET holding_library_name = ITEM_RESULT.branchname %] + [% SET holding_library_url = Branches.GetURL( ITEM_RESULT.holdingbranch ) %] + [% IF ( ITEM_RESULT.holding_library_info ) %] + + [% holding_library_name | html %] - [% ELSIF ( ITEM_RESULT.holding_branch.branchurl ) %] - - [% ITEM_RESULT.holding_branch.branchname | html %] + [% ELSIF holding_library_url %] + + [% holding_library_name | html %] [% ELSE %] - [% ITEM_RESULT.holding_branch.branchname | html %] + [% holding_library_name | html %] [% END %] [% IF ( Koha.Preference('OpacLocationOnDetail') == 'holding' || Koha.Preference('OpacLocationOnDetail') == 'both' ) %] @@ -1270,16 +1273,19 @@ - [% IF ( ITEM_RESULT.holding_branch.opac_info ) %] [%# FIXME Shouldn't this be home_branch instead of holding_branch? %] - - [% ITEM_RESULT.home_branch.branchname | html %] + [%# Show opac_info or branchurl from home library %] + [% SET home_library_name = Branches.GetName( ITEM_RESULT.homebranch ) %] + [% SET home_library_url = Branches.GetURL( ITEM_RESULT.homebranch ) %] + [% IF ( ITEM_RESULT.home_library_info ) %] + + [% home_library_name | html %] - [% ELSIF ( ITEM_RESULT.home_branch.branchurl ) %] - - [% ITEM_RESULT.home_branch.branchname | html %] + [% ELSIF home_library_url %] + + [% home_library_name | html %] [% ELSE %] - [% ITEM_RESULT.home_branch.branchname | html %] + [% home_library_name | html %] [% END %] [% IF ( Koha.Preference('OpacLocationOnDetail') == 'home' || Koha.Preference('OpacLocationOnDetail') == 'both' ) %] @@ -1997,29 +2003,42 @@ $(".library_info").on("click", function(e){ e.preventDefault(); - var branchcode = $(this).data("branchcode"); + var library_name = $(this).data("name"); + var opac_info = $(this).data("info"); var url = $(this).attr("href"); - $.ajax({ - url: "/api/v1/public/libraries/" + branchcode, - type: 'GET', - dataType: 'json', - success: function(result) { - $("#libraryInfoModalLabel").html( result.name ); - $("#libraryInfo").html( result.opac_info ); - if( result.url ){ - $("#libraryInfoLink").attr("href", result.url ); - $("#libraryInfoLink").show(); - } else { - $("#libraryInfoLink").hide(); - } - $("#libraryInfoModal").modal("show"); - }, - error: function(xhr, status, error) { - if( url ){ - location.href = url; - } + if( 1 ) { + $("#libraryInfoModalLabel").html( library_name ); + $("#libraryInfo").html( opac_info ); + if( url ){ + $("#libraryInfoLink").attr("href", url ); + $("#libraryInfoLink").show(); + } else { + $("#libraryInfoLink").hide(); } - }); + $("#libraryInfoModal").modal("show"); + } else { // FIXME Temporary disabled: see BZ 29144 + $.ajax({ + url: "/api/v1/public/libraries/" + branchcode, + type: 'GET', + dataType: 'json', + success: function(result) { + $("#libraryInfoModalLabel").html( result.name ); + $("#libraryInfo").html( opac_info ); + if( result.url ){ + $("#libraryInfoLink").attr("href", result.url ); + $("#libraryInfoLink").show(); + } else { + $("#libraryInfoLink").hide(); + } + $("#libraryInfoModal").modal("show"); + }, + error: function(xhr, status, error) { + if( url ){ + location.href = url; + } + } + }); + } }); $("#libraryInfoModal").on("hide.bs.modal", function(){ $("#libraryInfoModalLabel, #libraryInfo").html(""); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 1c5e7949ab..7f972c5a93 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -627,11 +627,12 @@ if ( $showcomp eq 'both' || $showcomp eq 'opac' ) { # XSLT processing of some stuff my $variables = {}; +my $lang = C4::Languages::getlanguage(); my @plugin_responses = Koha::Plugins->call( 'opac_detail_xslt_variables', { biblio_id => $biblionumber, - lang => C4::Languages::getlanguage(), + lang => $lang, patron_id => $borrowernumber, }, ); @@ -680,11 +681,21 @@ if ( not $viewallitems and $items->count > $max_items_to_display ) { ); } else { + my $library_info; while ( my $item = $items->next ) { my $item_info = $item->unblessed; $item_info->{holds_count} = $item_reserves{ $item->itemnumber }; $item_info->{priority} = $priority{ $item->itemnumber }; + # Get opac_info from Additional contents for home and holding library + my ( $opac_info_home, $opac_info_holding ); + $opac_info_holding = $library_info->{ $item->holdingbranch } // $item->holding_branch->opac_info({ lang => $lang }); + $library_info->{ $item->holdingbranch } = $opac_info_holding; + $opac_info_home = $library_info->{ $item->homebranch } // $item->home_branch->opac_info({ lang => $lang }); + $library_info->{ $item->homebranch } = $opac_info_home; + $item_info->{holding_library_info} = $opac_info_holding->content if $opac_info_holding; + $item_info->{home_library_info} = $opac_info_home->content if $opac_info_home; + $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } ) unless $allow_onshelf_holds; -- 2.20.1