cutom edit contribution modal

This commit is contained in:
2026-06-16 15:53:42 +02:00
parent c1dd6cc009
commit 70fe829e97
2 changed files with 65 additions and 40 deletions

View File

@@ -348,6 +348,33 @@ $news_items = $stmt->fetchAll();
</div>
</div>
<!-- ============================================================= -->
<!-- Edit Contribution Modal -->
<!-- ============================================================= -->
<div id="edit-modal" class="modal-overlay" style="display:none;">
<div class="modal-content">
<h2><i class="fa-solid fa-pen"></i> Beitrag bearbeiten</h2>
<div class="form-group">
<label for="edit-title">Titel</label>
<input type="text" id="edit-title" class="form-input">
</div>
<div class="form-group">
<label for="edit-description">Beschreibung</label>
<textarea id="edit-description" class="form-input" rows="4"></textarea>
</div>
<input type="hidden" id="edit-contribution-id">
<div class="modal-actions">
<button class="btn btn-secondary" onclick="closeEditModal()">Abbrechen</button>
<button class="btn btn-primary" onclick="submitEdit()">Speichern</button>
</div>
</div>
</div>
<!-- ============================================================= -->
<!-- Loads JavaScript Dependencies -->

View File

@@ -653,58 +653,55 @@ function closeCreateModal() {
}
// UPDATE: Edits existing Contributions
// UPDATE: Opens Edit Modal for existing Contributions
function editContribution(contributionId) {
// Finds Contribution in local Data
const contribution = contributionsData.find(function (f) {
return f.properties.contribution_id === contributionId;
});
if (!contribution) return;
const props = contribution.properties;
document.getElementById('edit-contribution-id').value = contributionId;
document.getElementById('edit-title').value = props.title;
document.getElementById('edit-description').value = props.description || '';
document.getElementById('edit-modal').style.display = 'flex';
}
Swal.fire({
title: 'Beitrag bearbeiten',
html:
'<div class="swal-form">' +
'<div class="swal-group">' +
'<label class="swal-label">Titel</label>' +
'<input id="swal-title" class="swal2-input" value="' + escapeHtml(props.title) + '">' +
'</div>' +
'<div>' +
'<label class="swal-label">Beschreibung</label>' +
'<textarea id="swal-description" class="swal2-textarea">' + escapeHtml(props.description || '') + '</textarea>' +
'</div>' +
'</div>',
showCancelButton: true,
confirmButtonText: 'Speichern',
cancelButtonText: 'Abbrechen',
confirmButtonColor: MUNICIPALITY.primaryColor,
preConfirm: function () {
return {
title: document.getElementById('swal-title').value.trim(),
description: document.getElementById('swal-description').value.trim()
};
// Submits Edit from Custom Modal
function submitEdit() {
const contributionId = document.getElementById('edit-contribution-id').value;
const title = document.getElementById('edit-title').value.trim();
const description = document.getElementById('edit-description').value.trim();
if (!title) {
Swal.fire('Titel fehlt', 'Bitte geben Sie einen Titel ein.', 'warning');
return;
}
apiCall({
action: 'update',
contribution_id: contributionId,
title: title,
description: description
}, function (response) {
if (response.error) {
Swal.fire('Fehler', response.error, 'error');
return;
}
}).then(function (result) {
if (!result.isConfirmed) return;
apiCall({
action: 'update',
contribution_id: contributionId,
title: result.value.title,
description: result.value.description
}, function (response) {
if (response.error) {
Swal.fire('Fehler', response.error, 'error');
return;
}
Swal.fire('Gespeichert!', 'Der Beitrag wurde aktualisiert.', 'success');
loadContributions();
});
closeEditModal();
Swal.fire('Gespeichert!', 'Der Beitrag wurde aktualisiert.', 'success');
loadContributions();
});
}
// Closes Edit Modal
function closeEditModal() {
document.getElementById('edit-modal').style.display = 'none';
document.getElementById('edit-contribution-id').value = '';
document.getElementById('edit-title').value = '';
document.getElementById('edit-description').value = '';
}
// DELETE: Deletes existing Contributions
function deleteContribution(contributionId) {
Swal.fire({
@@ -1082,6 +1079,7 @@ document.addEventListener('keydown', function (e) {
document.getElementById('welcome-modal').style.display = 'none';
document.getElementById('login-modal').style.display = 'none';
document.getElementById('create-modal').style.display = 'none';
document.getElementById('edit-modal').style.display = 'none';
}
});