From 066276f3b1cefff6397e08652ef0978d0d1b151f Mon Sep 17 00:00:00 2001 From: Chris Hallberg Date: Mon, 25 Mar 2024 17:04:58 -0400 Subject: [PATCH] Print prompt trigger fixes (#3512) --- themes/bootstrap3/js/check_item_statuses.js | 9 ++++++++- themes/bootstrap3/js/check_save_statuses.js | 10 +++++++++- themes/bootstrap3/js/trigger_print.js | 17 ++++++++++++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/themes/bootstrap3/js/check_item_statuses.js b/themes/bootstrap3/js/check_item_statuses.js index 3c7da8179cb..76ba52ec16c 100644 --- a/themes/bootstrap3/js/check_item_statuses.js +++ b/themes/bootstrap3/js/check_item_statuses.js @@ -219,7 +219,14 @@ VuFind.register('itemStatuses', function ItemStatuses() { } function checkAllItemStatuses(container = document) { - container.querySelectorAll(".ajaxItem").forEach(checkItemStatus); + const records = container.querySelectorAll(".ajaxItem"); + + if (records.length === 0) { + VuFind.emit("item-status-done"); + return; + } + + records.forEach(checkItemStatus); } function init($container = document) { diff --git a/themes/bootstrap3/js/check_save_statuses.js b/themes/bootstrap3/js/check_save_statuses.js index 084701d242c..572ed09e7d1 100644 --- a/themes/bootstrap3/js/check_save_statuses.js +++ b/themes/bootstrap3/js/check_save_statuses.js @@ -121,10 +121,18 @@ VuFind.register("saveStatuses", function ItemStatuses() { function checkAllSaveStatuses(container = document) { if (!userIsLoggedIn) { + VuFind.emit("save-status-done"); + return; + } + + const records = container.querySelectorAll(".result,.record"); + + if (records.length === 0) { + VuFind.emit("save-status-done"); return; } - container.querySelectorAll(".result,.record").forEach(checkSaveStatus); + records.forEach(checkSaveStatus); } function refresh() { diff --git a/themes/bootstrap3/js/trigger_print.js b/themes/bootstrap3/js/trigger_print.js index 8c913986cc5..1e8a3d385a2 100644 --- a/themes/bootstrap3/js/trigger_print.js +++ b/themes/bootstrap3/js/trigger_print.js @@ -1,12 +1,19 @@ /* global VuFind */ function waitForItemStatuses(fn) { - var itemDone = false; - var saveDone = false; + var itemDone = typeof VuFind.itemStatuses === "undefined"; + var saveDone = typeof VuFind.saveStatuses === "undefined"; + var fnCalled = false; + + if (itemDone && saveDone) { + fn(); + return; + } function checkBoth() { - if (itemDone && saveDone) { + if (!fnCalled && itemDone && saveDone) { fn(); + fnCalled = true; } } @@ -21,7 +28,7 @@ function waitForItemStatuses(fn) { }); } -$(function triggerPrint() { +(function triggerPrint() { if (!VuFind.isPrinting()) { return; } @@ -60,4 +67,4 @@ $(function triggerPrint() { // Make an ajax call to ensure that ajaxStop is triggered $.getJSON(VuFind.path + '/AJAX/JSON', {method: 'keepAlive'}); }); -}); +})();