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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-440 / +463 lines)
Lines 661-667 Link Here
661
                                [% UNLESS remaining_holds_for_record == 1 %]
661
                                [% UNLESS remaining_holds_for_record == 1 %]
662
                                    <li>
662
                                    <li>
663
                                        <label for="holds_to_place_count">Holds to place (count)</label>
663
                                        <label for="holds_to_place_count">Holds to place (count)</label>
664
                                        <input type="text" inputmode="numeric" pattern="[0-9]*" id="holds_to_place_count" name="holds_to_place_count" value="1" />
664
                                        <input
665
                                            type="number"
666
                                            inputmode="numeric"
667
                                            pattern="[0-9]*"
668
                                            id="holds_to_place_count"
669
                                            name="holds_to_place_count"
670
                                            value="1"
671
                                            min="1"
672
                                            [% IF max_holds_for_record %]max="[% max_holds_for_record | html %]"[% END %]
673
                                        />
674
                                        [% IF max_holds_for_record %]
675
                                            <p class="hint">The maximum number of holds to place is [% max_holds_for_record %].</p>
676
                                        [% ELSE %]
677
                                            <p class="hint">There is no set maximum for holds.</p>
678
                                        [% END %]
665
                                    </li>
679
                                    </li>
666
                                [% ELSE %]
680
                                [% ELSE %]
667
                                    <input type="hidden" name="holds_to_place_count" value="1" />
681
                                    <input type="hidden" name="holds_to_place_count" value="1" />
Lines 1432-1938 Link Here
1432
    [% END %]
1446
    [% END %]
1433
    <script>
1447
    <script>
1434
        $(document).ready(function () {
1448
        $(document).ready(function () {
1435
            hold_table_settings = [% TablesSettings.GetTableSettings( 'circ', 'holds', 'patron_holds_table', 'json' ) | $raw %];
1449
                    hold_table_settings = [% TablesSettings.GetTableSettings( 'circ', 'holds', 'patron_holds_table', 'json' ) | $raw %];
1436
            $("#patron_holds_table").kohaTable(
1450
                    $("#patron_holds_table").kohaTable(
1437
                {
1451
                        {
1438
                    paging: false,
1452
                            paging: false,
1439
                    bKohaColumnsUseNames: true,
1453
                            bKohaColumnsUseNames: true,
1440
                },
1454
                        },
1441
                hold_table_settings
1455
                        hold_table_settings
1442
            );
1456
                    );
1457
                });
1458
                var biblionumbers = [[% biblionumbers.join(', ') | $raw %]];
1459
                var borrowernumber = "[% patron.borrowernumber | $raw %]";
1460
                var patron_homebranch = "[% To.json( Branches.GetName( patron.branchcode ) ) | $raw %]";
1461
                var override_items = {[% FOREACH biblio_info IN biblioloop %][% FOREACH itemloo IN biblio_info.itemloop %][% IF ( itemloo.override ) %]
1462
                [% itemloo.itemnumber | html %]: {
1463
                    homebranch: "[% To.json( Branches.GetName( itemloo.homebranch ) ) | $raw %]",
1464
                    holdallowed: "[% itemloo.holdallowed | html %]"
1465
                    },
1466
                    [% END %][% END %][% END %]
1467
                };
1468
                var ERROR_MAP = {
1469
                    damaged: _("Item damaged"),
1470
                    ageRestricted: _("Age restricted"),
1471
                    tooManyHoldsForThisRecord: _("Exceeded max holds per record"),
1472
                    tooManyReservesToday: _("Daily hold limit reached for patron"),
1473
                    tooManyReserves: _("Too many holds"),
1474
                    notReservable: _("Not holdable"),
1475
                    noReservesAllowed: _("No reserves allowed"),
1476
                    cannotReserveFromOtherBranches: _("Patron is from different library"),
1477
                    itemAlreadyOnHold: _("Patron already has hold for this item"),
1478
                    cannotBeTransferred: _("Cannot be transferred to pickup library"),
1479
                    pickupNotInHoldGroup: _("Only pickup locations within the same hold group are allowed")
1480
                }
1481
1482
                var MSG_CANCEL_SELECTED = _("Cancel selected (%s)");
1483
                var MSG_CANCEL_ALERT    = _("This action will cancel <span class='badge bg-danger'>%s</span> hold(s).");
1484
                var MSG_CONFIRM_PLACE_HOLDS = _("Are you sure you want to place %s hold(s)?");
1485
                $.fn.select2.defaults.set("width", "100%" );
1486
                $.fn.select2.defaults.set("dropdownAutoWidth", true );
1487
                $("form").on("submit", function(e) {
1488
            var countInput = document.getElementById("holds_to_place_count");
1489
            if (countInput) {
1490
                var count = parseInt(countInput.value, 10) || 1;
1491
                if (count > 1 && !confirm(MSG_CONFIRM_PLACE_HOLDS.replace("%s", count))) {
1492
                    e.preventDefault();
1493
                }
1494
            }
1443
        });
1495
        });
1444
        var biblionumbers = [[% biblionumbers.join(', ') | $raw %]];
1445
        var borrowernumber = "[% patron.borrowernumber | $raw %]";
1446
        var patron_homebranch = "[% To.json( Branches.GetName( patron.branchcode ) ) | $raw %]";
1447
        var override_items = {[% FOREACH biblio_info IN biblioloop %][% FOREACH itemloo IN biblio_info.itemloop %][% IF ( itemloo.override ) %]
1448
        [% itemloo.itemnumber | html %]: {
1449
            homebranch: "[% To.json( Branches.GetName( itemloo.homebranch ) ) | $raw %]",
1450
            holdallowed: "[% itemloo.holdallowed | html %]"
1451
            },
1452
            [% END %][% END %][% END %]
1453
        };
1454
        var ERROR_MAP = {
1455
            damaged: _("Item damaged"),
1456
            ageRestricted: _("Age restricted"),
1457
            tooManyHoldsForThisRecord: _("Exceeded max holds per record"),
1458
            tooManyReservesToday: _("Daily hold limit reached for patron"),
1459
            tooManyReserves: _("Too many holds"),
1460
            notReservable: _("Not holdable"),
1461
            noReservesAllowed: _("No reserves allowed"),
1462
            cannotReserveFromOtherBranches: _("Patron is from different library"),
1463
            itemAlreadyOnHold: _("Patron already has hold for this item"),
1464
            cannotBeTransferred: _("Cannot be transferred to pickup library"),
1465
            pickupNotInHoldGroup: _("Only pickup locations within the same hold group are allowed")
1466
        }
1467
1496
1468
        var MSG_CANCEL_SELECTED = _("Cancel selected (%s)");
1497
                $(document).ready(function() {
1469
        var MSG_CANCEL_ALERT    = _("This action will cancel <span class='badge bg-danger'>%s</span> hold(s).");
1470
        $.fn.select2.defaults.set("width", "100%" );
1471
        $.fn.select2.defaults.set("dropdownAutoWidth", true );
1472
1473
        $(document).ready(function() {
1474
            $('#cancellation-reason-fieldset').hide();
1475
            $('.rank-request').on('change', function() {
1476
                if ( $(".rank-request option:selected[value='del']").length ) {
1477
                    $('#cancellation-reason-fieldset').show();
1478
                } else {
1479
                    $('#cancellation-reason-fieldset').hide();
1498
                    $('#cancellation-reason-fieldset').hide();
1480
                }
1499
                    $('.rank-request').on('change', function() {
1481
            });
1500
                        if ( $(".rank-request option:selected[value='del']").length ) {
1501
                            $('#cancellation-reason-fieldset').show();
1502
                        } else {
1503
                            $('#cancellation-reason-fieldset').hide();
1504
                        }
1505
                    });
1482
1506
1483
            if( $("#circ_holds_select").length > 0 ){
1507
                    if( $("#circ_holds_select").length > 0 ){
1484
                [% SET active = clubs ? 1 : 0 %]
1508
                        [% SET active = clubs ? 1 : 0 %]
1485
                /* Set active tab based on whether a club search was submitted */
1509
                        /* Set active tab based on whether a club search was submitted */
1486
                var tabs = $("#circ_holds_select li:eq(" + [% active | $raw %] + ") a").tab("show");
1510
                        var tabs = $("#circ_holds_select li:eq(" + [% active | $raw %] + ") a").tab("show");
1487
                $( tabs[0].hash ).find("input.focus").focus();
1511
                        $( tabs[0].hash ).find("input.focus").focus();
1488
1512
1489
                /* Change active focus when tabs change */
1513
                        /* Change active focus when tabs change */
1490
                $("#circ_holds_select a[data-bs-toggle='tab']").on("shown.bs.tab", function (e) {
1514
                        $("#circ_holds_select a[data-bs-toggle='tab']").on("shown.bs.tab", function (e) {
1491
                    active_tab = e.target.hash;
1515
                            active_tab = e.target.hash;
1492
                    $( active_tab ).find("input.focus").focus();
1516
                            $( active_tab ).find("input.focus").focus();
1493
                });
1517
                        });
1494
            }
1518
                    }
1495
1519
1496
1520
1497
            ToggleHoldsToPlace();
1521
                    ToggleHoldsToPlace();
1498
            $("#requestany,.requestspecific[name='request'],.requestgrp").on('change', function(){
1522
                    $("#requestany,.requestspecific[name='request'],.requestgrp").on('change', function(){
1499
                ToggleHoldsToPlace();
1523
                        ToggleHoldsToPlace();
1500
            });
1524
                    });
1501
1525
1502
            [% IF Koha.Preference('UseBranchTransferLimits') %]
1526
                    [% IF Koha.Preference('UseBranchTransferLimits') %]
1503
                $("#pickup,#pickup-next-avail,#pickup-item-group").on('change', function(){
1527
                        $("#pickup,#pickup-next-avail,#pickup-item-group").on('change', function(){
1504
                    var pickup = $(this).val();
1528
                            var pickup = $(this).val();
1505
                    var url = "?pickup=" + pickup;
1529
                            var url = "?pickup=" + pickup;
1506
                    url += "&borrowernumber=" + borrowernumber;
1530
                            url += "&borrowernumber=" + borrowernumber;
1507
                    url += "&biblionumber=" + biblionumbers[0];
1531
                            url += "&biblionumber=" + biblionumbers[0];
1508
                    window.location.replace(url);
1532
                            window.location.replace(url);
1509
                });
1533
                        });
1510
            [% END %]
1534
                    [% END %]
1511
1535
1512
            var my_table = $("#requestspecific").kohaTable({
1536
                    var my_table = $("#requestspecific").kohaTable({
1513
                paging: false,
1537
                        paging: false,
1514
                dom: '<"top pager"ilf>t',
1538
                        dom: '<"top pager"ilf>t',
1515
            });
1539
                    });
1516
1540
1517
            $("#club-request-form").on("submit", function() {
1541
                    $("#club-request-form").on("submit", function() {
1518
                let $t = $(this);
1542
                        let $t = $(this);
1519
                $('.clubalert, .holdalert').addClass('hide');
1543
                        $('.clubalert, .holdalert').addClass('hide');
1520
                const data = {
1544
                        const data = {
1521
                    pickup_library_id: $('select[name="pickup"]').val()
1545
                            pickup_library_id: $('select[name="pickup"]').val()
1522
                };
1546
                        };
1523
                if($('input[name="checkitem"]:checked').length)
1547
                        if($('input[name="checkitem"]:checked').length)
1524
                    data.item_id = $('input[name="checkitem"]:checked').val();
1548
                            data.item_id = $('input[name="checkitem"]:checked').val();
1525
                if($('input[name="item_group_id"]:checked').length)
1549
                        if($('input[name="item_group_id"]:checked').length)
1526
                    data.item_group_id = $('input[name="item_group_id"]:checked').val();
1550
                            data.item_group_id = $('input[name="item_group_id"]:checked').val();
1527
                if($('input[name="borrowernumber"]').length)
1551
                        if($('input[name="borrowernumber"]').length)
1528
                    data.patron_id = $('input[name="borrowernumber"]').val();
1552
                            data.patron_id = $('input[name="borrowernumber"]').val();
1529
                if($('textarea[name="notes"]').length)
1553
                        if($('textarea[name="notes"]').length)
1530
                    data.notes = $('textarea[name="notes"]').val()||null;
1554
                            data.notes = $('textarea[name="notes"]').val()||null;
1531
                if($('input[name="itemtype"]').length) {
1555
                        if($('input[name="itemtype"]').length) {
1532
                    data.item_type = $('input[name="itemtype"]').val()||null;
1556
                            data.item_type = $('input[name="itemtype"]').val()||null;
1533
                }
1557
                        }
1534
                if($('input[name="default_patron_home"]:checked').length) {
1558
                        if($('input[name="default_patron_home"]:checked').length) {
1535
                    data.default_patron_home = 1;
1559
                            data.default_patron_home = 1;
1536
                }
1560
                        }
1537
1561
1538
                const count = $('input[name="holds_to_place_count"]').length?$('input[name="holds_to_place_count"]').val():1;
1562
                        const count = $('input[name="holds_to_place_count"]').length?$('input[name="holds_to_place_count"]').val():1;
1539
                var newloc = 'request.pl?';
1563
                        var newloc = 'request.pl?';
1540
                biblionumbers.forEach(function (biblionumber) {
1564
                        biblionumbers.forEach(function (biblionumber) {
1541
                    newloc += '&biblionumber=' + biblionumber;
1565
                            newloc += '&biblionumber=' + biblionumber;
1542
                });
1566
                        });
1543
1567
1544
                biblionumbers.forEach(function(biblionumber) {
1568
                        biblionumbers.forEach(function(biblionumber) {
1545
                    data.biblio_id = biblionumber;
1569
                            data.biblio_id = biblionumber;
1546
                    let options = {
1570
                            let options = {
1547
                        url: $t.attr('action'),
1571
                                url: $t.attr('action'),
1548
                        method: $t.attr('method').toUpperCase(),
1572
                                method: $t.attr('method').toUpperCase(),
1549
                        contentType: 'application/json',
1573
                                contentType: 'application/json',
1550
                        data: JSON.stringify(data)
1574
                                data: JSON.stringify(data)
1551
                    };
1575
                            };
1552
                    for(let i = 0; i < count; i++) {
1576
                            for(let i = 0; i < count; i++) {
1553
                        $.ajax(options)
1577
                                $.ajax(options)
1554
                        .then(function(result) {
1578
                                .then(function(result) {
1555
                            document.location = newloc;
1579
                                    document.location = newloc;
1556
                        })
1580
                                })
1557
                        .fail(function(err) {
1581
                                .fail(function(err) {
1558
                            var message = err.responseJSON.error;
1582
                                    var message = err.responseJSON.error;
1559
                            var match = err.responseJSON.error.match(/Reason: (\w+)\s*$/);
1583
                                    var match = err.responseJSON.error.match(/Reason: (\w+)\s*$/);
1560
                            if(match && ERROR_MAP[match[1]]) {
1584
                                    if(match && ERROR_MAP[match[1]]) {
1561
                                message = '<div><strong>'+_("Cannot place hold")+'</strong></div><div>'+ERROR_MAP[match[1]]+'</div>'
1585
                                        message = '<div><strong>'+_("Cannot place hold")+'</strong></div><div>'+ERROR_MAP[match[1]]+'</div>'
1586
                                    }
1587
                                    $('.clubalert, .holdalert').removeClass('hide').html(message);
1588
                                });
1562
                            }
1589
                            }
1563
                            $('.clubalert, .holdalert').removeClass('hide').html(message);
1564
                        });
1590
                        });
1565
                    }
1566
                });
1567
1591
1568
                return false;
1592
                        return false;
1569
            });
1593
                    });
1570
1594
1571
            [% UNLESS ( multi_hold ) %]
1595
                    [% UNLESS ( multi_hold ) %]
1572
                $("#hold-request-form").on("submit", function(e){
1596
                        $("#hold-request-form").on("submit", function(e){
1573
                    return check(e, $(this));
1597
                            return check(e, $(this));
1574
                });
1598
                        });
1575
            [% ELSE %]
1599
                    [% ELSE %]
1576
                $("#hold-request-form").on("submit", function(){
1600
                        $("#hold-request-form").on("submit", function(){
1577
                    return checkMultiHold();
1601
                            return checkMultiHold();
1578
                });
1602
                        });
1579
            [% END %]
1603
                    [% END %]
1580
1604
1581
            $(".pickup_location_dropdown").each( function () {
1605
                    $(".pickup_location_dropdown").each( function () {
1582
                $(this).pickup_locations_dropdown();
1606
                        $(this).pickup_locations_dropdown();
1583
            });
1607
                    });
1584
1608
1585
            $("#pickup_multi").select2({
1609
                    $("#pickup_multi").select2({
1586
                width: '30%',
1610
                        width: '30%',
1587
                allowClear: true
1611
                        allowClear: true
1588
            });
1612
                    });
1589
1613
1590
            $('.multi_pickup_select').select2({
1614
                    $('.multi_pickup_select').select2({
1591
                width: '100%',
1615
                        width: '100%',
1592
                allowClear: true
1616
                        allowClear: true
1593
            });
1617
                    });
1594
1618
1595
            $("#pickup_multi").on("change", function() {
1619
                    $("#pickup_multi").on("change", function() {
1596
                var selection = $(this).val();
1620
                        var selection = $(this).val();
1597
                if ( selection != '' ) {
1621
                        if ( selection != '' ) {
1598
                    $(".multi_pickup_select").each(function() {
1622
                            $(".multi_pickup_select").each(function() {
1599
                        var valid_pickup_locations = $(this).data('pickup-locations');
1623
                                var valid_pickup_locations = $(this).data('pickup-locations');
1600
                        if ( valid_pickup_locations.includes(selection) ) {
1624
                                if ( valid_pickup_locations.includes(selection) ) {
1601
                            $(this).val(selection);
1625
                                    $(this).val(selection);
1602
                            $(this).trigger("change");
1626
                                    $(this).trigger("change");
1627
                                }
1628
                            });
1603
                        }
1629
                        }
1604
                    });
1630
                    });
1605
                }
1606
            });
1607
1631
1608
            $("#pickup,#pickup-item-group,#pickup-next-avail").each( function () {
1632
                    $("#pickup,#pickup-item-group,#pickup-next-avail").each( function () {
1609
                $(this).pickup_locations_dropdown();
1633
                        $(this).pickup_locations_dropdown();
1610
            });
1634
                    });
1611
1612
            $(".pickup_locations").each(function () {
1613
                $(this).pickup_locations_dropdown();
1614
            });
1615
        });
1616
1635
1617
        function ToggleHoldsToPlace() {
1636
                    $(".pickup_locations").each(function () {
1618
            if ( $("#requestany").prop('checked') ) {
1637
                        $(this).pickup_locations_dropdown();
1619
                $(".disable_request_any").prop('disabled',true).addClass('disabled').removeClass('enabled');
1638
                    });
1620
                $(".enable_request_any").prop('disabled',false).removeClass('disabled').addClass('enabled');
1639
                });
1621
                $(".requestspecific,.requestgrp").prop('checked', false);
1622
            } else if( $(".requestspecific").prop('checked') ) {
1623
                $(".disable_request_specific").prop('disabled',true).addClass('disabled').removeClass('enabled');
1624
                $(".enable_request_specific").prop('disabled',false).removeClass('disabled').addClass('enabled');
1625
                $("#requestany,.requestgrp").prop('checked', false);
1626
            } else {
1627
                $(".disable_request_group").prop('disabled',true).addClass('disabled').removeClass('enabled');
1628
                $(".enable_request_group").prop('disabled',false).removeClass('disabled').addClass('enabled');
1629
                $("#requestany,.requestspecific").prop('checked', false);
1630
            }
1631
        }
1632
1640
1633
        $('.any_specific').click(function() {
1641
                function ToggleHoldsToPlace() {
1634
            const fieldset = $(this).find('fieldset:first');
1642
                    if ( $("#requestany").prop('checked') ) {
1635
1643
                        $(".disable_request_any").prop('disabled',true).addClass('disabled').removeClass('enabled');
1636
            if ( fieldset.hasClass('disabled') ) {
1644
                        $(".enable_request_any").prop('disabled',false).removeClass('disabled').addClass('enabled');
1637
                $('.enable_request_specific, .enable_request_any, .enable_request_group').removeClass('enabled');
1645
                        $(".requestspecific,.requestgrp").prop('checked', false);
1638
                const specific_cb = $(this).find('#requestspecificitem');
1646
                    } else if( $(".requestspecific").prop('checked') ) {
1639
                const any_cb = $(this).find('#requestany');
1647
                        $(".disable_request_specific").prop('disabled',true).addClass('disabled').removeClass('enabled');
1640
                const itemgroup_cb = $(this).find('#requestgrp');
1648
                        $(".enable_request_specific").prop('disabled',false).removeClass('disabled').addClass('enabled');
1641
1649
                        $("#requestany,.requestgrp").prop('checked', false);
1642
                if ( specific_cb.length ) {
1650
                    } else {
1643
                    specific_cb.prop('checked', true);
1651
                        $(".disable_request_group").prop('disabled',true).addClass('disabled').removeClass('enabled');
1644
                } else if ( any_cb.length ) {
1652
                        $(".enable_request_group").prop('disabled',false).removeClass('disabled').addClass('enabled');
1645
                    any_cb.prop('checked', true);
1653
                        $("#requestany,.requestspecific").prop('checked', false);
1646
                } else {
1654
                    }
1647
                    itemgroup_cb.prop('checked', true);
1648
                }
1655
                }
1649
1656
1650
                fieldset.removeClass('disabled').addClass('enabled');
1657
                $('.any_specific').click(function() {
1651
                ToggleHoldsToPlace();
1658
                    const fieldset = $(this).find('fieldset:first');
1652
            }
1659
1653
        });
1660
                    if ( fieldset.hasClass('disabled') ) {
1661
                        $('.enable_request_specific, .enable_request_any, .enable_request_group').removeClass('enabled');
1662
                        const specific_cb = $(this).find('#requestspecificitem');
1663
                        const any_cb = $(this).find('#requestany');
1664
                        const itemgroup_cb = $(this).find('#requestgrp');
1665
1666
                        if ( specific_cb.length ) {
1667
                            specific_cb.prop('checked', true);
1668
                        } else if ( any_cb.length ) {
1669
                            any_cb.prop('checked', true);
1670
                        } else {
1671
                            itemgroup_cb.prop('checked', true);
1672
                        }
1654
1673
1655
        function check( e, table ) {
1674
                        fieldset.removeClass('disabled').addClass('enabled');
1675
                        ToggleHoldsToPlace();
1676
                    }
1677
                });
1656
1678
1657
            var msg = "";
1679
                function check( e, table ) {
1658
1680
1659
            if ( $(".requestspecific").is(":checked") ) {
1681
                    var msg = "";
1660
                // requestany not selected, go through the item-specific cases
1661
                var selected_items = $('#requestspecific input[name="checkitem"]:checked');
1662
                if ( selected_items.length > 0 ) {
1663
                    // got item-specific hold requests in the form!
1664
                    // verify they have a pickup location selected
1665
1682
1666
                    if ( selected_items.closest('tr').find(".pickup_locations").val() == '' ) {
1683
                    if ( $(".requestspecific").is(":checked") ) {
1684
                        // requestany not selected, go through the item-specific cases
1685
                        var selected_items = $('#requestspecific input[name="checkitem"]:checked');
1686
                        if ( selected_items.length > 0 ) {
1687
                            // got item-specific hold requests in the form!
1688
                            // verify they have a pickup location selected
1667
1689
1668
                        msg = _("- Please select a pickup location for the item") + "\n"
1690
                            if ( selected_items.closest('tr').find(".pickup_locations").val() == '' ) {
1669
                    }
1691
1670
                }
1692
                                msg = _("- Please select a pickup location for the item") + "\n"
1671
                else {
1693
                            }
1672
                    msg = _("- Please select an item to place a hold") + "\n";
1694
                        }
1673
                }
1695
                        else {
1674
            } else if ( $("#requestgrp").is(":checked") ) {
1696
                            msg = _("- Please select an item to place a hold") + "\n";
1675
                var selected_group = $('#requestgroup input[type="radio"]:checked');
1697
                        }
1676
                if( selected_group.length > 0 ){
1698
                    } else if ( $("#requestgrp").is(":checked") ) {
1677
                    if( $("#pickup-item-group").length < 1 || $("#pickup-item-grp").val() == "" ){
1699
                        var selected_group = $('#requestgroup input[type="radio"]:checked');
1678
                        msg = _("- Please select a pickup location for this hold" + "\n");
1700
                        if( selected_group.length > 0 ){
1701
                            if( $("#pickup-item-group").length < 1 || $("#pickup-item-grp").val() == "" ){
1702
                                msg = _("- Please select a pickup location for this hold" + "\n");
1703
                            }
1704
                        } else {
1705
                            msg = (_("- Please select an item group to place a hold") + "\n");
1706
                        }
1707
                    } else {
1708
                        // Requesting next available
1709
                        if( $("#pickup-next-avail").length < 1 || $("#pickup-next-avail").val() == "" || $('#pickup-next-avail').val() === null ){
1710
                            msg = _("- Please select a pickup location for this hold") + "\n";
1711
                        }
1679
                    }
1712
                    }
1680
                } else {
1681
                    msg = (_("- Please select an item group to place a hold") + "\n");
1682
                }
1683
            } else {
1684
                // Requesting next available
1685
                if( $("#pickup-next-avail").length < 1 || $("#pickup-next-avail").val() == "" || $('#pickup-next-avail').val() === null ){
1686
                    msg = _("- Please select a pickup location for this hold") + "\n";
1687
                }
1688
            }
1689
1713
1690
1714
1691
            if (msg == "") {
1715
                    if (msg == "") {
1692
                $('#hold-request-form').preventDoubleFormSubmit();
1716
                        $('#hold-request-form').preventDoubleFormSubmit();
1693
                return(true);
1717
                        return(true);
1694
            } else {
1718
                    } else {
1695
                e.preventDefault();
1719
                        e.preventDefault();
1696
                alert(msg);
1720
                        alert(msg);
1697
                return(false);
1721
                        return(false);
1698
            }
1722
                    }
1699
        }
1723
                }
1700
1724
1701
        function checkMultiHold() {
1725
                function checkMultiHold() {
1702
1726
1703
            var selected_bibs = $(".multi_hold_item_checkbox:checked");
1727
                    var selected_bibs = $(".multi_hold_item_checkbox:checked");
1704
            if ( selected_bibs.length > 0 ) {
1728
                    if ( selected_bibs.length > 0 ) {
1705
                // there are biblios selected in the form!
1729
                        // there are biblios selected in the form!
1706
                // verify they have a pickup location selected
1730
                        // verify they have a pickup location selected
1707
1731
1708
                var pickup_not_set = 0;
1732
                        var pickup_not_set = 0;
1709
                selected_bibs.each(function() {
1733
                        selected_bibs.each(function() {
1710
                    if ( $(this).closest('tr').find(".multi_pickup_select").val() === "" ) {
1734
                            if ( $(this).closest('tr').find(".multi_pickup_select").val() === "" ) {
1711
                        pickup_not_set++;
1735
                                pickup_not_set++;
1736
                            }
1737
                            else {
1738
                                var bibnum = $(this).attr("title");
1739
                            }
1740
                        });
1741
                        if ( pickup_not_set > 0 ) {
1742
                            alert( _("Please make sure all selected titles have a pickup location set") + "\n" );
1743
                            return false;
1744
                        }
1712
                    }
1745
                    }
1713
                    else {
1746
                    else {
1714
                        var bibnum = $(this).attr("title");
1747
                        alert( _("Please select at least one title") + "\n" );
1748
                        return false;
1715
                    }
1749
                    }
1716
                });
1717
                if ( pickup_not_set > 0 ) {
1718
                    alert( _("Please make sure all selected titles have a pickup location set") + "\n" );
1719
                    return false;
1720
                }
1721
            }
1722
            else {
1723
                alert( _("Please select at least one title") + "\n" );
1724
                return false;
1725
            }
1726
1750
1727
            $('#hold-request-form').preventDoubleFormSubmit();
1751
                    $('#hold-request-form').preventDoubleFormSubmit();
1728
1752
1729
            return true;
1753
                    return true;
1730
        }
1754
                }
1731
1755
1732
         $(document).ready(function() {
1756
                 $(document).ready(function() {
1733
1757
1734
            $("#always_show_holds").change(function(){
1758
                    $("#always_show_holds").change(function(){
1735
                if( $(this).prop('checked') ){
1759
                        if( $(this).prop('checked') ){
1736
                    document.cookie = "always_show_holds=DO";
1760
                            document.cookie = "always_show_holds=DO";
1737
                } else {
1761
                        } else {
1738
                    document.cookie = "always_show_holds=DONT";
1762
                            document.cookie = "always_show_holds=DONT";
1739
                }
1763
                        }
1740
            });
1764
                    });
1741
            $("input.needsoverride").click(function() { // This must be before the radio button/checkbox switch logic
1765
                    $("input.needsoverride").click(function() { // This must be before the radio button/checkbox switch logic
1742
                var itemnumber = this.value;
1766
                        var itemnumber = this.value;
1743
                var msg = '';
1767
                        var msg = '';
1744
1768
1745
                switch (override_items[itemnumber].holdallowed) {
1769
                        switch (override_items[itemnumber].holdallowed) {
1746
                    case "not_allowed": msg = _("This item normally cannot be put on hold."); break;
1770
                            case "not_allowed": msg = _("This item normally cannot be put on hold."); break;
1747
                    case "from_home_library": msg = _("This item normally cannot be put on hold except for patrons from %s.").format(override_items[itemnumber].homebranch); break;
1771
                            case "from_home_library": msg = _("This item normally cannot be put on hold except for patrons from %s.").format(override_items[itemnumber].homebranch); break;
1748
                }
1772
                        }
1749
1773
1750
                msg += "\n\n" + _("Place hold on this item?");
1774
                        msg += "\n\n" + _("Place hold on this item?");
1751
1775
1752
                return confirm(msg);
1776
                        return confirm(msg);
1753
            });
1777
                    });
1754
            $("button.warning").click(function() {
1778
                    $("button.warning").click(function() {
1755
                return confirm( _("None of these items can normally be put on hold for this patron.") + "\n\n" + _("Place hold?") );
1779
                        return confirm( _("None of these items can normally be put on hold for this patron.") + "\n\n" + _("Place hold?") );
1756
            });
1780
                    });
1757
            var prev_rank_request;
1781
                    var prev_rank_request;
1758
            $("select[name=rank-request]").on("focus", function() {
1782
                    $("select[name=rank-request]").on("focus", function() {
1759
                prev_rank_request = $(this).val();
1783
                        prev_rank_request = $(this).val();
1760
                var row = $(this).parents("tr:first");
1784
                        var row = $(this).parents("tr:first");
1761
            }).change(function() {
1785
                    }).change(function() {
1762
                var row = $(this).parents("tr:first");
1786
                        var row = $(this).parents("tr:first");
1763
                var value = parseInt($(this).val());
1787
                        var value = parseInt($(this).val());
1764
                var found_holds = $("select[name='rank-request'][disabled='disabled']").length ; //Count how many are found
1788
                        var found_holds = $("select[name='rank-request'][disabled='disabled']").length ; //Count how many are found
1765
                if( !isNaN(value) ) {  //If moved to 'del'
1789
                        if( !isNaN(value) ) {  //If moved to 'del'
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)
1790
                            var after = row.parent().find(`tr:nth-child(${value+found_holds})`); //Go to the row 1 after the new value (and skip found holds)
1767
                    if (prev_rank_request > value) {
1791
                            if (prev_rank_request > value) {
1768
                        row.insertBefore(after);
1792
                                row.insertBefore(after);
1769
                    } else {
1793
                            } else {
1770
                        row.insertAfter(after);
1794
                                row.insertAfter(after);
1771
                    }
1795
                            }
1772
                }
1796
                        }
1773
1797
1774
                var next_priority = 1;
1798
                        var next_priority = 1;
1775
                $("select[name=rank-request]").each(function () {
1799
                        $("select[name=rank-request]").each(function () {
1776
                    if( isNaN( $(this).val() ) ){ return true; } //Don't reset found or del holds
1800
                            if( isNaN( $(this).val() ) ){ return true; } //Don't reset found or del holds
1777
                    $(this).val(next_priority);
1801
                            $(this).val(next_priority);
1778
                    next_priority++;
1802
                            next_priority++;
1779
                });
1803
                        });
1780
            });
1804
                    });
1781
1805
1782
            $(".clear-date").on("click",function(e){
1806
                    $(".clear-date").on("click",function(e){
1783
                e.preventDefault();
1807
                        e.preventDefault();
1784
                var fieldID = this.id.replace("clear-date-","");
1808
                        var fieldID = this.id.replace("clear-date-","");
1785
                $("#" + fieldID).val("");
1809
                        $("#" + fieldID).val("");
1786
            });
1810
                    });
1787
1811
1788
            // Confirm cancellation of hold
1812
                    // Confirm cancellation of hold
1789
            let cancel_link;
1813
                    let cancel_link;
1790
            $(".cancel-hold").on("click",function(e) {
1814
                    $(".cancel-hold").on("click",function(e) {
1791
                e.preventDefault;
1815
                        e.preventDefault;
1792
                cancel_link = $(this);
1816
                        cancel_link = $(this);
1793
                $("#cancel_modal_form #inputs").empty();
1817
                        $("#cancel_modal_form #inputs").empty();
1794
                    let reserve_id = cancel_link.data('id');
1818
                            let reserve_id = cancel_link.data('id');
1795
                    let biblionumber = cancel_link.data('biblionumber');
1819
                            let biblionumber = cancel_link.data('biblionumber');
1796
                    $("#cancel_modal_form #inputs").append('<input type="hidden" name="reserve_id" value="' + reserve_id + '">');
1820
                            $("#cancel_modal_form #inputs").append('<input type="hidden" name="reserve_id" value="' + reserve_id + '">');
1797
                    $("#cancel_modal_form #inputs").append('<input type="hidden" name="biblionumber" value="' + biblionumber + '">');
1821
                            $("#cancel_modal_form #inputs").append('<input type="hidden" name="biblionumber" value="' + biblionumber + '">');
1798
                    $("#cancel_modal_form #inputs").append('<input type="hidden" name="op" value="cud-cancel">');
1822
                            $("#cancel_modal_form #inputs").append('<input type="hidden" name="op" value="cud-cancel">');
1799
                $('#cancelModal').modal('show');
1823
                        $('#cancelModal').modal('show');
1800
                return false;
1824
                        return false;
1801
            });
1825
                    });
1802
1826
1803
            [% UNLESS ( patron || patron.borrowernumber || borrowers || noitems || nobiblio ) %]
1827
                    [% UNLESS ( patron || patron.borrowernumber || borrowers || noitems || nobiblio ) %]
1804
                [% IF ( PatronAutoComplete ) %]
1828
                        [% IF ( PatronAutoComplete ) %]
1805
                    patron_autocomplete($(".search_patron_filter"), { 'link-to': 'reserve', 'url-params': '[% url_biblio_params | url %]' });
1829
                            patron_autocomplete($(".search_patron_filter"), { 'link-to': 'reserve', 'url-params': '[% url_biblio_params | url %]' });
1806
                [% END %]
1830
                        [% END %]
1807
            [% END %]
1831
                    [% END %]
1808
1832
1809
            [% IF Koha.Preference('EnableItemGroupHolds') %]
1833
                    [% IF Koha.Preference('EnableItemGroupHolds') %]
1810
                $(':radio[name="item_group_id"]').change(function(){
1834
                        $(':radio[name="item_group_id"]').change(function(){
1811
                    $('input[name="checkitem"]').prop('checked', false);
1835
                            $('input[name="checkitem"]').prop('checked', false);
1812
                });
1836
                        });
1813
1837
1814
                $('input[name="checkitem"]').change(function(){
1838
                        $('input[name="checkitem"]').change(function(){
1815
                    $(':radio[name="item_group_id"]').prop('checked', false);
1839
                            $(':radio[name="item_group_id"]').prop('checked', false);
1816
                });
1840
                        });
1817
            [% END %]
1841
                    [% END %]
1818
1842
1819
            if(!localStorage.selectedHolds  || document.referrer.replace(/\?.*/, '') !== document.location.origin+document.location.pathname) {
1843
                    if(!localStorage.selectedHolds  || document.referrer.replace(/\?.*/, '') !== document.location.origin+document.location.pathname) {
1820
                localStorage.selectedHolds = [];
1844
                        localStorage.selectedHolds = [];
1821
            }
1845
                    }
1822
1846
1823
            $('.holds_table .select_hold').each(function() {
1847
                    $('.holds_table .select_hold').each(function() {
1824
                if(localStorage.selectedHolds.includes($(this).data('id'))) {
1848
                        if(localStorage.selectedHolds.includes($(this).data('id'))) {
1825
                    $(this).prop('checked', true);
1849
                            $(this).prop('checked', true);
1826
                }
1850
                        }
1827
            });
1851
                    });
1828
1852
1829
            $('.holds_table .select_hold_all').each(function() {
1853
                    $('.holds_table .select_hold_all').each(function() {
1830
                var table = $(this).parents('.holds_table');
1854
                        var table = $(this).parents('.holds_table');
1831
                var count = $('.select_hold:not(:checked)', table).length;
1855
                        var count = $('.select_hold:not(:checked)', table).length;
1832
                $('.select_hold_all', table).prop('checked', !count);
1856
                        $('.select_hold_all', table).prop('checked', !count);
1833
            });
1857
                    });
1834
1858
1835
            $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
1859
                    $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
1836
1860
1837
            $('.holds_table .select_hold_all').click(function() {
1861
                    $('.holds_table .select_hold_all').click(function() {
1838
                var table = $(this).parents('.holds_table');
1862
                        var table = $(this).parents('.holds_table');
1839
                var count = $('.select_hold:checked', table).length;
1863
                        var count = $('.select_hold:checked', table).length;
1840
                $('.select_hold', table).prop('checked', !count);
1864
                        $('.select_hold', table).prop('checked', !count);
1841
                $(this).prop('checked', !count);
1865
                        $(this).prop('checked', !count);
1842
                $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
1866
                        $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
1843
                $('#cancel_hold_alert').html( MSG_CANCEL_ALERT.format($('.holds_table .select_hold:checked').length));
1867
                        $('#cancel_hold_alert').html( MSG_CANCEL_ALERT.format($('.holds_table .select_hold:checked').length));
1844
                $('#cancel_hold_alert').show();
1868
                        $('#cancel_hold_alert').show();
1845
                localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'));
1869
                        localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'));
1846
            });
1870
                    });
1847
1871
1848
            $('.holds_table .select_hold').click(function() {
1872
                    $('.holds_table .select_hold').click(function() {
1849
                var table = $(this).parents('.holds_table');
1873
                        var table = $(this).parents('.holds_table');
1850
                var count = $('.select_hold:not(:checked)', table).length;
1874
                        var count = $('.select_hold:not(:checked)', table).length;
1851
                $('.select_hold_all', table).prop('checked', !count);
1875
                        $('.select_hold_all', table).prop('checked', !count);
1852
                $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
1876
                        $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
1853
                $('#cancel_hold_alert').html( MSG_CANCEL_ALERT.format($('.holds_table .select_hold:checked').length));
1877
                        $('#cancel_hold_alert').html( MSG_CANCEL_ALERT.format($('.holds_table .select_hold:checked').length));
1854
                $('#cancel_hold_alert').show();
1878
                        $('#cancel_hold_alert').show();
1855
                localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'));
1879
                        localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'));
1856
            });
1880
                    });
1857
1881
1858
            $('.cancel_selected_holds').click(function(e) {
1882
                    $('.cancel_selected_holds').click(function(e) {
1859
                e.preventDefault();
1883
                        e.preventDefault();
1860
                if($('.holds_table .select_hold:checked').length) {
1884
                        if($('.holds_table .select_hold:checked').length) {
1861
                    cancel_link = $(this);
1885
                            cancel_link = $(this);
1862
                    $("#cancel_modal_form #inputs").empty();
1886
                            $("#cancel_modal_form #inputs").empty();
1863
                    biblionumbers.forEach( function(biblionumber){
1887
                            biblionumbers.forEach( function(biblionumber){
1864
                        $("#cancel_modal_form #inputs").append('<input type="hidden" name="biblionumber" value="'+biblionumber+'">');
1888
                                $("#cancel_modal_form #inputs").append('<input type="hidden" name="biblionumber" value="'+biblionumber+'">');
1889
                            });
1890
                            $("#cancel_modal_form #inputs").append('<input type="hidden" name="op" value="cud-cancel_bulk">');
1891
                            let hold_ids= $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')).join(',');
1892
                            $("#cancel_modal_form #inputs").append('<input type="hidden" name="ids" value="' + hold_ids + '">');
1893
                            delete localStorage.selectedHolds;
1894
                            $('#cancelModal').modal('show');
1895
                        }
1896
                        return false;
1865
                    });
1897
                    });
1866
                    $("#cancel_modal_form #inputs").append('<input type="hidden" name="op" value="cud-cancel_bulk">');
1867
                    let hold_ids= $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')).join(',');
1868
                    $("#cancel_modal_form #inputs").append('<input type="hidden" name="ids" value="' + hold_ids + '">');
1869
                    delete localStorage.selectedHolds;
1870
                    $('#cancelModal').modal('show');
1871
                }
1872
                return false;
1873
            });
1874
1898
1875
            $(".hold-arrow").click(function(e) {
1899
                    $(".hold-arrow").click(function(e) {
1876
                e.preventDefault();
1900
                        e.preventDefault();
1877
                let arrowForm = $("#hold-actions-form").attr({
1901
                        let arrowForm = $("#hold-actions-form").attr({
1878
                    action: 'request.pl',
1902
                            action: 'request.pl',
1879
                    method: 'post'
1903
                            method: 'post'
1880
                });
1904
                        });
1881
                let arrow_op = $("<input />").attr({
1905
                        let arrow_op = $("<input />").attr({
1882
                    name: 'op',
1906
                            name: 'op',
1883
                    type: 'hidden',
1907
                            type: 'hidden',
1884
                    value: $(this).data('op')
1908
                            value: $(this).data('op')
1885
                });
1909
                        });
1886
                let arrow_where = $("<input />").attr({
1910
                        let arrow_where = $("<input />").attr({
1887
                    name: 'where',
1911
                            name: 'where',
1888
                    type: 'hidden',
1912
                            type: 'hidden',
1889
                    value: $(this).data('where')
1913
                            value: $(this).data('where')
1890
                });
1914
                        });
1891
                let arrow_fp = $("<input />").attr({
1915
                        let arrow_fp = $("<input />").attr({
1892
                    name: 'first_priority',
1916
                            name: 'first_priority',
1893
                    type: 'hidden',
1917
                            type: 'hidden',
1894
                    value: $(this).data('first_priority')
1918
                            value: $(this).data('first_priority')
1895
                });
1919
                        });
1896
                let arrow_lp = $("<input />").attr({
1920
                        let arrow_lp = $("<input />").attr({
1897
                    name: 'last_priority',
1921
                            name: 'last_priority',
1898
                    type: 'hidden',
1922
                            type: 'hidden',
1899
                    value: $(this).data('last_priority')
1923
                            value: $(this).data('last_priority')
1900
                });
1924
                        });
1901
                let arrow_pp = $("<input />").attr({
1925
                        let arrow_pp = $("<input />").attr({
1902
                    name: 'prev_priority',
1926
                            name: 'prev_priority',
1903
                    type: 'hidden',
1927
                            type: 'hidden',
1904
                    value: $(this).data('prev_priority')
1928
                            value: $(this).data('prev_priority')
1905
                });
1929
                        });
1906
                let arrow_np = $("<input />").attr({
1930
                        let arrow_np = $("<input />").attr({
1907
                    name: 'next_priority',
1931
                            name: 'next_priority',
1908
                    type: 'hidden',
1932
                            type: 'hidden',
1909
                    value: $(this).data('next_priority')
1933
                            value: $(this).data('next_priority')
1910
                });
1934
                        });
1911
                let arrow_bn = $("<input />").attr({
1935
                        let arrow_bn = $("<input />").attr({
1912
                    name: 'borrowernumber',
1936
                            name: 'borrowernumber',
1913
                    type: 'hidden',
1937
                            type: 'hidden',
1914
                    value: $(this).data('borrowernumber')
1938
                            value: $(this).data('borrowernumber')
1915
                });
1939
                        });
1916
                let arrow_bb = $("<input />").attr({
1940
                        let arrow_bb = $("<input />").attr({
1917
                    name: 'biblionumber',
1941
                            name: 'biblionumber',
1918
                    type: 'hidden',
1942
                            type: 'hidden',
1919
                    value: $(this).data('biblionumber')
1943
                            value: $(this).data('biblionumber')
1920
                });
1944
                        });
1921
                let arrow_ri = $("<input />").attr({
1945
                        let arrow_ri = $("<input />").attr({
1922
                    name: 'reserve_id',
1946
                            name: 'reserve_id',
1923
                    type: 'hidden',
1947
                            type: 'hidden',
1924
                    value: $(this).data('reserve_id')
1948
                            value: $(this).data('reserve_id')
1925
                });
1949
                        });
1926
                let arrow_date = $("<input />").attr({
1950
                        let arrow_date = $("<input />").attr({
1927
                    name: 'date',
1951
                            name: 'date',
1928
                    type: 'hidden',
1952
                            type: 'hidden',
1929
                    value: $(this).data('date')
1953
                            value: $(this).data('date')
1954
                        });
1955
                        arrowForm.append(arrow_op,arrow_where,arrow_fp,arrow_lp,arrow_pp,arrow_np,arrow_bn,arrow_bb,arrow_ri,arrow_date);
1956
                        $("#hold-actions-form").submit();
1957
                        return true;
1958
                    })
1930
                });
1959
                });
1931
                arrowForm.append(arrow_op,arrow_where,arrow_fp,arrow_lp,arrow_pp,arrow_np,arrow_bn,arrow_bb,arrow_ri,arrow_date);
1932
                $("#hold-actions-form").submit();
1933
                return true;
1934
            })
1935
        });
1936
    </script>
1960
    </script>
1937
    <script>
1961
    <script>
1938
        table_settings = [% TablesSettings.GetTableSettings( 'circ', 'circulation', 'table_borrowers', 'json' ) | $raw %];
1962
        table_settings = [% TablesSettings.GetTableSettings( 'circ', 'circulation', 'table_borrowers', 'json' ) | $raw %];
1939
- 

Return to bug 39371