From 273fe9a28a4b62fbf842acf18a46e13f7eb28bb2 Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 13 May 2022 15:32:36 +0200 Subject: [PATCH] diverse fixes loading no longer existing legacy widgets like description --- api/js/etemplate/Et2Widget/Et2Widget.ts | 14 ++++++++----- api/js/etemplate/et2_core_widget.ts | 24 ++++++++++++++++++----- api/js/etemplate/et2_core_xml.ts | 16 +++++++++++---- api/js/etemplate/et2_widget_historylog.ts | 2 +- api/js/etemplate/et2_widget_template.ts | 5 ++--- api/js/etemplate/etemplate2.ts | 2 +- 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/api/js/etemplate/Et2Widget/Et2Widget.ts b/api/js/etemplate/Et2Widget/Et2Widget.ts index c64efb8d30..a9a7ae9cb3 100644 --- a/api/js/etemplate/Et2Widget/Et2Widget.ts +++ b/api/js/etemplate/Et2Widget/Et2Widget.ts @@ -629,7 +629,11 @@ const Et2WidgetMixin = (superClass) => { // Get the constructor - if the widget is readonly, use the special "_ro" // constructor if it is available - let constructor = et2_registry[typeof et2_registry[_nodeName] == "undefined" ? 'placeholder' : _nodeName]; + if (typeof et2_registry[_nodeName] === "undefined") + { + _nodeName = 'placeholder'; + } + let constructor = et2_registry[_nodeName]; if(readonly === true && typeof et2_registry[_nodeName + "_ro"] != "undefined") { constructor = et2_registry[_nodeName + "_ro"]; @@ -1257,7 +1261,7 @@ export const Et2Widget = dedupeMixin(Et2WidgetMixin); * @param parent Parent widget */ // @ts-ignore Et2Widget is I guess not the right type -export function loadWebComponent(_nodeName : string, _template_node : Element|{[index: string]: any}, parent : Et2Widget | et2_widget) : HTMLElement +export function loadWebComponent(_nodeName : string, _template_node : Element|{[index: string]: any}, parent : Et2Widget|et2_widget|undefined) : HTMLElement { let attrs = {}; let load_children = true; @@ -1293,10 +1297,10 @@ export function loadWebComponent(_nodeName : string, _template_node : Element|{[ throw Error("Unknown or unregistered WebComponent '" + _nodeName + "', could not find class. Also checked for " + tries.join(',')); } } - const readonly = parent.getArrayMgr("readonlys") ? + const readonly = parent?.getArrayMgr("readonlys") ? (parent.getArrayMgr("readonlys")).isReadOnly( attrs["id"], attrs["readonly"], - typeof parent.readonly !== "undefined" ? parent.readonly : false) : false; + typeof parent?.readonly !== "undefined" ? parent.readonly : false) : false; if(readonly === true && typeof window.customElements.get(_nodeName + "_ro") != "undefined") { _nodeName += "_ro"; @@ -1306,7 +1310,7 @@ export function loadWebComponent(_nodeName : string, _template_node : Element|{[ let widget = document.createElement(_nodeName); widget.textContent = _template_node.textContent; - widget.setParent(parent); + if (parent) widget.setParent(parent); // Set read-only. Doesn't really matter if it's a ro widget, but otherwise it needs set widget.readOnly = readonly; diff --git a/api/js/etemplate/et2_core_widget.ts b/api/js/etemplate/et2_core_widget.ts index e3a2b6678e..53ed62082c 100644 --- a/api/js/etemplate/et2_core_widget.ts +++ b/api/js/etemplate/et2_core_widget.ts @@ -106,17 +106,21 @@ export function et2_createWidget(_name: string, _attrs: object, _parent?: any): // determine which constructor is used var nodeName = _attrs["type"] = _name; var readonly = _attrs["readonly"] = - typeof _attrs["readonly"] == "undefined" ? false : _attrs["readonly"]; + typeof _attrs["readonly"] === "undefined" ? false : _attrs["readonly"]; // Get the constructor - if the widget is readonly, use the special "_ro" // constructor if it is available - let constructor = et2_registry[typeof et2_registry[nodeName] == "undefined" ? 'placeholder' : nodeName]; - if (readonly && typeof et2_registry[nodeName + "_ro"] != "undefined") + if (typeof et2_registry[nodeName] === "undefined") + { + nodeName = 'placeholder'; + } + let constructor = et2_registry[nodeName]; + if (readonly && typeof et2_registry[nodeName + "_ro"] !== "undefined") { constructor = et2_registry[nodeName + "_ro"]; } - // Do an sanity check for the attributes + // Do a sanity check for the attributes ClassWithAttributes.generateAttributeSet(et2_attribute_registry[constructor.name], _attrs); // Create the new widget and return it return new constructor(_parent, _attrs); @@ -784,9 +788,19 @@ export class et2_widget extends ClassWithAttributes _nodeName = attributes["type"] = this.getArrayMgr('content').expandName(_nodeName); } + // check and return web-components in case widget is no longer available as legacy widget + if (typeof et2_registry[_nodeName] === "undefined" && window.customElements.get('et2-'+_nodeName)) + { + return loadWebComponent('et2-'+_nodeName, _node, this); + } + // Get the constructor - if the widget is readonly, use the special "_ro" // constructor if it is available - var constructor = et2_registry[typeof et2_registry[_nodeName] == "undefined" ? 'placeholder' : _nodeName]; + if (typeof et2_registry[_nodeName] === "undefined") + { + _nodeName = 'placeholder'; + } + let constructor = et2_registry[_nodeName]; if(readonly === true && typeof et2_registry[_nodeName + "_ro"] != "undefined") { constructor = et2_registry[_nodeName + "_ro"]; diff --git a/api/js/etemplate/et2_core_xml.ts b/api/js/etemplate/et2_core_xml.ts index 9b73f74aa2..c02c8b2c67 100644 --- a/api/js/etemplate/et2_core_xml.ts +++ b/api/js/etemplate/et2_core_xml.ts @@ -47,6 +47,17 @@ export function et2_loadXMLFromURL(_url : string, _callback? : Function, _contex { win = egw.top; } + + // if preprocessor is missing --> add it + if (_url.indexOf('/etemplate.php/') === -1) + { + const parts = _url.match(/^(.*)(\/[^/]+\/templates\/.*)$/); + if (parts) + { + _url = parts[1]+'/api/etemplate.php'+parts[2]; + } + } + // we add the full url (protocol and domain) as sometimes just the path // gives a CSP error interpreting it as file:///path // (if there are a enough 404 errors in html content ...) @@ -113,7 +124,4 @@ export function et2_readAttrWithDefault(_node : HTMLElement, _name : string, _de let val = _node.getAttribute(_name); return (val === null) ? _default : val; -} - - - +} \ No newline at end of file diff --git a/api/js/etemplate/et2_widget_historylog.ts b/api/js/etemplate/et2_widget_historylog.ts index 86054b5314..79f2d100e4 100644 --- a/api/js/etemplate/et2_widget_historylog.ts +++ b/api/js/etemplate/et2_widget_historylog.ts @@ -528,7 +528,7 @@ export class et2_historylog extends et2_valueWidget implements et2_IDataProvider // Not set if(options[i] === "") continue; - const attr = widget.attributes[legacy[i]]; + const attr = widget.attributes[legacy[i]] || {}; let attrValue = options[i]; // If the attribute is marked as boolean, parse the diff --git a/api/js/etemplate/et2_widget_template.ts b/api/js/etemplate/et2_widget_template.ts index 0bbbfa9271..5966d6f350 100644 --- a/api/js/etemplate/et2_widget_template.ts +++ b/api/js/etemplate/et2_widget_template.ts @@ -135,9 +135,8 @@ export class et2_template extends et2_DOMWidget { var splitted = template_name.split('.'); var app = splitted.shift(); - // use template base url from initial template, to continue using webdav, if that was loaded via webdav - url = this.getRoot()._inst.template_base_url + app + "/templates/default/" + - splitted.join('.') + ".xet" + (cache_buster ? '?download=' + cache_buster : ''); + url = egw.link('/'+ app + "/templates/default/" + + splitted.join('.')+ ".xet", {download:cache_buster? cache_buster :(new Date).valueOf()}); } // if server did not give a cache-buster, fall back to current time if (url.indexOf('?') == -1) url += '?download='+(new Date).valueOf(); diff --git a/api/js/etemplate/etemplate2.ts b/api/js/etemplate/etemplate2.ts index d7e6ad6d4b..db5a22c614 100644 --- a/api/js/etemplate/etemplate2.ts +++ b/api/js/etemplate/etemplate2.ts @@ -830,7 +830,7 @@ export class etemplate2 public isDirty() { let dirty = false; - this._widgetContainer.iterateOver(function(_widget) + this._widgetContainer?.iterateOver(function(_widget) { if(_widget.isDirty && _widget.isDirty()) {