lufi/themes/default/templates/mail.html.ep

99 lines
3.8 KiB
Plaintext

% # vim:set sw=4 ts=4 sts=4 ft=html.epl expandtab:
<div class="box">
% if (defined(stash('msg'))) {
<div class="message is-danger">
<div class="message-body">
<%= stash('msg')%>
</div>
</div>
% }
<div class="message is-info">
<div class="message-body">
<p><%= l('If you send the mail from this server, the links will be sent to the server, which may lower your privacy protection.') %></p>
<p><%= l('Adding URLs not related to this Lufi instance to the mail body or subject is prohibited.') %></p>
</div>
</div>
<form class="field" action="<%= url_for('m') %>" method="post" class="mail-form">
%= csrf_field
<div class="field emails">
<label class="label" for="emails"><%= l('Comma-separated email addresses') %></label>
<div class="control">
<input class="input" type="text" name="emails" placeholder="<%= l('Emails') %>" value="<%= defined(stash('values')) ? stash('values')->{emails} : '' %>" required>
</div>
</div>
<div class="field subject">
<label class="label" for="subject"><%= l('Email subject') %></label>
<div class="control">
<input class="input" type="text" name="subject" placeholder="<%= l('Email subject') %>" value="<%= defined(stash('values')) ? stash('values')->{subject} : l('Here\'s some files') %>" required>
</div>
</div>
<div class="field body">
<label class="label" for="body"><%= l('Email body') %></label>
<div class="control">
<textarea class="textarea" id="body" name="body" placeholder="<%= l('Email body') %>" required><%= defined(stash('values')) ? stash('values')->{body} : "" %></textarea>
</div>
</div>
<div class="actions-buttons has-text-centered">
% if (!$self->config('disable_mail_sending')) {
<button type="submit" class="button action-submit is-primary"><%= l('Send with this server') %></button>
% }
<a href="#" class="button action-own-software is-primary"><%= l('Send with your own mail software') %></a>
</div>
</form>
</div>
<script type="text/javascript">
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 = "<%== 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));
});
</script>