Add indeterminate checkboxes to scopes tree

Each checkbox may have child checkboxes. If all those children are
checked, it be checked. If none are checked, it is unchecked. If some of
them are checked, then it’s in an indeterminate state (in this case
symbolically meaning “partially” checked).
multi-ogserver
Javier Sánchez Parra 2022-04-05 16:52:05 +02:00
parent 1120b31e38
commit 4c9c3b48db
2 changed files with 21 additions and 0 deletions

View File

@ -37,6 +37,25 @@ function storeCheckboxStatus(checkbox) {
localStorage.removeItem(checkbox.name);
}
function checkParentsCheckboxes() {
const checkboxes = $('input:checkbox[form|="scopesForm"]');
const reversedCheckboxes = $(checkboxes.get().reverse())
reversedCheckboxes.each(function() {
const checkbox = this;
const checkboxChildren = $('input:checkbox', this.parentNode).not(this);
if (checkboxChildren.length == 0) return;
const unCheckedChildren = checkboxChildren.filter(":not(:checked)");
checkbox.indeterminate =
unCheckedChildren.length > 0 &&
unCheckedChildren.length < checkboxChildren.length;
checkbox.checked = unCheckedChildren.length === 0;
});
}
function checkChildrenCheckboxes() {
const checkboxes = $('input:checkbox[form|="scopesForm"]')
@ -48,6 +67,7 @@ function checkChildrenCheckboxes() {
storeCheckboxStatus(this);
$(this).trigger('show-client');
});
checkParentsCheckboxes();
});
}

View File

@ -13,6 +13,7 @@
keepScopesTreeState();
keepSelectedClients();
checkChildrenCheckboxes();
checkParentsCheckboxes();
}
});
</script>