https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42713

--- Comment #1 from Christopher Brannon <[email protected]> ---
Here is our jQuery workaround for the time being:

  //Make Overdue Triggers easier to setup and change
  if ($('#tools_overduerules').length) {
    // 1. Find your original dropdown, clone it, and change its ID to avoid
duplicates
    var $branchDropdown = $('#branch').clone().attr('id', 'savetobranch');
    // 2. Append the label and the cloned dropdown to your fieldset
    $('fieldset.action').append(' Save rules to: ').append($branchDropdown);
    // 3. Keep the clone in sync with the current branch input
    var initialBranch = $('input[name="branch"]').val();
    if (initialBranch) {
      $branchDropdown.val(initialBranch);
    }
    // 4. Update the hidden input whenever the cloned dropdown changes
    $branchDropdown.on('change', function() {
      $('input[name="branch"]').val($(this).val());
    });
    //Quick Fill Columns
    // ==========================================
    // 1. Structural Column Injection Framework
    // ==========================================
    $('.overduerulest').on('draw.dt init.dt', function(e, settings) { 
        var api = new $.fn.dataTable.Api(settings); 
        var $table = $(api.table().node());
        // --- Delay Control Injection (Column 2) ---
        var $delayHeader = $table.find('thead th:nth-child(2)');
        if ($delayHeader.length &&
$delayHeader.find('.delay-control-wrap').length === 0) {
            $delayHeader.append('<div class="delay-control-wrap"><br><input
type="search" class="delay-all-input" placeholder="Type to set all..."
style="width: 90%;"></div>');
        }
        // --- Letter Control Injection (Column 3) ---
        var $letterHeader = $table.find('thead th:nth-child(3)');
        if ($letterHeader.length &&
$letterHeader.find('.dropdown-control-wrap').length === 0) {
            var $firstRowDropdown = $table.find('tbody tr:first-child
td:nth-child(3) select');
            var optionsHtml = $firstRowDropdown.length ?
$firstRowDropdown.html() : '<option value="A">A</option><option
value="B">B</option>';
            $letterHeader.append('<div
class="dropdown-control-wrap"><br><select class="dropdown-all-select"
style="max-width:100%;"><option value="">--Select--</option>' + optionsHtml +
'</select></div>');
        }
        // --- Self-Adjusting Checkbox Controls Injection (Column 4 up to Total
Columns) ---
        var totalColumns = $table.find('thead th').length;
        // Start at column 4, and stop automatically based on the actual number
of columns present
        for (var colNum = 4; colNum <= totalColumns; colNum++) {
            var $cbHeader = $table.find('thead th:nth-child(' + colNum + ')');

            if ($cbHeader.length && $cbHeader.find('.checkbox-btn-wrap').length
=== 0) {
                $cbHeader.append(
                    '<div class="checkbox-btn-wrap" style="font-size: 11px;
margin-top: 4px; font-weight: normal; white-space: nowrap;">' +
                        '<span class="master-cb-select-all"
style="cursor:pointer; color: #007bff; text-decoration: underline;">All</span>'
+
                        ' | ' +
                        '<span class="master-cb-clear-all"
style="cursor:pointer; color: #dc3545; text-decoration:
underline;">Clear</span>' +
                    '</div>'
                );
            }
        }
    });
    // ==========================================
    // 2. Instant Action Event Handlers
    // ==========================================
    // Instant Handler for Delay input (Triggers as you type)
    $(document).on('input', '.delay-all-input', function() { 
        var $input = $(this); 
        var targetValue = $input.val(); 
        var $table = $input.closest('table.overduerulest'); 
        var colIndex = $input.closest('th').index() + 1;

        $table.find('tbody tr td:nth-child(' + colIndex + ')
input').val(targetValue); 
    });
    // Instant Handler for Letter dropdown element (Triggers on selection)
    $(document).on('change', '.dropdown-all-select', function() {
        var $select = $(this);
        var targetValue = $select.val();
        var $table = $select.closest('table.overduerulest');
        var colIndex = $select.closest('th').index() + 1;
        $table.find('tbody tr td:nth-child(' + colIndex + ')
select').val(targetValue).change();
    });
    // Click Handler for "Select All" buttons (Dynamic Columns 4+)
    $(document).on('click', '.master-cb-select-all', function() {
        var $clickedBtn = $(this);
        var $table = $clickedBtn.closest('table.overduerulest');
        var colIndex = $clickedBtn.closest('th').index() + 1;
        $table.find('tbody tr td:nth-child(' + colIndex + ')
input[type="checkbox"]').each(function() {
            $(this).prop('checked', true).change();
        });
    });
    // Click Handler for "Clear All" buttons (Dynamic Columns 4+)
    $(document).on('click', '.master-cb-clear-all', function() {
        var $clickedBtn = $(this);
        var $table = $clickedBtn.closest('table.overduerulest');
        var colIndex = $clickedBtn.closest('th').index() + 1;
        $table.find('tbody tr td:nth-child(' + colIndex + ')
input[type="checkbox"]').each(function() {
            $(this).prop('checked', false).change();
        });
    });
    //Add Clear All button
    // 1. Target your existing submit button and insert the clear button right
after it
    var $submitBtn = $('form input[value="Save changes"], form
button[type="submit"]');

    if ($submitBtn.length && $('#clear-all-tables-btn').length === 0) {
        $submitBtn.after('<button type="button" id="clear-all-tables-btn"
class="btn btn-secondary" style="margin-left: 10px;">Clear All
Tables</button>');
    }

    // 2. Global Clear Button Click Event
    $(document).on('click', '#clear-all-tables-btn', function() {
        // Clear all top header control inputs
        $('.delay-all-input').val('');
        $('.master-cb-clear-all').click();
        $('.dropdown-all-select option').filter(function() {
          return $(this).text() === 'No notice';
        }).prop('selected', true).trigger('change');

        // Clear all inputs inside the table bodies
        $('table.overduerulest tbody tr input').val('');
    });
  }
  //END Make Overdue Triggers easier to setup and change

-- 
You are receiving this mail because:
You are watching all bug changes.
You are the assignee for the bug.
_______________________________________________
Koha-bugs mailing list
[email protected]
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to