Make edit panel work without dialog support
This commit is contained in:
@@ -302,13 +302,17 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if can_change %}
|
||||
<dialog class="w-full max-w-2xl rounded-3xl border-0 bg-white p-6 text-left shadow-2xl"
|
||||
data-edit-dialog="{{ claim.id }}">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-gray-500">{% trans "Redigera utlägg" %}</p>
|
||||
<h3 class="text-xl font-semibold text-gray-900">{{ claim.full_name }}</h3>
|
||||
</div>
|
||||
<div class="fixed inset-0 z-40 hidden items-center justify-center bg-slate-900/80 p-4"
|
||||
data-edit-panel="{{ claim.id }}"
|
||||
aria-hidden="true"
|
||||
role="dialog"
|
||||
aria-modal="true">
|
||||
<div class="w-full max-w-2xl rounded-3xl bg-white p-6 text-left shadow-2xl">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-gray-500">{% trans "Redigera utlägg" %}</p>
|
||||
<h3 class="text-xl font-semibold text-gray-900">{{ claim.full_name }}</h3>
|
||||
</div>
|
||||
<button type="button" data-close-edit class="rounded-full bg-gray-100 px-3 py-1 text-xs font-semibold text-gray-600 transition hover:bg-gray-200">
|
||||
{% trans "Stäng" %}
|
||||
</button>
|
||||
@@ -370,7 +374,8 @@
|
||||
{% trans "Aktivera JavaScript för att kunna redigera uppgifter direkt här." %}
|
||||
</p>
|
||||
</noscript>
|
||||
</dialog>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -425,34 +430,53 @@
|
||||
</aside>
|
||||
</div>
|
||||
</section>
|
||||
<style>
|
||||
dialog[data-edit-dialog]::backdrop {
|
||||
background-color: rgba(15, 23, 42, 0.75);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const filterButtons = Array.from(document.querySelectorAll("[data-filter-button]"));
|
||||
const cards = Array.from(document.querySelectorAll("[data-claim-card]"));
|
||||
const emptyState = document.querySelector("[data-claim-empty]");
|
||||
const editButtons = Array.from(document.querySelectorAll("[data-open-edit]"));
|
||||
const dialogs = Array.from(document.querySelectorAll("[data-edit-dialog]"));
|
||||
const panels = Array.from(document.querySelectorAll("[data-edit-panel]"));
|
||||
|
||||
const openPanel = (id) => {
|
||||
const panel = document.querySelector(`[data-edit-panel="${id}"]`);
|
||||
if (!panel) return;
|
||||
panel.classList.remove("hidden");
|
||||
panel.classList.add("flex");
|
||||
panel.setAttribute("aria-hidden", "false");
|
||||
};
|
||||
|
||||
const closePanel = (panel) => {
|
||||
panel.classList.add("hidden");
|
||||
panel.classList.remove("flex");
|
||||
panel.setAttribute("aria-hidden", "true");
|
||||
};
|
||||
|
||||
editButtons.forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
const dialog = document.querySelector(`[data-edit-dialog="${button.dataset.openEdit}"]`);
|
||||
if (dialog && typeof dialog.showModal === "function") {
|
||||
dialog.showModal();
|
||||
} else if (dialog) {
|
||||
dialog.setAttribute("open", "open");
|
||||
button.addEventListener("click", () => openPanel(button.dataset.openEdit));
|
||||
});
|
||||
|
||||
panels.forEach((panel) => {
|
||||
panel.addEventListener("click", (event) => {
|
||||
if (event.target === panel) {
|
||||
closePanel(panel);
|
||||
}
|
||||
});
|
||||
});
|
||||
dialogs.forEach((dialog) => {
|
||||
dialog.querySelectorAll("[data-close-edit]").forEach((btn) => {
|
||||
btn.addEventListener("click", () => dialog.close());
|
||||
panel.querySelectorAll("[data-close-edit]").forEach((btn) => {
|
||||
btn.addEventListener("click", () => closePanel(panel));
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape") {
|
||||
panels.forEach((panel) => {
|
||||
if (!panel.classList.contains("hidden")) {
|
||||
closePanel(panel);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (!filterButtons.length || !cards.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user