From 71b121bb6f42dd3f7fa66c2e9525e518f7c26287 Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Fri, 17 Apr 2026 16:00:22 +0200 Subject: [PATCH] Bug 42292: (follow-up) Fix OverDrive/OpenLibrary references in opac-results.tt Three issues introduced by the OPAC port of opac-results.tt: - The tt-allowed block sets OverDriveEnabled via `Koha.Preference("OverDriveEnabled")`, but OverDriveEnabled is a TT-side SET variable (computed from OverDriveLibraryID + OverDriveClientKey + OverDriveClientSecret), not a system preference, so Koha.prefs.OverDriveEnabled is always "". The code at line 621 then reads an unprefixed `OverDriveEnabled` identifier which is not declared -- the OverDrive result block never fires. - The neighbouring block `if (OpenLibrarySearch) { ... }` reads an unprefixed identifier for a value that is only exposed on Koha.prefs, so the OpenLibrary result block also never fires. - Both blocks build a throbber with `src=\`${interface}/${theme}/images/spinner-small.gif\`` inside a single-quoted JS string; the backticks are literal characters there, so the rendered src ends up as that literal template text, not a usable URL. Replace the OverDriveEnabled addPrefs entry with a plain `const OverDriveEnabled = [% OverDriveEnabled ? 1 : 0 | html %];` that reads the TT SET variable, prefix OpenLibrarySearch with Koha.prefs, and rebuild the throbber src via normal string concatenation. To test: - With OverDrive configured (OPACOverDrive, OverDriveLibraryID, OverDriveClientKey, OverDriveClientSecret), run a search in the OPAC: the OverDrive results panel shows the spinner and then the API results. - With OpenLibrarySearch enabled, the OpenLibrary panel does the same. - In both cases the spinner image loads (no broken-image icon). - Disable both prefs -> neither panel is rendered, no console errors. Signed-off-by: Paul Derscheid Signed-off-by: Jan Kissig Signed-off-by: Pedro Amorim --- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 2247963fae..91424f167d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -496,10 +496,10 @@ OpacCoce: [% Koha.Preference('OpacCoce') ? 1 : 0 | html %], CoceHost: "[% Koha.Preference('CoceHost') | html %]", CoceProviders: "[% Koha.Preference('CoceProviders') | html %]", - OverDriveEnabled: [% Koha.Preference("OverDriveEnabled") ? 1 : 0 | html %], OverDriveLibraryID: "[% Koha.Preference("OverDriveLibraryID") | html %]", OpenLibrarySearch: [% Koha.Preference("OpenLibrarySearch") ? 1 : 0 | html %], }); + const OverDriveEnabled = [% OverDriveEnabled ? 1 : 0 | html %]; const DidYouMean = [% DidYouMean ? 1 : 0 | html %]; // query_desc and querystring are set in opac-bottom.inc let query_desc_uri = "[% query_desc | uri %]"; @@ -619,7 +619,7 @@ }); } if (OverDriveEnabled && firstPage) { - var $overdrive_results = $('
' + _("Searching %s...").format("OverDrive") + '
'); + var $overdrive_results = $('
' + _("Searching %s...").format("OverDrive") + '
'); $("#numresults").after($overdrive_results); //Clean querystring, first we remove CCL entities, then decode HTML entities, then swap double quotes for single quotes //as the overdrive API treats double quotes as a search term and returns extra results @@ -641,8 +641,8 @@ } }); } - if (OpenLibrarySearch) { - var $openlibrary_results = $('
' + _("Searching %s...").format("OpenLibrary") + '
'); + if (Koha.prefs.OpenLibrarySearch) { + var $openlibrary_results = $('
' + _("Searching %s...").format("OpenLibrary") + '
'); $("#numresults").after($openlibrary_results); KOHA.OpenLibrary.search(querystring, null, function (data) { if (data.error) {