@@ -, +, @@ library page --- .../intranet-tmpl/prog/js/desk_selection.js | 79 +++++++++---------- 1 file changed, 37 insertions(+), 42 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/js/desk_selection.js +++ a/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(); +}); --