From 3c4f85155d9a097034450aabe2e709669ffb479b Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 22 Mar 2022 17:21:59 -0600 Subject: [PATCH] Get legacy et2_dialog working with createWidget() --- api/js/etemplate/et2_core_inheritance.ts | 12 ++-- api/js/etemplate/et2_widget_dialog.ts | 70 +++++++++++++++++++++++- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/api/js/etemplate/et2_core_inheritance.ts b/api/js/etemplate/et2_core_inheritance.ts index de28bf316d..cf1a3c50ae 100644 --- a/api/js/etemplate/et2_core_inheritance.ts +++ b/api/js/etemplate/et2_core_inheritance.ts @@ -13,8 +13,8 @@ */ import {egw, IegwAppLocal} from "../jsapi/egw_global"; -import {et2_checkType, et2_cloneObject, et2_no_init, et2_validateAttrib} from "./et2_core_common"; -import {et2_IDOMNode, et2_IInput, et2_IInputNode, et2_implements_registry} from "./et2_core_interfaces"; +import {et2_checkType, et2_no_init, et2_validateAttrib} from "./et2_core_common"; +import {et2_implements_registry} from "./et2_core_interfaces"; export class ClassWithInterfaces { @@ -200,11 +200,11 @@ export class ClassWithAttributes extends ClassWithInterfaces let n = 0; do { - n++; - class_tree.push(class_prototype); - class_prototype = Object.getPrototypeOf(class_prototype); + n++; + class_tree.push(class_prototype); + class_prototype = Object.getPrototypeOf(class_prototype); } - while (class_prototype !== ClassWithAttributes && n < 50); + while(class_prototype && class_prototype !== ClassWithAttributes && n < 50); for (let i = class_tree.length - 1; i >= 0; i--) { diff --git a/api/js/etemplate/et2_widget_dialog.ts b/api/js/etemplate/et2_widget_dialog.ts index d303ae65fd..c44540c076 100644 --- a/api/js/etemplate/et2_widget_dialog.ts +++ b/api/js/etemplate/et2_widget_dialog.ts @@ -9,6 +9,7 @@ */ import {Et2Dialog} from "./Et2Dialog/Et2Dialog"; +import {et2_attribute_registry, et2_register_widget, et2_widget} from "./et2_core_widget"; /** * Just a stub that wraps Et2Dialog @@ -16,4 +17,71 @@ import {Et2Dialog} from "./Et2Dialog/Et2Dialog"; */ export class et2_dialog extends Et2Dialog { -} \ No newline at end of file + + constructor(parent, attrs?) + { + super(parent.egw()); + if(attrs) + { + this.transformAttributes(attrs); + } + document.body.appendChild(this); + } + + get template() + { + return super.template || {}; + } + + set template(value) + { + super.template = value; + } + + get div() + { + return this; + } + + /** + * Create a parent to inject application specific egw object with loaded translations into et2_dialog + * + * @param {string|egw} _egw_or_appname egw object with already loaded translations or application name to load translations for + */ + static _create_parent(_egw_or_appname? : string | IegwAppLocal) + { + if(typeof _egw_or_appname == 'undefined') + { + // @ts-ignore + _egw_or_appname = egw_appName; + } + // create a dummy parent with a correct reference to an application specific egw object + let parent = new et2_widget(); + // if egw object is passed in because called from et2, just use it + if(typeof _egw_or_appname != 'string') + { + parent.setApiInstance(_egw_or_appname); + } + // otherwise use given appname to create app-specific egw instance and load default translations + else + { + parent.setApiInstance(egw(_egw_or_appname)); + parent.egw().langRequireApp(parent.egw().window, _egw_or_appname); + } + return parent; + } +} + +// Get it working transparently as a legacy dialog +et2_register_widget(et2_dialog, ["dialog", "legacy_dialog"]); +const type_map = {String: "string", Function: "js"}; +let attrs = {}; +for(const [key, value] of Object.entries(et2_dialog.properties)) +{ + let attr = et2_dialog.properties[key]; + + attrs[key] = {type: type_map[attr.type?.name || attr.name] || "string"}; +} +et2_attribute_registry[et2_dialog.name] = attrs + +customElements.define("legacy-dialog", et2_dialog); \ No newline at end of file