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

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