"
@@ -503,8 +529,12 @@ function mail_compose(is_quoted, references, quoted_msgnum, m_to, m_cc, m_subjec
+ "
"
;
- if (is_quoted) {
- compose_screen += "
";
+ // If this is a quoted reply, insert a div within which we will render the original message.
+ if (is_quoted && is_fwd) {
+ compose_screen += "
" + _("--- forwarded message ---") + "
QUOTE
";
+ }
+ else if (is_quoted) {
+ compose_screen += "
QUOTE
";
}
// The button bar is a Grid element, and is also a Flexbox container.
@@ -513,137 +543,48 @@ function mail_compose(is_quoted, references, quoted_msgnum, m_to, m_cc, m_subjec
${_("Send message")}
${_("Save to Drafts")}
- ${_("Attachments:")} ${num_attachments}
+ ${_("Attachments:")} ${uploads.length}
${_("Contacts")}
- ${_("Cancel")}
+ ${_("Cancel")}
`
;
+
document.getElementById("ctdl-main").innerHTML = compose_screen;
- mail_display_message(quoted_msgnum, document.getElementById(quoted_div_name), 0);
+
if (m_cc) {
document.getElementById("ctdl-compose-cc-label").style.display = "block";
document.getElementById("ctdl-compose-cc-field").style.display = "block";
}
- activate_uploads();
-}
-
-
-function activate_uploads() {
- document.getElementById("ctdl_big_modal").innerHTML = `
-
-
-
` + _("Attachments:") + " " + num_attachments + `
-
-
-
-
- - uploaded file
- - another uploaded file
- - philez and warez
-
-
-
-
- `;
-
- // activate drag and drop (shamelessly swiped from https://www.smashingmagazine.com/2018/01/drag-drop-file-uploader-vanilla-js/ )
- let dropArea = document.getElementById("drop-area");
- ;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
- dropArea.addEventListener(eventName, preventDefaults, false)
- })
- ;["dragenter", "dragover"].forEach(eventName => {
- dropArea.addEventListener(eventName, highlight, false)
- })
- ;['dragleave', 'drop'].forEach(eventName => {
- dropArea.addEventListener(eventName, unhighlight, false)
- })
- dropArea.addEventListener('drop', handleDrop, false);
-
- // make the modal smaller than the containing window but pretty big
- document.getElementById("ctdl_attachments_outer").style.width =
- Math.trunc((document.getElementById("ctdl-editor-body").getBoundingClientRect().width) * 0.60).toString() + "px";
- document.getElementById("ctdl_attachments_outer").style.height =
- Math.trunc((document.getElementById("ctdl-editor-body").getBoundingClientRect().height) * 0.60).toString() + "px";
-}
-
-
-// prevent drag and drop events from propagating up through the DOM
-function preventDefaults(e) {
- e.preventDefault();
- e.stopPropagation();
-}
-
-
-function handleDrop(e) {
- let dt = e.dataTransfer;
- let files = dt.files;
- handleFiles(files);
-}
-
-
-function handleFiles(files) {
- ([...files]).forEach(uploadFile)
-}
-
-
-function uploadFile(file) {
- var url = '/ctdl/zzz/attach_it;'
- var xhr = new XMLHttpRequest();
- var formData = new FormData();
- xhr.open('POST', url, true);
-
- xhr.addEventListener('readystatechange', function(e) {
- if (xhr.readyState == 4 && xhr.status == 200) {
- document.getElementById("ctdl_upload_list").innerHTML += "
succeeeeed";
- console.log("upload succeeded");
- }
- else if (xhr.readyState == 4 && xhr.status != 200) {
- document.getElementById("ctdl_upload_list").innerHTML += "
EPIC FAIL";
- console.log("upload failed");
- }
- })
-
- formData.append('file', file);
- xhr.send(formData);
-}
-
-
-function highlight(e) {
- let dropArea = document.getElementById("drop-area");
- dropArea.classList.add('highlight')
-}
-
-function unhighlight(e) {
- let dropArea = document.getElementById("drop-area");
- dropArea.classList.remove('highlight')
-}
-
+ activate_uploads("ctdl-editor-body"); // create the attachments window
+ attachment_counter_divs.push("ctdl_num_attachments"); // make the Attachments: count at the bottom update too
+ // If this is a quoted reply, render the original message into the div we set up earlier.
+ if (is_quoted) {
+ mail_display_message(quoted_msgnum, document.getElementById(quoted_div_name), 0);
+ }
-// Show or hide the attachments window in the composer
-function show_or_hide_attachments() {
+ // If this is a forwarded messages, preload its attachments into the forwarded copy.
+ if (is_fwd) {
+ forward_attachments(quoted_msgnum);
+ }
- if (document.getElementById("ctdl_big_modal").style.display == "block") {
- document.getElementById("ctdl_big_modal").style.display = "none";
+ if (is_reply) {
+ setTimeout(() => { document.getElementById("ctdl-editor-body").focus(); }, 0);
}
else {
- document.getElementById("ctdl_big_modal").style.display = "block";
+ setTimeout(() => { document.getElementById("ctdl-compose-to-field").focus(); }, 0);
}
-}
+}
// Called when the user clicks the button to make the hidden "CC" and "BCC" lines appear.
// It is also called automatically during a Reply when CC is pre-populated.
function make_cc_bcc_visible() {
document.getElementById("ctdl-cc-bcc-buttons").style.display = "none";
+ document.getElementById("ctdl-compose-cc-label").style.display = "block";
+ document.getElementById("ctdl-compose-cc-field").style.display = "block";
document.getElementById("ctdl-compose-bcc-label").style.display = "block";
document.getElementById("ctdl-compose-bcc-field").style.display = "block";
}
@@ -665,29 +606,29 @@ function msm_field(element_name, separator) {
function mail_send_message() {
document.body.style.cursor = "wait";
+ deactivate_uploads();
let url = "/ctdl/r/" + escapeHTMLURI(current_room)
+ "/dummy_name_for_new_mail"
- + "?wefw=" + msm_field("ctdl_mc_references", "!") // references (if present)
+ + "?wefw=" + msm_field("ctdl-mc-references", "!") // references (if present)
+ "&subj=" + msm_field("ctdl-compose-subject-field", " ") // subject (if present)
+ "&mailto=" + msm_field("ctdl-compose-to-field", ",") // To: (required)
+ "&mailcc=" + msm_field("ctdl-compose-cc-field", ",") // Cc: (if present)
+ "&mailbcc=" + msm_field("ctdl-compose-bcc-field", ",") // Bcc: (if present)
;
- boundary = randomString();
- body_text =
- "--" + boundary + "\r\n"
- + "Content-type: text/html\r\n"
- + "Content-transfer-encoding: quoted-printable\r\n"
- + "\r\n"
- + quoted_printable_encode(
- "" + document.getElementById("ctdl-editor-body").innerHTML + ""
- ) + "\r\n"
- + "--" + boundary + "--\r\n"
- ;
+ if (uploads.length > 0) {
+ url += "&att=";
+ for (let i=0; i