1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-16 23:41:57 +03:00

Added select-all helpers to permission tables

This commit is contained in:
Dan Brown
2019-04-13 12:07:27 +01:00
parent 36481bb73f
commit 07adfb2ff1
6 changed files with 92 additions and 17 deletions

View File

@ -0,0 +1,39 @@
class PermissionsTable {
constructor(elem) {
this.container = elem;
// Handle toggle all event
const toggleAll = elem.querySelector('[permissions-table-toggle-all]');
toggleAll.addEventListener('click', this.toggleAllClick.bind(this));
// Handle toggle row event
const toggleRowElems = elem.querySelectorAll('[permissions-table-toggle-all-in-row]');
for (let toggleRowElem of toggleRowElems) {
toggleRowElem.addEventListener('click', this.toggleRowClick.bind(this));
}
}
toggleAllClick(event) {
event.preventDefault();
this.toggleAllInElement(this.container);
}
toggleRowClick(event) {
event.preventDefault();
this.toggleAllInElement(event.target.closest('tr'));
}
toggleAllInElement(domElem) {
const inputsToSelect = domElem.querySelectorAll('input[type=checkbox]');
const currentState = inputsToSelect.length > 0 ? inputsToSelect[0].checked : false;
for (let checkbox of inputsToSelect) {
checkbox.checked = !currentState;
checkbox.dispatchEvent(new Event('change'));
}
}
}
export default PermissionsTable;