diff --git a/src/main/resources/static/js/fileView.js b/src/main/resources/static/js/fileView.js index 17021f3..bfd5876 100644 --- a/src/main/resources/static/js/fileView.js +++ b/src/main/resources/static/js/fileView.js @@ -1,14 +1,60 @@ -function copyToClipboard() { +function copyToClipboard(button) { const copyText = document.getElementById("downloadLink"); - const copyButton = document.querySelector(".copyButton"); - navigator.clipboard.writeText(copyText.value).then(function () { - copyButton.innerText = "Copied!"; - copyButton.classList.add("btn-success"); - }).catch(function (err) { - console.error("Could not copy text: ", err); - }); + + navigator.clipboard.writeText(copyText.value) + .then(() => { + button.innerText = "Copied!"; + button.classList.add("copied"); + + // Revert back after 2 seconds + setTimeout(() => { + button.innerText = "Copy Link"; + button.classList.remove("copied"); + }, 2000); + }) + .catch((err) => { + console.error("Could not copy text: ", err); + button.innerText = "Failed!"; + button.classList.add("btn-danger"); + + setTimeout(() => { + button.innerText = "Copy Link"; + button.classList.remove("btn-danger"); + }, 2000); + }); } function showPreparingMessage() { document.getElementById('preparingMessage').style.display = 'block'; +} + +document.addEventListener("DOMContentLoaded", function () { + const downloadLink = document.getElementById("downloadLink").value; // Get the file download link + const qrCodeContainer = document.getElementById("qrCodeContainer"); // Container for the QR code + + console.log("Download link:", downloadLink); // Debugging log + + if (downloadLink) { + QRCode.toCanvas(qrCodeContainer, encodeURI(downloadLink), { + width: 100, // Size of the QR Code + margin: 2 // Margin around the QR Code + }, function (error) { + if (error) { + console.error("QR Code generation failed:", error); + } + }); + } else { + console.error("Download link is empty or undefined."); + } +}); + +function updateCheckboxState(event, checkbox) { + event.preventDefault(); + const hiddenField = checkbox.form.querySelector('input[name="keepIndefinitely"][type="hidden"]'); + if (hiddenField) { + hiddenField.value = checkbox.checked; + } + + console.log('Submitting form...'); + checkbox.form.submit(); } \ No newline at end of file diff --git a/src/main/resources/templates/fileView.html b/src/main/resources/templates/fileView.html index 2f5e981..4cf63de 100644 --- a/src/main/resources/templates/fileView.html +++ b/src/main/resources/templates/fileView.html @@ -12,6 +12,14 @@ + +
@@ -123,23 +131,24 @@