mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
Add leaving event
This commit is contained in:
@@ -10,6 +10,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
const modifyBtn = document.getElementById("editBtn");
|
const modifyBtn = document.getElementById("editBtn");
|
||||||
const removeBtn = document.getElementById("removeBtn");
|
const removeBtn = document.getElementById("removeBtn");
|
||||||
const applyBtn = document.getElementById("applyBtn");
|
const applyBtn = document.getElementById("applyBtn");
|
||||||
|
const leaveBtn = document.getElementById("leaveBtn");
|
||||||
var org_id: number = -1;
|
var org_id: number = -1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -118,14 +119,41 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
} = await response.json();
|
} = await response.json();
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
(applyBtn as HTMLButtonElement).disabled = true;
|
window.location.href = `/view.html?event=${eventId}`;
|
||||||
(applyBtn as HTMLButtonElement).textContent = "Applied Succesfully";
|
|
||||||
} else {
|
} else {
|
||||||
alert(`Error: ${result.error_msg ?? "Unknown error occurred."}`);
|
alert(`Error: ${result.error_msg ?? "Unknown error occurred."}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to apply:", error);
|
console.error("Failed to apply:", error);
|
||||||
alert("Failed to apply due to a network or server error.");
|
alert("Failed to apply.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leaveBtn) {
|
||||||
|
leaveBtn.addEventListener("click", async (e) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/events/leave/${eventId}`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result: {
|
||||||
|
success: boolean;
|
||||||
|
error_msg?: string;
|
||||||
|
} = await response.json();
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
window.location.href = `/view.html?event=${eventId}`;
|
||||||
|
} else {
|
||||||
|
alert(`Error: ${result.error_msg ?? "Unknown error occurred."}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to leave:", error)
|
||||||
|
alert("Failed to leave.")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
|
|||||||
const modifyBtn = document.getElementById("editBtn");
|
const modifyBtn = document.getElementById("editBtn");
|
||||||
const removeBtn = document.getElementById("removeBtn");
|
const removeBtn = document.getElementById("removeBtn");
|
||||||
const applyBtn = document.getElementById("applyBtn");
|
const applyBtn = document.getElementById("applyBtn");
|
||||||
|
const leaveBtn = document.getElementById("leaveBtn");
|
||||||
var org_id = -1;
|
var org_id = -1;
|
||||||
try {
|
try {
|
||||||
var user = yield getMyAccount();
|
var user = yield getMyAccount();
|
||||||
@@ -37,7 +38,7 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
|
|||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
if (container !== null)
|
if (container !== null)
|
||||||
container.innerHTML = `<p class="text-danger">To wydarzenie nie istnieje! <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
|
container.innerHTML = `<p class="text-danger">To wydarzenie nie istnieje! <a href="/" style="color:#2898BD;">Powr<EFBFBD>t -></a></p>`;
|
||||||
}
|
}
|
||||||
if (thisEvent == null) {
|
if (thisEvent == null) {
|
||||||
if (container !== null)
|
if (container !== null)
|
||||||
@@ -116,8 +117,7 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
|
|||||||
});
|
});
|
||||||
const result = yield response.json();
|
const result = yield response.json();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
applyBtn.disabled = true;
|
window.location.href = `/view.html?event=${eventId}`;
|
||||||
applyBtn.textContent = "Applied Succesfully";
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
alert(`Error: ${(_b = result.error_msg) !== null && _b !== void 0 ? _b : "Unknown error occurred."}`);
|
alert(`Error: ${(_b = result.error_msg) !== null && _b !== void 0 ? _b : "Unknown error occurred."}`);
|
||||||
@@ -125,7 +125,31 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error("Failed to apply:", error);
|
console.error("Failed to apply:", error);
|
||||||
alert("Failed to apply due to a network or server error.");
|
alert("Failed to apply.");
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if (leaveBtn) {
|
||||||
|
leaveBtn.addEventListener("click", (e) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
var _c;
|
||||||
|
try {
|
||||||
|
const response = yield fetch(`/api/events/leave/${eventId}`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const result = yield response.json();
|
||||||
|
if (result.success) {
|
||||||
|
window.location.href = `/view.html?event=${eventId}`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alert(`Error: ${(_c = result.error_msg) !== null && _c !== void 0 ? _c : "Unknown error occurred."}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error("Failed to leave:", error);
|
||||||
|
alert("Failed to leave.");
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user