mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Make dashlet that needs to execute JS be able to do so in the first paint and when refreshed
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -58,4 +58,9 @@ class DashletWrapper extends UIBlock
|
||||
{
|
||||
return $this->aFormViewData;
|
||||
}
|
||||
|
||||
public function GetSubBlocks(): array
|
||||
{
|
||||
return [$this->oDashletContainer];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,9 @@ class DashboardGrid extends UIBlock
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetSubBlocks(): array
|
||||
{
|
||||
return $this->aSlots;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user