From 08549e25da8474de277a831ab9a9dab371a39733 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Tue, 1 Mar 2022 12:35:33 +0100 Subject: [PATCH] Make Et2WidgetWithSelect a Dedup Mixin in order to make it available cross widgets --- api/js/etemplate/Et2Select/Et2Select.ts | 343 +----------------- .../Et2Select/Et2WidgetWithSelectMixin.ts | 154 ++++++++ .../etemplate/Et2Select/FindSelectOptions.ts | 207 +++++++++++ 3 files changed, 365 insertions(+), 339 deletions(-) create mode 100644 api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts create mode 100644 api/js/etemplate/Et2Select/FindSelectOptions.ts diff --git a/api/js/etemplate/Et2Select/Et2Select.ts b/api/js/etemplate/Et2Select/Et2Select.ts index 28f4983171..64033907b7 100644 --- a/api/js/etemplate/Et2Select/Et2Select.ts +++ b/api/js/etemplate/Et2Select/Et2Select.ts @@ -1,5 +1,5 @@ /** - * EGroupware eTemplate2 - Description WebComponent + * EGroupware eTemplate2 - Select WebComponent * * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @package api @@ -9,157 +9,13 @@ import {LionSelect} from "@lion/select"; -import {Et2InputWidget} from "../Et2InputWidget/Et2InputWidget"; -import {et2_readAttrWithDefault} from "../et2_core_xml"; import {css, html, PropertyValues, render, repeat, TemplateResult} from "@lion/core"; import {cssImage} from "../Et2Widget/Et2Widget"; import {StaticOptions} from "./StaticOptions"; +import {Et2widgetWithSelectMixin} from "./Et2WidgetWithSelectMixin"; +import {SelectOption} from "./FindSelectOptions"; -export interface SelectOption -{ - value : string; - label : string; - // Hover help text - title? : string; -} - -/** - * Base class for things that do selectbox type behaviour, to avoid putting too much or copying into read-only - * selectboxes, also for common handling of properties for more special selectboxes. - * - * LionSelect (and any other LionField) use slots to wrap a real DOM node. ET2 doesn't expect this, - * so we have to create the input node (via slots()) and respect that it is _external_ to the Web Component. - * This complicates things like adding the options, since we can't just override _inputGroupInputTemplate() - * and include them when rendering - the parent expects to find the added via a slot, render() would + * put it inside the shadowDOM. That's fine, but then it doesn't get created until render(), and the parent + * (LionField) can't find it when it looks for it before then. + * + */ +export const Et2widgetWithSelectMixin = dedupeMixin((superclass) => +{ + class Et2WidgetWithSelect extends Et2InputWidget(superclass) + { + static get properties() + { + return { + ...super.properties, + /** + * Textual label for first row, eg: 'All' or 'None'. It's value will be '' + */ + empty_label: String, + + /** + * Select box options + * + * Will be found automatically based on ID and type, or can be set explicitly in the template using + *