From 70fe829e97d82d900d185da41b767f2f6994c52f Mon Sep 17 00:00:00 2001 From: patrickzerhusen Date: Tue, 16 Jun 2026 15:53:42 +0200 Subject: [PATCH] cutom edit contribution modal --- public/index.php | 27 +++++++++++++++++ public/js/app.js | 78 +++++++++++++++++++++++------------------------- 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/public/index.php b/public/index.php index 706264c..6596bd1 100644 --- a/public/index.php +++ b/public/index.php @@ -348,6 +348,33 @@ $news_items = $stmt->fetchAll(); + + + + + + diff --git a/public/js/app.js b/public/js/app.js index 44bf0a8..209c7e5 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -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: - '
' + - '
' + - '' + - '' + - '
' + - '
' + - '' + - '' + - '
' + - '
', - 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'; } });