Make dashlet that needs to execute JS be able to do so in the first paint and when refreshed

This commit is contained in:
Stephen Abello
2026-01-19 17:00:31 +01:00
parent 6aa8ac7ff1
commit cb61ae8d61
4 changed files with 32 additions and 5 deletions

View File

@@ -88,7 +88,8 @@ class IboGrid extends HTMLElement {
RefreshDashlet (sDashlet, aOptions = {}) {
const oParser = new DOMParser();
const oDocument = oParser.parseFromString(sDashlet, 'text/html');
const oNewDashlet = oDocument.body.firstElementChild;
const oNewDashlet = oDocument.body.querySelector('ibo-dashlet');
const oNewScript = oDocument.body.querySelectorAll('script');
// Can't use oNewDashet.sDashletId as it's not in the DOM yet and connectedCallback hasn't been called yet
const oExistingDashlet = this.GetDashletElement(oNewDashlet.getAttribute('data-dashlet-id') );
@@ -114,6 +115,21 @@ class IboGrid extends HTMLElement {
oSlotForExistingDashlet.innerHTML = oNewDashlet.outerHTML;
this.oGrid.makeWidget(oSlotForExistingDashlet);
}
// Append scripts to body so they are executed
oNewScript.forEach( oScript => {
if (oScript) {
const oNewScriptElement = document.createElement('script');
// copy attributes
[...oScript.attributes].forEach(attr =>
oNewScriptElement.setAttribute(attr.name, attr.value)
);
oNewScriptElement.text = oScript.textContent;
document.body.appendChild(oNewScriptElement);
}
});
}
CloneDashlet(sDashletId) {

View File

@@ -58,4 +58,9 @@ class DashletWrapper extends UIBlock
{
return $this->aFormViewData;
}
public function GetSubBlocks(): array
{
return [$this->oDashletContainer];
}
}

View File

@@ -61,4 +61,9 @@ class DashboardGrid extends UIBlock
return $this;
}
public function GetSubBlocks(): array
{
return $this->aSlots;
}
}

View File

@@ -36,10 +36,6 @@ class DashboardGridSlot extends UIBlock
$this->iHeight = $iHeight;
}
public function GetSubBlocks(): array
{
return [$this->oUIBlock];
}
public function HasPositionX(): bool
{
@@ -116,4 +112,9 @@ class DashboardGridSlot extends UIBlock
return $this;
}
public function GetSubBlocks(): array
{
return [$this->oDashlet];
}
}