From 765e83029d7921f0af769084f1b24d163f999de8 Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Thu, 30 Oct 2025 11:29:56 +0000 Subject: [PATCH] Bug 17387: add modal warning for items with deleted biblios --- .../prog/en/modules/tools/restore-records.tt | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/restore-records.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/restore-records.tt index 49d20120246..c0b48b85070 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/restore-records.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/restore-records.tt @@ -77,6 +77,34 @@ [% END #/ WRAPPER main-container.inc %] + + + [% MACRO jsinclude BLOCK %] [% Asset.js("js/tools-menu.js") | $raw %] [% INCLUDE 'datatables.inc' %] @@ -165,6 +193,7 @@ ajax: { url: "/api/v1/deleted/items", }, + embed: "biblio", order: [[5, "desc"]], columns: [ { @@ -288,6 +317,24 @@ var button = $(this); var item_id = button.data("item-id"); var barcode = button.data("barcode"); + var row = items_table_api.row(button.closest("tr")).data(); + + // Check if biblio is deleted + if (row.biblio && row.biblio.deleted_on) { + // Show modal with biblio info + $("#modal-biblio-id").text(row.biblio.biblio_id); + $("#modal-biblio-title").text(row.biblio.title || _("(No title)")); + $("#modal-biblio-author").text(row.biblio.author || _("(No author)")); + + // Store the item and biblio data for later + $("#restore-biblio-button").data("biblio-id", row.biblio.biblio_id); + $("#restore-biblio-button").data("item-id", item_id); + $("#restore-biblio-button").data("item-button", button); + + var modal = new bootstrap.Modal(document.getElementById("deletedBiblioModal")); + modal.show(); + return; + } if (!confirm(_("Are you sure you want to restore item %s (%s)?").format(item_id, barcode))) { return; @@ -315,6 +362,39 @@ }, }); }); + + // Restore biblio from modal + $("#restore-biblio-button").on("click", function () { + var button = $(this); + var biblio_id = button.data("biblio-id"); + var item_id = button.data("item-id"); + var item_button = button.data("item-button"); + + button.prop("disabled", true); + + $.ajax({ + url: "/api/v1/deleted/biblios/" + biblio_id, + type: "PUT", + headers: { + "x-koha-request-id": Math.random(), + }, + success: function (data) { + showMessage(_("Bibliographic record %s restored successfully").format(biblio_id), "success"); + bootstrap.Modal.getInstance(document.getElementById("deletedBiblioModal")).hide(); + biblios_table_api.ajax.reload(); + items_table_api.ajax.reload(); + button.prop("disabled", false); + }, + error: function (xhr) { + var error_msg = _("Error restoring bibliographic record %s").format(biblio_id); + if (xhr.responseJSON && xhr.responseJSON.error) { + error_msg += ": " + xhr.responseJSON.error; + } + showMessage(error_msg, "danger"); + button.prop("disabled", false); + }, + }); + }); }); [% END %] -- 2.39.5