feat: add mailing templates and mail the confirmed teamers of selected assignments

This commit is contained in:
fromme committed 2026-11-11 14:02:55 +01:00
1 parent 6c89f1b8a9
commit e285646bb2
57 files changed
+3525 -31

No files matched your search

@@ -0,0 +1,67 @@
{# Swapped as a whole whenever an assignment is added or removed, so the recipient count is
always the one for the list shown with it. #}
<div id="mailing-assignments" class="pb-6">
<div class="text-xl font-bold">
{{ recipients.eligibleCount }} Empfänger:innen
</div>
<div class="text-sm text-gray-500">
Teamer:innen mit bestätigter Einteilung, auch auf mehreren Einsätzen nur eine Mail.
Einsätze ohne bestätigte Teamer:innen werden weggelassen.
{% if recipients.hasSkipped %}
{{ include('admin/teamer/_mailing_skipped.html.twig', { 'recipients': recipients }) }}
{% endif %}
</div>
{% if recipients.eligibleCount > 0 %}
<div class="pt-2 text-sm">
{{ recipients.eligible|map(recipient => recipient.fullName)|join(', ') }}
</div>
{% endif %}
<ul class="flex flex-col space-y-1 py-4">
{% for assignment in mailingDto.assignments %}
<li class="flex items-center space-x-2 border rounded-sm px-2 py-1">
{{ icon('flag-' ~ assignment.destination.country, 'w-5 h-5 shrink-0') }}
<div class="flex-1">
<span class="whitespace-nowrap">
{{ assignment.destination.dateFrom|date('d.m.Y') }} - {{ assignment.destination.dateTo|date('d.m.Y') }}
</span>
{{ assignment.destination.hotel }}, {{ assignment.jobProfile.name }}
{# who is confirmed here, so a teamer on two of the assignments - counted once
above - is plain to see. Never empty: assignments nobody is confirmed on are
left out of the mailing, see AssignmentRepository::findForMailing(). #}
<div class="text-sm text-gray-500">
bestätigt: {{ assignment.dispositions
|filter(disposition => disposition.status == constant('App\\Entity\\Disposition::STATUS_CONFIRMED'))
|map(disposition => disposition.teamer.fullName)
|join(', ') }}
</div>
</div>
<button type="button"
class="text-red-500"
title="Einsatz entfernen"
hx-post="{{ path('app_administrative_assignment_mailing_remove', { 'uuid': assignment.uuid }) }}"
hx-target="#mailing-assignments"
hx-swap="outerHTML">
{{ icon('delete', 'w-5 h-5') }}
</button>
</li>
{% else %}
<li class="text-gray-500">
Noch kein Einsatz ausgewählt.
</li>
{% endfor %}
</ul>
{# Its own form, outside the mailing form: forms cannot nest, and typing here must not park
the search as a draft. The autocomplete dispatches a "select" event of its own; the
[detail] filter keeps out the native one a text selection in the input fires. #}
{{ form_start(addForm, { 'action': path('app_administrative_assignment_mailing_add') }) }}
{{ form_row(addForm.assignment, { 'attr': {
'hx-post': path('app_administrative_assignment_mailing_add'),
'hx-trigger': 'select[detail]',
'hx-target': '#mailing-assignments',
'hx-swap': 'outerHTML',
} }) }}
{{ form_rest(addForm) }}
{{ form_end(addForm) }}
</div>
@@ -0,0 +1,22 @@
{# The template's files, swapped when a template is picked. The files dropped for this mailing
are listed outside of it, by the dropzone, which a swap would otherwise empty. #}
<div id="mailing-attachments" {% if oob|default(false) %}hx-swap-oob="true"{% endif %}>
{% if mailingDto.template and mailingDto.template.attachments is not empty %}
<div class="text-sm text-gray-500 pb-1">
Aus der Vorlage, gehen immer mit:
</div>
<ul class="flex flex-col space-y-1 pb-2">
{% for attachment in mailingDto.template.attachments %}
<li class="flex items-center space-x-2 border rounded-sm px-2 py-1">
{{ icon('document', 'w-4 h-4 shrink-0') }}
<a href="{{ path('app_common_download', { 'uuid': attachment.uuid, 'inline': 1 }) }}"
target="_blank"
class="flex-1 underline">
{{ attachment.displayName ?? attachment.originalFilename }}
</a>
<span class="text-sm text-gray-500">{{ attachment.size|file_size(1) }}</span>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
@@ -0,0 +1,5 @@
{# Swapped when a template is picked, which replaces subject and message. #}
<div id="mailing-fields" class="flex flex-col space-y-4 pb-4">
{{ form_row(form.subject) }}
{{ form_row(form.message) }}
</div>
@@ -0,0 +1,119 @@
{% extends 'administrative/layout.html.twig' %}
{% block title %}Mail an Teamer:innen{% endblock %}
{% block content %}
<div class="flex items-start justify-between pb-4">
<h1 class="text-2xl font-bold">
Mail an die Teamer:innen von Einsätzen
</h1>
<a href="{{ returnUrl }}" class="btn btn--small btn--secondary shrink-0">
Zurück zur Einsatzübersicht
</a>
</div>
<div class="grid lg:grid-cols-2 gap-8 items-start">
<div>
{{ include('administrative/assignment_mailing/_assignments.html.twig') }}
{# Outside the mailing form, so picking a template is not also parked as a draft
by the form's input trigger - the template route parks it itself. #}
<div class="pb-4">
<label for="mailing-template" class="block font-bold pb-2">
Vorlage
</label>
<select id="mailing-template"
name="template"
class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-xs ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-primary text-sm"
hx-post="{{ path('app_administrative_assignment_mailing_template') }}"
hx-trigger="change"
hx-include="#mailing-form"
hx-target="#mailing-fields"
hx-swap="outerHTML">
<option value="">keine Vorlage</option>
{% for template in templates %}
<option value="{{ template.uuid }}" {% if mailingDto.template and mailingDto.template.uuid == template.uuid %}selected{% endif %}>
{{ template.name }}
</option>
{% endfor %}
</select>
<div class="pt-1 text-sm text-gray-500">
Betreff und Nachricht der Vorlage ersetzen, was oben steht. Änderungen hier gelten
nur für diese Mail, die Vorlage bleibt, wie sie ist.
<a href="{{ path('app_administrative_system_mailing_template_index') }}" class="underline">Vorlagen verwalten</a>
</div>
</div>
{# The draft trigger works as in the teamer mailing, see the comment there. #}
{% set guardAttr = stimulus_controller('form-upload-guard')|stimulus_action('form-upload-guard', 'guard', 'submit') %}
{{ form_start(form, { 'attr': {
'id': 'mailing-form',
'hx-post': path('app_administrative_assignment_mailing_draft'),
'hx-trigger': 'input delay:500ms',
'hx-target': '#mailing-preview',
'hx-swap': 'innerHTML',
'hx-indicator': '#mailing-preview-indicator',
}|merge(guardAttr.toArray()) }) }}
{{ include('administrative/assignment_mailing/_fields.html.twig') }}
<div class="flex flex-col space-y-4 pb-6">
{{ include('_partials/_mailing_placeholders.html.twig', { 'placeholders': placeholders }) }}
{{ include('_partials/_markdown_hint.html.twig') }}
</div>
<div class="pb-8">
<div class="font-bold">
Anhänge
</div>
<div class="pb-2 text-sm text-gray-500">
Nur PDF, bis 5 MB je Datei und {{ maxAttachmentBytes|file_size(0) }} zusammen.
</div>
{{ include('administrative/assignment_mailing/_attachments.html.twig') }}
{{ include('_partials/_pending_uploads.html.twig', { 'uploads': pending }) }}
{% include '_partials/_upload_collection_form.html.twig' with {
'endpoint_upload': path('_uploader_upload_mailing_attachment'),
'max_filesize': 5,
'accepted_files': 'application/pdf',
} %}
</div>
<div class="flex items-center space-x-2 pb-8">
<button type="button"
class="btn"
hx-post="{{ path('app_administrative_assignment_mailing_confirm') }}"
hx-include="closest form"
hx-target="body"
hx-swap="beforeend"
{{ stimulus_target('form-upload-guard', 'submit') }}>
{{ icon('mail', 'w-4 h-4 shrink-0') }}
<span>Senden</span>
</button>
<button type="submit" class="btn btn--secondary" {{ stimulus_target('form-upload-guard', 'submit') }}>
Vorschau an mich senden
</button>
{% if hasDraft %}
<a href="{{ path('app_administrative_assignment_mailing_discard') }}" class="btn btn--secondary">
Entwurf verwerfen
</a>
{% endif %}
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
</div>
<div class="lg:sticky lg:top-4">
<div class="font-bold pb-2">
Vorschau
</div>
<div class="relative">
<div id="mailing-preview">
{{ include('admin/teamer/_mailing_preview.html.twig', preview) }}
</div>
<div class="htmx-indicator absolute inset-0 bg-white/75 flex items-center justify-center"
id="mailing-preview-indicator">
{{ include('_partials/_spinner.html.twig', { 'class': 'w-8 h-8' }) }}
</div>
</div>
</div>
</div>
{% endblock %}
@@ -0,0 +1,56 @@
{% extends 'htmx_confirmation_modal.html.twig' %}
{% set sendable = valid and attachmentError is null and recipients.eligibleCount > 0 %}
{% block title %}Mail wirklich senden?{% endblock %}
{% block content %}
{% if not valid %}
<div class="pb-4">
Betreff und Nachricht müssen ausgefüllt sein, bevor die Mail gesendet werden kann.
</div>
{% elseif attachmentError is not null %}
<div class="pb-4">
{{ attachmentError }}
</div>
{% elseif recipients.eligibleCount == 0 %}
<div class="pb-4">
Auf den ausgewählten Einsätzen ist niemand bestätigt eingeteilt, dem geschrieben werden kann.
</div>
{% else %}
<div class="pb-4">
Die Mail geht an <strong>{{ recipients.eligibleCount }}</strong> Teamer:innen auf
{{ mailingDto.assignments|length }} {{ mailingDto.assignments|length == 1 ? 'Einsatz' : 'Einsätzen' }}.
Das lässt sich nicht zurücknehmen.
</div>
<div class="p-4 bg-gray-50 border border-gray-200 rounded-md">
<div class="font-bold pb-2">{{ mailingDto.subject }}</div>
<div class="text-sm">{{ mailingDto.message | u.truncate(400, '…', false) | nl2br }}</div>
</div>
{% set attachmentNames = (mailingDto.template ? mailingDto.template.attachments|map(a => a.displayName ?? a.originalFilename) : [])|merge(pending|map(u => u.originalFilename)) %}
{% if attachmentNames is not empty %}
<div class="pt-4 text-sm">
<span class="font-bold">Anhänge ({{ attachmentSize|file_size(1) }}):</span>
{{ attachmentNames|join(', ') }}
</div>
{% endif %}
{% if recipients.hasSkipped %}
<div class="pt-4 text-sm text-gray-500">
{{ include('admin/teamer/_mailing_skipped.html.twig', { 'recipients': recipients }) }}
</div>
{% endif %}
<div id="mailing-confirm-fields" class="hidden">
<input type="hidden" name="{{ field_name(form.subject) }}" value="{{ field_value(form.subject) }}">
{# a textarea keeps the line breaks of the message intact #}
<textarea name="{{ field_name(form.message) }}">{{ field_value(form.message) }}</textarea>
{% if form._token is defined %}
{{ form_widget(form._token) }}
{% endif %}
</div>
{% endif %}
{% endblock %}
{# without a sendable mail there is nothing to confirm, the button only leads back to the draft #}
{% block button_confirm %}{{ sendable ? 'Jetzt senden' : 'Zurück zum Entwurf' }}{% endblock %}
{% block button_attribute %}{% if sendable %}hx-post="{{ path('app_administrative_assignment_mailing_send') }}" hx-include="#mailing-confirm-fields"{% else %}{{ stimulus_action('modal', 'close') }}{% endif %}{% endblock %}
@@ -0,0 +1,5 @@
{{ include('administrative/assignment_mailing/_fields.html.twig') }}
{{ include('administrative/assignment_mailing/_attachments.html.twig', { 'oob': true }) }}
<div id="mailing-preview" hx-swap-oob="true">
{{ include('admin/teamer/_mailing_preview.html.twig', preview) }}
</div>