From c4f1f24a0ec92e95c7c159253065c6f9ea7a85aa Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Thu, 6 Jun 2019 19:18:19 +0000
Subject: [PATCH] Bug 8260: user rank order instead of absolute rank to set
 dropdowns on routing.pl

When deleting a borrower on a routing list we leave a gap in the numbering. It appears to only be a problem when viewing
or editing the list in the staff client.

Rather than use the rank in the DB to set the values, we use the implicit order

To test:
 1 - Create a subscription (or find one)
 2 - Add a routing list
 3 - Add five patrons
 4 - Delete the patron who is third in the list
 5 - Edit the routing list
 6 - Note the priority for the last patron is 1
 7 - Apply patch
 8 - Reload the page
 9 - Values look correct
10 - Confirm reordering works as expected

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
---
 koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt
index 317bfc4e05..0652f90343 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt
@@ -59,8 +59,9 @@
                 <td>
                     <select name="itemrank" class="itemrank" data-subscriptionid="[% subscriptionid | html %]" data-routingid="[% member.routingid | html %]">
                     [% rankings = [1 .. m_loop.size] %]
+                    [% SET cur_rank = loop.count() %]
                     [% FOREACH r IN rankings %]
-                        [% IF r == member.ranking %]
+                        [% IF r == cur_rank %]
                           <option selected="selected" value="[% r | html %]">[% r | html %]</option>
                         [% ELSE %]
                           <option value="[% r | html %]">[% r | html %]</option>
-- 
2.11.0