N°2634 / N°2735 Fix dashlets identifiers : was causing prb on widget init, prefs save

Dashlet id now includes :
* "CUSTOM-" if dashlet is contained in a custom dashboard, nothing elsewhere
* the ID of the dashboard
  - for menus : menu id escaped for HTML
  - for AttributeDashboard : <class>__<field>
* the row / cell / dashlet idx

Examples :
CUSTOM-UserRequestOverview_IDrow1-col0-0
Organization__overview_IDrow1-col0-12
This commit is contained in:
Pierre Goiffon
2020-02-13 18:11:22 +01:00
parent 76982a2846
commit cf83bc7364
5 changed files with 24 additions and 5 deletions

View File

@@ -495,7 +495,10 @@ EOF
$bCanEdit = UserRights::IsAdministrator() || $oAttDef->IsUserEditable();
$sDivId = $oDashboard->GetId();
$oPage->add('<div class="dashboard_contents" id="'.$sDivId.'">');
$aExtraParams = array('query_params' => $this->ToArgsForQuery());
$aExtraParams = array(
'query_params' => $this->ToArgsForQuery(),
'dashboard_div_id' => $sDivId,
);
$oDashboard->Render($oPage, false, $aExtraParams, $bCanEdit);
$oPage->add('</div>');
}

View File

@@ -825,6 +825,8 @@ class RuntimeDashboard extends Dashboard
$aRenderParams = $aExtraParams;
}
$aRenderParams['bCustomized'] = $this->bCustomized;
parent::Render($oPage, $bEditMode, $aRenderParams);
if (isset($aExtraParams['query_params']['this->object()']))
@@ -1092,9 +1094,11 @@ EOF
{
$aRenderParams = $aExtraParams;
}
$aRenderParams['dashboard_div_id'] = $aExtraParams['dashboard_div_id'];
$sJSExtraParams = json_encode($aExtraParams);
$oPage->add('<div id="dashboard_editor">');
$oPage->add('<div class="ui-layout-center">');
$this->SetCustomFlag(true);
$this->Render($oPage, true, $aRenderParams);
$oPage->add('</div>');
$oPage->add('<div class="ui-layout-east">');

View File

@@ -129,10 +129,20 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout
{
if ($oDashlet->IsVisible())
{
$sDashboardId = $oDashlet->GetID();
// N°2634 : we must have a unique id per dashlet !
// To avoid collision with other dashlets with the same ID we prefix it. Collisions typically happen with extensions.
$oDashlet->SetID("row$iRows-col$iCols-$sDashboardId");
$sDashletId = $oDashlet->GetID();
if(strpos($sDashletId, 'IDrow') === false)
{
$sDashboardDivId = $aExtraParams['dashboard_div_id'];
// N°2634 : we must have a unique id per dashlet !
// To avoid collision with other dashlets with the same ID we prefix it with row/cell id
// Collisions typically happen with extensions.
$sDashletId = $sDashboardDivId."_IDrow$iRows-col$iCols-$sDashletId";
if (array_key_exists('bCustomized', $aExtraParams) && ((bool)$aExtraParams['bCustomized']) === true)
{
$sDashletId = 'CUSTOM_'.$sDashletId;
}
$oDashlet->SetID($sDashletId);
}
$oDashlet->DoRender($oPage, $bEditMode, true /* bEnclosingDiv */, $aExtraParams);
}
}

View File

@@ -1205,6 +1205,7 @@ class DashboardMenuNode extends MenuNode
{
$sDivId = preg_replace('/[^a-zA-Z0-9_]/', '', $this->sMenuId);
$oPage->add('<div class="dashboard_contents" id="'.$sDivId.'">');
$aExtraParams['dashboard_div_id'] = $sDivId;
$oDashboard->SetReloadURL($this->GetHyperlink($aExtraParams));
$oDashboard->Render($oPage, false, $aExtraParams);
$oPage->add('</div>');

View File

@@ -1199,6 +1199,7 @@ EOF
case 'dashboard_editor':
$sId = utils::ReadParam('id', '', false, 'raw_data');
$aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data');
$aExtraParams['dashboard_div_id'] = preg_replace('/[^a-zA-Z0-9_]/', '', $sId);
$sDashboardFile = utils::ReadParam('file', '', false, 'raw_data');
$sReloadURL = utils::ReadParam('reload_url', '', false, 'raw_data');
$oKPI = new ExecutionKPI();