* @package Combodo\iTop\Application\UI\Base\Component\Panel * @since 3.0.0 */ class Panel extends UIContentBlock { use tUIContentAreas; // Overloaded constants public const BLOCK_CODE = 'ibo-panel'; public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/panel/layout'; public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/panel/layout'; // Specific constants /** @var string ENUM_COLOR_PRIMARY */ public const ENUM_COLOR_PRIMARY = 'primary'; /** @var string ENUM_COLOR_SECONDARY */ public const ENUM_COLOR_SECONDARY = 'secondary'; /** @var string ENUM_COLOR_NEUTRAL */ public const ENUM_COLOR_NEUTRAL = 'neutral'; /** @var string ENUM_COLOR_INFORMATION */ public const ENUM_COLOR_INFORMATION = 'information'; /** @var string ENUM_COLOR_SUCCESS */ public const ENUM_COLOR_SUCCESS = 'success'; /** @var string ENUM_COLOR_FAILURE */ public const ENUM_COLOR_FAILURE = 'failure'; /** @var string ENUM_COLOR_WARNING */ public const ENUM_COLOR_WARNING = 'warning'; /** @var string ENUM_COLOR_DANGER */ public const ENUM_COLOR_DANGER = 'danger'; /** @var string ENUM_COLOR_GREY */ public const ENUM_COLOR_GREY = 'grey'; /** @var string ENUM_COLOR_BLUEGREY */ public const ENUM_COLOR_BLUEGREY = 'blue-grey'; /** @var string ENUM_COLOR_BLUE */ public const ENUM_COLOR_BLUE = 'blue'; /** @var string ENUM_COLOR_CYAN */ public const ENUM_COLOR_CYAN = 'cyan'; /** @var string ENUM_COLOR_GREEN */ public const ENUM_COLOR_GREEN = 'green'; /** @var string ENUM_COLOR_ORANGE */ public const ENUM_COLOR_ORANGE = 'orange'; /** @var string ENUM_COLOR_RED */ public const ENUM_COLOR_RED = 'red'; /** @var string ENUM_COLOR_PINK */ public const ENUM_COLOR_PINK = 'pink'; /** @var string ENUM_CONTENT_AREA_MAIN The main content area (panel body) */ public const ENUM_CONTENT_AREA_MAIN = 'main'; /** @var string ENUM_CONTENT_AREA_TOOLBAR The toolbar content area (for actions) */ public const ENUM_CONTENT_AREA_TOOLBAR = 'toolbar'; /** @var string DEFAULT_COLOR */ public const DEFAULT_COLOR = self::ENUM_COLOR_NEUTRAL; /** @var string $sTitle */ protected $sTitle; /** @var string $sColor */ protected $sColor; /** @var string $sSubTitle */ protected $sSubTitle; /** @var bool $bIsCollapsible */ protected $bIsCollapsible; /** * Panel constructor. * * @param string $sTitle * @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aSubBlocks * @param string $sColor * @param string|null $sId */ public function __construct(string $sTitle = '', array $aSubBlocks = [], string $sColor = self::DEFAULT_COLOR, ?string $sId = null) { parent::__construct($sId); $this->sTitle = $sTitle; $this->aSubBlocks = $aSubBlocks; $this->sColor = $sColor; $this->SetMainBlocks([]); $this->SetToolBlocks([]); $this->bIsCollapsible = false; } /** * @return string */ public function GetTitle() { return $this->sTitle; } /** * @param string $sTitle * * @return $this */ public function SetTitle(string $sTitle) { $this->sTitle = $sTitle; return $this; } /** * @return string */ public function GetColor() { return $this->sColor; } /** * @param string $sColor * * @return $this */ public function SetColor(string $sColor) { $this->sColor = $sColor; return $this; } /** * @return string */ public function GetSubTitle() { return $this->sSubTitle; } /** * @param string $sSubTitle * * @return $this */ public function SetSubTitle(string $sSubTitle) { $this->sSubTitle = $sSubTitle; return $this; } /** * @return bool */ public function isIsCollapsible(): bool { return $this->bIsCollapsible; } /** * @param bool $bIsCollapsible * * @return $this */ public function SetIsCollapsible(bool $bIsCollapsible) { $this->bIsCollapsible = $bIsCollapsible; return $this; } //---------------------- // Specific content area //---------------------- /** * Set all main blocks at once. * * @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aBlocks * * @return $this */ public function SetMainBlocks(array $aBlocks) { $this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN, $aBlocks); return $this; } /** * Return all the main blocks * * @return \Combodo\iTop\Application\UI\Base\iUIBlock[] * @throws \Exception */ public function GetMainBlocks(): array { return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN); } /** * Add the $oBlock to the main blocks. * Note that if a block with the same ID already exists, it will be replaced. * * @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock * * @return $this */ public function AddMainBlock(iUIBlock $oBlock) { $this->AddBlockToContentArea(static::ENUM_CONTENT_AREA_MAIN, $oBlock); return $this; } /** * Remove the main block identified by $sBlockId. * Note that if no block with that ID exists, it will proceed silently. * * @param string $sBlockId * * @return $this */ public function RemoveMainBlock(string $sBlockId) { $this->RemoveBlockFromContentArea(static::ENUM_CONTENT_AREA_MAIN, $sBlockId); return $this; } /** * Set all toolbar blocks at once. * * @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aBlocks * * @return $this */ public function SetToolBlocks(array $aBlocks) { $this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_TOOLBAR, $aBlocks); return $this; } /** * Return all the toolbar blocks * * @return \Combodo\iTop\Application\UI\Base\iUIBlock[] * @throws \Exception */ public function GetToolbarBlocks(): array { return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_TOOLBAR); } /** * Add the $oBlock to the toolbar blocks. * Note that if a block with the same ID already exists, it will be replaced. * * @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock * * @return $this */ public function AddToolbarBlock(iUIBlock $oBlock) { $this->AddBlockToContentArea(static::ENUM_CONTENT_AREA_TOOLBAR, $oBlock); return $this; } /** * Remove the toolbar block identified by $sBlockId. * Note that if no block with that ID exists, it will proceed silently. * * @param string $sBlockId * * @return $this */ public function RemoveToolbarBlock(string $sBlockId) { $this->RemoveBlockFromContentArea(static::ENUM_CONTENT_AREA_TOOLBAR, $sBlockId); return $this; } //------------------------------- // iUIContentBlock implementation //------------------------------- /** * @inheritDoc */ public function AddHtml(string $sHtml) { $oBlock = new Html($sHtml); $this->AddMainBlock($oBlock); return $this; } /** * Add the $oSubBlock directly in the main area * * @inheritDoc */ public function AddSubBlock(?iUIBlock $oSubBlock) { if ($oSubBlock) { $this->AddMainBlock($oSubBlock); } return $this; } /** * Remove a specified subBlock from all the areas * * @param string $sId * * @return $this */ public function RemoveSubBlock(string $sId) { foreach ($this->GetContentAreas() as $oContentArea) { $oContentArea->RemoveSubBlock($sId); } return $this; } /** * Check if the specified subBlock is within one of all the areas * * @param string $sId * * @return bool */ public function HasSubBlock(string $sId): bool { foreach ($this->GetContentAreas() as $oContentArea) { if ($oContentArea->HasSubBlock($sId)) { return true; } } return false; } /** * Get a specific subBlock within all the areas * * @inheritDoc */ public function GetSubBlock(string $sId): ?iUIBlock { foreach ($this->GetContentAreas() as $oContentArea) { $oSubBlock = $oContentArea->GetSubBlock($sId); if (!is_null($oSubBlock)) { return $oSubBlock; } } return null; } /** * Set the MAIN AREA subBlocks * * @inheritDoc * @return $this|\Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock */ public function SetSubBlocks(array $aSubBlocks): iUIContentBlock { $this->SetMainBlocks($aSubBlocks); return $this; } /** * Get ALL the blocks in all the areas * * @inheritDoc */ public function GetSubBlocks(): array { $aSubBlocks = []; foreach ($this->GetContentAreas() as $oContentArea) { $aSubBlocks = array_merge($aSubBlocks, $oContentArea->GetSubBlocks()); } return $aSubBlocks; } }