From b975764ce7241c99207e677a3962b2d34e7e9697 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 Content-Type: text/plain; charset=utf-8 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 --- .../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 7c30dafda9..9968a558ee 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -1226,16 +1226,19 @@ - [% IF ( ITEM_RESULT.holding_branch_opac_info ) %] - - [% ITEM_RESULT.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.branchurl ) %] - - [% ITEM_RESULT.branchname | html %] + [% ELSIF holding_library_url %] + + [% holding_library_name | html %] [% ELSE %] - [% ITEM_RESULT.branchname | html %] + [% holding_library_name | html %] [% END %] [% IF ( Koha.Preference('OpacLocationOnDetail') == 'holding' || Koha.Preference('OpacLocationOnDetail') == 'both' ) %] @@ -1250,16 +1253,19 @@ - [% IF ( ITEM_RESULT.holding_branch_opac_info ) %] - - [% Branches.GetName( ITEM_RESULT.homebranch ) | 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 ( Branches.GetURL( ITEM_RESULT.homebranch ) ) %] - - [% Branches.GetName( ITEM_RESULT.homebranch ) | html %] + [% ELSIF home_library_url %] + + [% home_library_name | html %] [% ELSE %] - [% Branches.GetName( ITEM_RESULT.homebranch ) | html %] + [% home_library_name | html %] [% END %] [% IF ( Koha.Preference('OpacLocationOnDetail') == 'home' || Koha.Preference('OpacLocationOnDetail') == 'both' ) %] @@ -1971,29 +1977,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 1d1cdadc07..0360aa478c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -657,11 +657,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, }, ); @@ -709,11 +710,21 @@ if ( not $viewallitems and @items > $max_items_to_display ) { items_count => scalar( @items ), ); } else { + my $library_info; for my $itm (@items) { my $item = Koha::Items->find( $itm->{itemnumber} ); $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} }; $itm->{priority} = $priority{ $itm->{itemnumber} }; + # Get opac_info from Additional contents for home and holding library + my ( $opac_info_home, $opac_info_holding ); + $opac_info_holding = $library_info->{ $itm->{holdingbranch} } // $item->holding_branch->opac_info({ lang => $lang }); + $library_info->{ $itm->{holdingbranch} } = $opac_info_holding; + $opac_info_home = $library_info->{ $itm->{homebranch} } // $item->home_branch->opac_info({ lang => $lang }); + $library_info->{ $itm->{homebranch} } = $opac_info_home; + $itm->{holding_library_info} = $opac_info_holding->content if $opac_info_holding; + $itm->{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