Add week planner entry editing popups

This commit is contained in:
2026-04-13 14:57:36 +02:00
parent 7b751b4d47
commit 6c7c1f01c9
4 changed files with 204 additions and 2 deletions
+69
View File
@@ -95,12 +95,14 @@
}
const result = await response.json();
rememberScroll();
if (result.redirect_url) {
window.location.href = result.redirect_url;
} else {
window.location.reload();
}
} catch (_error) {
rememberScroll();
window.location.reload();
}
});
@@ -196,6 +198,72 @@
});
};
const initWeekEntryDialogs = () => {
const board = document.querySelector(".week-board");
if (!board) return;
const openDialog = (trigger) => {
const dialogId = trigger.getAttribute("data-week-entry-dialog-id");
if (!dialogId) return;
const dialog = document.getElementById(dialogId);
if (!(dialog instanceof HTMLDialogElement)) return;
if (!dialog.open) {
dialog.showModal();
}
};
board.querySelectorAll("[data-week-entry-open]").forEach((entry) => {
entry.addEventListener("click", (event) => {
if (event.target instanceof Element && event.target.closest("button, a, input, select, textarea, label, form")) {
return;
}
openDialog(entry);
});
entry.addEventListener("keydown", (event) => {
if (event.key !== "Enter" && event.key !== " ") return;
event.preventDefault();
openDialog(entry);
});
});
document.querySelectorAll(".week-entry-dialog").forEach((dialog) => {
if (!(dialog instanceof HTMLDialogElement)) return;
dialog.addEventListener("click", (event) => {
const rect = dialog.getBoundingClientRect();
const clickedInside =
rect.top <= event.clientY &&
event.clientY <= rect.top + rect.height &&
rect.left <= event.clientX &&
event.clientX <= rect.left + rect.width;
if (!clickedInside) {
dialog.close();
}
});
});
document.querySelectorAll("[data-week-entry-close]").forEach((button) => {
button.addEventListener("click", () => {
const dialog = button.closest(".week-entry-dialog");
if (dialog instanceof HTMLDialogElement) {
dialog.close();
}
});
});
document.querySelectorAll(".js-week-entry-submit").forEach((form) => {
form.addEventListener("submit", async (event) => {
event.preventDefault();
try {
await postAndRefreshInPlace(form);
} catch (_error) {
window.location.reload();
}
});
});
};
const syncActionContainerVisibility = (container) => {
if (!(container instanceof HTMLElement)) return;
const hasVisibleButtons = Array.from(container.querySelectorAll("button")).some((button) => {
@@ -285,6 +353,7 @@
initWeekDragAndDrop();
initWeekCopyForward();
initWeekSlotPicker();
initWeekEntryDialogs();
initDaySnackReveal();
initWeekSnackReveal();
});