mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-29 21:48:45 +02:00
N°2847 - Form and Input WIP
This commit is contained in:
91
sources/application/UI/Component/Input/Input.php
Normal file
91
sources/application/UI/Component/Input/Input.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Component\Input;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
|
||||
/**
|
||||
* Class Input
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Component\Input
|
||||
*/
|
||||
class Input extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-input';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'components/input/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'components/input/layout';
|
||||
|
||||
public const INPUT_HIDDEN = 'hidden';
|
||||
|
||||
/** @var string */
|
||||
protected $sType;
|
||||
/** @var string */
|
||||
protected $sName;
|
||||
/** @var string */
|
||||
protected $sValue;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetType(): string
|
||||
{
|
||||
return $this->sType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sType
|
||||
*
|
||||
* @return Input
|
||||
*/
|
||||
public function SetType(string $sType): Input
|
||||
{
|
||||
$this->sType = $sType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetName(): string
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return Input
|
||||
*/
|
||||
public function SetName(string $sName): Input
|
||||
{
|
||||
$this->sName = $sName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValue(): string
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return Input
|
||||
*/
|
||||
public function SetValue(string $sValue): Input
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
46
sources/application/UI/Component/Input/InputFactory.php
Normal file
46
sources/application/UI/Component/Input/InputFactory.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Component\Input;
|
||||
|
||||
|
||||
class InputFactory
|
||||
{
|
||||
|
||||
public static function MakeForHidden(string $sName, string $sValue, ?string $sId = null): Input
|
||||
{
|
||||
$oInput = new Input($sId);
|
||||
|
||||
$oInput->SetType(Input::INPUT_HIDDEN)
|
||||
->SetName($sName)
|
||||
->SetValue($sValue);
|
||||
|
||||
return $oInput;
|
||||
}
|
||||
|
||||
public static function MakeForSelect(string $sName, string $sLabel, ?string $sId = null): Select
|
||||
{
|
||||
$oInput = new Select($sId);
|
||||
|
||||
$oInput->SetName($sName)
|
||||
->SetLabel($sLabel);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
37
sources/application/UI/Component/Input/InputWithLabel.php
Normal file
37
sources/application/UI/Component/Input/InputWithLabel.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Component\Input;
|
||||
|
||||
|
||||
class InputWithLabel extends Input
|
||||
{
|
||||
public const HTML_TEMPLATE_REL_PATH = 'components/input/InputWithLabel';
|
||||
|
||||
/** @var string */
|
||||
protected $sLabel;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel(): string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return InputWithLabel
|
||||
*/
|
||||
public function SetLabel(string $sLabel): InputWithLabel
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
33
sources/application/UI/Component/Input/Select.php
Normal file
33
sources/application/UI/Component/Input/Select.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Component\Input;
|
||||
|
||||
|
||||
class Select extends InputWithLabel
|
||||
{
|
||||
public const HTML_TEMPLATE_REL_PATH = 'components/input/Select';
|
||||
|
||||
/** @var array */
|
||||
protected $aOptions;
|
||||
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->aOptions = [];
|
||||
}
|
||||
|
||||
public function AddOption(SelectOption $oOption)
|
||||
{
|
||||
$this->aOptions[$oOption->GetId()] = $oOption;
|
||||
}
|
||||
|
||||
public function GetSubBlocks()
|
||||
{
|
||||
return $this->aOptions;
|
||||
}
|
||||
}
|
||||
81
sources/application/UI/Component/Input/SelectOption.php
Normal file
81
sources/application/UI/Component/Input/SelectOption.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Component\Input;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
|
||||
class SelectOption extends UIBlock
|
||||
{
|
||||
public const HTML_TEMPLATE_REL_PATH = 'components/input/selectoption';
|
||||
|
||||
/** @var string */
|
||||
protected $sValue;
|
||||
/** @var string */
|
||||
protected $sLabel;
|
||||
/** @var bool */
|
||||
protected $bSelected;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValue(): string
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return SelectOption
|
||||
*/
|
||||
public function SetValue(string $sValue): SelectOption
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel(): string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return SelectOption
|
||||
*/
|
||||
public function SetLabel(string $sLabel): SelectOption
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsSelected(): bool
|
||||
{
|
||||
return $this->bSelected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bSelected
|
||||
*
|
||||
* @return SelectOption
|
||||
*/
|
||||
public function SetSelected(bool $bSelected): SelectOption
|
||||
{
|
||||
$this->bSelected = $bSelected;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user