diff --git a/api/js/etemplate/Et2Date/Et2Date.ts b/api/js/etemplate/Et2Date/Et2Date.ts index 9f5b7a306b..ef425edf71 100644 --- a/api/js/etemplate/Et2Date/Et2Date.ts +++ b/api/js/etemplate/Et2Date/Et2Date.ts @@ -18,6 +18,7 @@ import {LitFlatpickr} from "lit-flatpickr"; import "flatpickr/dist/plugins/scrollPlugin.js"; import {holidays} from "./Holidays"; import flatpickr from "flatpickr"; +import {egw} from "../../jsapi/egw_global"; // Request this year's holidays now holidays(new Date().getFullYear()); @@ -29,7 +30,7 @@ const l10n = [ 'mn', 'ms', 'my', 'nl', 'no', 'pa', 'pl', 'pt', 'ro', 'ru', 'si', 'sk', 'sl', 'sq', 'sr-cyr', 'sr', 'sv', 'th', 'tr', 'uk', 'uz', 'uz_latn', 'vn', 'zh-tw', 'zh', ]; -const lang = egw.preference('lang'); +const lang = egw ? egw.preference('lang') || "" : ""; // only load localization, if we have one if (l10n.indexOf(lang) >= 0) { @@ -424,7 +425,7 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(ValidateMixin(LitFl */ protected _localize(options) { - let first_dow = this.egw().preference('weekdaystarts', 'calendar') || 'Monday'; + let first_dow = this.egw()?.preference('weekdaystarts', 'calendar') || 'Monday'; const DOW_MAP = {Monday: 1, Sunday: 0, Saturday: 6}; options.locale = { firstDayOfWeek: DOW_MAP[first_dow] diff --git a/api/js/etemplate/Et2Date/Holidays.ts b/api/js/etemplate/Et2Date/Holidays.ts index 202c269725..a2f428bae3 100644 --- a/api/js/etemplate/Et2Date/Holidays.ts +++ b/api/js/etemplate/Et2Date/Holidays.ts @@ -2,6 +2,8 @@ * Static holiday cache * access through holidays(year) */ +import {egw} from "../../jsapi/egw_global"; + let _holiday_cache = {}; /** @@ -19,7 +21,7 @@ let _holiday_cache = {}; export function holidays(year) : Promise<{ [key : string] : Array }> | { [key : string] : Array } { // No country selected causes error, so skip if it's missing - if(!egw.preference('country', 'common')) + if(!egw || !egw.preference('country', 'common')) { return {}; } diff --git a/api/js/etemplate/Et2Description/Et2Description.ts b/api/js/etemplate/Et2Description/Et2Description.ts index aa6cceaa81..fde86462cf 100644 --- a/api/js/etemplate/Et2Description/Et2Description.ts +++ b/api/js/etemplate/Et2Description/Et2Description.ts @@ -137,7 +137,7 @@ export class Et2Description extends Et2Widget(LitElement) implements et2_IDetach super.requestUpdate(...arguments); // Due to how we do the rendering into the light DOM (not sure it's right) we need this after // value change or it won't actually show up - if(attribute == "value" && this.parentNode) + if(["value", "href", "activate_links"].indexOf(attribute) != -1 && this.parentNode) { this.updateComplete.then(() => render(this._renderContent(), this)); } diff --git a/api/js/etemplate/Et2Description/test/Et2Description.test.ts b/api/js/etemplate/Et2Description/test/Et2Description.test.ts index 7e56292917..01dff9cc79 100644 --- a/api/js/etemplate/Et2Description/test/Et2Description.test.ts +++ b/api/js/etemplate/Et2Description/test/Et2Description.test.ts @@ -56,7 +56,7 @@ describe("Textbox widget", () => await elementUpdated(element); // Firefox puts the style tag in, so it's not an exact match - assert.match(element.shadowRoot.textContent, new RegExp(value)); + assert.match(element.textContent, new RegExp(value)); }); it("translates its value", async() => @@ -78,7 +78,7 @@ describe("Textbox widget", () => await elementUpdated(element); // Firefox puts the style tag in, so it's not an exact match - assert.match(element.shadowRoot.textContent, new RegExp("Translated!")); + assert.match(element.textContent, new RegExp("Translated!")); }); it("links when given href", async() => @@ -92,7 +92,7 @@ describe("Textbox widget", () => // @ts-ignore TypeScript doesn't recognize widgets as Elements await elementUpdated(element); - let a = element.shadowRoot.querySelector("a"); + let a = element.querySelector("a"); assert.isNotNull(a, "Did not find A tag"); assert.match(a.href, new RegExp(href), "A tag had wrong href"); }); @@ -107,7 +107,7 @@ describe("Textbox widget", () => await elementUpdated(element); // Not turned on, make sure there is no links - assert.isNull(element.shadowRoot.querySelector("a"), "Links got activated when activate_links property is false"); + assert.isNull(element.querySelector("a"), "Links got activated when activate_links property is false"); // Turn it on element.activate_links = true; @@ -116,8 +116,8 @@ describe("Textbox widget", () => // @ts-ignore TypeScript doesn't recognize widgets as Elements await elementUpdated(element); - assert.isNotNull(element.shadowRoot.querySelector("a"), "Links did not get activated when activate_links property is true"); - assert.equal(element.shadowRoot.querySelector("a").href, "http://www.egroupware.org/", "Incorrect href in activated link"); + assert.isNotNull(element.querySelector("a"), "Links did not get activated when activate_links property is true"); + assert.equal(element.querySelector("a").href, "http://www.egroupware.org/", "Incorrect href in activated link"); }); }); diff --git a/api/js/etemplate/Et2Widget/Et2Widget.ts b/api/js/etemplate/Et2Widget/Et2Widget.ts index ae79e8d9bb..f714b10eca 100644 --- a/api/js/etemplate/Et2Widget/Et2Widget.ts +++ b/api/js/etemplate/Et2Widget/Et2Widget.ts @@ -6,6 +6,7 @@ import {et2_compileLegacyJS} from "../et2_core_legacyJSFunctions"; import {et2_cloneObject, et2_csvSplit} from "../et2_core_common"; // @ts-ignore import type {IegwAppLocal} from "../../jsapi/egw_global"; +import {egw} from "../../jsapi/egw_global"; import {ClassWithAttributes, ClassWithInterfaces} from "../et2_core_inheritance"; import {css, dedupeMixin, PropertyValues, unsafeCSS} from "@lion/core"; import type {et2_container} from "../et2_core_baseWidget"; @@ -87,7 +88,7 @@ const Et2WidgetMixin = (superClass) => static get styles() { return [ - ...(super.styles ? (Symbol.iterator in Object(super.styles) ? super.styles : [super.styles]) : []), + ...(super.styles ? (Array.isArray(super.styles) ? super.styles : [super.styles]) : []), css` :host([disabled]) { display: none; @@ -789,7 +790,7 @@ const Et2WidgetMixin = (superClass) => transformAttributes(this, this.getArrayMgr("content"), attrs); // Add in additional modifications - if(this.id && this.getArrayMgr("modifications").getEntry(this.id)) + if(this.id && this.getArrayMgr("modifications")?.getEntry(this.id)) { transformAttributes(this, this.getArrayMgr("content"), this.getArrayMgr("modifications").getEntry(this.id)); } diff --git a/api/js/etemplate/Styles/shoelace.ts b/api/js/etemplate/Styles/shoelace.ts index c3dd75db9a..62adfd80ef 100644 --- a/api/js/etemplate/Styles/shoelace.ts +++ b/api/js/etemplate/Styles/shoelace.ts @@ -8,7 +8,10 @@ import {egw} from "../../jsapi/egw_global"; * This makes sure the built-in icons can be found */ registerIconLibrary('default', { - resolver: name => `${egw.webserverUrl}/node_modules/@shoelace-style/shoelace/dist/assets/icons/${name}.svg`, + resolver: name => + { + return typeof egw !== "undefined" ? `${egw.webserverUrl}/node_modules/@shoelace-style/shoelace/dist/assets/icons/${name}.svg` : '' + }, }); /** @@ -22,7 +25,7 @@ const egw_icons = {'chevron-down': 'arrow_down', 'x': 'close', 'x-circle-fill': registerIconLibrary("system", { resolver: (name) => { - if(egw_icons[name]) + if(egw_icons[name] && egw) { return `${egw.webserverUrl}/pixelegg/images/${egw_icons[name]}.svg`; }