From 85e90732288f07873e3ae61228be4ec877ea5e73 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 16 Dec 2020 15:57:23 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B03537=20run=5Fquery=20:=20use=20Field=20i?= =?UTF-8?q?nstead=20of=20InputWithLabel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/cmdbabstract.class.inc.php | 5 ++- css/backoffice/components/_field.scss | 3 +- pages/run_query.php | 21 +++++----- .../UI/Base/Component/Field/Field.php | 13 ++++-- .../UI/Base/Component/Input/InputFactory.php | 26 +++++------- .../Base/Component/Input/InputWithLabel.php | 40 ++++++++++--------- .../components/input/inputwithlabel.html.twig | 1 - 7 files changed, 60 insertions(+), 49 deletions(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index ec0d79d4e..5f692fcdf 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -954,7 +954,10 @@ EOF $val['attflags'] = ($bEditMode) ? $this->GetFormAttributeFlags($sAttCode) : OPT_ATT_READONLY; // - How the field should be rendered - $val['layout'] = (in_array($oAttDef->GetEditClass(), static::GetAttEditClassesToRenderAsLargeField())) ? 'large' : 'small'; + $val['layout'] = + (in_array($oAttDef->GetEditClass(), static::GetAttEditClassesToRenderAsLargeField())) + ? Field::ENUM_FIELD_LAYOUT_LARGE + : Field::ENUM_FIELD_LAYOUT_SMALL; // - For simple fields, we get the raw (stored) value as well $bExcludeRawValue = false; diff --git a/css/backoffice/components/_field.scss b/css/backoffice/components/_field.scss index ad5e8b73e..6cb7a7e3f 100644 --- a/css/backoffice/components/_field.scss +++ b/css/backoffice/components/_field.scss @@ -22,7 +22,8 @@ $ibo-field--label--description--color: $ibo-color-grey-700 !default; display: inherit; .ibo-field--label { - display: inherit; + display: inherit; + max-width: none; } } diff --git a/pages/run_query.php b/pages/run_query.php index 26c2be6bf..c18edf1db 100644 --- a/pages/run_query.php +++ b/pages/run_query.php @@ -19,9 +19,11 @@ use Combodo\iTop\Application\UI\Base\Component\Alert\AlertFactory; use Combodo\iTop\Application\UI\Base\Component\Button\ButtonFactory; +use Combodo\iTop\Application\UI\Base\Component\Field\Field; use Combodo\iTop\Application\UI\Base\Component\Form\Form; use Combodo\iTop\Application\UI\Base\Component\Html\Html; -use Combodo\iTop\Application\UI\Base\Component\Input\InputFactory; +use Combodo\iTop\Application\UI\Base\Component\Input\TextArea; +use Combodo\iTop\Renderer\BlockRenderer; require_once('../approot.inc.php'); require_once(APPROOT.'/application/application.inc.php'); @@ -160,14 +162,15 @@ try $oHiddenParams = new Html($oAppContext->GetForForm()); $oQueryForm->AddSubBlock($oHiddenParams); - $oQueryTextarea = InputFactory::MakeForTextareaWithLabel( - 'expression', - Dict::S('UI:RunQuery:ExpressionToEvaluate'), - 'expression', - utils::HtmlEntities($sExpression), - 120, 8 - ); - $oQueryForm->AddSubBlock($oQueryTextarea); + $oQueryTextArea = new TextArea(utils::HtmlEntities($sExpression), 'expression', 120, 8); + $oQueryTextAreaRenderer = new BlockRenderer($oQueryTextArea); + $oQueryTextArea->SetName('expression'); + $oQueryField = new Field([ + 'layout' => Field::ENUM_FIELD_LAYOUT_LARGE, + 'label' => Dict::S('UI:RunQuery:ExpressionToEvaluate'), + 'value' => $oQueryTextAreaRenderer->RenderHtml(), + ]); + $oQueryForm->AddSubBlock($oQueryField); $oQuerySubmit = ButtonFactory::MakeForPrimaryAction( Dict::S('UI:Button:Evaluate'), diff --git a/sources/application/UI/Base/Component/Field/Field.php b/sources/application/UI/Base/Component/Field/Field.php index df2296c57..910459eff 100644 --- a/sources/application/UI/Base/Component/Field/Field.php +++ b/sources/application/UI/Base/Component/Field/Field.php @@ -20,12 +20,19 @@ use Combodo\iTop\Application\UI\Base\UIBlock; class Field extends UIBlock { // Overloaded constants - /** @inheritdoc */ + /** @inheritdoc */ public const BLOCK_CODE = 'ibo-field'; - /** @inheritdoc */ + /** @inheritdoc */ public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/field/layout'; - /** @var array Array of various parameters of the field. This should be exploded in dedicated properties instead of a grey array. */ + public const ENUM_FIELD_LAYOUT_SMALL = 'small'; + public const ENUM_FIELD_LAYOUT_LARGE = 'large'; + + /** + * @var array Array of various parameters of the field. + * This should be exploded in dedicated properties instead of a grey array. + * See in the corresponding Twig file for keys to use + */ protected $aParams; public function __construct(array $aParams, ?string $sId = null) diff --git a/sources/application/UI/Base/Component/Input/InputFactory.php b/sources/application/UI/Base/Component/Input/InputFactory.php index c84fd4668..8409aa1a0 100644 --- a/sources/application/UI/Base/Component/Input/InputFactory.php +++ b/sources/application/UI/Base/Component/Input/InputFactory.php @@ -8,6 +8,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\Input; +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; @@ -25,6 +26,15 @@ class InputFactory return $oInput; } + /** + * If you need to have a real field with a label, you might use a {@link Field} component instead + * + * @param string $sName + * @param string $sLabel + * @param string|null $sId + * + * @return \Combodo\iTop\Application\UI\Base\Component\Input\InputWithLabel + */ public static function MakeForSelectWithLabel(string $sName, string $sLabel, ?string $sId = null): InputWithLabel { $oInput = new Select($sId); @@ -38,22 +48,6 @@ class InputFactory 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); diff --git a/sources/application/UI/Base/Component/Input/InputWithLabel.php b/sources/application/UI/Base/Component/Input/InputWithLabel.php index 785ad3e60..a07f12cac 100644 --- a/sources/application/UI/Base/Component/Input/InputWithLabel.php +++ b/sources/application/UI/Base/Component/Input/InputWithLabel.php @@ -10,36 +10,46 @@ namespace Combodo\iTop\Application\UI\Base\Component\Input; use Combodo\iTop\Application\UI\Base\UIBlock; +/** + * You might want to use a {@link \Combodo\iTop\Application\UI\Base\Component\Field\Field} component instead... + * + * @package Combodo\iTop\Application\UI\Base\Component\Input + */ class InputWithLabel extends UIBlock { public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/inputwithlabel'; /** @var string */ protected $sLabel; - /** @var \Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput */ + /** @var \Combodo\iTop\Application\UI\Base\Component\Input\Input */ protected $oInput; - /** @var bool */ - protected $bHasBr; - public function __construct(string $sLabel, AbstractInput $oInput, ?string $sId, ?bool $bHasBr = null) + /** + * @param string $sLabel + * @param \Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput $oInput + * @param string|null $sId + */ + public function __construct(string $sLabel, AbstractInput $oInput, ?string $sId) { parent::__construct($sId); $this->sLabel = $sLabel; $this->oInput = $oInput; - - if (is_null($bHasBr)) { - $this->bHasBr = ($oInput instanceof TextArea); - } else { - $this->bHasBr = $bHasBr; - } } - public function GetInput(): AbstractInput + /** + * @return \Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput + */ + public function GetInput() { return $this->oInput; } - public function SetInput(AbstractInput $oInput): InputWithLabel + /** + * @param \Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput $oInput + * + * @return $this + */ + public function SetInput(AbstractInput $oInput) { $this->oInput = $oInput; @@ -63,12 +73,6 @@ class InputWithLabel extends UIBlock public function SetLabel(string $sLabel): InputWithLabel { $this->sLabel = $sLabel; - return $this; } - - public function HasBr(): bool - { - return $this->bHasBr; - } } \ No newline at end of file diff --git a/templates/base/components/input/inputwithlabel.html.twig b/templates/base/components/input/inputwithlabel.html.twig index ad879eb57..898a2273f 100644 --- a/templates/base/components/input/inputwithlabel.html.twig +++ b/templates/base/components/input/inputwithlabel.html.twig @@ -1,5 +1,4 @@ {% block iboInputLabel %} - {% if oUIBlock.HasBr() %}
{% endif %} {{ render_block(oUIBlock.GetInput()) }} {% endblock %}