View | Details | Raw Unified | Return to bug 40654
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-17 / +45 lines)
Lines 1756-1782 Link Here
1756
            });
1756
            });
1757
            var prev_rank_request;
1757
            var prev_rank_request;
1758
            $("select[name=rank-request]").on("focus", function() {
1758
            $("select[name=rank-request]").on("focus", function() {
1759
                prev_rank_request = $(this).val();
1759
                prev_rank_request = parseInt($(this).val());
1760
                var row = $(this).parents("tr:first");
1761
            }).change(function() {
1760
            }).change(function() {
1762
                var row = $(this).parents("tr:first");
1761
                var this_rank = $(this);
1763
                var value = parseInt($(this).val());
1762
                var new_rank = parseInt(this_rank.val());
1764
                var found_holds = $("select[name='rank-request'][disabled='disabled']").length ; //Count how many are found
1763
                var old_rank = prev_rank_request;
1765
                if( !isNaN(value) ) {  //If moved to 'del'
1764
1766
                    var after = row.parent().find(`tr:nth-child(${value+found_holds})`); //Go to the row 1 after the new value (and skip found holds)
1765
                //if new_rank is NaN, bail
1767
                    if (prev_rank_request > value) {
1766
                if ( isNaN( new_rank ) ) return;
1768
                        row.insertBefore(after);
1767
1769
                    } else {
1768
                if ( isNaN( old_rank ) ) {
1770
                        row.insertAfter(after);
1769
                    $("select[name=rank-request]").not('[disabled]').not(this_rank).each(function() {
1770
                        var current_rank = parseInt($(this).val());
1771
                        if ( !isNaN(current_rank) && current_rank >= new_rank ) {
1772
                            $(this).val(current_rank + 1);
1773
                        }
1774
                    });
1775
                    prev_rank_request = new_rank;
1776
                    return;
1777
                }
1778
1779
                if ( isNaN( new_rank ) ) {
1780
                    if ( !isNaN( old_rank ) ) {
1781
                        $("select[name=rank-request]").not('[disabled]').not(this).each(function() {
1782
                            var current_rank = parseInt($(this).val());
1783
                            if ( !isNaN(current_rank) && current_rank > old_rank ) {
1784
                                $(this).val(current_rank - 1);
1785
                            }
1786
                        });
1771
                    }
1787
                    }
1788
                    return;
1772
                }
1789
                }
1773
1790
1774
                var next_priority = 1;
1791
                // Adjust ranks
1775
                $("select[name=rank-request]").each(function () {
1792
                $("select[name=rank-request]").not('[disabled]').not(this).each(function() {
1776
                    if( isNaN( $(this).val() ) ){ return true; } //Don't reset found or del holds
1793
                    var current_rank = parseInt($(this).val());
1777
                    $(this).val(next_priority);
1794
                    //if current_rank is NaN, bail
1778
                    next_priority++;
1795
                    if ( isNaN( current_rank ) ) return;
1796
1797
                    if ( old_rank > new_rank ) {
1798
                        if ( current_rank >= new_rank && current_rank < old_rank ) {
1799
                            $(this).val(current_rank + 1);
1800
                        }
1801
                    } else {
1802
                        if ( current_rank > old_rank && current_rank <= new_rank ) {
1803
                            $(this).val(current_rank - 1);
1804
                        }
1805
                    }
1779
                });
1806
                });
1807
1808
                prev_rank_request = new_rank;
1780
            });
1809
            });
1781
1810
1782
            $(".clear-date").on("click",function(e){
1811
            $(".clear-date").on("click",function(e){
1783
- 

Return to bug 40654