Skip to content

Commit

Permalink
browser: treeview: remove unnecessary loops
Browse files Browse the repository at this point in the history
Change-Id: Icf084135e9c743d84522b4bc9f09925300363af2
Signed-off-by: Henry Castro <[email protected]>
  • Loading branch information
hcvcastro committed Jan 8, 2025
1 parent b6712dc commit 9e8fe4d
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions browser/src/control/jsdialog/Widget.TreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,17 @@ class TreeViewControl {
return false;
}

findEntryWithRow(
entries: Array<TreeEntryJSON>,
row: number | string,
): TreeEntryJSON {
for (const i in entries) {
if (i == row) return entries[i];
else if (entries[i].children) {
var found = this.findEntryWithRow(entries[i].children, row);
if (found) return found;
}
}

return null;
}

changeCheckboxStateOnClick(
checkbox: HTMLInputElement,
checkbox: any,
treeViewData: TreeWidget,
builder: any,
entry: TreeEntryJSON,
) {
let foundEntry: TreeEntryJSON;
if (checkbox.checked) {
foundEntry = this.findEntryWithRow(treeViewData.entries, entry.row);
if (foundEntry) checkbox.checked = foundEntry.state = true;
if (typeof checkbox._state !== 'undefined') {
checkbox.checked = checkbox._state = true;
}

builder.callback(
'treeview',
'change',
Expand All @@ -180,8 +166,10 @@ class TreeViewControl {
builder,
);
} else {
foundEntry = this.findEntryWithRow(treeViewData.entries, entry.row);
if (foundEntry) checkbox.checked = foundEntry.state = false;
if (typeof checkbox._state !== 'undefined') {
checkbox.checked = checkbox._state = false;
}

builder.callback(
'treeview',
'change',
Expand Down Expand Up @@ -236,7 +224,7 @@ class TreeViewControl {
entry: TreeEntryJSON,
builder: any,
) {
let selectionElement: HTMLInputElement;
let selectionElement: any;
const checkboxtype = treeViewData.checkboxtype;
if (checkboxtype == 'radio') {
selectionElement = this.createRadioButton(
Expand All @@ -253,6 +241,7 @@ class TreeViewControl {
entry,
);
}
selectionElement._state = entry.state;

if (entry.enabled === false) selectionElement.disabled = true;

Expand Down

0 comments on commit 9e8fe4d

Please sign in to comment.