Make clone dashlet ask for a rendered dashlet to the backend

This commit is contained in:
Stephen Abello
2026-01-12 10:34:57 +01:00
parent f79bb9d51c
commit ff11aec7fe
3 changed files with 14 additions and 13 deletions

View File

@@ -89,7 +89,7 @@ class IboGrid extends HTMLElement {
const oParser = new DOMParser();
const oDocument = oParser.parseFromString(sDashlet, 'text/html');
const oNewDashlet = oDocument.body.firstChild;
debugger;
// 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') );
oExistingDashlet.replaceWith(oNewDashlet);
@@ -103,11 +103,9 @@ class IboGrid extends HTMLElement {
const sWidth = oSlot.iWidth;
const sHeight = oSlot.iHeight;
// TODO 3.3: Should ask a rendered dashlet for its content to avoid duplicating IDs
// Still we'll position it automatically and take care of height/width
const sDashletContent = oSlot.oDashlet.innerHTML;
this.AddDashlet(sDashletContent, {
// Ask a new rendered dashlet to avoid duplicating IDs
// Still we'll copy width and height
this.closest('ibo-dashboard')?.AddNewDashlet(oSlot.oDashlet.sType, oSlot.oDashlet.formData, {
'w': sWidth,
'h': sHeight
});

View File

@@ -83,7 +83,7 @@ class IboDashboard extends HTMLElement {
}
}
AddNewDashlet(sDashletClass, aDashletOptions = {}) {
AddNewDashlet(sDashletClass, sDashletValues, aDashletOptions = {}) {
const sNewDashletUrl = GetAbsoluteUrlAppRoot() + '/pages/UI.php?route=dashboard.get_dashlet&dashlet_class='+encodeURIComponent(sDashletClass);
fetch(sNewDashletUrl)
.then(async data => {

View File

@@ -3,11 +3,14 @@
$('#{{ oUIBlock.GetId() }} .ibo-dashlet-entry').on('click', (event) => {
const sDashletClass = event.currentTarget.getAttribute('data-dashlet-class');
const oDashboard = document.querySelector('ibo-dashboard');
oDashboard.AddNewDashlet(sDashletClass, {
'minW': event.currentTarget.getAttribute('data-min-width'),
'minH': event.currentTarget.getAttribute('data-min-height'),
'w': event.currentTarget.getAttribute('data-preferred-width'),
'h': event.currentTarget.getAttribute('data-preferred-height')
});
oDashboard.AddNewDashlet(sDashletClass,
{},
{
'minW': event.currentTarget.getAttribute('data-min-width'),
'minH': event.currentTarget.getAttribute('data-min-height'),
'w': event.currentTarget.getAttribute('data-preferred-width'),
'h': event.currentTarget.getAttribute('data-preferred-height')
}
);
});
})();