From 2cbcff6d0cda75386690d4f7c138e935108bfff8 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Mon, 27 Nov 2023 10:35:15 +0000 Subject: [PATCH] Bug 34479: Move patron selection history to a re-useable file This patch takes some of the functionality for maintaining patron selections and moves it to a new file that can be used in other template files. It also introduces a new method for determining whether to delete the history after an operation is complete, along with an .inc file containing the checkbox that manages this Test plan: 1) Navigate to Patrons and run a search 2) Use the checkboxes to select some patrons and run the three different options in the menu bar: Add to patron list, Merge selected patrons, Batch patron modification. 3) For each operation, you should see a checkbox asking if you want to "Keep patrons selected for anew operation". N.B. For adding patrons to a list, you will only see this when selecting to add them to a new list 4) When you run the operations, if you select the checkbox to keep the patrons then when you return tho the patron search, those patrons should all be still selected. 5) If you don't check the box, when you return to the search, your patron selection history should be empty and no patrons should be selected N.B. If you have run a merge operation and elected to keep the patron history, you will only keep the patron who was kept --- .../en/includes/members-patron-selections.inc | 6 ++ .../prog/js/members-patron-selections.js | 61 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/members-patron-selections.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/js/members-patron-selections.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/members-patron-selections.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/members-patron-selections.inc new file mode 100644 index 0000000000..dfa54fab5f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/members-patron-selections.inc @@ -0,0 +1,6 @@ + + + + + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/members-patron-selections.js b/koha-tmpl/intranet-tmpl/prog/js/members-patron-selections.js new file mode 100644 index 0000000000..228cad3293 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/members-patron-selections.js @@ -0,0 +1,61 @@ +function persistPatronSelections(form) { + var selected_patrons; + var persistence_checkbox = $("#maintain_selections_" + form)[0]; + var persist = persistence_checkbox.checked + if (form === 'patron-merge-form' && persist) { + // We should only keep the id for the patron that is being kept in the merge + var keeper_checkboxes = $(".keeper") + var patron_to_keep = keeper_checkboxes.filter(":checked") + var patron_id = patron_to_keep[0].value + selected_patrons = [ patron_id ] + } else { + selected_patrons = persist ? JSON.parse(localStorage.getItem("patron_search_selections")) : []; + } + localStorage.setItem('patron_search_selections', JSON.stringify(selected_patrons)); +} + +function showPatronSelections(number) { + if (number === 0) { + $("#table_search_selections").hide() + } else { + $("#table_search_selections").show().find("span").text(_("Patrons selected: " + number)); + } +} + +function prepSelections() { + var selected_patrons = JSON.parse(localStorage.getItem("patron_search_selections")); + if (selected_patrons && selected_patrons.length > 0) { + showPatronSelections(selected_patrons.length); + + $('#merge-patrons').prop('disabled', true); + $("input.selection").each(function () { + var cardnumber = $(this).val(); + if (selected_patrons.indexOf(cardnumber) >= 0) { + $(this).prop("checked", true); + } + }); + + if (selected_patrons.length > 1) { + $('#batch-mod-patrons, #merge-patrons, #patronlist-menu').removeClass("disabled").prop('disabled', false); + } + } else { + showPatronSelections(0); + $('#merge-patrons').prop('disabled', true); + $("input.selection").each(function () { + $(this).prop("checked", false); + }); + $('#batch-mod-patrons, #merge-patrons, #patronlist-menu').addClass("disabled").prop('disabled', true); + } +} + +$(document).ready(function () { + var form_identifier = $("#form-identifier").data(); + if(form_identifier && form_identifier.hasOwnProperty('identifier') && form_identifier.identifier) { + var form_id = form_identifier.identifier; + if (form_id !== 'new-patron-list_form') { + $("#" + form_id).on("submit", function(e){ + persistPatronSelections(form_id) + }); + } + } +}) -- 2.37.1 (Apple Git-137.1)