Add UIBlocks to twig (Changed classes name)

This commit is contained in:
Eric
2021-01-19 17:21:48 +01:00
parent c15a60170d
commit 01c4dff035
27 changed files with 182 additions and 122 deletions

View File

@@ -33,7 +33,7 @@ use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
class AlertUIBlockFactory extends AbstractUIBlockFactory
{
public const TWIG_TAG_NAME = 'UIAlert';
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\Alert\\Alert";
public const UI_BLOCK_CLASS_NAME = Alert::class;
/**
* Make a basis Alert component

View File

@@ -34,7 +34,7 @@ use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
class ButtonUIBlockFactory extends AbstractUIBlockFactory
{
public const TWIG_TAG_NAME = 'UIButton';
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\Button\\Button";
public const UI_BLOCK_CLASS_NAME = Button::class;
//---------------------------------------------
// Regular action buttons, mostly used in forms

View File

@@ -13,7 +13,7 @@ use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
class CollapsibleSectionUIBlockFactory extends AbstractUIBlockFactory
{
public const TWIG_TAG_NAME = 'UICollapsibleSection';
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\CollapsibleSection\\CollapsibleSection";
public const UI_BLOCK_CLASS_NAME = CollapsibleSection::class;
public static function MakeStandard(string $sTitle, ?string $sId = null)
{

View File

@@ -36,7 +36,7 @@ use WebPage;
class DataTableUIBlockFactory extends AbstractUIBlockFactory
{
public const TWIG_TAG_NAME = 'UIDataTable';
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\DataTable\\DataTable";
public const UI_BLOCK_CLASS_NAME = DataTable::class;
/**
* @param \WebPage $oPage

View File

@@ -17,7 +17,7 @@ use Combodo\iTop\Application\UI\Base\UIBlock;
class FieldUIBlockFactory extends AbstractUIBlockFactory
{
public const TWIG_TAG_NAME = 'UIField';
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\Field\\Field";
public const UI_BLOCK_CLASS_NAME = Field::class;
public static function MakeFromParams($aParams)
{

View File

@@ -13,9 +13,9 @@ use ormStyle;
class FieldBadgeUIBlockFactory extends AbstractUIBlockFactory
{
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\FieldBadge\\FieldBadge";
public const TWIG_TAG_NAME = 'UIFieldBadge';
public const UI_BLOCK_CLASS_NAME = FieldBadge::class;
/**
* @param string $sValue
* @param \ormStyle|null $oStyle

View File

@@ -12,8 +12,8 @@ use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
class FieldSetUIBlockFactory extends AbstractUIBlockFactory
{
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\FieldSet\\FieldSet";
public const TWIG_TAG_NAME = 'UIFieldSet';
public const UI_BLOCK_CLASS_NAME = FieldSet::class;
public static function MakeStandard(string $sLegend, ?string $sId = null): FieldSet
{

View File

@@ -12,8 +12,8 @@ use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
class FormUIBlockFactory extends AbstractUIBlockFactory
{
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\Form\\Form";
public const TWIG_TAG_NAME = 'UIForm';
public const UI_BLOCK_CLASS_NAME = Form::class;
public static function MakeStandard(string $sId = null)
{

View File

@@ -11,12 +11,11 @@ namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Field\Field;
use Combodo\iTop\Application\UI\Base\Component\Input\Select\Select;
use Combodo\iTop\Application\UI\Base\Component\Input\Select\SelectOption;
class InputUIBlockFactory extends AbstractUIBlockFactory
{
public const TWIG_TAG_NAME = 'UIInput';
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\Input";
public const UI_BLOCK_CLASS_NAME = Input::class;
public static function MakeForHidden(string $sName, string $sValue, ?string $sId = null): Input
{
@@ -63,6 +62,17 @@ class InputUIBlockFactory extends AbstractUIBlockFactory
return static::MakeInputWithLabel($sInputName, $sLabel, $oInput, $sInputId);
}
private static function MakeInputWithLabel(string $sName, string $sLabel, Input $oInput, ?string $sId = null)
{
$oInput->SetName($sName);
if (is_null($sId)) {
$sId = $oInput->GetId();
}
return new InputWithLabel($sLabel, $oInput, $sId);
}
/**
* If you need to have a real field with a label, you might use a {@link Field} component instead
*
@@ -75,12 +85,6 @@ class InputUIBlockFactory extends AbstractUIBlockFactory
public static function MakeForSelectWithLabel(string $sName, string $sLabel, ?string $sId = null): InputWithLabel
{
$oInput = new Select($sId);
return static::MakeInputWithLabel($sName, $sLabel, $oInput, $sId);
}
private static function MakeInputWithLabel(string $sName, string $sLabel, Input $oInput, ?string $sId = null)
{
$oInput->SetName($sName);
if (is_null($sId)) {
@@ -90,23 +94,4 @@ class InputUIBlockFactory extends AbstractUIBlockFactory
return new InputWithLabel($sLabel, $oInput, $sId);
}
public static function MakeForSelect(string $sName, ?string $sId = null): Select
{
$oInput = new Select($sId);
$oInput->SetName($sName);
return $oInput;
}
public static function MakeForSelectOption(string $sValue, string $sLabel, bool $bSelected, ?string $sId = null): SelectOption
{
$oInput = new SelectOption($sId);
$oInput->SetValue($sValue)
->SetLabel($sLabel)
->SetSelected($bSelected);
return $oInput;
}
}

View File

@@ -21,15 +21,15 @@ class InputWithLabel extends UIBlock
/** @var string */
protected $sLabel;
/** @var \Combodo\iTop\Application\UI\Base\Component\Input\Input */
/** @var \Combodo\iTop\Application\UI\Base\UIBlock */
protected $oInput;
/**
* @param string $sLabel
* @param \Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput $oInput
* @param \Combodo\iTop\Application\UI\Base\UIBlock $oInput
* @param string|null $sId
*/
public function __construct(string $sLabel, AbstractInput $oInput, ?string $sId)
public function __construct(string $sLabel, UIBlock $oInput, ?string $sId)
{
parent::__construct($sId);
$this->sLabel = $sLabel;
@@ -37,7 +37,7 @@ class InputWithLabel extends UIBlock
}
/**
* @return \Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput
* @return UIBlock
*/
public function GetInput()
{
@@ -45,11 +45,11 @@ class InputWithLabel extends UIBlock
}
/**
* @param \Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput $oInput
* @param \Combodo\iTop\Application\UI\Base\UIBlock $oInput
*
* @return $this
*/
public function SetInput(AbstractInput $oInput)
public function SetInput(UIBlock $oInput)
{
$this->oInput = $oInput;

View File

@@ -8,28 +8,81 @@
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
use Combodo\iTop\Application\UI\Base\Component\Input\Input;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
class Select extends Input
class Select extends UIContentBlock
{
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/select/select';
/** @var array */
protected $aOptions;
/** @var string */
protected $sName;
/** @var string */
protected $sValue;
/** @var bool */
protected $bSubmitOnChange = false;
public function __construct(?string $sId = null)
{
parent::__construct($sId);
$this->aOptions = [];
}
public function AddOption(SelectOption $oOption)
{
$this->aOptions[$oOption->GetId()] = $oOption;
$this->AddSubBlock($oOption);
}
public function GetSubBlocks()
public function GetName(): string
{
return $this->aOptions;
return $this->sName;
}
/**
* @param string $sName
*
* @return $this
*/
public function SetName(string $sName)
{
$this->sName = $sName;
return $this;
}
public function GetValue(): ?string
{
return $this->sValue;
}
/**
* @param string|null $sValue
*
* @return $this
*/
public function SetValue(?string $sValue)
{
$this->sValue = $sValue;
return $this;
}
/**
* @return bool
*/
public function GetSubmitOnChange(): bool
{
return $this->bSubmitOnChange;
}
/**
* @param bool $bSubmitOnChange
*
* @return $this
*/
public function SetSubmitOnChange(bool $bSubmitOnChange)
{
$this->bSubmitOnChange = $bSubmitOnChange;
return $this;
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
class SelectOptionUIBlockFactory extends AbstractUIBlockFactory
{
public const TWIG_TAG_NAME = 'UISelectOption';
public const UI_BLOCK_CLASS_NAME = SelectOption::class;
public static function MakeForSelectOption(string $sValue, string $sLabel, bool $bSelected, ?string $sId = null): SelectOption
{
$oInput = new SelectOption($sId);
$oInput->SetValue($sValue)
->SetLabel($sLabel)
->SetSelected($bSelected);
return $oInput;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\Select\Select;
class SelectUIBlockFactory extends AbstractUIBlockFactory
{
public const TWIG_TAG_NAME = 'UISelect';
public const UI_BLOCK_CLASS_NAME = Select::class;
/**
* @param string $sName
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Select\Select
*/
public static function MakeForSelect(string $sName, ?string $sId = null): Select
{
$oInput = new Select($sId);
$oInput->SetName($sName);
return $oInput;
}
}

View File

@@ -273,9 +273,10 @@ class Panel extends UIContentBlock
*
* @inheritDoc
*/
public function AddSubBlock(iUIBlock $oSubBlock) {
$this->AddMainBlock($oSubBlock);
public function AddSubBlock(?iUIBlock $oSubBlock) {
if ($oSubBlock) {
$this->AddMainBlock($oSubBlock);
}
return $this;
}

View File

@@ -36,7 +36,7 @@ use ormStyle;
class PanelUIBlockFactory extends AbstractUIBlockFactory
{
public const TWIG_TAG_NAME = 'UIPanel';
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\Panel\\Panel";
public const UI_BLOCK_CLASS_NAME = Panel::class;
/**
* Make a basis Panel component

View File

@@ -12,8 +12,8 @@ use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
class SpinnerUIBlockFactory extends AbstractUIBlockFactory
{
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\Spinner\\Spinner";
public const TWIG_TAG_NAME = 'UISpinner';
public const UI_BLOCK_CLASS_NAME = Spinner::class;
public static function MakeStandard(?string $sId = null)
{

View File

@@ -15,8 +15,8 @@ use MetaModel;
class TitleUIBlockFactory extends AbstractUIBlockFactory
{
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\Component\\Title\\Title";
public const TWIG_TAG_NAME = 'UITitle';
public const UI_BLOCK_CLASS_NAME = Title::class;
public static function MakeForPage(string $sTitle, ?string $sId = null)
{