mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 10:08:45 +02:00
Add option display to form (css needs updates)
Add options with_run_button and with_book_button to FormBlockOql
This commit is contained in:
@@ -75,3 +75,18 @@ collection-entry-element {
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.ibo-form-compact{
|
||||
|
||||
.ibo-content-block{
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
label{
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ class FormBlock extends AbstractTypeFormBlock
|
||||
{
|
||||
parent::RegisterOptions($oOptionsRegister);
|
||||
$oOptionsRegister->SetOption('compound', true);
|
||||
$oOptionsRegister->SetOption('display', 'cosy');
|
||||
$oOptionsRegister->SetOptionArrayValue('attr', 'class', 'form');
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ class OqlFormBlock extends TextAreaFormBlock
|
||||
{
|
||||
parent::RegisterOptions($oOptionsRegister);
|
||||
$oOptionsRegister->SetOption('with_ai_button', false);
|
||||
$oOptionsRegister->SetOption('with_book_button', true);
|
||||
$oOptionsRegister->SetOption('with_run_button', true);
|
||||
$oOptionsRegister->SetOptionArrayValue('attr', 'placeholder', 'SELECT Contact');
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use Combodo\iTop\Forms\FormType\FormTypeHelper;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Form type.
|
||||
@@ -28,14 +29,30 @@ class FormType extends AbstractType
|
||||
return \Symfony\Component\Form\Extension\Core\Type\FormType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefault('display', 'cosy');
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
parent::buildView($view, $form, $options);
|
||||
|
||||
/** @var FormBlock $oBlock */
|
||||
$oBlock = $options['form_block'];
|
||||
$view->vars['blocks'] = $this->GetChildrenBlocks($options['form_block'], $form);
|
||||
$view->vars['display'] = $options['display'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBlock $oBlock
|
||||
* @param FormInterface $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function GetChildrenBlocks(FormBlock $oBlock, FormInterface $form): array
|
||||
{
|
||||
$aData = [];
|
||||
foreach ($oBlock->GetChildren() as $oChild) {
|
||||
if (!$oChild instanceof AbstractTypeFormBlock) {
|
||||
@@ -44,20 +61,21 @@ class FormType extends AbstractType
|
||||
|
||||
if ($oChild->IsAdded()) {
|
||||
$aData[] = [
|
||||
'name' => $oChild->GetName(),
|
||||
'name' => $oChild->GetName(),
|
||||
'added' => $oChild->IsAdded(),
|
||||
'id' => FormTypeHelper::GetFormId($form).'_'.$oChild->GetName(),
|
||||
'id' => FormTypeHelper::GetFormId($form).'_'.$oChild->GetName(),
|
||||
];
|
||||
} else {
|
||||
$aData[] = [
|
||||
'name' => $oChild->GetName(),
|
||||
'name' => $oChild->GetName(),
|
||||
'added' => $oChild->IsAdded(),
|
||||
'id' => FormTypeHelper::GetFormId($form).'_'.$oChild->GetName(),
|
||||
'id' => FormTypeHelper::GetFormId($form).'_'.$oChild->GetName(),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
$view->vars['blocks'] = $aData;
|
||||
|
||||
return $aData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,23 +21,27 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class OqlFormType extends AbstractType
|
||||
{
|
||||
/** @inheritdoc */
|
||||
/** @inheritdoc */
|
||||
public function getParent(): string
|
||||
{
|
||||
return TextareaType::class;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
/** @inheritdoc */
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefined('with_ai_button');
|
||||
$resolver->setDefined('with_book_button');
|
||||
$resolver->setDefined('with_run_button');
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
/** @inheritdoc */
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
parent::buildView($view, $form, $options);
|
||||
|
||||
$view->vars['with_ai_button'] = $options['with_ai_button'];
|
||||
$view->vars['with_book_button'] = $options['with_book_button'];
|
||||
$view->vars['with_run_button'] = $options['with_run_button'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{%- else -%}
|
||||
{% set form_method = "POST" %}
|
||||
{%- endif -%}
|
||||
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' ibo-form')}) -%}
|
||||
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' ibo-form ibo-form-' ~ display)}) -%}
|
||||
<form is="itop-form-element" {% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
|
||||
{%- if form_method != method -%}
|
||||
<input type="hidden" name="_method" value="{{ method }}" />
|
||||
@@ -150,20 +150,24 @@
|
||||
{%- block oql_form_widget -%}
|
||||
<textarea is="oql-element" {{ block('widget_attributes') }} data-modal-title-text="{{ 'UI:Edit:SearchQuery'|trans }}" data-empty-text="{{ 'Use the search form above to search for objects to be added'|trans }}" data-valid-query-text="{{ 'OQL is valid'|trans }}" data-invalid-query-text="{{ 'OQL is invalid'|trans }}">{{ value }}</textarea>
|
||||
<div class="ibo-form-actions">
|
||||
{% if with_ai_button is defined and with_ai_button %}
|
||||
{% if with_ai_button %}
|
||||
<button class="ibo-button ibo-button ibo-block ibo-is-alternative ibo-is-neutral " data-role="ibo-button" type="button" name="AI" value="" aria-label="AI">
|
||||
<span class="ibo-button--icon fas fa-magic"></span>
|
||||
{{ 'UI:Edit:AI'|trans }}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if with_run_button %}
|
||||
<button class="ibo-button ibo-button ibo-block ibo-is-alternative ibo-is-success" data-role="ibo-button" data-action="run" type="button" name="Run Query" value="" aria-label="Run Query">
|
||||
<span class="ibo-button--icon fas fa-play"></span>
|
||||
{{ 'UI:Edit:TestQuery'|trans }}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if with_book_button %}
|
||||
<button class="ibo-button ibo-button ibo-block ibo-is-alternative ibo-is-neutral " data-role="ibo-button" data-action="book" type="button" name="Open Book" value="" aria-label="Open Query Phrases Book">
|
||||
<span class="ibo-button--icon fas fa-book"></span>
|
||||
{{ 'UI:Edit:SearchQuery'|trans }}
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- endblock oql_form_widget -%}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user