async function checkChildElements()

in frontend/src/assets/js/toolWindows.js [19:44]


        async function checkChildElements(elem) {
            var checked = $(elem).prop('checked');
            var isParent = !!$(elem).closest('li').find(' > ul').length;
            if (isParent) {
                // if a parent level checkbox is changed, locate all children
                var children = $(elem).closest('li').find('ul input[type=checkbox]');
                children.prop({
                    checked
                }); // all children will have what parent has
            } else {
                console.log("is not parent")
                // if a child checkbox is changed, locate parent and all children
                var parent = $(elem).closest('ul').closest('li').find('>label input[type=checkbox]');
                var children = $(elem).closest('ul').find('input[type=checkbox]');
                if (children.filter(':checked').length === 0) {
                    // if all children are unchecked
                    parent.prop({ checked: false, indeterminate: false });
                } else if (children.length === children.filter(':checked').length) {
                    // if all children are checked
                    parent.prop({ checked: true, indeterminate: false });
                } else {
                    // if some of the children are checked
                    parent.prop({ checked: true, indeterminate: true });
                }
            }
        }