Files
eventmanager-bundle/contao/templates/frontend/organization_edit.html.twig
T
2026-03-01 10:56:38 +01:00

208 lines
7.6 KiB
Twig

{% extends "@Contao/frontend_module/_base.html.twig" %}
{% block content %}
{% if error is defined and error %}
<p role="alert">{{ error }}</p>
<p><a href="{{ backUrl }}">Zurück</a></p>
{% elseif form is defined and form %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css">
<link rel="stylesheet" href="https://unpkg.com/filepond/dist/filepond.min.css">
<link rel="stylesheet" href="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css">
<style>
.module-organization-edit .filepond--root {
width: 400px;
height: 400px;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script>
<script src="https://unpkg.com/filepond/dist/filepond.min.js"></script>
<script src="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.js"></script>
<script src="https://unpkg.com/filepond-plugin-image-resize/dist/filepond-plugin-image-resize.min.js"></script>
<script src="https://unpkg.com/filepond-plugin-image-transform/dist/filepond-plugin-image-transform.min.js"></script>
{{ form_start(form, { attr: { 'aria-live': 'polite' } }) }}
<input type="hidden" name="REQUEST_TOKEN" value="{{ requestToken }}">
<input type="hidden" id="remove_logo" name="remove_logo" value="0">
{{ form_widget(form) }}
<div class="actions" aria-label="Formularaktionen">
<button type="submit" id="save-btn" disabled>Speichern</button>
<button type="submit" id="save-back-btn" name="save_back" value="1" disabled>Speichern und Zurück</button>
<a href="{{ backUrl }}" aria-label="Zurück zur vorherigen Seite">Zurück</a>
</div>
{{ form_end(form) }}
<script>
(function () {
const typeSelect = document.querySelector('select.js-organization-tags-choice');
if (typeSelect && typeof window.Choices === 'function') {
new window.Choices(typeSelect, {
searchEnabled: false,
shouldSort: false,
removeItemButton: true,
itemSelectText: '',
placeholder: true,
placeholderValue: typeSelect.dataset.placeholder || 'Typ auswählen …',
noResultsText: 'Keine Treffer',
noChoicesText: 'Keine Optionen verfügbar'
});
}
const currentLogoPath = {{ (currentLogoPath is defined and currentLogoPath) ? ('/' ~ currentLogoPath)|json_encode|raw : 'null' }};
const logoInput = document.querySelector('input.js-logo-upload');
const removeLogoInput = document.getElementById('remove_logo');
const hadInitialLogo = !!currentLogoPath;
let pondDirty = false;
const form = document.querySelector('form');
const saveButton = document.getElementById('save-btn');
const saveBackButton = document.getElementById('save-back-btn');
if (!form || !saveButton || !saveBackButton) {
return;
}
const initial = new FormData(form);
const hasChanges = () => {
const current = new FormData(form);
for (const [key, value] of current.entries()) {
if (initial.getAll(key).join(',') !== current.getAll(key).join(',')) {
return true;
}
}
return false;
};
const updateButtons = () => {
const changed = hasChanges() || pondDirty;
saveButton.disabled = !changed;
saveBackButton.disabled = !changed;
};
if (logoInput && typeof window.FilePond !== 'undefined') {
if (typeof window.FilePondPluginImagePreview !== 'undefined') {
window.FilePond.registerPlugin(window.FilePondPluginImagePreview);
}
if (typeof window.FilePondPluginImageResize !== 'undefined') {
window.FilePond.registerPlugin(window.FilePondPluginImageResize);
}
if (typeof window.FilePondPluginImageTransform !== 'undefined') {
window.FilePond.registerPlugin(window.FilePondPluginImageTransform);
}
const filePondOptions = {
instantUpload: false,
storeAsFile: true,
allowMultiple: false,
allowReplace: true,
credits: false,
acceptedFileTypes: ['image/*'],
allowImageResize: true,
imageResizeUpscale: false,
allowImageTransform: true,
onaddfile: function (error, fileItem) {
if (error || !fileItem || typeof fileItem.setMetadata !== 'function') {
return;
}
const fileType = fileItem.fileType || (fileItem.file && fileItem.file.type) || '';
if (fileType === 'image/svg+xml') {
fileItem.setMetadata('resize', null);
return;
}
fileItem.setMetadata('resize', {
mode: 'contain',
upscale: false,
size: {
width: 800,
height: 800
}
});
},
labelIdle: 'Logo hierher ziehen oder <span class="filepond--label-action">durchsuchen</span>'
};
if (currentLogoPath) {
filePondOptions.files = [
{
source: currentLogoPath,
options: {
type: 'local'
}
}
];
filePondOptions.server = {
load: (source, load, error, progress, abort) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', source);
xhr.responseType = 'blob';
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
load(xhr.response);
} else {
error('Laden fehlgeschlagen');
}
};
xhr.onerror = function () {
error('Laden fehlgeschlagen');
};
xhr.send();
return {
abort: () => {
xhr.abort();
abort();
}
};
}
};
}
const pond = window.FilePond.create(logoInput, filePondOptions);
const syncPondState = () => {
const files = pond.getFiles();
const hasLocalFile = files.some((file) => window.FilePond.FileOrigin && file.origin === window.FilePond.FileOrigin.LOCAL);
const hasNewFile = files.some((file) => window.FilePond.FileOrigin && file.origin !== window.FilePond.FileOrigin.LOCAL);
pondDirty = hasNewFile || (hadInitialLogo && !hasLocalFile);
if (removeLogoInput) {
removeLogoInput.value = hadInitialLogo && !hasLocalFile && !hasNewFile ? '1' : '0';
}
updateButtons();
};
syncPondState();
pond.on('removefile', function (error, file) {
if (error) {
return;
}
syncPondState();
});
pond.on('addfile', function () {
syncPondState();
});
pond.on('updatefiles', function () {
syncPondState();
});
}
form.addEventListener('input', function () {
updateButtons();
});
form.addEventListener('change', function () {
updateButtons();
});
})();
</script>
{% else %}
<p>Kein Formular verfügbar.</p>
{% endif %}
{% endblock %}