From 27a4dd8daaa79c2e42baf44d41604b6c166a7bc9 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 4 Aug 2026 09:04:52 +0100 Subject: [PATCH] Bug 42915: (QA follow-up) Defer coded_values declaration until document ready holds.js declared `coded_values` as a bare top-level global, evaluated immediately at script-parse time, reading `all_libraries` which is only ever defined by the including template (request.tt, or patron-detail-tabs.inc for circulation.tt/moremember.tt). This works today only because those templates happen to emit their `all_libraries` script block before Asset.js("js/holds.js") in the rendered HTML - a fragile, easy-to-break ordering dependency between separate template files, not something holds.js itself can guarantee. Move the assignment into the existing $(document).ready() handler, setting it explicitly on `window` so it remains visible as a global to datatables.js's build_query(), which reads `coded_values` unqualified. This defers evaluation until all synchronous inline scripts (including whichever template defined all_libraries) have already run, regardless of future include/ordering changes. To test: 1. Place holds on a title for two different pickup libraries 2. Confirm the holds table on reserve/request.tt, the patron's Holds tab (circulation.pl and moremember.pl) all load with no console errors 3. Confirm filtering the holds table by pickup library name/branchcode still works on all three pages Signed-off-by: Lucas Gass --- koha-tmpl/intranet-tmpl/prog/js/holds.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js index 3d701c0a50..1aad92a65c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/holds.js +++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js @@ -105,12 +105,12 @@ function display_pickup_location(state) { }; })(jQuery); -var coded_values = { - library: new Map(all_libraries.map(l => [l.branchname, l.branchcode])), -}; - /* global __ borrowernumber SuspendHoldsIntranet */ $(document).ready(function () { + window.coded_values = { + library: new Map(all_libraries.map(l => [l.branchname, l.branchcode])), + }; + let patron_page = holds_table_patron_page(); function suspend_hold(hold_ids, end_date) { var params = { hold_ids: hold_ids };