Allow to set a customized placeholder for ajax tabs in scrollable mode

This commit is contained in:
Stephen Abello
2021-02-19 17:38:27 +01:00
parent e5d8c885bc
commit ea502e9c81
13 changed files with 355 additions and 46 deletions

View File

@@ -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
//-------------------------------

View File

@@ -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;
}