Files
GoMFT/components/file_metadata/utils/file_metadata_js_templ.go
T
StarFleetCPTN c52edb75df feat: Implement file metadata management components
- Added new types for file metadata filtering and data structures.
- Created templates for displaying file metadata details, lists, and search functionalities.
- Implemented JavaScript utilities for handling modals and notifications related to file metadata actions.
- Enhanced the user interface with Tailwind CSS for better styling and responsiveness.
- Introduced pagination and search capabilities for file metadata management.
2025-03-28 08:24:09 -07:00

42 lines
3.9 KiB
Go

// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.833
package utils
//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"
// fileMetadataJS provides common JavaScript functions for file metadata components
func fileMetadataJS() 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// Show a modal by ID\n\t\tfunction showModal(modalId) {\n\t\t\tconst modal = document.getElementById(modalId);\n\t\t\tif (modal) {\n\t\t\t\tmodal.classList.remove('hidden');\n\t\t\t\tmodal.classList.add('flex');\n\t\t\t}\n\t\t}\n\n\t\t// Close a modal by ID\n\t\tfunction closeModal(modalId) {\n\t\t\tconst modal = document.getElementById(modalId);\n\t\t\tif (modal) {\n\t\t\t\tmodal.classList.add('hidden');\n\t\t\t\tmodal.classList.remove('flex');\n\t\t\t}\n\t\t}\n\n\t\t// Show a toast notification\n\t\tfunction showToast(message, type = 'info') {\n\t\t\tconst container = document.getElementById('toast-container');\n\t\t\tif (!container) return;\n\n\t\t\tconst toast = document.createElement('div');\n\t\t\ttoast.className = `p-4 rounded-lg shadow-lg ${\n\t\t\t\ttype === 'success' ? 'bg-green-500' :\n\t\t\t\ttype === 'error' ? 'bg-red-500' :\n\t\t\t\ttype === 'warning' ? 'bg-yellow-500' :\n\t\t\t\t'bg-blue-500'\n\t\t\t} text-white`;\n\t\t\ttoast.textContent = message;\n\n\t\t\tcontainer.appendChild(toast);\n\n\t\t\t// Remove the toast after 5 seconds\n\t\t\tsetTimeout(() => {\n\t\t\t\ttoast.remove();\n\t\t\t}, 5000);\n\t\t}\n\n\t\t// Close modal when clicking outside\n\t\tdocument.addEventListener('click', function(event) {\n\t\t\tif (event.target.classList.contains('fixed')) {\n\t\t\t\tevent.target.classList.add('hidden');\n\t\t\t\tevent.target.classList.remove('flex');\n\t\t\t}\n\t\t});\n\n\t\t// Handle delete confirmation\n\t\tdocument.addEventListener('click', function(event) {\n\t\t\tif (event.target.id === 'confirm-delete') {\n\t\t\t\tconst fileId = event.target.dataset.fileId;\n\t\t\t\tif (!fileId) return;\n\n\t\t\t\tfetch(`/files/${fileId}`, {\n\t\t\t\t\tmethod: 'DELETE',\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\t.then(response => {\n\t\t\t\t\tif (response.ok) {\n\t\t\t\t\t\tshowToast('File deleted successfully', 'success');\n\t\t\t\t\t\t// Reload the page after a short delay\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\twindow.location.reload();\n\t\t\t\t\t\t}, 1000);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('Failed to delete file');\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(error => {\n\t\t\t\t\tshowToast(error.message, 'error');\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tcloseModal('delete-dialog');\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\t// Handle HTMX request errors\n\t\tdocument.body.addEventListener('htmx:responseError', function(evt) {\n\t\t\tshowToast('An error occurred while processing your request', 'error');\n\t\t});\n\t</script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate