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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-3 / +177 lines)
Lines 1441-1449 Link Here
1441
    [% INCLUDE 'datatables.inc' %]
1441
    [% INCLUDE 'datatables.inc' %]
1442
    [% INCLUDE 'calendar.inc' %]
1442
    [% INCLUDE 'calendar.inc' %]
1443
    [% INCLUDE 'format_price.inc' %]
1443
    [% INCLUDE 'format_price.inc' %]
1444
    <style>
1445
        #default-circulation-rules_wrapper .top {
1446
            margin-bottom: 1em;
1447
            display: flex;
1448
            gap: 1em;
1449
            align-items: center;
1450
            flex-wrap: wrap;
1451
        }
1452
        #default-circulation-rules_wrapper .dt-buttons {
1453
            display: flex;
1454
            flex-wrap: wrap;
1455
            gap: 0.5em;
1456
            align-items: center;
1457
            padding: 0.5em;
1458
            background-color: #f8f9fa;
1459
            border: 1px solid #dee2e6;
1460
            border-radius: 4px;
1461
            order: -1; /* Place on the left */
1462
        }
1463
        #default-circulation-rules_wrapper .dt-buttons button {
1464
            margin: 0 !important;
1465
            white-space: nowrap;
1466
        }
1467
        /* Hide the clear filter button since we disabled search */
1468
        #default-circulation-rules_wrapper .dt_button_clear_filter {
1469
            display: none !important;
1470
        }
1471
    </style>
1444
    <script>
1472
    <script>
1445
        $(document).ready(function () {
1473
        $(document).ready(function () {
1446
            $("#default-circulation-rules").kohaTable({
1474
            // Calculate column indices dynamically based on enabled preferences
1475
            let colIndex = 6; // Start after Note column (0-5 are: hidden, patron category, hidden, item type, actions, note)
1476
            const columnGroups = {
1477
                checkout: { start: colIndex, end: colIndex + 4 }, // 5 columns: checkouts, on-site, loan period, days mode, unit
1478
            };
1479
            colIndex += 5;
1480
1481
            columnGroups.dueDate = { start: colIndex, end: colIndex + 1 }; // 2 columns: hard due date, decreased loan
1482
            colIndex += 2;
1483
1484
            columnGroups.fines = { start: colIndex, end: colIndex + 9 }; // 10 columns: fine settings
1485
            colIndex += 10;
1486
1487
            columnGroups.renewals = { start: colIndex, end: colIndex + 6 }; // Base 7 columns
1488
            [% IF Koha.Preference('UnseenRenewals') %]
1489
                columnGroups.renewals.end += 1; // Add 1 for unseen renewals
1490
                colIndex += 8;
1491
            [% ELSE %]
1492
                colIndex += 7;
1493
            [% END %]
1494
1495
            columnGroups.holds = { start: colIndex, end: colIndex + 5 }; // 6 columns: holds settings
1496
            colIndex += 6;
1497
1498
            [% IF Koha.Preference('ArticleRequests') %]
1499
                columnGroups.articleRequests = { start: colIndex, end: colIndex };
1500
                colIndex += 1;
1501
            [% END %]
1502
1503
            columnGroups.rental = { start: colIndex, end: colIndex };
1504
            colIndex += 1;
1505
1506
            [% IF Koha.Preference('UseRecalls') %]
1507
                columnGroups.recalls = { start: colIndex, end: colIndex + 5 }; // 6 columns: recalls settings
1508
                colIndex += 6;
1509
            [% END %]
1510
1511
            // Helper to create range arrays
1512
            const range = (start, end) => Array.from({length: end - start + 1}, (_, i) => i + start);
1513
1514
            // Initialize the table first with kohaTable
1515
            var table = $("#default-circulation-rules").kohaTable({
1447
                columnDefs: [
1516
                columnDefs: [
1448
                    { visible: false, targets: [0, 2] },
1517
                    { visible: false, targets: [0, 2] },
1449
                    { orderable: false, targets: ["_all"] },
1518
                    { orderable: false, targets: ["_all"] },
Lines 1455-1462 Link Here
1455
                    [3, "asc"],
1524
                    [3, "asc"],
1456
                ],
1525
                ],
1457
                paging: false,
1526
                paging: false,
1458
                autoWidth: false,
1527
                searching: false,
1528
                autoWidth: false
1529
            });
1530
1531
            // Get the DataTables API instance
1532
            var dtApi = table.DataTable();
1533
1534
            // Add our custom column visibility buttons
1535
            const visibilityButtons = [
1536
                {
1537
                    text: 'Checkouts',
1538
                    className: 'btn btn-sm btn-default',
1539
                    action: function (e, dt, node, config) {
1540
                        dt.columns().visible(false);
1541
                        dt.columns([1, 3, 4, 5].concat(range(columnGroups.checkout.start, columnGroups.checkout.end)).concat([dt.columns()[0].length - 1])).visible(true);
1542
                    }
1543
                },
1544
                {
1545
                    text: 'Due dates',
1546
                    className: 'btn btn-sm btn-default',
1547
                    action: function (e, dt, node, config) {
1548
                        dt.columns().visible(false);
1549
                        dt.columns([1, 3, 4, 5].concat(range(columnGroups.dueDate.start, columnGroups.dueDate.end)).concat([dt.columns()[0].length - 1])).visible(true);
1550
                    }
1551
                },
1552
                {
1553
                    text: 'Fines',
1554
                    className: 'btn btn-sm btn-default',
1555
                    action: function (e, dt, node, config) {
1556
                        dt.columns().visible(false);
1557
                        dt.columns([1, 3, 4, 5].concat(range(columnGroups.fines.start, columnGroups.fines.end)).concat([dt.columns()[0].length - 1])).visible(true);
1558
                    }
1559
                },
1560
                {
1561
                    text: 'Renewals',
1562
                    className: 'btn btn-sm btn-default',
1563
                    action: function (e, dt, node, config) {
1564
                        dt.columns().visible(false);
1565
                        dt.columns([1, 3, 4, 5].concat(range(columnGroups.renewals.start, columnGroups.renewals.end)).concat([dt.columns()[0].length - 1])).visible(true);
1566
                    }
1567
                },
1568
                {
1569
                    text: 'Holds',
1570
                    className: 'btn btn-sm btn-default',
1571
                    action: function (e, dt, node, config) {
1572
                        dt.columns().visible(false);
1573
                        dt.columns([1, 3, 4, 5].concat(range(columnGroups.holds.start, columnGroups.holds.end)).concat([dt.columns()[0].length - 1])).visible(true);
1574
                    }
1575
                }
1576
            ];
1577
1578
            [% IF Koha.Preference('ArticleRequests') %]
1579
            visibilityButtons.push({
1580
                text: 'Article requests',
1581
                className: 'btn btn-sm btn-default',
1582
                action: function (e, dt, node, config) {
1583
                    dt.columns().visible(false);
1584
                    dt.columns([1, 3, 4, 5, columnGroups.articleRequests.start, dt.columns()[0].length - 1]).visible(true);
1585
                }
1586
            });
1587
            [% END %]
1588
1589
            [% IF Koha.Preference('UseRecalls') %]
1590
            visibilityButtons.push({
1591
                text: 'Recalls',
1592
                className: 'btn btn-sm btn-default',
1593
                action: function (e, dt, node, config) {
1594
                    dt.columns().visible(false);
1595
                    dt.columns([1, 3, 4, 5].concat(range(columnGroups.recalls.start, columnGroups.recalls.end)).concat([dt.columns()[0].length - 1])).visible(true);
1596
                }
1459
            });
1597
            });
1598
            [% END %]
1599
1600
            // Add 'Show all' button at the end
1601
            visibilityButtons.push({
1602
                text: 'Show all',
1603
                className: 'btn btn-sm btn-default',
1604
                action: function (e, dt, node, config) {
1605
                    dt.columns().visible(true);
1606
                    dt.columns([0, 2]).visible(false); // Keep sorting columns hidden
1607
                }
1608
            });
1609
1610
            // Create a button container
1611
            var buttonContainer = $('<div class="dt-buttons"></div>');
1612
1613
            // Add each button manually
1614
            visibilityButtons.forEach(function(buttonConfig) {
1615
                var button = $('<button type="button"></button>')
1616
                    .addClass(buttonConfig.className)
1617
                    .text(buttonConfig.text)
1618
                    .on('click', function() {
1619
                        // Remove active class from all buttons
1620
                        buttonContainer.find('button').removeClass('btn-primary').addClass('btn-default');
1621
                        // Add active class to clicked button
1622
                        $(this).removeClass('btn-default').addClass('btn-primary');
1623
                        // Execute the button action
1624
                        buttonConfig.action(null, dtApi, $(this), buttonConfig);
1625
                    });
1626
                buttonContainer.append(button);
1627
            });
1628
1629
            // Insert into the top area
1630
            var wrapper = $('#default-circulation-rules_wrapper');
1631
            wrapper.find('.top').append(buttonContainer);
1632
1633
            // Default to Checkouts view on page load
1634
            buttonContainer.find('button:first').trigger('click');
1460
        });
1635
        });
1461
1636
1462
        function clear_edit() {
1637
        function clear_edit() {
1463
- 

Return to bug 41439