Skip to content

Commit

Permalink
browser: treeview: handle checkbox/radio events
Browse files Browse the repository at this point in the history
Change-Id: Ib4c5c2770cbbdb9f56d5219599142893ed0c05c9
Signed-off-by: Henry Castro <[email protected]>
  • Loading branch information
hcvcastro committed Jan 9, 2025
1 parent c744545 commit f93e4e9
Showing 1 changed file with 36 additions and 46 deletions.
82 changes: 36 additions & 46 deletions browser/src/control/jsdialog/Widget.TreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,39 +166,6 @@ class TreeViewControl {
return false;
}

changeCheckboxStateOnClick(
checkbox: any,
treeViewData: TreeWidget,
builder: any,
entry: TreeEntryJSON,
) {
if (checkbox.checked) {
if (typeof checkbox._state !== 'undefined') {
checkbox.checked = checkbox._state = true;
}

builder.callback(
'treeview',
'change',
treeViewData,
{ row: entry.row, value: true },
builder,
);
} else {
if (typeof checkbox._state !== 'undefined') {
checkbox.checked = checkbox._state = false;
}

builder.callback(
'treeview',
'change',
treeViewData,
{ row: entry.row, value: false },
builder,
);
}
}

createCheckbox(
parent: HTMLElement,
treeViewData: TreeWidgetJSON,
Expand Down Expand Up @@ -261,20 +228,10 @@ class TreeViewControl {
);
}
selectionElement._state = entry.state;
selectionElement._row = entry.row;

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

if (treeViewData.enabled !== false) {
selectionElement.addEventListener('change', () => {
this.changeCheckboxStateOnClick(
selectionElement,
treeViewData,
builder,
entry,
);
});
}

return selectionElement;
}

Expand Down Expand Up @@ -805,8 +762,8 @@ class TreeViewControl {
});

this.selectEntry(parentContainer, checkbox);
if (checkbox)
this.changeCheckboxStateOnClick(checkbox, treeViewData, builder, entry);
/*if (checkbox)
this.changeCheckboxStateOnClick(checkbox, treeViewData, builder, entry);*/

if (select)
builder.callback(
Expand Down Expand Up @@ -1252,6 +1209,39 @@ class TreeViewControl {
return;
}

let target = e.target;
if (target.localName === 'input') {
TreeViewControl.onCheckBoxClick(treeview, target);
return;
}
}

static onCheckBoxClick(treeview: any, checkbox: any) {
if (checkbox.checked) {
if (typeof checkbox._state !== 'undefined') {
checkbox.checked = checkbox._state = true;
}

treeview._builder.callback(
'treeview',
'change',
treeview._data,
{ row: checkbox._row, value: true },
treeview._builder,
);
} else {
if (typeof checkbox._state !== 'undefined') {
checkbox.checked = checkbox._state = false;
}

treeview._builder.callback(
'treeview',
'change',
treeview._data,
{ row: checkbox._row, value: false },
treeview._builder,
);
}
}
}

Expand Down

0 comments on commit f93e4e9

Please sign in to comment.