HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall_new/buyercall/buyercall/assets/scripts/bulk-delete.js
var pluralize = require('./pluralize');

class BulkDelete {
    constructor() {
        this.body = $('body');

        this.selectAll = '#select_all';
        this.checkedItems = '.checkbox-item';

        this.colHeader = '.col-header';
        this.selectedRow = 'warning';

        this.updateScope = '#scope';
        this.bulkActions = '#bulk_actions';
    }

    listenForEvents() {
        var self = this;

        this.body.on('change', this.checkedItems, function () {
            var checkedSelector = `${self.checkedItems}:checked`;
            var itemCount = $(checkedSelector).length;
            var pluralizeItem = pluralize('item', itemCount);
            var scopeOptionText = `${itemCount} selected ${pluralizeItem}`;

            if ($(this).is(':checked')) {
                $(this).closest('tr').addClass(self.selectedRow);

                $(self.colHeader).hide();
                $(self.bulkActions).show();
            }
            else {
                $(this).closest('tr').removeClass(self.selectedRow);

                if (itemCount === 0) {
                    $(self.bulkActions).hide();
                    $(self.colHeader).show();
                }
            }

            $(`${self.updateScope} option:first`).text(scopeOptionText)
        });

        this.body.on('change', this.selectAll, function () {
            var checkedStatus = this.checked;

            $(self.checkedItems).each(function () {
                $(this).prop('checked', checkedStatus);
                $(this).trigger('change');
            });
        });
    }
}

module.exports = BulkDelete;