diff --git a/themes/default/public/js/mail.js b/themes/default/public/js/mail.js new file mode 100644 index 0000000..60787cf --- /dev/null +++ b/themes/default/public/js/mail.js @@ -0,0 +1,56 @@ +import { formatDate } from "~/lib/utils.js"; + +const retrieveItemFromStorage = (serverKey) => + (JSON.parse(localStorage.getItem(`${prefix}files`)) || []).find( + (item) => item.short === serverKey + ); + +const updateMailtoLink = () => { + const ownSoftwareButtonDOM = document.querySelector(".action-own-software"); + const emails = document.querySelector(".emails input").value; + const subject = document.querySelector(".subject input").value; + const body = document.querySelector(".body textarea").value; + + ownSoftwareButtonDOM.href = `mailto:${encodeURIComponent( + emails + )}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`; +}; + +const populateBody = () => { + const links = + JSON.parse(new URL(window.location).searchParams.get("links")) || []; + + let text = i18n.intro; + + links.forEach((serverKey) => { + const item = retrieveItemFromStorage(serverKey); + if (item) { + const limit = + item.delay == 0 + ? null + : formatDate(item.delay * 86400 + item.created_at); + + text += `- ${item.name}${i18n.colon} ${item.url}`; + + if (limit !== null) { + text += `\n (${i18n.deadline}${limit})`; + } + text += "\n"; + } + }); + + if (!isLdapDefined && !isHtpasswdDefined) { + text += `\n-- \n${i18n.footer}`; + } + + document.querySelector(".body textarea").value = text; + updateMailtoLink(); +}; + +document.addEventListener("DOMContentLoaded", () => { + populateBody(); + + document + .querySelectorAll(".control > *") + .forEach((node) => node.addEventListener("change", updateMailtoLink)); +}); diff --git a/themes/default/templates/mail.html.ep b/themes/default/templates/mail.html.ep index 7fda2a8..54c8afd 100644 --- a/themes/default/templates/mail.html.ep +++ b/themes/default/templates/mail.html.ep @@ -49,51 +49,15 @@ - const populateBody = () => { - const links = JSON.parse(new URL(window.location).searchParams.get("links")) || []; - - let text = "<%== l('Hello,\n\nHere\'s some files I want to share with you:\n') %>"; - - - links.forEach((serverKey, index) => { - const item = retrieveItemFromStorage(serverKey); - if (item) { - const limit = (item.delay == 0) ? null : formatDate(item.delay * 86400 + item.created_at); - - text += `- ${item.name}<%= l(':') %> ${item.url}`; - - if (limit !== null) { - text += `\n (<%= l('deadline: ') %>${limit})`; - } - text += "\n"; - } - }); - - % if (!defined(config('ldap')) && !defined(config('htpasswd'))) { - text += "\n-- \n<%= l('Share your files in total privacy on %1', url_for('/')->to_abs) %>"; - % } - - document.querySelector('.body textarea').value = text; - updateMailtoLink(); - } - - document.addEventListener('DOMContentLoaded', () => { - populateBody(); - - document.querySelectorAll(".control > *") - .forEach(node => node.addEventListener('change', updateMailtoLink)); - }); - \ No newline at end of file +%= javascript '/js/minified/mail.min.js', type => 'module', defer => "true" \ No newline at end of file