@@ -645,6 +696,144 @@ $counts['total'] = count($all_contributions);
});
});
}
+
+
+ // =============================================================
+ // Create News Article
+ // =============================================================
+
+ function createNews() {
+ Swal.fire({
+ title: 'Neue Nachricht',
+ html:
+ '
' +
+ '
' +
+ '' +
+ '' +
+ '
' +
+ '
' +
+ '' +
+ '' +
+ '
' +
+ '
',
+ showCancelButton: true,
+ confirmButtonText: 'Veröffentlichen',
+ cancelButtonText: 'Abbrechen',
+ confirmButtonColor: PRIMARY_COLOR,
+ preConfirm: function () {
+ const title = document.getElementById('swal-news-title').value.trim();
+ const content = document.getElementById('swal-news-content').value.trim();
+ if (!title || !content) {
+ Swal.showValidationMessage('Titel und Inhalt sind Pflichtfelder.');
+ return false;
+ }
+ return { title: title, content: content };
+ }
+ }).then(function (result) {
+ if (!result.isConfirmed) return;
+
+ const formData = new FormData();
+ formData.append('action', 'create_news');
+ formData.append('municipality_id', MUNICIPALITY_ID);
+ formData.append('title', result.value.title);
+ formData.append('content', result.value.content);
+
+ fetch(API_URL, { method: 'POST', body: formData })
+ .then(function (r) { return r.json(); })
+ .then(function (response) {
+ if (response.error) {
+ Swal.fire('Fehler', response.error, 'error');
+ return;
+ }
+ Swal.fire('Veröffentlicht!', 'Nachricht wurde erstellt.', 'success')
+ .then(function () { location.reload(); });
+ });
+ });
+ }
+
+
+ // =============================================================
+ // Edit News Article
+ // =============================================================
+ function editNews(newsId, currentTitle, currentContent) {
+ Swal.fire({
+ title: 'Nachricht bearbeiten',
+ html:
+ '
' +
+ '
' +
+ '' +
+ '' +
+ '
' +
+ '
' +
+ '' +
+ '' +
+ '
' +
+ '
',
+ showCancelButton: true,
+ confirmButtonText: 'Speichern',
+ cancelButtonText: 'Abbrechen',
+ confirmButtonColor: PRIMARY_COLOR,
+ preConfirm: function () {
+ return {
+ title: document.getElementById('swal-news-title').value.trim(),
+ content: document.getElementById('swal-news-content').value.trim()
+ };
+ }
+ }).then(function (result) {
+ if (!result.isConfirmed) return;
+
+ const formData = new FormData();
+ formData.append('action', 'update_news');
+ formData.append('news_id', newsId);
+ formData.append('title', result.value.title);
+ formData.append('content', result.value.content);
+
+ fetch(API_URL, { method: 'POST', body: formData })
+ .then(function (r) { return r.json(); })
+ .then(function (response) {
+ if (response.error) {
+ Swal.fire('Fehler', response.error, 'error');
+ return;
+ }
+ Swal.fire('Gespeichert!', 'Nachricht wurde aktualisiert.', 'success')
+ .then(function () { location.reload(); });
+ });
+ });
+ }
+
+
+ // =============================================================
+ // Create News Article
+ // =============================================================
+ function deleteNews(newsId) {
+ Swal.fire({
+ title: 'Nachricht löschen?',
+ text: 'Diese Aktion kann nicht rückgängig gemacht werden.',
+ icon: 'warning',
+ showCancelButton: true,
+ confirmButtonText: 'Löschen',
+ cancelButtonText: 'Abbrechen',
+ confirmButtonColor: '#c62828'
+ }).then(function (result) {
+ if (!result.isConfirmed) return;
+
+ const formData = new FormData();
+ formData.append('action', 'delete_news');
+ formData.append('news_id', newsId);
+
+ fetch(API_URL, { method: 'POST', body: formData })
+ .then(function (r) { return r.json(); })
+ .then(function (response) {
+ if (response.error) {
+ Swal.fire('Fehler', response.error, 'error');
+ return;
+ }
+ Swal.fire('Gelöscht!', 'Nachricht wurde entfernt.', 'success')
+ .then(function () { location.reload(); });
+ });
+ });
+ }
+