-/**
- * @extends {Component}
- */
-class EntityPermissions {
+import {htmlToDom} from "../services/dom";
+import {Component} from "./component";
+
+export class EntityPermissions extends Component {
setup() {
this.container = this.$el;
// 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)
}
});
// 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