documentation for all JS files

This commit is contained in:
2025-05-28 16:01:18 +02:00
parent 1134f5b099
commit 5c5829c487
22 changed files with 984 additions and 26 deletions

View File

@@ -1,6 +1,18 @@
/**
* @fileoverview Manages the trash functionality for the document management system.
* This file handles the trash view, empty trash operations, and view preferences.
* It provides functionality to view trashed items in grid or list view,
* empty the trash, and manage user view preferences.
*/
let currentView = 'grid';
// Make functions globally available
/**
* Shows the empty trash confirmation modal.
* @function
* @global
* @throws {Error} If the modal element is not found or if there's an error showing the modal
*/
window.showEmptyTrashModal = function() {
console.log('Showing Empty Trash Modal');
const modalEl = document.getElementById('emptyTrashModal');
@@ -20,6 +32,16 @@ window.showEmptyTrashModal = function() {
}
};
/**
* Empties the trash by permanently deleting all trashed files.
* This function:
* 1. Fetches all trashed files to get their room IDs
* 2. Makes API calls to empty trash in each room
* 3. Updates the UI to reflect the changes
* @function
* @global
* @throws {Error} If CSRF token is not available or if API calls fail
*/
window.emptyTrash = function() {
console.log('Emptying Trash');
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
@@ -85,6 +107,11 @@ window.emptyTrash = function() {
});
};
/**
* Initializes the trash view when the DOM content is loaded.
* Sets up event listeners for empty trash functionality and initializes the view.
* @function
*/
document.addEventListener('DOMContentLoaded', function() {
console.log('DOM Content Loaded');
@@ -112,6 +139,13 @@ document.addEventListener('DOMContentLoaded', function() {
initializeView();
});
/**
* Initializes the view based on user preferences.
* Fetches the user's preferred view (grid or list) and applies it.
* Falls back to grid view if there's an error.
* @async
* @function
*/
async function initializeView() {
try {
const response = await fetch('/api/user/preferred_view');
@@ -125,6 +159,13 @@ async function initializeView() {
}
}
/**
* Toggles between grid and list views.
* Updates the UI and saves the user's view preference.
* @function
* @param {string} view - The view to switch to ('grid' or 'list')
* @throws {Error} If the view preference cannot be saved
*/
function toggleView(view) {
currentView = view;
const grid = document.getElementById('fileGrid');