Panel: Refactor title as a block container (like subtitle)

This commit is contained in:
Molkobain
2021-03-05 10:53:24 +01:00
parent fc98bc781b
commit 4cb9cc7d68
2 changed files with 71 additions and 12 deletions

View File

@@ -27,6 +27,7 @@ use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\UI\Base\tUIContentAreas;
use MetaModel;
use ormStyle;
use utils;
/**
* Class Panel
@@ -103,8 +104,8 @@ class Panel extends UIContentBlock
/** @var bool */
public const DEFAULT_ICON_AS_MEDALLION = false;
/** @var string $sTitle */
protected $sTitle;
/** @var UIContentBlock $oTitleBlock */
protected $oTitleBlock;
/** @var UIContentBlock */
protected $oSubTitleBlock;
/** @var null|string $sIconUrl */
@@ -129,7 +130,13 @@ class Panel extends UIContentBlock
public function __construct(string $sTitle = '', array $aSubBlocks = [], string $sColor = self::DEFAULT_COLOR, ?string $sId = null)
{
parent::__construct($sId);
$this->sTitle = $sTitle;
if (empty($sTitle)) {
$this->oTitleBlock = new UIContentBlock();
} else {
$this->SetTitle($sTitle);
}
$this->oSubTitleBlock = new UIContentBlock();
$this->aSubBlocks = $aSubBlocks;
$this->sIconUrl = static::DEFAULT_ICON_URL;
@@ -142,25 +149,41 @@ class Panel extends UIContentBlock
}
/**
* @see static::$sTitle
* @see static::$oTitleBlock
* @return bool
*/
public function HasTitle(): bool
{
return !empty($this->sTitle);
return $this->oTitleBlock->HasSubBlocks();
}
/**
* @see static::$sTitle
* @see static::$oTitleBlock
* @return string
*/
public function GetTitle()
public function GetTitleBlock()
{
return $this->sTitle;
return $this->oTitleBlock;
}
/**
* @see static::$sTitle
* Set the title from the $oBlock, replacing any existing content
*
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
*
* @return $this
*/
public function SetTitleBlock(iUIBlock $oBlock)
{
$this->oSubTitleBlock = $oBlock;
return $this;
}
/**
* Helper to set the title from a simple text ($sTitle), replacing any existnig block
*
* @see static::$oTitleBlock
*
* @param string $sTitle
*
@@ -168,7 +191,42 @@ class Panel extends UIContentBlock
*/
public function SetTitle(string $sTitle)
{
$this->sTitle = $sTitle;
$this->oTitleBlock = new UIContentBlock();
$this->oTitleBlock->AddHtml(utils::EscapeHtml($sTitle));
return $this;
}
/**
* Add a UIBlock to the title
*
* @see static::$oTitleBlock
*
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
*
* @return $this
*/
public function AddTitleBlock(iUIBlock $oBlock)
{
$this->oTitleBlock->AddSubBlock($oBlock);
return $this;
}
/**
* Add all $aBlocks to the title
*
* @see static::$oTitleBlock
*
* @param array $aBlocks
*
* @return $this
*/
public function AddTitleBlocks(array $aBlocks)
{
foreach ($aBlocks as $oBlock) {
$this->AddTitleBlock($oBlock);
}
return $this;
}
@@ -218,7 +276,8 @@ class Panel extends UIContentBlock
*/
public function SetSubTitle(string $sSubTitle)
{
$this->oSubTitleBlock->AddHtml($sSubTitle);
$this->oSubTitleBlock = new UIContentBlock();
$this->oSubTitleBlock->AddHtml(utils::EscapeHtml($sSubTitle));
return $this;
}

View File

@@ -25,7 +25,7 @@
<div class="ibo-panel--titles">
{% block iboPanelTitles %}
{% if oUIBlock.HasTitle() %}
<div class="ibo-panel--title">{% block iboPanelTitle %}{{ oUIBlock.GetTitle() |raw }}{% endblock %}</div>
<div class="ibo-panel--title">{% block iboPanelTitle %}{{ render_block(oUIBlock.GetTitleBlock()) }}{% endblock %}</div>
{% endif %}
{% if oUIBlock.HasSubTitle() %}
<div class="ibo-panel--subtitle">{% block iboPanelSubTitle %}{{ render_block(oUIBlock.GetSubTitleBlock()) }}{% endblock %}</div>