From c266b19b823c0bf7bf1759e6a13d2db9e07db088 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 30 Jul 2025 10:12:27 +0200 Subject: [PATCH] Bug 40544: Move some bundles related code out of document.ready On bug 40127 we moved the build_items_table calls outside of document ready, but createChild is defined in document.ready (and so defined too late). This patches fix the following JS error: "Uncaught ReferenceError: createChild is not defined" Signed-off-by: David Nind Signed-off-by: Caroline Cyr La Rose --- .../prog/en/modules/catalogue/detail.tt | 542 +++++++++--------- 1 file changed, 271 insertions(+), 271 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 0fc818512a5..6c195eb3c20 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1768,317 +1768,317 @@ [% END # /IF bundlesEnabled %] }); - $(document).ready(function() { - [% IF bundlesEnabled %] // Bundle handling - function createChild ( row, itemnumber, duedate ) { - // Toolbar - var bundle_toolbar = $('
'); - bundle_toolbar.append(' ' + _("Add to bundle") + ''); - bundle_toolbar.append(' ' + _("Remove from bundle") + ''); - + [% IF bundlesEnabled %] // Bundle handling + function createChild ( row, itemnumber, duedate ) { // Toolbar var bundle_toolbar = $('
'); bundle_toolbar.append(' ' + _("Add to bundle") + ''); bundle_toolbar.append(' ' + _("Remove from bundle") + ''); - // This is the table we'll convert into a DataTable - var bundles_table = $(''); + // Toolbar + var bundle_toolbar = $('
'); + bundle_toolbar.append(' ' + _("Add to bundle") + ''); + bundle_toolbar.append(' ' + _("Remove from bundle") + ''); - // Display it the child row - row.child( bundle_toolbar.add(bundles_table), 'bundle' ).show(); + // This is the table we'll convert into a DataTable + var bundles_table = $('
'); - // Initialise as a DataTable - var bundle_table_url = "/api/v1/items/" + itemnumber + "/bundled_items?"; - var bundle_table = bundles_table.kohaTable({ - "ajax": { - "url": bundle_table_url + // Display it the child row + row.child( bundle_toolbar.add(bundles_table), 'bundle' ).show(); + + // Initialise as a DataTable + var bundle_table_url = "/api/v1/items/" + itemnumber + "/bundled_items?"; + var bundle_table = bundles_table.kohaTable({ + "ajax": { + "url": bundle_table_url + }, + "embed": [ + "biblio", + "return_claim.patron" + ], + "order": [[ 1, "asc" ]], + "columnDefs": [ { + "targets": [0,1,2,3], + "render": function (data, type, row, meta) { + if ( data && type == 'display' ) { + return data.escapeHtml(); + } + return data; + } + } ], + "columns": [ + { + "data": "biblio.title:biblio.subtitle:biblio.medium", + "title": _("Title"), + "searchable": true, + "orderable": true, + "render": function(data, type, row, meta) { + return $biblio_to_html(row.biblio, { link: 1 }); + } }, - "embed": [ - "biblio", - "return_claim.patron" - ], - "order": [[ 1, "asc" ]], - "columnDefs": [ { - "targets": [0,1,2,3], - "render": function (data, type, row, meta) { - if ( data && type == 'display' ) { - return data.escapeHtml(); + { + "data": "biblio.author", + "title": _("Author"), + "searchable": true, + "orderable": true, + }, + { + "data": "copy_number", + "title": _("Copy number"), + "searchable": true, + "orderable": true, + }, + { + "data": "callnumber", + "title": _("Callnumber"), + "searchable": true, + "orderable": true, + }, + { + "data": "external_id", + "title": _("Barcode"), + "searchable": true, + "orderable": true, + }, + { + "data": "lost_status:last_seen_date:return_claim.patron", + "title": _("Status"), + "searchable": false, + "orderable": false, + "render": function(data, type, row, meta) { + if ( row.lost_status == bundle_lost_value ) { + let out = '' + _("Last seen") + ': ' + $date(row.last_seen_date) + ''; + if ( row.return_claim ) { + out = out + '' + _("Claims returned by") + ': ' + $patron_to_html( row.return_claim.patron, { display_cardnumber: false, url: true } ) + ''; + } + return out; } - return data; - } - } ], - "columns": [ - { - "data": "biblio.title:biblio.subtitle:biblio.medium", - "title": _("Title"), - "searchable": true, - "orderable": true, - "render": function(data, type, row, meta) { - return $biblio_to_html(row.biblio, { link: 1 }); + else if ( row.lost_status !== 0 ) { + return '' + _("Lost") + ': ' + row.lost_status + ''; } - }, - { - "data": "biblio.author", - "title": _("Author"), - "searchable": true, - "orderable": true, - }, - { - "data": "copy_number", - "title": _("Copy number"), - "searchable": true, - "orderable": true, - }, - { - "data": "callnumber", - "title": _("Callnumber"), - "searchable": true, - "orderable": true, - }, - { - "data": "external_id", - "title": _("Barcode"), - "searchable": true, - "orderable": true, - }, - { - "data": "lost_status:last_seen_date:return_claim.patron", - "title": _("Status"), - "searchable": false, - "orderable": false, - "render": function(data, type, row, meta) { - if ( row.lost_status == bundle_lost_value ) { - let out = '' + _("Last seen") + ': ' + $date(row.last_seen_date) + ''; - if ( row.return_claim ) { - out = out + '' + _("Claims returned by") + ': ' + $patron_to_html( row.return_claim.patron, { display_cardnumber: false, url: true } ) + ''; - } - return out; - } - else if ( row.lost_status !== 0 ) { - return '' + _("Lost") + ': ' + row.lost_status + ''; - } - return '' + _("Present") + ''; + return '' + _("Present") + ''; + } + }, + { + "data": function( row, type, val, meta ) { + var result; + if (duedate) { + result = '\n'.format(_("This bundle is checked out, it cannot be modified"), _("Remove")); + } else { + result = '\n'; } + return result; }, - { - "data": function( row, type, val, meta ) { - var result; - if (duedate) { - result = '\n'.format(_("This bundle is checked out, it cannot be modified"), _("Remove")); - } else { - result = '\n'; - } - return result; - }, - "title": _("Actions"), - "searchable": false, - "orderable": false, - "class": "no-export" - } - ] - }, bundle_settings, 1); - $(".tbundle").on("click", ".remove:not(.disabled)", function(){ - var bundle_table = $(this).closest('table'); - var host_itemnumber = bundle_table.data('itemnumber'); - var component_itemnumber = $(this).data('itemnumber'); - var unlink_item_url = "/api/v1/items/" + host_itemnumber + "/bundled_items/" + component_itemnumber; - $.ajax({ - type: "DELETE", - url: unlink_item_url, - success: function(){ - bundle_table.DataTable({ 'retrieve': true }).draw(false); - } - }); + "title": _("Actions"), + "searchable": false, + "orderable": false, + "class": "no-export" + } + ] + }, bundle_settings, 1); + $(".tbundle").on("click", ".remove:not(.disabled)", function(){ + var bundle_table = $(this).closest('table'); + var host_itemnumber = bundle_table.data('itemnumber'); + var component_itemnumber = $(this).data('itemnumber'); + var unlink_item_url = "/api/v1/items/" + host_itemnumber + "/bundled_items/" + component_itemnumber; + $.ajax({ + type: "DELETE", + url: unlink_item_url, + success: function(){ + bundle_table.DataTable({ 'retrieve': true }).draw(false); + } }); + }); - return; - } + return; + } - var bundle_changed; - var bundle_form_active; - $("#addToBundleModal").on("shown.bs.modal", function(e){ - var button = $(e.relatedTarget); - var item_id = button.data('item'); - $("#addResult").replaceWith('
'); - $("#addToBundleForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items'); - $("#external_id").focus(); - bundle_changed = 0; - bundle_form_active = item_id; - }); + var bundle_changed; + var bundle_form_active; + $("#addToBundleModal").on("shown.bs.modal", function(e){ + var button = $(e.relatedTarget); + var item_id = button.data('item'); + $("#addResult").replaceWith('
'); + $("#addToBundleForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items'); + $("#external_id").focus(); + bundle_changed = 0; + bundle_form_active = item_id; + }); - function addToBundle (url, data) { - /* Send the data using post with external_id */ - var posting = $.post({ - url: url, - data: JSON.stringify(data), - contentType: "application/json; charset=utf-8", - dataType: "json" - }); + function addToBundle (url, data) { + /* Send the data using post with external_id */ + var posting = $.post({ + url: url, + data: JSON.stringify(data), + contentType: "application/json; charset=utf-8", + dataType: "json" + }); - const barcode = data.external_id; - const marc_link = data.marc_link; + const barcode = data.external_id; + const marc_link = data.marc_link; - /* Report the results */ - posting.done(function(data) { - $('#addResult').replaceWith('
'+_("Success: Added '%s'").format(barcode)+'
'); - $('#external_id').val('').focus(); - bundle_changed = 1; - }); - posting.fail(function(data) { - if ( data.status === 409 ) { - var response = data.responseJSON; - if ( response.error_code === 'already_bundled' ) { - $('#addResult').replaceWith('
'+_("Warning: Item '%s' already attached").format(barcode)+'
'); - } else if (response.error_code === 'bundle_checkout_out') { - $('#addResult').replaceWith('
'+_("Failure: Bundle is currently checked out")+'
'); - } else if (response.error_code === 'checked_out') { - const button = $('