fix: js recursive parent selector for admin

This commit is contained in:
Jean-Baptiste Pasquier 2019-10-29 15:38:33 +01:00
parent 5adbd98f51
commit c50e05530e
No known key found for this signature in database
GPG Key ID: F2702E6D22ED4D62
1 changed files with 13 additions and 4 deletions

View File

@ -1,3 +1,13 @@
function querySelectorParentChild(el, selector) {
while(el !== document.body) {
if(el.querySelector(selector)) {
break;
}
el = el.parentNode;
}
return el.querySelector(selector);
}
document.addEventListener('DOMContentLoaded', function (event) {
const menuWrappers = Array.from(document.querySelectorAll('.menu-wrapper'));
const rightMenus = Array.from(document.querySelectorAll('nav.jsRightMenu'));
@ -46,11 +56,10 @@ document.addEventListener('DOMContentLoaded', function (event) {
for(sibForm of document.querySelectorAll('[set-user-id-select]')) {
sibForm.addEventListener('populate', () => {
document.querySelectorAll('sib-form[submit-button^="Join"]').forEach(el=>el.style.display = 'none');
if(document.querySelectorAll('sib-ac-checker:not([hidden]) > sib-delete[data-label^="Leave"]').length == 0) {
document.querySelectorAll('sib-form[submit-button^="Join"]').forEach(el=>el.style.display = 'inline-block');
}
// BUG: Populate event trigger before the view is fully loaded! - https://git.happy-dev.fr/startinblox/framework/sib-core/issues/521
document.querySelectorAll('sib-ac-checker:not([hidden]) > sib-delete[data-label^="Leave"]').forEach((el)=>{
querySelectorParentChild(el, 'sib-form[submit-button^="Join"]').style.display = "none";
});
for(select of sibForm.querySelectorAll('select[name="'+sibForm.getAttribute('set-user-id-select')+'"]')) {
for(option of select.options) {
option.selected = (option.getAttribute('value') == '{"@id": "'+user['@id']+'"}');