Skip to content

Commit

Permalink
if all of a node's children are selected then deselect them all but k…
Browse files Browse the repository at this point in the history
…eep the parent selected
  • Loading branch information
jambun committed Oct 12, 2021
1 parent a34aa70 commit f4de15c
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions frontend/assets/work_order_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,39 @@

// update record 'selected' state
var index = getIndexForUri(flattened, uri);
flattened[index].selected = $checkbox.is(":checked");

// update all children
var level = flattened[index].level;
for (var i = index + 1; i < flattened.length; i++) {
if (flattened[i].level > level) {
flattened[i].selected = $checkbox.is(":checked");
// only get fancy if we are a parent
if (flattened[index].children) {
var lastIndex = index + 1;
var allSelected = true;
var level = flattened[index].level;

// find out if all children are selected
for (var i = index + 1; i < flattened.length; i++) {
if (flattened[i].level > level) {
lastIndex = i;
allSelected = allSelected && flattened[i].selected;
} else {
break;
}
}

if (flattened[index].selected && allSelected) {
// if the parent is currently selected and all children are selected
// then keep parent selected but deselect the children
$checkbox.prop("checked", true);
for (var i = index + 1; i <= lastIndex; i++) {
flattened[i].selected = false;
}
} else {
break;
// otherwise just set them all to match
flattened[index].selected = $checkbox.is(":checked");
for (var i = index + 1; i <= lastIndex; i++) {
flattened[i].selected = $checkbox.is(":checked");
}
}
} else {
flattened[index].selected = $checkbox.is(":checked");
}

var offsetTop = workOrderFatTable.scroll.scrollTop;
Expand Down

0 comments on commit f4de15c

Please sign in to comment.