From 7096d0056031dccf61ead7d8e1342954c4565b21 Mon Sep 17 00:00:00 2001 From: Brendan Lawlor Date: Wed, 3 Apr 2024 18:59:45 +0000 Subject: [PATCH] Bug 30123: Set desk default to logged-in-desk-id on set library page This patch refactors the javascript that runs on the set library page. If the logged in user branch code is the same as the seleceted library, default the desk selection to the current logged in desk id. Otherwise set the default desk selection to the first option for the current branch. Test plan: 1. Turn on UseCirculationDesks 2. Create a few desks with unique names for a few different libraries 3. Set your library and desk 4. Reload set-library.pl and notice that the desk always defaults to the last option for the library selected 5. Apply patch and restart_all 6. Reload set-library.pl and notice that the desk selection defaults to your current logged in desk 7. Try changing the library selection to libraries with and without desks 8. Notice that the desk selection defaults to the first option available for the selected library 9. Notice that the desk selection defaults to the --- no desk for libraries without desks 10. Notice the desk selection defaults to the currenty logged in desk if you select the library you are currently logged into --- .../intranet-tmpl/prog/js/desk_selection.js | 79 +++++++++---------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/desk_selection.js b/koha-tmpl/intranet-tmpl/prog/js/desk_selection.js index ab42768d13..228935b678 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/desk_selection.js +++ b/koha-tmpl/intranet-tmpl/prog/js/desk_selection.js @@ -1,42 +1,37 @@ -$(document).ready(function() { - $("#desk_id").children().each(function() { - var selectedBranch = $("#branch"). children("option:selected"). val(); - if ($(this).attr('id') === "nodesk") { //set no desk by default, should be first element - $(this).prop("selected", true); - $(this).prop("disabled", false); - $(this).show(); - } - else if ($(this).hasClass(selectedBranch)) { - $('#nodesk').prop("disabled", true); // we have desk, no need for nodesk option - $('#nodesk').hide(); - $(this).prop("disabled", false); - $(this).show(); - $(this).prop("selected", true) - } else { - $(this).prop("disabled", true); - $(this).hide(); - } - }); - - $("#branch").on("change", function() { - - $("#desk_id").children().each(function() { - var selectedBranch = $("#branch"). children("option:selected"). val(); - if ($(this).attr('id') === "nodesk") { //set no desk by default, should be first element - $(this).prop("selected", true); - $(this).prop("disabled", false); - $(this).show(); - } - else if ($(this).hasClass(selectedBranch)) { - $('#nodesk').prop("disabled", true); // we have desk, no need for nodesk option - $('#nodesk').hide(); - $(this).prop("disabled", false); - $(this).show(); - $(this).prop("selected", true) - } else { - $(this).prop("disabled", true); - $(this).hide(); - } - }); - }); -}) ; +$(document).ready(function () { + $("#branch") + .on("change", function () { + $("#desk_id") + .children() + .each(function () { + var selectedBranch = $("#branch") + .children("option:selected") + .val(); + if ($(this).attr("id") === "nodesk") { + // set no desk by default, should be first element + $(this).prop("selected", true); + $(this).prop("disabled", false); + $(this).show(); + } else if ($(this).hasClass(selectedBranch)) { + $("#nodesk").prop("disabled", true); // we have desk, no need for nodesk option + $("#nodesk").hide(); + $(this).prop("disabled", false); + $(this).show(); + if ( + selectedBranch == $(".logged-in-branch-code").html() + ) { + $("#desk_id").val($(".logged-in-desk-id").html()); + } else { + $("#nodesk").hide(); + $("#desk_id").val( + $("#desk_id option:not([disabled]):first").val() + ); + } + } else { + $(this).prop("disabled", true); + $(this).hide(); + } + }); + }) + .change(); +}); -- 2.30.2