fix: recursiveAdaptWidgets
This commit is contained in:
@ -1,50 +1,47 @@
|
||||
function recursiveAdaptWidgets(prefix, element, user) {
|
||||
//- This function is a workaround for the currently unworking populate
|
||||
//- Feel free to see examples on page-circles-
|
||||
|
||||
element.querySelectorAll("[" + prefix + "-user-id]").forEach(el => {
|
||||
el.setAttribute(el.getAttribute(prefix + "-user-id"), user["@id"]);
|
||||
});
|
||||
|
||||
if (element != document) {
|
||||
//- Allow to bind-user on selected attribute
|
||||
if (element.getAttribute(prefix + "-user-id")) {
|
||||
element.setAttribute(
|
||||
element.getAttribute(prefix + "-user-id"),
|
||||
user["@id"]
|
||||
);
|
||||
}
|
||||
|
||||
//- Allow to set data-src to a children sib-form
|
||||
if (element.getAttribute(prefix + "-bind-resources")) {
|
||||
let form = element.querySelector(
|
||||
element.getAttribute(prefix + "-bind-resources") + " sib-form"
|
||||
);
|
||||
if (form) {
|
||||
form.setAttribute(
|
||||
"data-src",
|
||||
element.component.resourceId.replace("members/", "")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//- Allow to put user on a targetted search field
|
||||
if (element.getAttribute(prefix + "-bind-user2input")) {
|
||||
element.querySelector(
|
||||
element.getAttribute(prefix + "-bind-user2input")
|
||||
).value = user["@id"];
|
||||
}
|
||||
|
||||
//- In case your sib-display use a multiple, you have to target sub-sib-display auto-generated
|
||||
element.querySelectorAll("sib-display, sib-form, div > sib-display, div > sib-form").forEach(el => {
|
||||
el.setAttribute(prefix + "-widgets", "");
|
||||
});
|
||||
function applyAdapt(prefix, sibDisplay, user) {
|
||||
|
||||
//- Allow to bind-user on selected attribute
|
||||
if (sibDisplay.getAttribute(prefix + "-user-id")) {
|
||||
sibDisplay.setAttribute(
|
||||
sibDisplay.getAttribute(prefix + "-user-id"),
|
||||
user["@id"]
|
||||
);
|
||||
}
|
||||
|
||||
//- This function is hooked every time a sib-something with prefix+"-widgets" is populated
|
||||
element.querySelectorAll("[" + prefix + "-widgets]").forEach(elementChild => {
|
||||
elementChild.addEventListener("populate", () => {
|
||||
recursiveAdaptWidgets(prefix, elementChild, user);
|
||||
//- Allow to set data-src to a children sib-form
|
||||
if (sibDisplay.getAttribute(prefix + "-bind-resources")) {
|
||||
let form = sibDisplay.querySelector(
|
||||
sibDisplay.getAttribute(prefix + "-bind-resources") + " sib-form"
|
||||
);
|
||||
if (form) {
|
||||
form.setAttribute(
|
||||
"data-src",
|
||||
sibDisplay.component.resourceId.replace("members/", "")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//- Allow to put user on a targetted search field
|
||||
if (sibDisplay.getAttribute(prefix + "-bind-user2input")) {
|
||||
sibDisplay.querySelector(
|
||||
sibDisplay.getAttribute(prefix + "-bind-user2input")
|
||||
).value = user["@id"];
|
||||
}
|
||||
}
|
||||
|
||||
function recursiveAdaptWidgets(prefix, element, user) {
|
||||
|
||||
element.addEventListener("populate", () => {
|
||||
|
||||
//- This function is a workaround for the currently unworking populate
|
||||
//- Feel free to see examples on page-circles-
|
||||
element.querySelectorAll("[" + prefix + "-user-id]").forEach(el => {
|
||||
el.setAttribute(el.getAttribute(prefix + "-user-id"), user["@id"]);
|
||||
});
|
||||
applyAdapt(prefix, element, user);
|
||||
|
||||
document.querySelectorAll('sib-display, sib-form').forEach(sibDisplay => {
|
||||
applyAdapt(prefix, sibDisplay, user);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -219,8 +216,10 @@ document.addEventListener("DOMContentLoaded", function(event) {
|
||||
document
|
||||
.querySelector('button[role="log in"]')
|
||||
.setAttribute("style", "display:none !important");
|
||||
// Set current user id on set-user-id of sib-display
|
||||
recursiveAdaptWidgets("hd-inherit", document, user);
|
||||
document.querySelectorAll('sib-display, sib-form').forEach(element => {
|
||||
// Set current user id on set-user-id of sib-display
|
||||
recursiveAdaptWidgets("hd-inherit", element, user);
|
||||
});
|
||||
for (leaveBtn of document.querySelectorAll(
|
||||
"admin-circle-leave > sib-ac-checker:not([hidden])"
|
||||
)) {
|
||||
|
Reference in New Issue
Block a user