diff --git a/application/dashboardlayout.class.inc.php b/application/dashboardlayout.class.inc.php index a2041d6d2..013f162f1 100644 --- a/application/dashboardlayout.class.inc.php +++ b/application/dashboardlayout.class.inc.php @@ -151,7 +151,7 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout } $iCellIdx++; } - $sJSReload .= $oDashboardRow->GetJSRefresh()."\n"; + $sJSReload .= $oDashboardRow->GetJSRefreshCallback()."\n"; } $oPage->add_script("function updateDashboard".$aExtraParams['dashboard_div_id']."(){".$sJSReload."}"); diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 09c3389d8..3ab5797b3 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -430,11 +430,7 @@ class DisplayBlock public function GetDisplay(WebPage $oPage, $sId, $aExtraParams = array()): UIContentBlock { - if (isset($aExtraParams['withJSRefreshCallBack'])) { - $oHtml = new UIContentBlockWithJSRefreshCallback($sId); - } else { - $oHtml = new UIContentBlock($sId); - } + $oHtml = new UIContentBlock($sId); $oHtml->AddCSSClass("display_block"); $aExtraParams = array_merge($aExtraParams, $this->m_aParams); diff --git a/sources/application/UI/Base/Component/Alert/Alert.php b/sources/application/UI/Base/Component/Alert/Alert.php index e1acf32c1..8facc3e2c 100644 --- a/sources/application/UI/Base/Component/Alert/Alert.php +++ b/sources/application/UI/Base/Component/Alert/Alert.php @@ -276,8 +276,4 @@ class Alert extends UIContentBlock return $this->sSectionStateStorageKey; } - public function GetJSRefresh(): string - { - return ""; - } } \ No newline at end of file diff --git a/sources/application/UI/Base/Component/Dashlet/DashletBadge.php b/sources/application/UI/Base/Component/Dashlet/DashletBadge.php index 50fa63554..a41063b14 100644 --- a/sources/application/UI/Base/Component/Dashlet/DashletBadge.php +++ b/sources/application/UI/Base/Component/Dashlet/DashletBadge.php @@ -8,8 +8,12 @@ namespace Combodo\iTop\Application\UI\Base\Component\Dashlet; +use Combodo\iTop\Application\UI\Base\tJSRefreshCallback; + class DashletBadge extends DashletContainer { + use tJSRefreshCallback; + public const BLOCK_CODE = 'ibo-dashlet-badge'; public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/dashlet/dashlet-badge'; public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/dashlet/dashlet-badge'; @@ -73,6 +77,7 @@ class DashletBadge extends DashletContainer public function SetCreateActionUrl(string $sCreateActionUrl): DashletBadge { $this->sCreateActionUrl = $sCreateActionUrl; + return $this; } @@ -92,6 +97,7 @@ class DashletBadge extends DashletContainer public function SetCreateActionLabel(string $sCreateActionLabel): DashletBadge { $this->sCreateActionLabel = $sCreateActionLabel; + return $this; } @@ -111,6 +117,7 @@ class DashletBadge extends DashletContainer public function SetClassIconUrl(string $sClassIconUrl): DashletBadge { $this->sClassIconUrl = $sClassIconUrl; + return $this; } @@ -130,6 +137,7 @@ class DashletBadge extends DashletContainer public function SetHyperlink(string $sHyperlink): DashletBadge { $this->sHyperlink = $sHyperlink; + return $this; } @@ -149,6 +157,7 @@ class DashletBadge extends DashletContainer public function SetCount(string $iCount): DashletBadge { $this->iCount = $iCount; + return $this; } diff --git a/sources/application/UI/Base/Component/Dashlet/DashletContainer.php b/sources/application/UI/Base/Component/Dashlet/DashletContainer.php index 60f5ec650..2dea6f1d3 100644 --- a/sources/application/UI/Base/Component/Dashlet/DashletContainer.php +++ b/sources/application/UI/Base/Component/Dashlet/DashletContainer.php @@ -9,11 +9,9 @@ namespace Combodo\iTop\Application\UI\Base\Component\Dashlet; use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock; -use Combodo\iTop\Application\UI\Base\tJSRefreshCallback; class DashletContainer extends UIContentBlock { - use tJSRefreshCallback; public const BLOCK_CODE = 'ibo-dashlet'; public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/layouts/content-block/layout'; diff --git a/sources/application/UI/Base/Component/DataTable/DataTable.php b/sources/application/UI/Base/Component/DataTable/DataTable.php index fc5413672..41968f29f 100644 --- a/sources/application/UI/Base/Component/DataTable/DataTable.php +++ b/sources/application/UI/Base/Component/DataTable/DataTable.php @@ -8,6 +8,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\DataTable; use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock; +use Combodo\iTop\Application\UI\Base\tJSRefreshCallback; use DataTableConfig; /** @@ -18,6 +19,8 @@ use DataTableConfig; */ class DataTable extends UIContentBlock { + use tJSRefreshCallback; + // Overloaded constants public const BLOCK_CODE = 'ibo-datatable'; public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/datatable/layout'; @@ -159,8 +162,9 @@ class DataTable extends UIContentBlock $this->aOptions = $aOptions; } - public function GetJSRefresh():array{ - return ["$('#".$this->sId."').DataTable().clearPipeline(); - $('#".$this->sId."').DataTable().ajax.reload(null, false);"]; + public function GetJSRefresh(): string + { + return "$('#".$this->sId."').DataTable().clearPipeline(); + $('#".$this->sId."').DataTable().ajax.reload(null, false);"; } } diff --git a/sources/application/UI/Base/Component/Panel/Panel.php b/sources/application/UI/Base/Component/Panel/Panel.php index 2168ff95c..b6b319b88 100644 --- a/sources/application/UI/Base/Component/Panel/Panel.php +++ b/sources/application/UI/Base/Component/Panel/Panel.php @@ -355,8 +355,4 @@ class Panel extends UIContentBlock return $aSubBlocks; } - public function GetJSRefresh(): string - { - return ""; - } } diff --git a/sources/application/UI/Base/tJSRefreshCallback.php b/sources/application/UI/Base/tJSRefreshCallback.php index 685a3c390..d1934a4ec 100644 --- a/sources/application/UI/Base/tJSRefreshCallback.php +++ b/sources/application/UI/Base/tJSRefreshCallback.php @@ -6,34 +6,61 @@ namespace Combodo\iTop\Application\UI\Base; -use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock; -use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock; -use Dict; - /** * Trait tJSRefreshCallback * - * This brings the ability to a UIBlock to have give the JS to use in order to refresh it + * This brings the ability to a UIBlock to give the JS to use in order to refresh it + * All bricks with JS refresh must use directly this trait in order to be found by the function class_uses in GetRecursiveJSRefresh * - * @package Combodo\iTop\Application\UI\Base * @internal + * @package Combodo\iTop\Application\UI\Base * @since 3.0.0 */ -trait tJSRefreshCallback { +trait tJSRefreshCallback +{ /** @var string */ protected $sJSRefresh = ""; /** + * Get JS refresh for $this + * * @return string */ - public function GetJSRefresh():string + public function GetJSRefresh(): string { - $sJSRefresh = $this->sJSRefresh; - foreach ($this->GetSubBlocks() as $oSubBlock) { - if( $oSubBlock->GetJSRefresh() !="") { - $sJSRefresh =$oSubBlock->GetJSRefresh().'\n'.$sJSRefresh; + return $this->sJSRefresh; + } + + /** + * Get the global JS refresh for all subblocks + * + * @return string + */ + public function GetJSRefreshCallback(): string + { + $sJSRefresh = $this->GetJSRefresh(); + tJSRefreshCallback::GetRecursiveJSRefresh($this, $sJSRefresh); + + return $sJSRefresh; + } + + /** + * method only for private use in GetJSRefreshCallback + * + * @param $oBlock + * @param $sJSRefresh + * + * @return string + */ + public static function GetRecursiveJSRefresh($oBlock, &$sJSRefresh): string + { + foreach ($oBlock->GetSubBlocks() as $oSubBlock) { + $usingTrait = in_array('Combodo\iTop\Application\UI\Base\tJSRefreshCallback', class_uses(get_class($oSubBlock))); + if ($usingTrait && $oSubBlock->GetJSRefresh() != "") { + $sJSRefresh = $oSubBlock->GetJSRefresh().'\n'.$sJSRefresh; } + tJSRefreshCallback::GetRecursiveJSRefresh($oSubBlock, $sJSRefresh); } return $sJSRefresh;