From e86ace621012be3037610b84d411a219d9637600 Mon Sep 17 00:00:00 2001 From: Henry Castro Date: Fri, 10 Jan 2025 06:46:01 -0400 Subject: [PATCH] browser: treeview: add 'dblclick' event handler Change-Id: I82646ef5133595788d5c02bea6b0f68fbb25c448 Signed-off-by: Henry Castro --- .../src/control/Control.ServerAuditDialog.ts | 4 + .../src/control/jsdialog/Widget.TreeView.ts | 84 +++++-------------- 2 files changed, 27 insertions(+), 61 deletions(-) diff --git a/browser/src/control/Control.ServerAuditDialog.ts b/browser/src/control/Control.ServerAuditDialog.ts index b880bfe2ca24c..26c6523b251e2 100644 --- a/browser/src/control/Control.ServerAuditDialog.ts +++ b/browser/src/control/Control.ServerAuditDialog.ts @@ -135,6 +135,7 @@ class ServerAuditDialog { if (status) { entries.push({ row: 0, + state: false, columns: [ entry.status === 'ok' ? okIcon : errorIcon, { text: status[0] }, @@ -145,6 +146,9 @@ class ServerAuditDialog { } : { text: '' }, ], + children: [ + { row: 2, columns: [ { text: 'a2' } ] } + ], } as TreeEntryJSON); } } else { diff --git a/browser/src/control/jsdialog/Widget.TreeView.ts b/browser/src/control/jsdialog/Widget.TreeView.ts index 786016b6bf86a..1210395ceef1e 100644 --- a/browser/src/control/jsdialog/Widget.TreeView.ts +++ b/browser/src/control/jsdialog/Widget.TreeView.ts @@ -108,6 +108,7 @@ class TreeViewControl { if (data.enabled !== false) { this._container.addEventListener('click', this.onClick.bind(this)); + this._container.addEventListener('dblclick', this.onDoubleClick.bind(this)); } } @@ -552,34 +553,13 @@ class TreeViewControl { } } - /*var doubleClickFunction = this.createClickFunction( - tr, - selectionElement, - false, - true, - builder, - treeViewData, - entry, - ); - - this.setupEntryMouseEvents( - tr, - entry, - treeViewData, - builder, - selectionElement, - expander, - clickFunction, - doubleClickFunction, - ); - - this.setupEntryKeyEvent( + /*this.setupEntryKeyEvent( tr, entry, selectionElement, expander, clickFunction, - ); */ + );*/ this.setupEntryContextMenuEvent(tr, entry, treeViewData, builder); } @@ -602,44 +582,6 @@ class TreeViewControl { }); } - setupEntryMouseEvents( - tr: HTMLElement, - entry: TreeEntryJSON, - treeViewData: TreeWidgetJSON, - builder: any, - selectionElement: HTMLInputElement, - expander: HTMLElement, - clickFunction: any, - doubleClickFunction: any, - ) { - tr.addEventListener('click', clickFunction as any); - - if (!this._singleClickActivate) { - if (window.ThisIsTheiOSApp) { - // TODO: remove this hack - tr.addEventListener('click', () => { - if (L.DomUtil.hasClass(tr, 'disabled')) return; - - if ( - entry.row == lastClickHelperRow && - treeViewData.id == lastClickHelperId - ) - doubleClickFunction(undefined); - else { - lastClickHelperRow = entry.row; - lastClickHelperId = treeViewData.id; - setTimeout(() => { - lastClickHelperRow = -1; - }, 300); - } - }); - // TODO: remove this hack - } else { - $(tr).dblclick(doubleClickFunction as any); - } - } - } - setupEntryKeyEvent( tr: HTMLElement, entry: TreeEntryJSON, @@ -1212,6 +1154,26 @@ class TreeViewControl { this.toggleEntry(expander, this._data, expander._row, this._builder); } } + + onDoubleClick(e: any) { + let target = e.target; + let row = TreeViewControl.getElement(target, 'row'); + if (row && !L.DomUtil.hasClass(row, 'disabled')) { + this.onRowDoubleClick(row); + } + } + + onRowDoubleClick(row: any) { + if (!this._singleClickActivate) { + this._builder.callback( + 'treeview', + 'activate', + this._data, + row._row, + this._builder, + ); + } + } } JSDialog.treeView = function (