Files
GoMFT/components/notifications/list/list_js_templ.go
T
StarFleetCPTN 28fa65df9d feat: Enhance file metadata and notification components
- Added sorting capabilities to file metadata lists, including SortBy and SortDir fields.
- Integrated a toast notification system for user feedback on actions.
- Updated templates and JavaScript for improved user interaction and responsiveness.
- Refactored file metadata handlers to utilize new sorting features and ensure proper data flow.
- Introduced new notification dialog components for better user confirmation on actions.
2025-03-28 22:22:35 -07:00

42 lines
9.7 KiB
Go

// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.833
package list
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
// ListScripts contains JavaScript specific to the notification list page.
func ListScripts() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
if templ_7745c5c3_Var1 == nil {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<script>\n\t\t// Notification system (showToast function is now in shared/toast/toast_js.templ)\n\n\t\t// Track all HTMX events for debugging\n\t\tdocument.addEventListener('htmx:beforeRequest', function(event) {\n\t\t\t// Check if this is a DELETE request for a notification service\n\t\t\tconst path = event.detail.path;\n\t\t\tconst method = event.detail.verb;\n\n\t\t\tconsole.log(`Request path: ${path}, method: ${method}`);\n\n\t\t\t// Pattern match for notification service deletions (e.g., /admin/settings/notifications/123)\n\t\t\tif (path && method === 'DELETE' && path.match(/^\\/admin\\/settings\\/notifications\\/\\d+$/)) {\n\t\t\t\tconsole.log(\"Detected notification service deletion request via URL pattern\");\n\n\t\t\t\t// This is definitely a delete request - store this information\n\t\t\t\twindow.isServiceDeleteRequest = true;\n\t\t\t}\n\t\t});\n\n\t\tdocument.addEventListener('htmx:afterRequest', function(event) {\n\t\t\t// Check for notification service deletion multiple ways\n\t\t\tconst isDeleteRequest =\n\t\t\t\t// Check global flag from the triggerServiceDelete function\n\t\t\t\twindow.currentlyDeletingService ||\n\t\t\t\t// Check flag from beforeRequest handler\n\t\t\t\twindow.isServiceDeleteRequest ||\n\t\t\t\t// Check URL pattern directly from this event\n\t\t\t\t(event.detail.pathInfo &&\n\t\t\t\t\tevent.detail.pathInfo.requestPath &&\n\t\t\t\t\tevent.detail.pathInfo.requestPath.match(/^\\/admin\\/settings\\/notifications\\/\\d+$/) &&\n\t\t\t\t\tevent.detail.verb === 'DELETE');\n\n\t\t\tconsole.log(`Is delete request: ${isDeleteRequest}`);\n\n\t\t\t// If this is a successful delete request, show notification\n\t\t\tif (isDeleteRequest && event.detail.successful) {\n\t\t\t\tconsole.log(\"Delete request was successful\");\n\n\t\t\t\tlet serviceName = \"Unknown\";\n\n\t\t\t\t// Try multiple sources for service name\n\t\t\t\tif (event.detail.elt && event.detail.elt.getAttribute) {\n\t\t\t\t\tserviceName = event.detail.elt.getAttribute('data-service-name') || serviceName;\n\t\t\t\t}\n\n\t\t\t\tif (serviceName === \"Unknown\" && window.lastDeletedService) {\n\t\t\t\t\t// Fallback to our stored service info\n\t\t\t\t\tserviceName = window.lastDeletedService.name;\n\t\t\t\t}\n\n\t\t\t\tconsole.log(`Showing success notification for deleted service: ${serviceName}`);\n\t\t\t\t// Ensure showToast is globally available\n\t\t\t\tif (typeof showToast === 'function') {\n\t\t\t\t\tshowToast(`Notification service \"${serviceName}\" deleted successfully`, 'success');\n\t\t\t\t} else {\n\t\t\t\t\tconsole.error(\"showToast function not found!\");\n\t\t\t\t}\n\n\n\t\t\t\t// Clear flags\n\t\t\t\twindow.currentlyDeletingService = false;\n\t\t\t\twindow.isServiceDeleteRequest = false;\n\t\t\t\twindow.lastDeletedService = null;\n\t\t\t}\n\t\t});\n\n\t\tdocument.addEventListener('htmx:responseError', function(event) {\n\t\t\tconsole.log(\"HTMX response error:\", event.detail);\n\n\t\t\t// Similar logic as success but for errors\n\t\t\tconst isDeleteRequest =\n\t\t\t\twindow.currentlyDeletingService ||\n\t\t\t\twindow.isServiceDeleteRequest ||\n\t\t\t\t(event.detail.pathInfo &&\n\t\t\t\t\tevent.detail.pathInfo.requestPath &&\n\t\t\t\t\tevent.detail.pathInfo.requestPath.match(/^\\/admin\\/settings\\/notifications\\/\\d+$/) &&\n\t\t\t\t\tevent.detail.verb === 'DELETE');\n\n\t\t\tlet errorMsg = 'An error occurred';\n\t\t\tif (event.detail.xhr && event.detail.xhr.responseText) {\n\t\t\t\terrorMsg = event.detail.xhr.responseText;\n\t\t\t}\n\n\t\t\tif (isDeleteRequest) {\n\t\t\t\tconsole.log(\"Delete request failed\");\n\n\t\t\t\tlet serviceName = \"Unknown\";\n\n\t\t\t\t// Try multiple sources for service name\n\t\t\t\tif (event.detail.elt && event.detail.elt.getAttribute) {\n\t\t\t\t\tserviceName = event.detail.elt.getAttribute('data-service-name') || serviceName;\n\t\t\t\t}\n\n\t\t\t\tif (serviceName === \"Unknown\" && window.lastDeletedService) {\n\t\t\t\t\t// Fallback to our stored service info\n\t\t\t\t\tserviceName = window.lastDeletedService.name;\n\t\t\t\t}\n\n\t\t\t\tlet specificErrorMsg = `Failed to delete notification service \"${serviceName}\"`;\n\n\t\t\t\tif (event.detail.xhr && event.detail.xhr.responseText) {\n\t\t\t\t\t// Try to provide a more specific error from the response\n\t\t\t\t\tspecificErrorMsg = `Error deleting \"${serviceName}\": ${event.detail.xhr.responseText}`;\n\t\t\t\t}\n\n\t\t\t\tconsole.log(`Showing error notification: ${specificErrorMsg}`);\n\t\t\t\tif (typeof showToast === 'function') {\n\t\t\t\t\tshowToast(specificErrorMsg, 'error');\n\t\t\t\t} else {\n\t\t\t\t\tconsole.error(\"showToast function not found!\");\n\t\t\t\t}\n\n\n\t\t\t\t// Clear flags\n\t\t\t\twindow.currentlyDeletingService = false;\n\t\t\t\twindow.isServiceDeleteRequest = false;\n\t\t\t\twindow.lastDeletedService = null;\n\t\t\t} else {\n\t\t\t\t// General error toast\n\t\t\t\tif (typeof showToast === 'function') {\n\t\t\t\t\tshowToast(errorMsg, 'error');\n\t\t\t\t} else {\n\t\t\t\t\tconsole.error(\"showToast function not found!\");\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Handle modal hide buttons (This might be better placed globally or in layout if modals are used elsewhere)\n\t\tdocument.addEventListener('DOMContentLoaded', function() {\n\t\t\t// This listener handles closing modals via data-modal-hide attribute\n\t\t\t// It might conflict or be redundant if Flowbite's JS handles this already.\n\t\t\t// Consider removing if Flowbite is initialized globally.\n\t\t\tconst hideButtons = document.querySelectorAll('[data-modal-hide]');\n\t\t\thideButtons.forEach(button => {\n\t\t\t\tbutton.addEventListener('click', function() {\n\t\t\t\t\tconst modalId = this.getAttribute('data-modal-hide');\n\t\t\t\t\tconst modal = document.getElementById(modalId);\n\t\t\t\t\tif (modal) {\n\t\t\t\t\t\tmodal.classList.add('hidden');\n\t\t\t\t\t\tmodal.classList.remove('flex');\n\t\t\t\t\t}\n\t\t\t\t\tconst backdrop = document.getElementById(modalId + \"-backdrop\");\n\t\t\t\t\tif (backdrop) {\n\t\t\t\t\t\tbackdrop.classList.add(\"hidden\");\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\n\t\t\t// Show any success or error messages passed via data struct as toasts\n\t\t\tconst successDiv = document.querySelector('.success-message');\n\t\t\tif (successDiv) {\n\t\t\t\tconst successMsg = successDiv.textContent.trim();\n\t\t\t\tif (successMsg && typeof showToast === 'function') {\n\t\t\t\t\tshowToast(successMsg, 'success');\n\t\t\t\t} else if (successMsg) {\n\t\t\t\t\tconsole.error(\"showToast function not found, cannot display success message:\", successMsg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst errorDiv = document.querySelector('.error-message');\n\t\t\tif (errorDiv) {\n\t\t\t\tconst errorMsg = errorDiv.textContent.trim();\n\t\t\t\tif (errorMsg && typeof showToast === 'function') {\n\t\t\t\t\tshowToast(errorMsg, 'error');\n\t\t\t\t} else if (errorMsg) {\n\t\t\t\t\tconsole.error(\"showToast function not found, cannot display error message:\", errorMsg);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Script for handling the service deletion trigger\n\t\tfunction triggerServiceDelete(dialogId, serviceID, serviceName) {\n\t\t\t// Hide the dialog first\n\t\t\tcloseModal(dialogId); // Reuse closeModal logic\n\n\t\t\t// Add debugging info\n\t\t\tconsole.log(`Notification service deletion triggered for: ${serviceName} (ID: ${serviceID})`);\n\n\t\t\t// Store data in a way that's accessible to event handlers\n\t\t\twindow.lastDeletedService = {\n\t\t\t\tid: serviceID,\n\t\t\t\tname: serviceName\n\t\t\t};\n\n\t\t\t// Add custom marker to track this deletion\n\t\t\twindow.currentlyDeletingService = true;\n\t\t}\n\n\t\t// Script for closing the modal\n\t\tfunction closeModal(id) {\n\t\t\tconst dialog = document.getElementById(id);\n\t\t\tif (dialog) {\n\t\t\t\tdialog.classList.add(\"hidden\");\n\t\t\t\tdialog.classList.remove(\"flex\");\n\t\t\t}\n\t\t\tconst backdrop = document.getElementById(id + \"-backdrop\");\n\t\t\tif (backdrop) {\n\t\t\t\t// Instead of removing, hide it to potentially reuse\n\t\t\t\tbackdrop.classList.add(\"hidden\");\n\t\t\t}\n\t\t}\n\n\t\t// Script for showing the modal\n\t\tfunction showModal(id) {\n\t\t\tconst dialog = document.getElementById(id);\n\t\t\tif (dialog) {\n\t\t\t\tdialog.classList.remove(\"hidden\");\n\t\t\t\tdialog.classList.add(\"flex\"); // Use flex to center content\n\t\t\t}\n\t\t\tconst backdrop = document.getElementById(id + \"-backdrop\");\n\t\t\tif (backdrop) {\n\t\t\t\tbackdrop.classList.remove(\"hidden\");\n\t\t\t}\n\t\t}\n\t</script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate