]> BookStack Code Mirror - bookstack/blobdiff - resources/js/components/entity-permissions.js
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / resources / js / components / entity-permissions.js
index a18fc7a97aedbceb8e913baf8b25f6fe0e48f4df..b020c5d85ba8f785785df1e2f98e2607f0e9b385 100644 (file)
@@ -1,7 +1,7 @@
-/**
- * @extends {Component}
- */
-class EntityPermissions {
+import {htmlToDom} from '../services/dom.ts';
+import {Component} from './component';
+
+export class EntityPermissions extends Component {
 
     setup() {
         this.container = this.$el;
@@ -18,7 +18,7 @@ class EntityPermissions {
         // "Everyone Else" inherit toggle
         this.everyoneInheritToggle.addEventListener('change', event => {
             const inherit = event.target.checked;
-            const permissions = document.querySelectorAll('input[type="checkbox"][name^="restrictions[0]["]');
+            const permissions = document.querySelectorAll('input[name^="permissions[0]["]');
             for (const permission of permissions) {
                 permission.disabled = inherit;
                 permission.checked = false;
@@ -29,12 +29,12 @@ class EntityPermissions {
         this.container.addEventListener('click', event => {
             const button = event.target.closest('button');
             if (button && button.dataset.roleId) {
-                this.removeRowOnButtonClick(button)
+                this.removeRowOnButtonClick(button);
             }
         });
 
         // Role select change
-        this.roleSelect.addEventListener('change', event => {
+        this.roleSelect.addEventListener('change', () => {
             const roleId = this.roleSelect.value;
             if (roleId) {
                 this.addRoleRow(roleId);
@@ -53,19 +53,16 @@ class EntityPermissions {
 
         // Get and insert new row
         const resp = await window.$http.get(`/permissions/form-row/${this.entityType}/${roleId}`);
-        const wrap = document.createElement('div');
-        wrap.innerHTML = resp.data;
-        const row = wrap.children[0];
+        const row = htmlToDom(resp.data);
         this.roleContainer.append(row);
-        window.components.init(row);
 
         this.roleSelect.disabled = false;
     }
 
     removeRowOnButtonClick(button) {
-        const row = button.closest('.content-permissions-row');
-        const roleId = button.dataset.roleId;
-        const roleName = button.dataset.roleName;
+        const row = button.closest('.item-list-row');
+        const {roleId} = button.dataset;
+        const {roleName} = button.dataset;
 
         const option = document.createElement('option');
         option.value = roleId;
@@ -76,5 +73,3 @@ class EntityPermissions {
     }
 
 }
-
-export default EntityPermissions;
\ No newline at end of file