]> BookStack Code Mirror - bookstack/blobdiff - resources/js/components/entity-permissions.js
Aligned logic to entity_permission role_id usage change
[bookstack] / resources / js / components / entity-permissions.js
index 917dcc72de016b7716bdd2c290ea2a989cb5407d..b1b6c508489f69382772375d98d0e30fdd6d41b5 100644 (file)
@@ -1,7 +1,7 @@
-/**
- * @extends {Component}
- */
-class EntityPermissions {
+import {htmlToDom} from "../services/dom";
+import {Component} from "./component";
+
+export class EntityPermissions extends Component {
 
     setup() {
         this.container = this.$el;
@@ -28,7 +28,7 @@ class EntityPermissions {
         // Remove role row button click
         this.container.addEventListener('click', event => {
             const button = event.target.closest('button');
-            if (button && button.dataset.roleId) {
+            if (button && button.dataset.modelType) {
                 this.removeRowOnButtonClick(button)
             }
         });
@@ -53,28 +53,27 @@ 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 modelId = button.dataset.modelId;
+        const modelName = button.dataset.modelName;
+        const modelType = button.dataset.modelType;
 
         const option = document.createElement('option');
-        option.value = roleId;
-        option.textContent = roleName;
+        option.value = modelId;
+        option.textContent = modelName;
 
-        this.roleSelect.append(option);
+        if (modelType === 'role') {
+            this.roleSelect.append(option);
+        }
+        // TODO - User role!
         row.remove();
     }
 
-}
-
-export default EntityPermissions;
\ No newline at end of file
+}
\ No newline at end of file