Skip to content

Commit

Permalink
1015: Updated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Sep 24, 2024
1 parent 09c2126 commit 3a5121d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 14 deletions.
20 changes: 20 additions & 0 deletions assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,24 @@ const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]
window.addEventListener('load', () => {
[...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
window.dispatchEvent(new Event('ajaxload'))

const recipientSelector = '.digital-post-recipient'
const digitalPostRecipientWrapper = document.querySelector(recipientSelector)?.parentNode?.parentNode
const digitalPostAttachmentsInfo = document.querySelector('.digital-post-attachments-info')
if (digitalPostRecipientWrapper && digitalPostAttachmentsInfo) {
const recipients = digitalPostRecipientWrapper.querySelectorAll(recipientSelector)
const updateStuff = () => {
const recipientTheCannotReceiveDigitalPost = [...recipients]
.filter(el => !el.dataset.digitalPostAllowed &&
el.querySelector('input[type="checkbox"]').checked);

[...digitalPostAttachmentsInfo.querySelectorAll('.digital-post-attachments-info-item')]
.forEach(el => {
el.hidden = !(el.dataset.digitalPostAllowed ^ (recipientTheCannotReceiveDigitalPost.length > 0))
})
}

[...recipients].forEach(el => el.addEventListener('change', (event) => updateStuff()))
updateStuff()
}
})
20 changes: 20 additions & 0 deletions assets/content/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@ th, td {
text-align: right;
}
}

.digital-post-recipient,
.digital-post-attachments-info-item {
&[data-digital-post-allowed=""] {
.digital-post-message {
color: red;
}
}
}

// .tvist1-can-receive-digital-post {
// color: green;
// }

// https://css-tricks.com/almanac/properties/l/line-clamp/#aa-hey-cant-i-do-this-with-text-overflow
.document-name {
max-width: 20em;
overflow: hidden;
// https://stackoverflow.com/a/43562036/2502647
}
24 changes: 24 additions & 0 deletions src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Entity\MailTemplate;
use App\Service\DocumentDeletableHelper;
use App\Service\MailTemplateHelper;
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
Expand All @@ -26,6 +28,7 @@ public function getFunctions(): array
new TwigFunction('type', 'gettype'),
new TwigFunction('isDocumentDeletable', [$this, 'isDocumentDeletable']),
new TwigFunction('getCustomFields', [$this, 'getCustomFields']),
new TwigFunction('get_choice', $this->getChoice(...)),
];
}

Expand Down Expand Up @@ -69,4 +72,25 @@ public function getCustomFields(MailTemplate $mailTemplate): array
{
return $this->mailTemplateHelper->getCustomFields($mailTemplate);
}

/**
* Get choice by value from a (nested) list of choices.
*/
public function getChoice(array $choices, string $value): ?ChoiceView
{
$choice = null;
\Safe\array_walk_recursive($choices, function ($item) use ($value, &$choice) {
if ($item instanceof ChoiceGroupView) {
/** @var ChoiceView $choiceView */
foreach ($item as $choiceView) {
if ($choiceView->value === $value) {
$choice = $choiceView;
break;
}
}
}
});

return $choice;
}
}
12 changes: 12 additions & 0 deletions templates/case/hearing/_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
{% endfor %}

<div class="attachments mb-3">
<div class="digital-post-attachments-info">
<div class="digital-post-attachments-info-item" data-digital-post-allowed="{{ true }}" hidden>
<div class="alert alert-success">
<span class="digital-post-message">{{ 'All recipients can receive digital post'|trans }}</span>
</div>
</div>
<div class="digital-post-attachments-info-item" data-digital-post-allowed="{{ false }}" hidden>
<div class="alert alert-warning">
<span class="digital-post-message">{{ 'Some recipients cannot receive digital post'|trans }}</span>
</div>
</div>
</div>
{{ form_label(form.attachments) }}
{# store the prototype on the data-prototype attribute #}
<ul id="attachment-fields-list"
Expand Down
45 changes: 31 additions & 14 deletions templates/form/theme.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,37 @@
{{ block('address_widget') }}
{% endblock %}

{% block _hearing_post_request_recipients_entry_widget %}
{% set canReceiveDigitalPost = null %}
{% for key in form.parent.vars.choices|keys %}
{% for choice in form.parent.vars.choices[key] %}
{% if choice.value == value and class(choice.data) == 'Party' %}
{% set canReceiveDigitalPost = choice.data.canReceiveDigitalPost %}
{% endif %}
{% endfor %}
{% endfor %}
{% macro digital_post_recipient_widget(form, value, content) %}
{% set choice = get_choice(form.parent.vars.choices, value) %}

<div class="tvist1-{{ (canReceiveDigitalPost ? 'can' : 'cannot') }}-receive-digital-post">
<fieldset>
<legend>tvist1-{{ (canReceiveDigitalPost ? 'can' : 'cannot') }}-receive-digital-post</legend>
{{ block('checkbox_widget') }}
</fieldset>
<div class="digital-post-recipient" data-digital-post-allowed="{{ choice.data.canReceiveDigitalPost|default(false) }}">
{{ content|raw }}
</div>
{% endmacro %}

{% macro digital_post_recipient_label(form, value, content) %}
{% if content %}
{{ content|raw }}

{% set choice = get_choice(form.parent.vars.choices, value) %}
<span class="digital-post-message">
({{ choice.data.canReceiveDigitalPost|default(false) ? 'can receive digital post'|trans : 'cannot receive digital post'|trans }})
</span>
{% endif %}
{% endmacro %}

{% block _hearing_post_request_recipients_entry_widget %}
{{ _self.digital_post_recipient_widget(form, value, block('checkbox_widget')) }}
{% endblock %}

{% block _hearing_post_request_recipients_entry_label %}
{{ _self.digital_post_recipient_label(form, value, block('checkbox_label')) }}
{% endblock %}

{% block _briefing_recipients_entry_widget %}
{ _self.digital_post_recipient_widget(form, value, block('checkbox_widget')) }
{% endblock %}

{% block _briefing_recipients_entry_label %}
{ _self.digital_post_recipient_label(form, value, block('checkbox_label')) }
{% endblock %}

0 comments on commit 3a5121d

Please sign in to comment.