-
+
@@ -858,95 +870,8 @@ import JSZip from "jszip";
}
function showFilePreview(file: { url: string; type: string; name: string }) {
- const filePreviewSection = document.getElementById("filePreviewSection");
- const filesContent = document.getElementById("filesContent");
- const previewContent = document.getElementById("previewContent");
- const previewFileName = document.getElementById("previewFileName");
- const modalTitle = document.getElementById("modalTitle");
-
- if (
- !filePreviewSection ||
- !filesContent ||
- !previewContent ||
- !previewFileName
- )
- return;
-
- filePreviewSection.classList.remove("hidden");
- filesContent.classList.add("hidden");
- previewFileName.textContent = file.name;
- if (modalTitle) modalTitle.textContent = "File Preview";
-
- const fileType = file.type.toLowerCase();
- showLoading();
-
- // Create the PocketBase URL
- const baseUrl = "https://pocketbase.ieeeucsd.org";
- const fileUrl = `${baseUrl}/api/files/events/${currentEventId}/${file.name}`;
-
- if (!isPreviewableType(fileType)) {
- previewContent.innerHTML = `
-
- `;
- hideLoading();
- return;
- }
-
- if (fileType.startsWith("image/")) {
- previewContent.innerHTML = `
-

- `;
- } else if (fileType.startsWith("video/")) {
- previewContent.innerHTML = `
-
- `;
- } else if (fileType === "application/pdf") {
- previewContent.innerHTML = `
-
- `;
- } else if (
- fileType.startsWith("text/") ||
- fileType === "application/json"
- ) {
- previewContent.innerHTML = `
-
- `;
- } else if (fileType.startsWith("audio/")) {
- previewContent.innerHTML = `
-
- `;
- }
+ console.log('showFilePreview called with:', file);
+ window.previewFileEvents(file.url, file.name);
}
function handlePreviewError() {
@@ -954,24 +879,67 @@ import JSZip from "jszip";
const previewContent = document.getElementById("previewContent");
if (previewContent) {
previewContent.innerHTML = `
-
-
-
Failed to load file preview
-
- `;
+
+
+
Failed to load file preview
+
+ `;
}
}
- // Make helper functions available globally
- window.showFilePreview = showFilePreview;
- window.backToFileList = backToFileList;
- window.handlePreviewError = handlePreviewError;
- window.showLoading = showLoading;
- window.hideLoading = hideLoading;
+ // Universal file preview function for events section
+ window.previewFileEvents = function (url: string, filename: string) {
+ console.log('previewFileEvents called with:', { url, filename });
+ const modal = document.getElementById("filePreviewModal") as HTMLDialogElement;
+ const previewFileName = document.getElementById("previewFileName");
+ const previewContent = document.getElementById("previewContent");
+
+ if (modal && previewFileName && previewContent) {
+ console.log('Found all required elements');
+ // Update the filename display
+ previewFileName.textContent = filename;
+
+ // Show the modal
+ modal.showModal();
- // Add openDetailsModal function
+ // Dispatch state change event
+ window.dispatchEvent(new CustomEvent('filePreviewStateChange', {
+ detail: { url, filename }
+ }));
+ }
+ };
+
+ // Close file preview for events section
+ window.closeFilePreviewEvents = function () {
+ console.log('closeFilePreviewEvents called');
+ const modal = document.getElementById("filePreviewModal") as HTMLDialogElement;
+ const previewFileName = document.getElementById("previewFileName");
+ const previewContent = document.getElementById("previewContent");
+
+ if (modal && previewFileName && previewContent) {
+ console.log('Resetting preview and closing modal');
+ // Reset the preview state
+ window.dispatchEvent(new CustomEvent('filePreviewStateChange', {
+ detail: { url: "", filename: "" }
+ }));
+
+ // Reset the UI
+ previewFileName.textContent = "";
+
+ // Close the modal
+ modal.close();
+ }
+ };
+
+ // Update the showFilePreview function for events section
+ window.showFilePreviewEvents = function (file: { url: string; name: string }) {
+ console.log('showFilePreviewEvents called with:', file);
+ window.previewFileEvents(file.url, file.name);
+ };
+
+ // Update the openDetailsModal function to use the events-specific preview
window.openDetailsModal = function (event: any) {
const modal = document.getElementById(
"eventDetailsModal",
@@ -979,13 +947,9 @@ import JSZip from "jszip";
const filesContent = document.getElementById(
"filesContent",
) as HTMLDivElement;
- const filePreviewSection = document.getElementById(
- "filePreviewSection",
- ) as HTMLDivElement;
// Reset state
currentEventId = event.id;
- if (filePreviewSection) filePreviewSection.classList.add("hidden");
if (filesContent) filesContent.classList.remove("hidden");
// Populate files content
@@ -995,58 +959,53 @@ import JSZip from "jszip";
const recordId = event.id;
filesContent.innerHTML = `
-
-
-
-
- File Name |
- Actions |
-
-
-
- ${event.files
- .map((file: string) => {
- const fileUrl = `${baseUrl}/api/files/${collectionId}/${recordId}/${file}`;
- const fileType = getFileType(file);
- return `
-
- ${file} |
-
-
-
-
-
- |
-
- `;
- })
- .join("")}
-
-
-
- `;
+
+
+
+
+ File Name |
+ Actions |
+
+
+
+ ${event.files
+ .map((file: string) => {
+ const fileUrl = `${baseUrl}/api/files/${collectionId}/${recordId}/${file}`;
+ const fileType = getFileType(file);
+ const previewData = JSON.stringify({ url: fileUrl, name: file }).replace(/'/g, "\\'");
+ return `
+
+ ${file} |
+
+
+
+
+
+ |
+
+ `;
+ })
+ .join("")}
+
+
+
+ `;
} else {
filesContent.innerHTML = `
-
-
-
No files attached to this event
-
- `;
+
+
+
No files attached to this event
+
+ `;
}
modal.showModal();
@@ -1120,6 +1079,36 @@ import JSZip from "jszip";
}
};
+ // Close event details modal
+ window.closeEventDetailsModal = function () {
+ const modal = document.getElementById("eventDetailsModal") as HTMLDialogElement;
+ const filesContent = document.getElementById("filesContent");
+
+ if (modal) {
+ // Reset the files content
+ if (filesContent) {
+ filesContent.innerHTML = '';
+ }
+
+ // Reset any other state if needed
+ currentEventId = '';
+
+ // Close the modal
+ modal.close();
+ }
+ };
+
+ // Make helper functions available globally
+ window.showFilePreview = showFilePreview;
+ window.handlePreviewError = handlePreviewError;
+ window.showLoading = showLoading;
+ window.hideLoading = hideLoading;
+ window.previewFileEvents = previewFileEvents;
+ window.closeFilePreviewEvents = closeFilePreviewEvents;
+ window.showFilePreviewEvents = showFilePreviewEvents;
+ window.openDetailsModal = openDetailsModal;
+ window.closeEventDetailsModal = closeEventDetailsModal;
+
// Add TypeScript interface for Window
declare global {
interface Window {
diff --git a/src/components/dashboard/Officer_EventManagement.astro b/src/components/dashboard/Officer_EventManagement.astro
index b892496..bd816a9 100644
--- a/src/components/dashboard/Officer_EventManagement.astro
+++ b/src/components/dashboard/Officer_EventManagement.astro
@@ -648,27 +648,7 @@ const currentPage = eventResponse.page;