N°3537 run_query : replace main form by components

This commit is contained in:
Pierre Goiffon
2020-12-14 16:18:54 +01:00
parent 3d27e59269
commit 4bb59548d0
10 changed files with 192 additions and 100 deletions

View File

@@ -0,0 +1,45 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
* @package Combodo\iTop\Application\UI\Base\Component\Input
*/
class AbstractInput extends UIBlock
{
/** @var string */
protected $sName;
/** @var string */
protected $sValue;
public function GetName(): string
{
return $this->sName;
}
public function SetName(string $sName): AbstractInput
{
$this->sName = $sName;
return $this;
}
public function GetValue(): ?string
{
return $this->sValue;
}
public function SetValue(?string $sValue): AbstractInput
{
$this->sValue = $sValue;
return $this;
}
}

View File

@@ -7,14 +7,12 @@
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
* Class Input
*
* @package Combodo\iTop\Application\UI\Base\Component\Input
*/
class Input extends UIBlock
class Input extends AbstractInput
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-input';
@@ -24,67 +22,15 @@ class Input extends UIBlock
/** @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;
}
}

View File

@@ -27,18 +27,38 @@ class InputFactory
public static function MakeForSelectWithLabel(string $sName, string $sLabel, ?string $sId = null): InputWithLabel
{
$oInput = new Select();
$oInput = new Select($sId);
$oInput->SetName($sName);
if (is_null($sId)) {
$sId = $oInput->GetId();
}
$oInputWithLabel = new InputWithLabel($sLabel, $oInput, $sId);
return $oInputWithLabel;
}
}
public static function MakeForTextareaWithLabel(
string $sName, string $sLabel, ?string $sId = null, ?string $sValue = null,
?int $iCols = null, ?int $iRows = null
): InputWithLabel
{
$oTextArea = new TextArea($sValue, $sId, $iCols, $iRows);
$oTextArea->SetName($sName);
if (is_null($sId)) {
$sId = $oTextArea->GetId();
}
$oInputWithLabel = new InputWithLabel($sLabel, $oTextArea, $sId);
return $oInputWithLabel;
}
public static function MakeForSelect(string $sName, ?string $sId = null): Select
{
$oInput = new Select($sId);
$oInput->SetName($sName);
return $oInput;
}

View File

@@ -16,38 +16,33 @@ class InputWithLabel extends UIBlock
/** @var string */
protected $sLabel;
/** @var \Combodo\iTop\Application\UI\Base\Component\Input\Input */
/** @var \Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput */
protected $oInput;
/** @var bool */
protected $bHasBr;
/**
* InputWithLabel constructor.
*
* @param string $sLabel
* @param \Combodo\iTop\Application\UI\Base\Component\Input\Input $oInput
*/
public function __construct(string $sLabel, \Combodo\iTop\Application\UI\Base\Component\Input\Input $oInput, ?string $sId)
public function __construct(string $sLabel, AbstractInput $oInput, ?string $sId, ?bool $bHasBr = null)
{
parent::__construct($sId);
$this->sLabel = $sLabel;
$this->oInput = $oInput;
if (is_null($bHasBr)) {
$this->bHasBr = ($oInput instanceof TextArea);
} else {
$this->bHasBr = $bHasBr;
}
}
/**
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Input
*/
public function GetInput(): \Combodo\iTop\Application\UI\Base\Component\Input\Input
public function GetInput(): AbstractInput
{
return $this->oInput;
}
/**
* @param \Combodo\iTop\Application\UI\Base\Component\Input\Input $oInput
*
* @return $this
*/
public function SetInput(\Combodo\iTop\Application\UI\Base\Component\Input\Input $oInput): InputWithLabel
public function SetInput(AbstractInput $oInput): InputWithLabel
{
$this->oInput = $oInput;
return $this;
}
@@ -68,7 +63,12 @@ class InputWithLabel extends UIBlock
public function SetLabel(string $sLabel): InputWithLabel
{
$this->sLabel = $sLabel;
return $this;
}
public function HasBr(): bool
{
return $this->bHasBr;
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
/**
* @package Combodo\iTop\Application\UI\Base\Component\Input
*/
class TextArea extends AbstractInput
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-textarea';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/input-textarea';
/** @var int */
protected $iCols;
/** @var int */
protected $iRows;
public function __construct(?string $sValue, ?string $sId = null, ?int $iCols = null, ?int $iRows = null)
{
parent::__construct($sId);
$this->sValue = $sValue;
$this->iCols = $iCols;
$this->iRows = $iRows;
}
public function GetCols(): int
{
return $this->iCols;
}
public function SetCols(int $iCols): TextArea
{
$this->iCols = $iCols;
return $this;
}
public function GetRows(): int
{
return $this->iRows;
}
public function SetRows(int $iRows): TextArea
{
$this->iRows = $iRows;
return $this;
}
}