Implement parent_node attribute

Fixes calendar sidebox was not shown
This commit is contained in:
nathan 2021-11-10 13:41:23 -07:00
parent 7b11a25b8d
commit d15d7a3426

View File

@ -47,6 +47,13 @@ const Et2WidgetMixin = (superClass) =>
private _inst : etemplate2 | null = null; private _inst : etemplate2 | null = null;
private supportedWidgetClasses = []; private supportedWidgetClasses = [];
/**
* If we put the widget somewhere other than as a child of its parent, we need to record that so
* we don't move it back to the parent.
* @type {Element}
* @protected
*/
protected _parent_node : Element;
/** /**
* Not actually required by et2_widget, but needed to keep track of non-webComponent children * Not actually required by et2_widget, but needed to keep track of non-webComponent children
*/ */
@ -101,6 +108,12 @@ const Et2WidgetMixin = (superClass) =>
reflect: true reflect: true
}, },
/**
* Widget ID of another node to insert this node into instead of the normal location
* This isn't a normal property...
*/
parent_node: {type: String},
/** /**
* Tooltip which is shown for this element on hover * Tooltip which is shown for this element on hover
*/ */
@ -616,7 +629,7 @@ const Et2WidgetMixin = (superClass) =>
* rest themselves with their normal lifecycle (especially connectedCallback(), which is kind * rest themselves with their normal lifecycle (especially connectedCallback(), which is kind
* of the equivalent of doLoadingFinished() * of the equivalent of doLoadingFinished()
*/ */
if(this.getParent() instanceof et2_widget && (<et2_DOMWidget>this.getParent()).getDOMNode(this) != this.parentNode) if(!this._parent_node && this.getParent() instanceof et2_widget && (<et2_DOMWidget>this.getParent()).getDOMNode(this) != this.parentNode)
{ {
this.getParent().getDOMNode(this).append(this); this.getParent().getDOMNode(this).append(this);
} }
@ -678,6 +691,25 @@ const Et2WidgetMixin = (superClass) =>
return check_children(this.getChildren()) || null; return check_children(this.getChildren()) || null;
} }
/**
* Parent is different than what is specified in the template / hierarchy.
* Find it and re-parent there.
*
* @param {string} parent
*/
set parent_node(parent : string | Element)
{
if(typeof parent === "string")
{
parent = document.querySelector("#" + parent);
}
if(parent)
{
parent.append(this);
this._parent_node = parent;
}
}
setParent(new_parent : Et2WidgetClass | et2_widget) setParent(new_parent : Et2WidgetClass | et2_widget)
{ {
this._parent = new_parent; this._parent = new_parent;