From a92a05d328fc2c6818c6fb5e7ec952231d914f25 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 14 Aug 2025 18:42:17 +0000 Subject: [PATCH] Bug 40654: [24.11.x] Fix how rank/priority is adjusted when changing from the UI To test: 0 - APPLY PATCH 1 - Place 50 holds on a bib record https://github.com/kidclamp/handy-koha-script/blob/main/randhold.pl 2 - View the holds page for the record 3 - Sort the holds alphabetically 4 - Change the dropdown priortiy for the alphabetically first hold to 1 5 - All the priorities should now ajust accordingly but they will NOT be resorted on the fly 6 - Play with adjusting some priorities, making sure everything correctly adjusts. 7 - Click 'Update holds' to make sure the priorities adjust right 8 - Make sure you test with the 'del' option and the adjustments still work. Signed-off-by: David Flater Signed-off-by: Emily Lamancusa --- .../prog/en/includes/holds_table.inc | 103 +++++++++--------- .../prog/en/modules/reserve/request.tt | 70 +++++++++--- 2 files changed, 107 insertions(+), 66 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc index 36ca90c6cd4..11bc576f8cc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -35,61 +35,64 @@ [% FOREACH hold IN holds %] - [%- IF !hold.found && first_priority == 0 -%] - [%- first_priority = hold.priority -%] - [%- found_holds = loop.index() -%] - [%- END -%] - [%- IF Koha.Preference('HoldsSplitQueueNumbering') == 'actual' -%] - [%- this_priority = hold.priority -%] - [%- ELSE -%] - [%- this_priority = loop.count() - found_holds -%] - [%- END -%] - [% IF hold.suspend %] - - [% ELSE %] - - [% END %] - - - - - - [% IF ( CAN_user_reserveforothers_modify_holds_priority ) %] - [% IF Koha.Preference('HoldsSplitQueue') == "nothing" && !hold.found %] - + +
+ + + + [% IF ( CAN_user_reserveforothers_modify_holds_priority ) %] + [% IF Koha.Preference('HoldsSplitQueue') == "nothing" && !hold.found %] + + [% ELSE %] - + + [% END %] - - [% ELSE %] - - + [% END %] - [% ELSE %] - - [% hold.priority | html %] - [% END %] +
+ + [% hold.priority | html %] +
+
[%- IF ( CAN_user_reserveforothers_modify_holds_priority ) -%] [%- UNLESS hold.found -%] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index 3884124a9c0..13cfda885d2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -102,6 +102,14 @@ :disabled{ opacity:0.5 } + .current_priority { + width: 50px; + text-align: left; + margin-top: 5px; + } + .rank-request { + width: 50px; + } [% END %] @@ -1815,27 +1823,57 @@ }); var prev_rank_request; $("select[name=rank-request]").on("focus", function() { - prev_rank_request = $(this).val(); - var row = $(this).parents("tr:first"); + prev_rank_request = parseInt($(this).val()); }).change(function() { - var row = $(this).parents("tr:first"); - var value = parseInt($(this).val()); - var found_holds = $("select[name='rank-request'][disabled='disabled']").length ; //Count how many are found - if( !isNaN(value) ) { //If moved to 'del' - var after = row.parent().find(`tr:nth-child(${value+found_holds})`); //Go to the row 1 after the new value (and skip found holds) - if (prev_rank_request > value) { - row.insertBefore(after); - } else { - row.insertAfter(after); + var this_rank = $(this); + var new_rank = parseInt(this_rank.val()); + var old_rank = prev_rank_request; + + if ( isNaN( old_rank ) ) { + $("select[name=rank-request]").not('[disabled]').not(this_rank).each(function() { + var current_rank = parseInt($(this).val()); + if ( !isNaN(current_rank) && current_rank >= new_rank ) { + $(this).val(current_rank + 1); + } + }); + prev_rank_request = new_rank; + return; + } + + if ( isNaN( new_rank ) ) { + if ( !isNaN( old_rank ) ) { + $("select[name=rank-request]").not('[disabled]').not(this).each(function() { + var current_rank = parseInt($(this).val()); + if ( !isNaN(current_rank) && current_rank > old_rank ) { + $(this).val(current_rank - 1); + } + }); } + prev_rank_request = NaN; + return; } - var next_priority = 1; - $("select[name=rank-request]").each(function () { - if( isNaN( $(this).val() ) ){ return true; } //Don't reset found or del holds - $(this).val(next_priority); - next_priority++; + //if new rank is old rank, don't continue + if ( new_rank === old_rank ) return; + + // Adjust ranks + $("select[name=rank-request]").not('[disabled]').not(this).each(function() { + var current_rank = parseInt($(this).val()); + //if current_rank is NaN, bail + if ( isNaN( current_rank ) ) return; + + if ( old_rank > new_rank ) { + if ( current_rank >= new_rank && current_rank < old_rank ) { + $(this).val(current_rank + 1); + } + } else { + if ( current_rank > old_rank && current_rank <= new_rank ) { + $(this).val(current_rank - 1); + } + } }); + + prev_rank_request = new_rank; }); $(".clear-date").on("click",function(e){ -- 2.39.5