diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-04-05 16:52:05 +0200 |
---|---|---|
committer | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-04-08 08:03:10 +0200 |
commit | 4c9c3b48db02bcc27a89da694cd9ef5aad1c14c5 (patch) | |
tree | ddff644cc25d5363d4a92d90cff7280020710afc /ogcp/static | |
parent | 1120b31e3838f3c7806df83cdeaab6a02b95eca6 (diff) |
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).
Diffstat (limited to 'ogcp/static')
-rw-r--r-- | ogcp/static/js/ogcp.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ogcp/static/js/ogcp.js b/ogcp/static/js/ogcp.js index ac31c65..86a9282 100644 --- a/ogcp/static/js/ogcp.js +++ b/ogcp/static/js/ogcp.js @@ -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(); }); } |