Skip to content

Drop in javascript for your tables

Josh Brody edited this page May 4, 2019 · 1 revision

This isn't fool-proof but it was good enough(TM) for my use.

$(document).ready(function() {
    $('.active_actions_selection').on('change', function() {
        if($(this).is(':checked')) {
            $(this).closest('tr').addClass('table-success');
        } else {
            $(this).closest('tr').removeClass('table-success');
            $('.active_actions_select_all').prop('checked', false);
        }
        if($('.active_actions_selection:checked').length > 0) {
            $('.active_actions_button').removeAttr('disabled');
        } else {
            $('.active_actions_button').attr('disabled', 'disabled');
        }
    });
    $('.active_actions_select_all').on('change', function() {
        if($(this).is(':checked')) {
            $(this).closest('table').find('input:checkbox').not(this).prop('checked', this.checked);
            $(this).closest('table').find('tbody tr').addClass('table-success');
            $('.active_actions_button').removeAttr('disabled');
        } else {
            $(this).closest('table').find('input:checkbox').not(this).prop('checked', false);
            $(this).closest('table').find('tbody tr').removeClass('table-success');
            $('.active_actions_button').attr('disabled', 'disabled');
        }
    })
    $('.active_action').on('click', function() {
        var form = $(this).closest('form');
        form.attr('action', form.attr('action') + "/" + $(this).attr('data-action'));
        form.submit();
    });
})
Clone this wiki locally