diff --git a/resources/assets/js/components/permissions-table.js b/resources/assets/js/components/permissions-table.js index 96d95bb3d..baad75258 100644 --- a/resources/assets/js/components/permissions-table.js +++ b/resources/assets/js/components/permissions-table.js @@ -13,6 +13,12 @@ class PermissionsTable { for (let toggleRowElem of toggleRowElems) { toggleRowElem.addEventListener('click', this.toggleRowClick.bind(this)); } + + // Handle toggle column event + const toggleColumnElems = elem.querySelectorAll('[permissions-table-toggle-all-in-column]'); + for (let toggleColElem of toggleColumnElems) { + toggleColElem.addEventListener('click', this.toggleColumnClick.bind(this)); + } } toggleAllClick(event) { @@ -25,10 +31,31 @@ class PermissionsTable { this.toggleAllInElement(event.target.closest('tr')); } + toggleColumnClick(event) { + event.preventDefault(); + + const tableCell = event.target.closest('th,td'); + const colIndex = Array.from(tableCell.parentElement.children).indexOf(tableCell); + const tableRows = tableCell.closest('table').querySelectorAll('tr'); + const inputsToToggle = []; + + for (let row of tableRows) { + const targetCell = row.children[colIndex]; + if (targetCell) { + inputsToToggle.push(...targetCell.querySelectorAll('input[type=checkbox]')); + } + } + this.toggleAllInputs(inputsToToggle); + } + toggleAllInElement(domElem) { - const inputsToSelect = domElem.querySelectorAll('input[type=checkbox]'); - const currentState = inputsToSelect.length > 0 ? inputsToSelect[0].checked : false; - for (let checkbox of inputsToSelect) { + const inputsToToggle = domElem.querySelectorAll('input[type=checkbox]'); + this.toggleAllInputs(inputsToToggle); + } + + toggleAllInputs(inputsToToggle) { + const currentState = inputsToToggle.length > 0 ? inputsToToggle[0].checked : false; + for (let checkbox of inputsToToggle) { checkbox.checked = !currentState; checkbox.dispatchEvent(new Event('change')); } diff --git a/resources/views/settings/roles/form.blade.php b/resources/views/settings/roles/form.blade.php index d3c1d9070..6d7230867 100644 --- a/resources/views/settings/roles/form.blade.php +++ b/resources/views/settings/roles/form.blade.php @@ -55,10 +55,10 @@