From d28ca728f9bf71582712656972ebd71fded72332 Mon Sep 17 00:00:00 2001 From: Musselman Date: Wed, 26 Jun 2024 11:00:36 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Chore:=20Format=20list.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/build/list.js | 146 +++++++++++++++++++++---------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/static/build/list.js b/static/build/list.js index c7b436d..7242c53 100644 --- a/static/build/list.js +++ b/static/build/list.js @@ -1,77 +1,77 @@ - // Function to convert Unix timestamps to local time - function convertUnixTimeToLocalTime(unixTime, element) { - const date = new Date(unixTime * 1000); - element.textContent = date.toLocaleString(); +// Function to convert Unix timestamps to local time +function convertUnixTimeToLocalTime(unixTime, element) { + const date = new Date(unixTime * 1000); + element.textContent = date.toLocaleString(); +} + +// Call the function for each timestamp on page load +window.onload = function () { + const creationTimeElements = document.querySelectorAll(".creation-time"); + const lastEditedTimeElements = document.querySelectorAll(".last-edited-time"); + + creationTimeElements.forEach((element) => { + const unixTime = parseInt(element.getAttribute("data-unix")); + convertUnixTimeToLocalTime(unixTime, element); + }); + + lastEditedTimeElements.forEach((element) => { + const unixTime = parseInt(element.getAttribute("data-unix")); + convertUnixTimeToLocalTime(unixTime, element); + }); +}; + +const deleteForm = document.getElementById("deleteForm"); +const checkAllButton = document.getElementById("checkAll"); +const checkboxes = document.querySelectorAll('input[type="checkbox"]'); +checkAllButton.addEventListener("click", function () { + checkboxes.forEach((checkbox) => { + checkbox.checked = true; + }); +}); + +deleteForm.addEventListener("submit", function (event) { + event.preventDefault(); // Stop form submission + + // Get all checkboxes in the delete form + const checkboxes = deleteForm.querySelectorAll('input[type="checkbox"]'); + const filesToDelete = []; + + // Get the filenames of the selected files + checkboxes.forEach((checkbox) => { + if (checkbox.checked) { + filesToDelete.push(checkbox.value); } + }); + console.log(filesToDelete); - // Call the function for each timestamp on page load - window.onload = function () { - const creationTimeElements = document.querySelectorAll('.creation-time'); - const lastEditedTimeElements = document.querySelectorAll('.last-edited-time'); + // Call the deleteFiles function to send the request to the server + deleteFiles(filesToDelete); +}); - creationTimeElements.forEach(element => { - const unixTime = parseInt(element.getAttribute('data-unix')); - convertUnixTimeToLocalTime(unixTime, element); - }); - - lastEditedTimeElements.forEach(element => { - const unixTime = parseInt(element.getAttribute('data-unix')); - convertUnixTimeToLocalTime(unixTime, element); - }); - }; - - const deleteForm = document.getElementById("deleteForm"); - const checkAllButton = document.getElementById("checkAll"); - const checkboxes = document.querySelectorAll('input[type="checkbox"]'); - checkAllButton.addEventListener("click", function () { - checkboxes.forEach(checkbox => { - checkbox.checked = true; - }); +function deleteFiles(filesToDelete) { + // Send a POST request to the server to delete the selected files + fetch("/delete", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ files: filesToDelete }), + }) + .then((response) => { + if (response.ok) { + // Files deleted successfully + location.reload(); // Refresh the page to reflect the changes + } else { + // Handle the error, e.g., display an error message + console.error("Error deleting files"); + } + }) + .catch((error) => { + console.error("Error deleting files:", error); }); - - deleteForm.addEventListener("submit", function (event) { - event.preventDefault(); // Stop form submission - - // Get all checkboxes in the delete form - const checkboxes = deleteForm.querySelectorAll('input[type="checkbox"]'); - const filesToDelete = []; - - // Get the filenames of the selected files - checkboxes.forEach(checkbox => { - if (checkbox.checked) { - filesToDelete.push(checkbox.value); - } - }); - - // Call the deleteFiles function to send the request to the server - deleteFiles(filesToDelete); - }); - - - function deleteFiles(filesToDelete) { - // Send a POST request to the server to delete the selected files - fetch("/delete", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ files: filesToDelete }), - }) - .then(response => { - if (response.ok) { - // Files deleted successfully - location.reload(); // Refresh the page to reflect the changes - } else { - // Handle the error, e.g., display an error message - console.error("Error deleting files"); - } - }) - .catch(error => { - console.error("Error deleting files:", error); - }); - } - // Handle exportFolder button click - const exportFolderButton = document.getElementById("exportFolder"); - exportFolderButton.addEventListener("click", function () { - window.location.href = "/export"; - }); \ No newline at end of file +} +// Handle exportFolder button click +const exportFolderButton = document.getElementById("exportFolder"); +exportFolderButton.addEventListener("click", function () { + window.location.href = "/export"; +});