Add UIBlocks to twig (Generalize IsHidden parameter)

This commit is contained in:
Eric
2021-01-15 11:47:25 +01:00
parent 5fe8ca178e
commit 648cfd9af4
18 changed files with 56 additions and 95 deletions

View File

@@ -84,8 +84,6 @@ class Alert extends UIContentBlock
public const DEFAULT_IS_COLLAPSIBLE = true;
/** @var bool Default value for static::$bIsOpenedByDefault */
public const DEFAULT_IS_OPENED_BY_DEFAULT = true;
/** @var bool Default value for static::$bIsHidden */
public const DEFAULT_IS_HIDDEN = false;
/** @var string $sTitle */
protected $sTitle;
@@ -95,8 +93,6 @@ class Alert extends UIContentBlock
protected $bIsClosable;
/** @var bool Whether the alert can be collapsed or not */
protected $bIsCollapsible;
/** @var bool Whether the alert is hidden or not */
protected $bIsHidden;
/** @var bool Whether the alert is opened by default or not, only works when $bIsCollapsible set to true */
protected $bIsOpenedByDefault;
/** @var boolean if true will store collapsible state */
@@ -120,7 +116,6 @@ class Alert extends UIContentBlock
$this->bIsClosable = static::DEFAULT_IS_CLOSABLE;
$this->bIsCollapsible = static::DEFAULT_IS_COLLAPSIBLE;
$this->bIsOpenedByDefault = static::DEFAULT_IS_OPENED_BY_DEFAULT;
$this->bIsHidden = static::DEFAULT_IS_HIDDEN;
if (!empty($sContent)) {
$this->AddSubBlock(new Html($sContent));
}
@@ -280,25 +275,4 @@ class Alert extends UIContentBlock
{
return $this->sSectionStateStorageKey;
}
/**
* @return bool
*/
public function IsHidden(): bool
{
return $this->bIsHidden;
}
/**
* @param bool $bIsHidden
*
* @return $this
*/
public function SetIsHidden(bool $bIsHidden)
{
$this->bIsHidden = $bIsHidden;
return $this;
}
}

View File

@@ -32,8 +32,6 @@ class Field extends UIContentBlock
/** @var string */
protected $sAttLabel;
/** @var bool */
protected $bIsHidden = false;
/** @var bool */
protected $bIsReadOnly = false;
/** @var bool */
protected $bIsMandatory = false;
@@ -143,26 +141,6 @@ class Field extends UIContentBlock
return $this;
}
/**
* @return bool
*/
public function IsHidden(): bool
{
return $this->bIsHidden;
}
/**
* @param bool $bIsHidden
*
* @return Field
*/
public function SetIsHidden(bool $bIsHidden)
{
$this->bIsHidden = $bIsHidden;
return $this;
}
/**
* @return bool
*/

View File

@@ -20,32 +20,8 @@ class Spinner extends UIBlock
public const BLOCK_CODE = 'ibo-spinner';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/spinner/layout';
protected $bIsHidden;
public function __construct(?string $sId = null)
{
parent::__construct($sId);
$this->bIsHidden = false;
}
/**
* @return false
*/
public function IsHidden(): bool
{
return $this->bIsHidden;
}
/**
* @param false $bIsHidden
*
* @return $this
*/
public function SetIsHidden(bool $bIsHidden)
{
$this->bIsHidden = $bIsHidden;
return $this;
}
}

View File

@@ -45,7 +45,7 @@ abstract class UIBlock implements iUIBlock
public const DEFAULT_HTML_TEMPLATE_REL_PATH = null;
/** @var array JS_FILES_REL_PATH Relative paths (from <ITOP>/) to the JS files */
public const DEFAULT_JS_FILES_REL_PATH = [];
/** @var string|null JS_TEMPLATE_REL_PATH Relative path (from <ITOP>/templates/) to the JS template on dom ready*/
/** @var string|null JS_TEMPLATE_REL_PATH Relative path (from <ITOP>/templates/) to the JS template on dom ready */
public const DEFAULT_JS_TEMPLATE_REL_PATH = null;
/** @var string|null Relative path (from <ITOP>/templates/) to the JS template not deferred */
public const DEFAULT_JS_LIVE_TEMPLATE_REL_PATH = null;
@@ -55,6 +55,8 @@ abstract class UIBlock implements iUIBlock
public const DEFAULT_CSS_FILES_REL_PATH = [];
/** @var string|null CSS_TEMPLATE_REL_PATH Relative path (from <ITOP>/templates/) to the CSS template */
public const DEFAULT_CSS_TEMPLATE_REL_PATH = null;
/** @var bool Default value for $bIsHidden */
public const DEFAULT_IS_HIDDEN = false;
/** @var string ENUM_BLOCK_FILES_TYPE_JS */
public const ENUM_BLOCK_FILES_TYPE_JS = 'js';
@@ -80,8 +82,10 @@ abstract class UIBlock implements iUIBlock
protected $aJsFilesRelPath;
/** @var array */
protected $aCssFilesRelPath;
/** @var array Array <KEY> => <VALUE> which will be output as HTML data-xxx attributes (eg. data-<KEY>="<VALUE>") */
/** @var array Array <KEY> => <VALUE> which will be output as HTML data-xxx attributes (eg. data-<KEY>="<VALUE>") */
protected $aDataAttributes;
/** @var bool show or hide the current block */
protected $bIsHidden;
/**
* UIBlock constructor.
@@ -100,6 +104,7 @@ abstract class UIBlock implements iUIBlock
$this->sCssTemplateRelPath = static::DEFAULT_CSS_TEMPLATE_REL_PATH;
$this->sGlobalTemplateRelPath = static::DEFAULT_GLOBAL_TEMPLATE_REL_PATH;
$this->aDataAttributes = [];
$this->bIsHidden = static::DEFAULT_IS_HIDDEN;
}
/**
@@ -353,4 +358,23 @@ abstract class UIBlock implements iUIBlock
$this->aDataAttributes[$sName] = $sValue;
return $this;
}
/**
* @return bool
*/
public function IsHidden(): bool
{
return $this->bIsHidden;
}
/**
* @param bool $bIsHidden
*
* @return $this
*/
public function SetIsHidden(bool $bIsHidden)
{
$this->bIsHidden = $bIsHidden;
return $this;
}
}

View File

@@ -10,6 +10,7 @@
value="{{ oUIBlock.GetValue() }}"
{% if oUIBlock.IsDisabled() is same as(true) %} disabled {% endif %}
{% if oUIBlock.GetTooltip() is not empty %} data-tooltip-content="{{ oUIBlock.GetTooltip() }}" {% endif %}
{% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}
>
{% if oUIBlock.GetIconClass() is not empty %}
<span class="ibo-button--icon {{ oUIBlock.GetIconClass() }}"></span>

View File

@@ -1,10 +1,11 @@
<div id="{{ oUIBlock.GetId() }}"
class="ibo-collapsible-section {{ oUIBlock.GetCSSClasses() }}{% if oUIBlock.IsOpenedByDefault() %} ibo-is-opened{% endif %}">
class="ibo-collapsible-section {{ oUIBlock.GetCSSClasses() }}{% if oUIBlock.IsOpenedByDefault() %} ibo-is-opened{% endif %}"
{% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}>
<div class="ibo-collapsible-section--header" data-role="ibo-collapsible-section--collapse-toggler">
<div class="ibo-collapsible-section--action-button ibo-collapsible-section--maximize-button"><i
class="fas fa-caret-down"></i></div>
class="fas fa-caret-down"></i></div>
<div class="ibo-collapsible-section--action-button ibo-collapsible-section--minimize-button"><i
class="fas fa-caret-up"></i>
class="fas fa-caret-up"></i>
</div>
<div class="ibo-collapsible-section--title">{{ oUIBlock.GetTitle() }}</div>
</div>

View File

@@ -1,7 +1,7 @@
{# @copyright Copyright (C) 2010-2020 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% apply spaceless %}
<div class="ibo-dashlet-badge--body">
<div class="ibo-dashlet-badge--body" id="{{ oUIBlock.GetId() }}" {% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}>
<div class="ibo-dashlet-badge--icon-container">
<img class="ibo-dashlet-badge--icon" src="{{ oUIBlock.GetClassIconUrl() }}">
</div>

View File

@@ -1,7 +1,7 @@
{# @copyright Copyright (C) 2010-2020 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% apply spaceless %}
<div class="ibo-dashlet-header-static">
<div class="ibo-dashlet-header-static" id="{{ oUIBlock.GetId() }}" {% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}>
<div class="ibo-dashlet-header-static--body">
{% if oUIBlock.GetIconUrl() is not empty %}
<div class="ibo-dashlet-header-static--icon-container">

View File

@@ -12,7 +12,7 @@
{% endif %}
{% endif %}
<table id="{{ oUIBlock.GetId() }}" width="100%" class="{{ oUIBlock.GetBlockCode() }}">
<table id="{{ oUIBlock.GetId() }}" width="100%" class="{{ oUIBlock.GetBlockCode() }}" {% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}>
<thead>
{% if oUIBlock.GetOption("select_mode") is not empty %}
<th></th>

View File

@@ -4,7 +4,7 @@
<input type="hidden" name="attr_{{ oUIBlock.GetRef() }}" value="">
{% set columns = oUIBlock.GetColumns() %}
<table id="{{ oUIBlock.GetId() }}" class="ibo-datatable listResults" style="width:100%;">
<table id="{{ oUIBlock.GetId() }}" class="ibo-datatable listResults" style="width:100%; {% if oUIBlock.IsHidden() %}display: none;{% endif %}">
<thead>
<tr>
{% for column in columns %}

View File

@@ -2,7 +2,7 @@
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% set columns = oUIBlock.GetColumns() %}
<table id="{{ oUIBlock.GetId() }}" class="ibo-datatable listResults" style="width:100%;">
<table id="{{ oUIBlock.GetId() }}" class="ibo-datatable listResults" style="width:100%; {% if oUIBlock.IsHidden() %} display: none;{% endif %}">
<thead>
<tr>
{% for column in columns %}

View File

@@ -4,8 +4,8 @@
data-attribute-code="{{ oUIBlock.GetAttCode() }}"
data-attribute-type="{{ oUIBlock.GetAttType() }}"
data-attribute-label="{{ oUIBlock.GetAttLabel() }}"
{# Note: This might not the best way to this, we might rather have some properties for this flags in te Field class. #}
{# For the moment this just aims at restoring the metadata introduced in iTop 2.7. Refactoring the Field class with specialization for each type must be designed by all the team #}
{# Note: This might not the best way to this, we might rather have some properties for this flags in te Field class. #}
{# For the moment this just aims at restoring the metadata introduced in iTop 2.7. Refactoring the Field class with specialization for each type must be designed by all the team #}
{# as we might want to re-use / adapt the Field classes introduced with the end-user portal #}
data-attribute-flag-hidden="{{ oUIBlock.IsHidden()|var_export }}"
data-attribute-flag-read-only="{{ oUIBlock.IsReadOnly()|var_export }}"
@@ -14,6 +14,7 @@
data-attribute-flag-must-prompt="{{ oUIBlock.IsMustPrompt()|var_export }}"
data-attribute-flag-slave="{{ oUIBlock.IsSlave()|var_export }}"
data-value-raw="{{ aParams.value_raw }}"
{% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}
>
<div class="ibo-field--label">{{ oUIBlock.GetLabel()|raw }}</div>
<div class="ibo-field--value" {% if oUIBlock.GetValueId() %}id="{{ oUIBlock.GetValueId() }}"{% endif %}>

View File

@@ -1,8 +1,8 @@
{% if oUIBlock.GetSubBlocks() %}
<fieldset class="ibo-fieldset">
<legend class="ibo-fieldset-legend">{{ oUIBlock.GetLegend() }}</legend>
{% for oSubBlock in oUIBlock.GetSubBlocks() %}
{{ render_block(oSubBlock, {aPage: aPage}) }}
{% endfor %}
</fieldset>
<fieldset class="ibo-fieldset" id="{{ oUIBlock.GetId() }}" {% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}>
<legend class="ibo-fieldset-legend">{{ oUIBlock.GetLegend() }}</legend>
{% for oSubBlock in oUIBlock.GetSubBlocks() %}
{{ render_block(oSubBlock, {aPage: aPage}) }}
{% endfor %}
</fieldset>
{% endif %}

View File

@@ -5,6 +5,7 @@
{% if oUIBlock.GetAction() %}
action="{{ oUIBlock.GetAction() }}"
{% endif %}
{% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}
>
{% apply spaceless %}
{% block iboContentBlockContainer %}

View File

@@ -3,5 +3,6 @@
{% block iboInput %}
<input type="{{ oUIBlock.GetType() }}" id="{{ oUIBlock.GetId() }}" name="{{ oUIBlock.GetName() }}" value="{{ oUIBlock.GetValue()|raw }}"
{% if oUIBlock.IsChecked() %}checked="checked"{% endif %}
{% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}
>
{% endblock %}

View File

@@ -1,7 +1,8 @@
{# @copyright Copyright (C) 2010-2020 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% apply spaceless %}
<div id="{{ oUIBlock.GetId() }}" class="ibo-panel ibo-is-{{ oUIBlock.GetColor() }} {{ oUIBlock.GetCSSClasses() }}" {% block iboPanelMetaData %}{% endblock %}>
<div id="{{ oUIBlock.GetId() }}" class="ibo-panel ibo-is-{{ oUIBlock.GetColor() }} {{ oUIBlock.GetCSSClasses() }}" {% block iboPanelMetaData %}{% endblock %}
{% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}>
<div class="ibo-panel--header">
{% block iboPanelHeader %}
<div class="ibo-panel--header-left">

View File

@@ -1,5 +1,5 @@
{% apply spaceless %}
<div class="ibo-title {% if oUIBlock.HasIcon() %}ibo-has-icon{% endif %}">
<div id="{{ oUIBlock.GetId() }}" class="ibo-title {% if oUIBlock.HasIcon() %}ibo-has-icon{% endif %}" {% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}>
{% if oUIBlock.HasIcon() %}
<div class="ibo-title--medallion">
<img class="ibo-title--icon ibo-title--icon--must-{{ oUIBlock.GetIconCoverMethod() }}" src="{{ oUIBlock.GetIconUrl() }}">

View File

@@ -2,9 +2,11 @@
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{# Content Block #}
{% apply spaceless %}
{% block iboContentBlockContainer %}
{% if oUIBlock.GetCSSClasses() or oUIBlock.GetDataAttributes() %}
{% set bHasDiv = (oUIBlock.GetCSSClasses() or oUIBlock.GetDataAttributes()) %}
{% block iboContentBlockContainer %}
{% if bHasDiv %}
<div id="{{ oUIBlock.GetId() }}"
{% if oUIBlock.GetCSSClasses() %}class="{{ oUIBlock.GetCSSClasses() }}"{% endif %}
{% if oUIBlock.GetDataAttributes() %}
@@ -12,6 +14,7 @@
data-{{ sName }}="{{ sValue }}"
{% endfor %}
{% endif %}
{% if oUIBlock.IsHidden() %}style="display: none;"{% endif %}
>
{% endif %}
@@ -19,7 +22,7 @@
{{ render_block(oSubBlock, {aPage: aPage}) }}
{% endfor %}
{% if oUIBlock.GetCSSClasses() %}
{% if bHasDiv %}
</div>
{% endif %}