mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
Lekkie zmiany
Trzeba dodać logowanie tak jak reszte(nie wiem gdzie było logowanie ale zaraz się znajdzie)
This commit is contained in:
@@ -1,25 +1,32 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Obsługuje kliknięcie na przycisk "Usuń"
|
||||
document.body.addEventListener("click", async (e) => {
|
||||
const target = e.target as HTMLElement;
|
||||
|
||||
if (!target.matches(".delete-btn")) return;
|
||||
if (!target.matches(".delete-btn")) return; // Sprawdza, czy kliknięto przycisk "Usuń"
|
||||
|
||||
const id = target.getAttribute("data-id");
|
||||
const id = target.getAttribute("data-id"); // Pobiera ID wydarzenia
|
||||
if (!id) return;
|
||||
|
||||
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?");
|
||||
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?"); // Potwierdzenie usunięcia
|
||||
if (!confirmed) return;
|
||||
|
||||
const response = await fetch(`/api/events/${id}`, {
|
||||
try {
|
||||
// Wysyła żądanie DELETE do API
|
||||
const response = await fetch(`/api/events/${id}`, {
|
||||
method: "DELETE"
|
||||
});
|
||||
|
||||
method: "DELETE"
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const card = target.closest(".col");
|
||||
if (card) card.remove();
|
||||
} else {
|
||||
alert("Nie udało się usunąć wydarzenia.");
|
||||
if (response.ok) {
|
||||
// Usuwa kartę z DOM (bez przeładowania strony)
|
||||
const card = target.closest(".event-card");
|
||||
if (card) card.remove();
|
||||
} else {
|
||||
alert("Błąd podczas usuwania wydarzenia.");
|
||||
}
|
||||
} catch (err) {
|
||||
alert("Błąd połączenia z serwerem.");
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -13,29 +13,20 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Wyczyść kontener przed dodaniem nowych
|
||||
container.innerHTML = '';
|
||||
|
||||
for (const ev of events) {
|
||||
const card = document.createElement("div");
|
||||
card.className = "col";
|
||||
card.className = "event-card filled";
|
||||
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>
|
||||
`;
|
||||
|
||||
<span>${ev.title}</span>
|
||||
<button class="remove-btn delete-btn" data-id="${ev.eventId}">−</button>
|
||||
`;
|
||||
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