separated utils from room template

This commit is contained in:
2025-05-25 14:45:50 +02:00
parent e9fb1ec7d8
commit c244c3a98a
2 changed files with 19 additions and 7 deletions

15
static/js/utils.js Normal file
View File

@@ -0,0 +1,15 @@
// Utility functions for DocuPulse
/**
* Formats a Unix timestamp into a localized date and time string
* @param {number} ts - Unix timestamp in seconds
* @returns {string} Formatted date and time string
*/
function formatDate(ts) {
if (!ts) return '';
const d = new Date(ts * 1000);
return d.toLocaleDateString() + ' ' + d.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
}
// Export the functions
export { formatDate };

View File

@@ -5,6 +5,7 @@
{% block content %}
<meta name="csrf-token" content="{{ csrf_token }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/room.css') }}">
<script type="module" src="{{ url_for('static', filename='js/utils.js') }}"></script>
<div class="container mt-4">
<div class="row mb-4">
<div class="col">
@@ -95,7 +96,9 @@
{% include 'components/overwrite_confirm_modal.html' %}
{% include 'components/move_modal.html' %}
<script>
<script type="module">
import { formatDate } from "{{ url_for('static', filename='js/utils.js') }}";
// Define showDetailsModal function first
function showDetailsModal(idx) {
// Check if currentFiles exists and idx is valid
@@ -199,12 +202,6 @@ async function initializeView() {
toggleView(currentView);
}
function formatDate(ts) {
if (!ts) return '';
const d = new Date(ts * 1000);
return d.toLocaleDateString() + ' ' + d.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
}
function renderBreadcrumb() {
const bc = document.getElementById('breadcrumb');
bc.innerHTML = '';