fixed edit popup not showing
This commit is contained in:
parent
1d4803a0f6
commit
ba52ca0b91
1 changed files with 126 additions and 0 deletions
|
@ -1745,4 +1745,130 @@ declare global {
|
||||||
|
|
||||||
// Initial fetch
|
// Initial fetch
|
||||||
fetchEvents();
|
fetchEvents();
|
||||||
|
|
||||||
|
// Add openEditModal function
|
||||||
|
window.openEditModal = async function (event?: any) {
|
||||||
|
const modal = document.getElementById(
|
||||||
|
"editEventModal"
|
||||||
|
) as HTMLDialogElement;
|
||||||
|
const form = document.getElementById(
|
||||||
|
"editEventForm"
|
||||||
|
) as HTMLFormElement;
|
||||||
|
const modalTitle = document.getElementById("editModalTitle");
|
||||||
|
const currentFiles = document.getElementById("currentFiles");
|
||||||
|
const newFiles = document.getElementById("newFiles");
|
||||||
|
|
||||||
|
if (!modal || !form) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Clear previous form data
|
||||||
|
form.reset();
|
||||||
|
if (currentFiles) currentFiles.innerHTML = "";
|
||||||
|
if (newFiles) newFiles.innerHTML = "";
|
||||||
|
|
||||||
|
// Set modal title based on whether we're editing or creating
|
||||||
|
if (modalTitle) {
|
||||||
|
modalTitle.textContent = event ? "Edit Event" : "Add New Event";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
// Fetch fresh data from PocketBase for the event
|
||||||
|
const freshEventData = await get.getOne<Event>(
|
||||||
|
"events",
|
||||||
|
event.id
|
||||||
|
);
|
||||||
|
|
||||||
|
// Populate form with fresh data
|
||||||
|
const idInput = document.getElementById(
|
||||||
|
"editEventId"
|
||||||
|
) as HTMLInputElement;
|
||||||
|
const nameInput = document.getElementById(
|
||||||
|
"editEventName"
|
||||||
|
) as HTMLInputElement;
|
||||||
|
const codeInput = document.getElementById(
|
||||||
|
"editEventCode"
|
||||||
|
) as HTMLInputElement;
|
||||||
|
const locationInput = document.getElementById(
|
||||||
|
"editEventLocation"
|
||||||
|
) as HTMLInputElement;
|
||||||
|
const pointsInput = document.getElementById(
|
||||||
|
"editEventPoints"
|
||||||
|
) as HTMLInputElement;
|
||||||
|
const startDateInput = document.getElementById(
|
||||||
|
"editEventStartDate"
|
||||||
|
) as HTMLInputElement;
|
||||||
|
const endDateInput = document.getElementById(
|
||||||
|
"editEventEndDate"
|
||||||
|
) as HTMLInputElement;
|
||||||
|
const descriptionInput = document.getElementById(
|
||||||
|
"editEventDescription"
|
||||||
|
) as HTMLTextAreaElement;
|
||||||
|
const publishedInput = document.getElementById(
|
||||||
|
"editEventPublished"
|
||||||
|
) as HTMLInputElement;
|
||||||
|
const hasFoodInput = document.getElementById(
|
||||||
|
"editEventHasFood"
|
||||||
|
) as HTMLInputElement;
|
||||||
|
|
||||||
|
if (idInput) idInput.value = freshEventData.id;
|
||||||
|
if (nameInput) nameInput.value = freshEventData.event_name;
|
||||||
|
if (codeInput) codeInput.value = freshEventData.event_code;
|
||||||
|
if (locationInput)
|
||||||
|
locationInput.value = freshEventData.location;
|
||||||
|
if (pointsInput)
|
||||||
|
pointsInput.value =
|
||||||
|
freshEventData.points_to_reward.toString();
|
||||||
|
if (startDateInput)
|
||||||
|
startDateInput.value = new Date(freshEventData.start_date)
|
||||||
|
.toISOString()
|
||||||
|
.slice(0, 16);
|
||||||
|
if (endDateInput)
|
||||||
|
endDateInput.value = new Date(freshEventData.end_date)
|
||||||
|
.toISOString()
|
||||||
|
.slice(0, 16);
|
||||||
|
if (descriptionInput)
|
||||||
|
descriptionInput.value = freshEventData.event_description;
|
||||||
|
if (publishedInput)
|
||||||
|
publishedInput.checked = freshEventData.published;
|
||||||
|
if (hasFoodInput)
|
||||||
|
hasFoodInput.checked = freshEventData.has_food;
|
||||||
|
|
||||||
|
// Display current files if any
|
||||||
|
if (
|
||||||
|
currentFiles &&
|
||||||
|
freshEventData.files &&
|
||||||
|
freshEventData.files.length > 0
|
||||||
|
) {
|
||||||
|
currentFiles.innerHTML = freshEventData.files
|
||||||
|
.map(
|
||||||
|
(filename) => `
|
||||||
|
<div class="flex items-center justify-between p-2 bg-base-200 rounded-lg">
|
||||||
|
<span class="truncate">${filename}</span>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<button type="button" class="btn btn-ghost btn-xs" onclick="window.previewFile('${fileManager.getFileUrl("events", freshEventData.id, filename)}', '${filename}')">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
<path d="M10 12a2 2 0 100-4 2 2 0 000 4z"/>
|
||||||
|
<path fill-rule="evenodd" d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z" clip-rule="evenodd"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-ghost btn-xs text-error" onclick="window.deleteFile('${freshEventData.id}', '${filename}')">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
<path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the modal
|
||||||
|
modal.showModal();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to open edit modal:", error);
|
||||||
|
// Show error toast or alert
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue