Get legacy et2_dialog working with createWidget()

This commit is contained in:
nathan 2022-03-22 17:21:59 -06:00
parent 56ed4e1267
commit 3c4f85155d
2 changed files with 75 additions and 7 deletions

View File

@ -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--)
{

View File

@ -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
{
}
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);