X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/6adc642d2f19a998dea9bcc7b9d3f07f0c50cd6a..refs/pull/3878/head:/resources/js/components/permissions-table.js diff --git a/resources/js/components/permissions-table.js b/resources/js/components/permissions-table.js index df3c055ca..58ead1d57 100644 --- a/resources/js/components/permissions-table.js +++ b/resources/js/components/permissions-table.js @@ -1,8 +1,11 @@ +import {Component} from "./component"; -class PermissionsTable { +export class PermissionsTable extends Component { setup() { this.container = this.$el; + this.cellSelector = this.$opts.cellSelector || 'td,th'; + this.rowSelector = this.$opts.rowSelector || 'tr'; // Handle toggle all event for (const toggleAllElem of (this.$manyRefs.toggleAll || [])) { @@ -27,15 +30,15 @@ class PermissionsTable { toggleRowClick(event) { event.preventDefault(); - this.toggleAllInElement(event.target.closest('tr')); + this.toggleAllInElement(event.target.closest(this.rowSelector)); } toggleColumnClick(event) { event.preventDefault(); - const tableCell = event.target.closest('th,td'); + const tableCell = event.target.closest(this.cellSelector); const colIndex = Array.from(tableCell.parentElement.children).indexOf(tableCell); - const tableRows = tableCell.closest('table').querySelectorAll('tr'); + const tableRows = this.container.querySelectorAll(this.rowSelector); const inputsToToggle = []; for (let row of tableRows) { @@ -60,6 +63,4 @@ class PermissionsTable { } } -} - -export default PermissionsTable; \ No newline at end of file +} \ No newline at end of file