7 Commits

5 changed files with 287 additions and 168 deletions

View File

@@ -334,9 +334,9 @@ $counts['total'] = count($all_contributions);
<i class="fa-solid fa-trash"></i> Löschen <i class="fa-solid fa-trash"></i> Löschen
</button> </button>
<a class="btn btn-map" href="index.php" target="_blank"> <!-- <a class="btn btn-map" href="index.php" target="_blank">
<i class="fa-solid fa-map-location-dot"></i> Karte <i class="fa-solid fa-map-location-dot"></i> Karte
</a> </a> -->
</div> </div>
</div> </div>
</div> </div>
@@ -538,6 +538,74 @@ $counts['total'] = count($all_contributions);
</div> </div>
<!-- ============================================================= -->
<!-- Edit Contribution Modal (Admin) -->
<!-- ============================================================= -->
<div id="admin-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="admin-edit-title">Titel</label>
<input type="text" id="admin-edit-title" class="form-input">
</div>
<div class="form-group">
<label for="admin-edit-description">Beschreibung</label>
<textarea id="admin-edit-description" class="form-input" rows="4"></textarea>
</div>
<input type="hidden" id="admin-edit-id">
<div class="modal-actions">
<button class="btn btn-secondary" onclick="closeAdminModal('admin-edit-modal')">Abbrechen</button>
<button class="btn btn-primary" onclick="submitAdminEdit()">Speichern</button>
</div>
</div>
</div>
<!-- ============================================================= -->
<!-- Edit Comment Modal (Admin) -->
<!-- ============================================================= -->
<div id="admin-comment-modal" class="modal-overlay" style="display:none;">
<div class="modal-content">
<h2><i class="fa-solid fa-pen"></i> Kommentar bearbeiten</h2>
<div class="form-group">
<label for="admin-comment-content">Inhalt</label>
<textarea id="admin-comment-content" class="form-input" rows="4"></textarea>
</div>
<input type="hidden" id="admin-comment-id">
<div class="modal-actions">
<button class="btn btn-secondary" onclick="closeAdminModal('admin-comment-modal')">Abbrechen</button>
<button class="btn btn-primary" onclick="submitAdminComment()">Speichern</button>
</div>
</div>
</div>
<!-- ============================================================= -->
<!-- Create/Edit News Modal (Admin) -->
<!-- ============================================================= -->
<div id="admin-news-modal" class="modal-overlay" style="display:none;">
<div class="modal-content">
<h2 id="admin-news-modal-title"><i class="fa-solid fa-newspaper"></i> Neuigkeit hinzufügen</h2>
<div class="form-group">
<label for="admin-news-title">Titel</label>
<input type="text" id="admin-news-title" class="form-input" placeholder="Titel der Neuigkeit">
</div>
<div class="form-group">
<label for="admin-news-content">Inhalt</label>
<textarea id="admin-news-content" class="form-input" rows="4" placeholder="Neuigkeit verfassen..."></textarea>
</div>
<div class="form-group">
<label for="admin-news-author">Autor</label>
<input type="text" id="admin-news-author" class="form-input" value="Stadtverwaltung">
</div>
<input type="hidden" id="admin-news-id">
<input type="hidden" id="admin-news-mode">
<div class="modal-actions">
<button class="btn btn-secondary" onclick="closeAdminModal('admin-news-modal')">Abbrechen</button>
<button class="btn btn-primary" onclick="submitAdminNews()">Speichern</button>
</div>
</div>
</div>
<!-- ============================================================= --> <!-- ============================================================= -->
<!-- Loads JavaScript Dependencies --> <!-- Loads JavaScript Dependencies -->

View File

@@ -167,6 +167,16 @@ $news_items = $stmt->fetchAll();
<div class="list-search"> <div class="list-search">
<input type="text" id="list-search-input" placeholder="Beiträge durchsuchen..." class="form-input"> <input type="text" id="list-search-input" placeholder="Beiträge durchsuchen..." class="form-input">
</div> </div>
<div class="list-controls">
<select id="list-sort" class="form-input list-sort-select" onchange="updateContributionsList()">
<option value="date-desc">Neueste zuerst</option>
<option value="date-asc">Älteste zuerst</option>
<option value="category">Nach Kategorie</option>
<option value="likes">Meiste Bewertungen</option>
<option value="comments">Meiste Kommentare</option>
</select>
<span id="list-count" class="list-count"></span>
</div>
<div id="contributions-list"> <div id="contributions-list">
<!-- Contribution Cards — populated by app.js --> <!-- Contribution Cards — populated by app.js -->
</div> </div>
@@ -185,6 +195,14 @@ $news_items = $stmt->fetchAll();
<input type="text" id="news-search-input" placeholder="Neuigkeiten durchsuchen..." class="form-input" oninput="filterNews()"> <input type="text" id="news-search-input" placeholder="Neuigkeiten durchsuchen..." class="form-input" oninput="filterNews()">
</div> </div>
<div class="list-controls">
<select id="news-sort" class="form-input list-sort-select" onchange="sortNews()">
<option value="date-desc">Neueste zuerst</option>
<option value="date-asc">Älteste zuerst</option>
</select>
<span class="list-count"><?= count($news_items) ?> Neuigkeiten</span>
</div>
<!-- News Items Container --> <!-- News Items Container -->
<div id="news-list"> <div id="news-list">
<?php if (empty($news_items)): ?> <?php if (empty($news_items)): ?>
@@ -192,9 +210,10 @@ $news_items = $stmt->fetchAll();
<?php else: ?> <?php else: ?>
<?php foreach ($news_items as $news): ?> <?php foreach ($news_items as $news): ?>
<div class="news-item" <div class="news-item"
data-title="<?= htmlspecialchars(strtolower($news['title'])) ?>" data-title="<?= htmlspecialchars(strtolower($news['title'])) ?>"
data-content="<?= htmlspecialchars(strtolower($news['content'])) ?>" data-content="<?= htmlspecialchars(strtolower($news['content'])) ?>"
data-author="<?= htmlspecialchars(strtolower($news['author_name'])) ?>"> data-author="<?= htmlspecialchars(strtolower($news['author_name'])) ?>"
data-date="<?= $news['published_at'] ?>">
<h3><?= htmlspecialchars($news['title']) ?></h3> <h3><?= htmlspecialchars($news['title']) ?></h3>
<p><?= nl2br(htmlspecialchars($news['content'])) ?></p> <p><?= nl2br(htmlspecialchars($news['content'])) ?></p>
<span class="news-date"> <span class="news-date">

View File

@@ -319,6 +319,22 @@ function escapeHtml(text) {
return div.innerHTML; return div.innerHTML;
} }
// Closes Admin Modals by ID
function closeAdminModal(modalId) {
document.getElementById(modalId).style.display = 'none';
}
// Closes Admin Modals on Escape Key
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') {
document.querySelectorAll('.modal-overlay').forEach(function (modal) {
modal.style.display = 'none';
});
}
});
// ===================================================================== // =====================================================================
// Block 9: CRUD Operations for Contributions // Block 9: CRUD Operations for Contributions
// ===================================================================== // =====================================================================
@@ -354,45 +370,36 @@ function changeStatus(contributionId, newStatus) {
// UPDATE: Edits existing Contributions // UPDATE: Edits existing Contributions
function editContribution(contributionId, currentTitle, currentDescription) { function editContribution(contributionId, currentTitle, currentDescription) {
Swal.fire({ document.getElementById('admin-edit-id').value = contributionId;
title: 'Beitrag bearbeiten', document.getElementById('admin-edit-title').value = currentTitle;
html: document.getElementById('admin-edit-description').value = currentDescription;
'<div class="swal-form">' + document.getElementById('admin-edit-modal').style.display = 'flex';
'<div class="swal-group">' + }
'<label class="swal-label">Titel</label>' +
'<input id="swal-title" class="swal2-input" value="' + escapeHtml(currentTitle) + '">' +
'</div>' +
'<div>' +
'<label class="swal-label">Beschreibung</label>' +
'<textarea id="swal-description" class="swal2-textarea">' + escapeHtml(currentDescription) + '</textarea>' +
'</div>' +
'</div>',
showCancelButton: true,
confirmButtonText: 'Speichern',
cancelButtonText: 'Abbrechen',
confirmButtonColor: ADMIN_CONFIG.primaryColor,
preConfirm: function () {
return {
title: document.getElementById('swal-title').value.trim(),
description: document.getElementById('swal-description').value.trim()
};
}
}).then(function (result) {
if (!result.isConfirmed) return;
apiCall({ // Submits Edit from Custom Modal
action: 'update', function submitAdminEdit() {
contribution_id: contributionId, var id = document.getElementById('admin-edit-id').value;
title: result.value.title, var title = document.getElementById('admin-edit-title').value.trim();
description: result.value.description var description = document.getElementById('admin-edit-description').value.trim();
}).then(function (response) {
if (response.error) { if (!title) {
Swal.fire('Fehler', response.error, 'error'); Swal.fire('Titel fehlt', 'Bitte geben Sie einen Titel ein.', 'warning');
return; return;
} }
Swal.fire('Gespeichert!', 'Beitrag wurde aktualisiert.', 'success')
.then(function () { location.reload(); }); apiCall({
}); action: 'update',
contribution_id: id,
title: title,
description: description
}).then(function (response) {
if (response.error) {
Swal.fire('Fehler', response.error, 'error');
return;
}
closeAdminModal('admin-edit-modal');
Swal.fire('Gespeichert!', 'Beitrag wurde aktualisiert.', 'success')
.then(function () { location.reload(); });
}); });
} }
@@ -458,35 +465,33 @@ function changeCommentStatus(commentId, newStatus) {
// UPDATE: Edits existing Comments // UPDATE: Edits existing Comments
function editModComment(commentId, currentContent) { function editModComment(commentId, currentContent) {
Swal.fire({ document.getElementById('admin-comment-id').value = commentId;
title: 'Kommentar bearbeiten', document.getElementById('admin-comment-content').value = currentContent;
html: document.getElementById('admin-comment-modal').style.display = 'flex';
'<div class="swal-form">' + }
'<label class="swal-label">Inhalt</label>' +
'<textarea id="swal-comment-content" class="swal2-textarea">' + escapeHtml(currentContent) + '</textarea>' +
'</div>',
showCancelButton: true,
confirmButtonText: 'Speichern',
cancelButtonText: 'Abbrechen',
confirmButtonColor: ADMIN_CONFIG.primaryColor,
preConfirm: function () {
return { content: document.getElementById('swal-comment-content').value.trim() };
}
}).then(function (result) {
if (!result.isConfirmed) return;
apiCall({ // Submits Comment Edit from Custom Modal
action: 'update_comment', function submitAdminComment() {
comment_id: commentId, var id = document.getElementById('admin-comment-id').value;
content: result.value.content var content = document.getElementById('admin-comment-content').value.trim();
}).then(function (response) {
if (response.error) { if (!content) {
Swal.fire('Fehler', response.error, 'error'); Swal.fire('Inhalt fehlt', 'Bitte geben Sie einen Inhalt ein.', 'warning');
return; return;
} }
Swal.fire('Gespeichert!', 'Kommentar wurde aktualisiert.', 'success')
.then(function () { location.reload(); }); apiCall({
}); action: 'update_comment',
comment_id: id,
content: content
}).then(function (response) {
if (response.error) {
Swal.fire('Fehler', response.error, 'error');
return;
}
closeAdminModal('admin-comment-modal');
Swal.fire('Gespeichert!', 'Kommentar wurde aktualisiert.', 'success')
.then(function () { location.reload(); });
}); });
} }
@@ -523,107 +528,68 @@ function deleteModComment(commentId) {
// Block 11: CRUD Operations for News // Block 11: CRUD Operations for News
// ===================================================================== // =====================================================================
// CREATE: Submits new News Article // CREATE: Creates News
function createNews() { function createNews() {
Swal.fire({ document.getElementById('admin-news-modal-title').innerHTML = '<i class="fa-solid fa-newspaper"></i> Neuigkeit hinzufügen';
title: 'Neuigkeit hinzufügen', document.getElementById('admin-news-id').value = '';
html: document.getElementById('admin-news-mode').value = 'create';
'<div class="swal-form">' + document.getElementById('admin-news-title').value = '';
'<div class="swal-group">' + document.getElementById('admin-news-content').value = '';
'<label class="swal-label">Titel</label>' + document.getElementById('admin-news-author').value = 'Stadtverwaltung';
'<input id="swal-news-title" class="swal2-input" placeholder="Titel der Neuigkeit">' + document.getElementById('admin-news-modal').style.display = 'flex';
'</div>' +
'<div class="swal-group">' +
'<label class="swal-label">Inhalt</label>' +
'<textarea id="swal-news-content" class="swal2-textarea" placeholder="Neuigkeit verfassen..."></textarea>' +
'</div>' +
'<div>' +
'<label class="swal-label">Autor</label>' +
'<input id="swal-news-author" class="swal2-input" value="Stadtverwaltung">' +
'</div>' +
'</div>',
showCancelButton: true,
confirmButtonText: 'Veröffentlichen',
cancelButtonText: 'Abbrechen',
confirmButtonColor: ADMIN_CONFIG.primaryColor,
preConfirm: function () {
const title = document.getElementById('swal-news-title').value.trim();
const content = document.getElementById('swal-news-content').value.trim();
const author = document.getElementById('swal-news-author').value.trim() || 'Stadtverwaltung';
if (!title || !content) {
Swal.showValidationMessage('Titel und Inhalt sind Pflichtfelder.');
return false;
}
return { title, content, author_name: author };
}
}).then(function (result) {
if (!result.isConfirmed) return;
apiCall({
action: 'create_news',
municipality_id: ADMIN_CONFIG.id,
title: result.value.title,
content: result.value.content,
author_name: result.value.author_name
}).then(function (response) {
if (response.error) {
Swal.fire('Fehler', response.error, 'error');
return;
}
Swal.fire('Veröffentlicht!', 'Neuigkeit wurde veröffentlicht.', 'success')
.then(function () { location.reload(); });
});
});
} }
// UPDATE: Edits existing News // UPDATE: Edits existing News
function editNews(newsId, currentTitle, currentContent, currentAuthor) { function editNews(newsId, currentTitle, currentContent, currentAuthor) {
Swal.fire({ document.getElementById('admin-news-modal-title').innerHTML = '<i class="fa-solid fa-pen"></i> Neuigkeit bearbeiten';
title: 'Neuigkeit bearbeiten', document.getElementById('admin-news-id').value = newsId;
html: document.getElementById('admin-news-mode').value = 'edit';
'<div class="swal-form">' + document.getElementById('admin-news-title').value = currentTitle;
'<div class="swal-group">' + document.getElementById('admin-news-content').value = currentContent;
'<label class="swal-label">Titel</label>' + document.getElementById('admin-news-author').value = currentAuthor;
'<input id="swal-news-title" class="swal2-input" value="' + escapeHtml(currentTitle) + '">' + document.getElementById('admin-news-modal').style.display = 'flex';
'</div>' + }
'<div class="swal-group">' +
'<label class="swal-label">Inhalt</label>' +
'<textarea id="swal-news-content" class="swal2-textarea">' + escapeHtml(currentContent) + '</textarea>' +
'</div>' +
'<div>' +
'<label class="swal-label">Autor</label>' +
'<input id="swal-news-author" class="swal2-input" value="' + escapeHtml(currentAuthor) + '">' +
'</div>' +
'</div>',
showCancelButton: true,
confirmButtonText: 'Speichern',
cancelButtonText: 'Abbrechen',
confirmButtonColor: ADMIN_CONFIG.primaryColor,
preConfirm: function () {
return {
title: document.getElementById('swal-news-title').value.trim(),
content: document.getElementById('swal-news-content').value.trim(),
author_name: document.getElementById('swal-news-author').value.trim() || 'Stadtverwaltung'
};
}
}).then(function (result) {
if (!result.isConfirmed) return;
apiCall({ // Submits News from Custom Modal (Create or Edit)
function submitAdminNews() {
var mode = document.getElementById('admin-news-mode').value;
var title = document.getElementById('admin-news-title').value.trim();
var content = document.getElementById('admin-news-content').value.trim();
var author = document.getElementById('admin-news-author').value.trim() || 'Stadtverwaltung';
if (!title || !content) {
Swal.fire('Pflichtfelder', 'Titel und Inhalt sind Pflichtfelder.', 'warning');
return;
}
var data;
if (mode === 'create') {
data = {
action: 'create_news',
municipality_id: ADMIN_CONFIG.id,
title: title,
content: content,
author_name: author
};
} else {
data = {
action: 'update_news', action: 'update_news',
news_id: newsId, news_id: document.getElementById('admin-news-id').value,
title: result.value.title, title: title,
content: result.value.content, content: content,
author_name: result.value.author_name author_name: author
}).then(function (response) { };
if (response.error) { }
Swal.fire('Fehler', response.error, 'error');
return; apiCall(data).then(function (response) {
} if (response.error) {
Swal.fire('Gespeichert!', 'Neuigkeit wurde aktualisiert.', 'success') Swal.fire('Fehler', response.error, 'error');
.then(function () { location.reload(); }); return;
}); }
closeAdminModal('admin-news-modal');
var msg = mode === 'create' ? 'Neuigkeit wurde veröffentlicht.' : 'Neuigkeit wurde aktualisiert.';
Swal.fire('Gespeichert!', msg, 'success')
.then(function () { location.reload(); });
}); });
} }

View File

@@ -829,11 +829,25 @@ function updateContributionsList() {
return matchesCategory && matchesSearch; return matchesCategory && matchesSearch;
}); });
// Sorts by Date (newest first) // Sorts by selected Option
var sortBy = document.getElementById('list-sort') ? document.getElementById('list-sort').value : 'date-desc';
filtered.sort(function (a, b) { filtered.sort(function (a, b) {
return new Date(b.properties.created_at) - new Date(a.properties.created_at); if (sortBy === 'date-desc') return new Date(b.properties.created_at) - new Date(a.properties.created_at);
if (sortBy === 'date-asc') return new Date(a.properties.created_at) - new Date(b.properties.created_at);
if (sortBy === 'likes') return b.properties.likes_count - a.properties.likes_count;
if (sortBy === 'comments') return (b.properties.comment_count || 0) - (a.properties.comment_count || 0);
if (sortBy === 'category') {
var catA = (CATEGORIES[a.properties.category] || CATEGORIES.other).label;
var catB = (CATEGORIES[b.properties.category] || CATEGORIES.other).label;
return catA.localeCompare(catB);
}
return 0;
}); });
// Updates Count Display
var countEl = document.getElementById('list-count');
if (countEl) countEl.textContent = filtered.length + ' Beiträge';
// Builds HTML // Builds HTML
if (filtered.length === 0) { if (filtered.length === 0) {
container.innerHTML = '<p class="empty-state">Keine Beiträge gefunden.</p>'; container.innerHTML = '<p class="empty-state">Keine Beiträge gefunden.</p>';
@@ -1145,6 +1159,21 @@ function filterNews() {
}); });
} }
// Sorts News Items in Sidebar by Date
function sortNews() {
var sortBy = document.getElementById('news-sort').value;
var container = document.getElementById('news-list');
var items = Array.from(container.querySelectorAll('.news-item'));
items.sort(function (a, b) {
if (sortBy === 'date-desc') return new Date(b.dataset.date) - new Date(a.dataset.date);
if (sortBy === 'date-asc') return new Date(a.dataset.date) - new Date(b.dataset.date);
return 0;
});
items.forEach(function (item) { container.appendChild(item); });
}
// Loads and Displays Comments forContributions in Popups // Loads and Displays Comments forContributions in Popups
function loadComments(contributionId) { function loadComments(contributionId) {
apiCall({ apiCall({

View File

@@ -657,12 +657,39 @@ select.form-input { cursor: pointer; }
font-size: var(--font-sm); font-size: var(--font-sm);
} }
.leaflet-sidebar-close {
color: white;
font-size: var(--font-lg);
}
/* ----------------------------------------------------------------- /* -----------------------------------------------------------------
4.4 Sidebar Contributions List 4.4 Sidebar Contributions List
----------------------------------------------------------------- */ ----------------------------------------------------------------- */
.list-search { margin-bottom: var(--space-md); } .list-search { margin-bottom: var(--space-md); }
.list-controls {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: var(--space-md);
gap: var(--space-sm);
}
.list-sort-select {
width: auto;
min-width:185px;
padding: 6px var(--space-sm);
font-size: var(--font-sm);
flex-shrink: 0;
}
.list-count {
font-size: var(--font-sm);
color: var(--color-text-secondary);
white-space: nowrap;
}
.contribution-card { .contribution-card {
padding: var(--space-md); padding: var(--space-md);
margin-bottom: var(--space-sm); margin-bottom: var(--space-sm);
@@ -675,7 +702,7 @@ select.form-input { cursor: pointer; }
.contribution-card:hover { .contribution-card:hover {
border-color: var(--color-primary); border-color: var(--color-primary);
box-shadow: var(--shadow-sm); box-shadow: var(--shadow-md);
} }
.contribution-card-header { display: flex; align-items: center; gap: var(--space-sm); margin-bottom: var(--space-xs); } .contribution-card-header { display: flex; align-items: center; gap: var(--space-sm); margin-bottom: var(--space-xs); }
@@ -710,6 +737,10 @@ select.form-input { cursor: pointer; }
color: var(--color-text-secondary); color: var(--color-text-secondary);
} }
.category-filter-label input[type="checkbox"] {
accent-color: var(--color-primary);
}
.category-filter-total { .category-filter-total {
margin-top: 10px; margin-top: 10px;
font-size: var(--font-sm); font-size: var(--font-sm);
@@ -729,6 +760,12 @@ select.form-input { cursor: pointer; }
border-radius: var(--radius-md); border-radius: var(--radius-md);
} }
.news-item:hover {
border-color: var(--color-primary);
box-shadow: var(--shadow-sm);
transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}
.news-date { font-size: var(--font-sm); color: var(--color-text-secondary); } .news-date { font-size: var(--font-sm); color: var(--color-text-secondary); }
.news-item h3 { font-size: var(--font-md); margin: var(--space-xs) 0; color: var(--color-text); } .news-item h3 { font-size: var(--font-md); margin: var(--space-xs) 0; color: var(--color-text); }