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 <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2026-08-04 09:04:52 +01:00 committed by Lucas Gass
parent da5a337632
commit 27a4dd8daa
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 4 additions and 4 deletions

View File

@ -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 };