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 b7ab391 commit 7efff23
Showing 1 changed file with 37 additions and 47 deletions.
84 changes: 37 additions & 47 deletions browser/src/control/jsdialog/Widget.TreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,39 +155,6 @@ class TreeViewControl {
return false;
}

changeCheckboxStateOnClick(
checkbox: any,
treeViewData: TreeWidgetJSON,
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 @@ -250,20 +217,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 @@ -794,8 +751,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 @@ -1235,7 +1192,40 @@ class TreeViewControl {

// --------- Event Handlers
//
onClick() {
onClick(e: any) {
let target = e.target;
if (target.localName === 'input') {
this.onCheckBoxClick(target);
return;
}
}

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

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

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

Expand Down

0 comments on commit 7efff23

Please sign in to comment.