From 824ebe514c5cbbd44c862f3e92360581c342cabc Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 30 Mar 2023 08:32:26 -0600 Subject: [PATCH] Et2SelectDayOfWeek: Fix missing all days, weekday, weekend options --- api/js/etemplate/Et2Select/Et2Select.ts | 46 +++++++++++++++++++-- api/js/etemplate/Et2Select/StaticOptions.ts | 6 +-- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2Select.ts b/api/js/etemplate/Et2Select/Et2Select.ts index 1c70c6fb40..dbffefa3b7 100644 --- a/api/js/etemplate/Et2Select/Et2Select.ts +++ b/api/js/etemplate/Et2Select/Et2Select.ts @@ -11,7 +11,7 @@ import {css, html, PropertyValues, TemplateResult} from "@lion/core"; import {Et2StaticSelectMixin, StaticOptions as so} from "./StaticOptions"; import {Et2widgetWithSelectMixin} from "./Et2WidgetWithSelectMixin"; -import {SelectOption} from "./FindSelectOptions"; +import {cleanSelectOptions, SelectOption} from "./FindSelectOptions"; import {SlMenuItem, SlSelect} from "@shoelace-style/shoelace"; import shoelace from "../Styles/shoelace"; import {Et2WithSearchMixin} from "./SearchMixin"; @@ -902,11 +902,49 @@ customElements.define("et2-select-day", Et2SelectDay); export class Et2SelectDayOfWeek extends Et2StaticSelectMixin(Et2Select) { - constructor() + connectedCallback() { - super(); + super.connectedCallback(); - this.static_options = so.dow(this, {other: this.other || []}); + // Wait for connected instead of constructor because attributes make a difference in + // which options are offered + this.fetchComplete = so.dow(this, {other: this.other || []}).then(options => + { + this.set_static_options(cleanSelectOptions(options)); + }); + } + + set value(new_value) + { + let expanded_value = typeof new_value == "object" ? new_value : []; + if(new_value && (typeof new_value == "string" || typeof new_value == "number")) + { + let int_value = parseInt(new_value); + this.updateComplete.then(() => + { + this.fetchComplete.then(() => + { + let options = this.select_options; + for(let index in options) + { + let right = parseInt(options[index].value); + + if((int_value & right) == right) + { + expanded_value.push("" + right); + } + } + super.value = expanded_value; + }) + }); + return; + } + super.value = expanded_value; + } + + get value() + { + return super.value; } } diff --git a/api/js/etemplate/Et2Select/StaticOptions.ts b/api/js/etemplate/Et2Select/StaticOptions.ts index 60ab060d42..57e430950c 100644 --- a/api/js/etemplate/Et2Select/StaticOptions.ts +++ b/api/js/etemplate/Et2Select/StaticOptions.ts @@ -343,10 +343,10 @@ export const StaticOptions = new class StaticOptionsType return this.cached_server_side(widget, 'select-state', options); } - dow(widget : Et2SelectWidgets, attrs) : SelectOption[] | Promise + dow(widget : Et2SelectWidgets, attrs) : Promise { - var options = ',' + (attrs.other || []).join(','); - return this.cached_server_side(widget, 'select-dow', options); + var options = (widget.rows || "") + ',' + (attrs.other || []).join(','); + return >this.cached_server_side(widget, 'select-dow', options, true); } lang(widget : Et2SelectWidgets, attrs) : SelectOption[] | Promise