From 0057d92c9c1034e353154b6a24b7f97aded84089 Mon Sep 17 00:00:00 2001 From: milan Date: Thu, 14 Mar 2024 15:56:16 +0100 Subject: [PATCH] fixed a bug where no currently selected Item was set, when onChange has not been called yet --- api/js/etemplate/Et2Tree/Et2Tree.ts | 23 ++++++++++++++++------- mail/js/app.js | 8 ++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/api/js/etemplate/Et2Tree/Et2Tree.ts b/api/js/etemplate/Et2Tree/Et2Tree.ts index aeecd9471d..80462ad962 100644 --- a/api/js/etemplate/Et2Tree/Et2Tree.ts +++ b/api/js/etemplate/Et2Tree/Et2Tree.ts @@ -4,7 +4,6 @@ import {find_select_options, SelectOption} from "../Et2Select/FindSelectOptions" import {Et2WidgetWithSelectMixin} from "../Et2Select/Et2WidgetWithSelectMixin"; import {css, html, LitElement, nothing, PropertyValues, TemplateResult} from "lit"; import {repeat} from "lit/directives/repeat.js"; -import {query} from "lit/decorators/query.js"; import shoelace from "../Styles/shoelace"; import {property} from "lit/decorators/property.js"; import {state} from "lit/decorators/state.js"; @@ -48,7 +47,14 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) */ static RESULT_LIMIT: number = 100; //does not work because it would need to be run on the shadow root - @query("sl-tree-item[selected]") selected: SlTreeItem; + //@query("sl-tree-item[selected]") selected: SlTreeItem; + + /** + * get the first selected node using attributes on the shadow root elements + */ + private get selected(){ + return this.shadowRoot.querySelector("sl-tree-item[selected]") + } @property({type: Boolean}) multiple: Boolean = false; @property({type: String}) @@ -95,7 +101,6 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) @state() selectedNodes: SlTreeItem[] - private input: any = null; private _actionManager: EgwAction; private get _tree() { return this.shadowRoot.querySelector('sl-tree') ?? null}; @@ -118,8 +123,6 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) } firstUpdated() { - // This is somehow required to set the autoload URL properly? - // TODO: Make this not needed, either this.autoload_url should be properly set or go away in favour of using this.autoload if (this.autoloading) { // @ts-ignore from static get properties @@ -750,7 +753,10 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) (event) => { event.detail.id = event.target.id event.detail.item = event.target - this.onopenstart(event.detail.id, this, 1) + if (this.onopenstart) + { + this.onopenstart(event.detail.id, this, 1) + } } } @sl-after-expand=${ @@ -758,7 +764,10 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) event.detail.id = event.target.id event.detail.item = event.target - this.onopenend(event.detail.id, this, -1) + if (this.onopenend) + { + this.onopenend(event.detail.id, this, -1) + } } } diff --git a/mail/js/app.js b/mail/js/app.js index 282e3bded2..7d50d001bd 100755 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -2169,10 +2169,10 @@ app.classes.mail = AppJS.extend( */ mail_reduceCounterWithoutServerRoundtrip: function() { - var ftree = this.et2.getWidgetById(this.nm_index+'[foldertree]'); - var _foldernode = ftree.getSelectedItem(); - var counter = _foldernode.badge; - var icounter = 0; + const ftree = this.et2.getWidgetById(this.nm_index+'[foldertree]'); + const _foldernode = ftree.getSelectedItem(); + let counter = _foldernode.badge; + let icounter = 0; if (counter) icounter = parseInt(counter); if (icounter>0) {