mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
Wersja probna
powinno cos dzialac
This commit is contained in:
@@ -1,24 +1,25 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const deleteButtons = document.querySelectorAll(".delete-btn");
|
||||
document.body.addEventListener("click", async (e) => {
|
||||
const target = e.target as HTMLElement;
|
||||
|
||||
deleteButtons.forEach(button => {
|
||||
button.addEventListener("click", async () => {
|
||||
const id = (button as HTMLButtonElement).dataset.id;
|
||||
if (!id) return;
|
||||
if (!target.matches(".delete-btn")) return;
|
||||
|
||||
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?");
|
||||
if (!confirmed) return;
|
||||
const id = target.getAttribute("data-id");
|
||||
if (!id) return;
|
||||
|
||||
const response = await fetch(`/api/events/${id}`, {
|
||||
method: "DELETE"
|
||||
});
|
||||
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?");
|
||||
if (!confirmed) return;
|
||||
|
||||
if (response.ok) {
|
||||
const row = button.closest("tr");
|
||||
if (row) row.remove();
|
||||
} else {
|
||||
alert("Nie udało się usunąć wydarzenia.");
|
||||
}
|
||||
const response = await fetch(`/api/events/${id}`, {
|
||||
|
||||
method: "DELETE"
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const card = target.closest(".col");
|
||||
if (card) card.remove();
|
||||
} else {
|
||||
alert("Nie udało się usunąć wydarzenia.");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
41
WebApp/ts/eventList.ts
Normal file
41
WebApp/ts/eventList.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
const container = document.getElementById("eventList");
|
||||
if (!container) return;
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/events");
|
||||
if (!res.ok) throw new Error("Błąd pobierania wydarzeń");
|
||||
|
||||
const events = await res.json();
|
||||
|
||||
if (events.length === 0) {
|
||||
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||
return;
|
||||
}
|
||||
|
||||
for (const ev of events) {
|
||||
const card = document.createElement("div");
|
||||
card.className = "col";
|
||||
card.innerHTML = `
|
||||
<div class="card shadow-sm h-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${ev.title}</h5>
|
||||
<p class="card-text">
|
||||
<strong>Miejsce:</strong> ${ev.location}<br/>
|
||||
<strong>Data:</strong> ${new Date(ev.eventDate).toLocaleString()}<br/>
|
||||
<strong>Organizacja ID:</strong> ${ev.organisationId}
|
||||
</p>
|
||||
<button class="btn btn-outline-danger delete-btn" data-id="${ev.eventId}">
|
||||
🗑️ Usuń
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
container.appendChild(card);
|
||||
}
|
||||
} catch (err) {
|
||||
container.innerHTML = `<p class="text-danger">Błąd ładowania danych.</p>`;
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user