mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
Allow to set a customized placeholder for ajax tabs in scrollable mode
This commit is contained in:
@@ -24,6 +24,7 @@ use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use Combodo\iTop\Application\UI\Base\UIException;
|
||||
use Dict;
|
||||
use TabManager;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class AjaxTab
|
||||
@@ -33,15 +34,37 @@ use TabManager;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class AjaxTab extends Tab {
|
||||
|
||||
const ENUM_TAB_PLACEHOLDER_REL_PATH_LIST = 'images/placeholders/skeleton-list.svg';
|
||||
const ENUM_TAB_PLACEHOLDER_REL_PATH_DASHBOARD = 'images/placeholders/skeleton-dashboard.svg';
|
||||
const ENUM_TAB_PLACEHOLDER_REL_PATH_OBJECT = 'images/placeholders/skeleton-object.svg';
|
||||
const ENUM_TAB_PLACEHOLDER_REL_PATH_MISC = 'images/placeholders/skeleton.svg';
|
||||
|
||||
const DEFAULT_TAB_PLACEHOLDER_REL_PATH = self::ENUM_TAB_PLACEHOLDER_REL_PATH_MISC;
|
||||
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-ajax-tab';
|
||||
public const TAB_TYPE = TabManager::ENUM_TAB_TYPE_AJAX;
|
||||
|
||||
/** @var string Placeholder displayed before tab is loaded */
|
||||
private $sPlaceholderRelPath;
|
||||
/** @var string The target URL to be loaded asynchronously */
|
||||
private $sUrl;
|
||||
/** @var bool Whether the tab should should be cached by the browser or always refreshed */
|
||||
private $bCache;
|
||||
|
||||
/**
|
||||
* Tab constructor.
|
||||
*
|
||||
* @param string $sTabCode
|
||||
* @param string $sTitle
|
||||
* @param string $sPlaceholderRelPath
|
||||
*/
|
||||
public function __construct(string $sTabCode, string $sTitle, string $sPlaceholderRelPath = AjaxTab::DEFAULT_TAB_PLACEHOLDER_REL_PATH)
|
||||
{
|
||||
parent::__construct($sTabCode, $sTitle);
|
||||
$this->sPlaceholderRelPath = $sPlaceholderRelPath;
|
||||
}
|
||||
/**
|
||||
* @param string $sUrl
|
||||
*
|
||||
@@ -82,6 +105,35 @@ class AjaxTab extends Tab {
|
||||
return $this->bCache ? 'true' : 'false';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sPlaceholderRelPath
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetPlaceholderRelPath(string $sPlaceholderRelPath) {
|
||||
$this->sPlaceholderRelPath = $sPlaceholderRelPath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetPlaceholderRelPath(): string {
|
||||
return $this->sPlaceholderRelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetPlaceholderAbsPath(): string {
|
||||
return utils::GetAbsoluteUrlAppRoot().$this->sPlaceholderRelPath;
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// iUIBlock implementation
|
||||
//-------------------------------
|
||||
|
||||
@@ -113,13 +113,17 @@ class TabContainer extends UIContentBlock
|
||||
/**
|
||||
* @param string $sTabCode
|
||||
* @param string $sTitle
|
||||
* @param string|null $sPlaceholder
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\TabContainer\Tab\Tab
|
||||
* @throws \Combodo\iTop\Application\UI\Base\UIException
|
||||
*/
|
||||
public function AddAjaxTab(string $sTabCode, string $sTitle): Tab
|
||||
public function AddAjaxTab(string $sTabCode, string $sTitle, ?string $sPlaceholder = null): Tab
|
||||
{
|
||||
$oTab = new AjaxTab($sTabCode, $sTitle);
|
||||
if($sPlaceholder === null){
|
||||
$sPlaceholder = AjaxTab::DEFAULT_TAB_PLACEHOLDER_REL_PATH;
|
||||
}
|
||||
$oTab = new AjaxTab($sTabCode, $sTitle, $sPlaceholder);
|
||||
$this->AddSubBlock($oTab);
|
||||
return $oTab;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\TabContainer\Tab\AjaxTab;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\TabContainer\Tab\Tab;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\TabContainer\TabContainer;
|
||||
|
||||
@@ -198,17 +199,18 @@ class TabManager
|
||||
* the tab to be reloaded upon each activation.
|
||||
*
|
||||
* @param string|null $sTabTitle
|
||||
* @param string $sPlaceholder
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \Combodo\iTop\Application\UI\Base\UIException
|
||||
* @since 2.0.3
|
||||
*/
|
||||
public function AddAjaxTab(string $sTabCode, string $sUrl, bool $bCache = true, string $sTabTitle = null): string
|
||||
public function AddAjaxTab(string $sTabCode, string $sUrl, bool $bCache = true, string $sTabTitle = null, string $sPlaceholder = null): string
|
||||
{
|
||||
// Set the content of the tab
|
||||
/** @var \Combodo\iTop\Application\UI\Base\Layout\TabContainer\Tab\AjaxTab $oTab */
|
||||
$oTab = $this->InitTab($this->m_sCurrentTabContainer, $sTabCode, static::ENUM_TAB_TYPE_AJAX, $sTabTitle);
|
||||
$oTab = $this->InitTab($this->m_sCurrentTabContainer, $sTabCode, static::ENUM_TAB_TYPE_AJAX, $sTabTitle, $sPlaceholder);
|
||||
$oTab->SetUrl($sUrl)
|
||||
->SetCache($bCache);
|
||||
|
||||
@@ -311,12 +313,13 @@ class TabManager
|
||||
* @param string $sTabCode
|
||||
* @param string $sTabType
|
||||
* @param string|null $sTabTitle
|
||||
* @param string|null $sPlaceholder
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\TabContainer\Tab\Tab
|
||||
* @throws \Combodo\iTop\Application\UI\Base\UIException
|
||||
* @since 2.7.0
|
||||
*/
|
||||
protected function InitTab(string $sTabContainer, string $sTabCode, string $sTabType = self::DEFAULT_TAB_TYPE, string $sTabTitle = null): Tab
|
||||
protected function InitTab(string $sTabContainer, string $sTabCode, string $sTabType = self::DEFAULT_TAB_TYPE, string $sTabTitle = null, string $sPlaceholder = null): Tab
|
||||
{
|
||||
$oTab = null;
|
||||
if (!$this->TabExists($sTabContainer, $sTabCode)) {
|
||||
@@ -330,7 +333,7 @@ class TabManager
|
||||
|
||||
switch ($sTabType) {
|
||||
case static::ENUM_TAB_TYPE_AJAX:
|
||||
$oTab = $oTabContainer->AddAjaxTab($sTabCode, $sTitle);
|
||||
$oTab = $oTabContainer->AddAjaxTab($sTabCode, $sTitle, $sPlaceholder);
|
||||
break;
|
||||
|
||||
case static::ENUM_TAB_TYPE_HTML:
|
||||
|
||||
@@ -1045,9 +1045,9 @@ EOF
|
||||
* @throws \Exception
|
||||
* @since 2.0.3
|
||||
*/
|
||||
public function AddAjaxTab($sTabCode, $sUrl, $bCache = true, $sTabTitle = null)
|
||||
public function AddAjaxTab($sTabCode, $sUrl, $bCache = true, $sTabTitle = null, $sPlaceholder = null)
|
||||
{
|
||||
$this->add($this->m_oTabs->AddAjaxTab($sTabCode, $sUrl, $bCache, $sTabTitle));
|
||||
$this->add($this->m_oTabs->AddAjaxTab($sTabCode, $sUrl, $bCache, $sTabTitle, $sPlaceholder));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user