Bug 42611: Fix Javascript error when no Circulation history

This patch checks that "table" is defined before trying to access
the DataTable object for it.

This patch also moves the Javascript from the .tt file into a separate .js
file since it doesn't need any Template::Toolkit itself.

Test plan:
0. Apply the patch (and reset_all)
1. Log into the staff interface
2. Go to http://localhost:8081/cgi-bin/koha/members/readingrec.pl?borrowernumber=51
3. Open the console and see there is no longer a Javascript error
4. Check out an item like 39999000001310 to this user
5. Review the "Circulation history" and note that the DataTable appears
and there are no Javascript errors

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
David Cook 2026-05-15 02:34:14 +00:00 committed by Lucas Gass
parent 70820a2a3e
commit 97ea38692f
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 23 additions and 23 deletions

View File

@ -169,29 +169,7 @@
var table_settings = [% TablesSettings.GetTableSettings('members', 'checkouthistory', 'checkouthistory-table', 'json') | $raw %];
</script>
<script nonce="[% Koha.CSPNonce | $raw %]">
$(document).ready(function () {
var table = $("#table_readingrec").kohaTable(
{
pagingType: "full",
order: [[column_sort, "desc"]],
},
table_settings
);
let table_dt = table.DataTable();
$("#tabs a[data-bs-toggle='tab']").on("shown.bs.tab", function (e) {
active_tab = $(this).attr("href");
let pattern = "";
if (active_tab == "#tab_checkout_panel") {
pattern = "standard_checkout";
} else if (active_tab == "#tab_onsite_checkout_panel") {
pattern = "onsite_checkout";
}
table_dt.columns(0).search(pattern).draw();
});
});
</script>
[% Asset.js("js/members/readingrec.js") %]
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]

View File

@ -0,0 +1,22 @@
$(document).ready(function () {
let table = $("#table_readingrec").kohaTable(
{
pagingType: "full",
order: [[column_sort, "desc"]],
},
table_settings
);
if (table) {
let table_dt = table.DataTable();
$("#tabs a[data-bs-toggle='tab']").on("shown.bs.tab", function (e) {
active_tab = $(this).attr("href");
let pattern = "";
if (active_tab == "#tab_checkout_panel") {
pattern = "standard_checkout";
} else if (active_tab == "#tab_onsite_checkout_panel") {
pattern = "onsite_checkout";
}
table_dt.columns(0).search(pattern).draw();
});
}
});