2009-07-19 18:41:42 +02:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-08-28 16:48:45 +02:00
|
|
|
|
2006-10-03 18:21:25 +02:00
|
|
|
var contactSelectorAction = 'mailer-contacts';
|
2007-12-13 00:56:01 +01:00
|
|
|
var attachmentCount = 0;
|
2007-11-20 22:11:23 +01:00
|
|
|
var MailEditor = {
|
2009-08-04 17:42:02 +02:00
|
|
|
currentField: null,
|
|
|
|
selectedIndex: -1,
|
|
|
|
delay: 750,
|
|
|
|
delayedSearch: false,
|
|
|
|
signatureLength: 0,
|
|
|
|
textFirstFocus: true
|
2007-11-20 22:11:23 +01:00
|
|
|
};
|
2006-10-03 18:21:25 +02:00
|
|
|
|
2011-12-02 08:22:47 +01:00
|
|
|
function onContactAdd(button) {
|
|
|
|
var div = $("contacts");
|
|
|
|
if (div.visible()) {
|
2011-12-08 23:50:42 +01:00
|
|
|
div.hide();
|
|
|
|
$("rightPanel").setStyle({ left: "0px" });
|
2011-12-02 08:22:47 +01:00
|
|
|
$(button).removeClassName("active");
|
|
|
|
}
|
2009-08-04 17:42:02 +02:00
|
|
|
else {
|
2011-12-02 08:22:47 +01:00
|
|
|
$("rightPanel").setStyle({ left: $("leftPanel").getStyle("width") });
|
2011-12-08 23:50:42 +01:00
|
|
|
div.show();
|
2011-12-02 08:22:47 +01:00
|
|
|
$(button).addClassName("active");
|
2009-08-04 17:42:02 +02:00
|
|
|
}
|
2011-12-02 08:22:47 +01:00
|
|
|
|
|
|
|
$("hiddenDragHandle").adjust();
|
2011-12-14 04:13:00 +01:00
|
|
|
onWindowResize(null);
|
2007-10-25 19:56:47 +02:00
|
|
|
}
|
2007-03-29 20:04:41 +02:00
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
|
2009-08-04 17:42:02 +02:00
|
|
|
if (!mailIsRecipient(contactEmail)) {
|
|
|
|
var neededOptionValue = 0;
|
|
|
|
if (tag == "cc")
|
|
|
|
neededOptionValue = 1;
|
|
|
|
else if (tag == "bcc")
|
|
|
|
neededOptionValue = 2;
|
|
|
|
|
|
|
|
var stop = false;
|
|
|
|
var counter = 0;
|
|
|
|
var currentRow = $('row_' + counter);
|
|
|
|
while (currentRow && !stop) {
|
|
|
|
var currentValue = $(currentRow.childNodesWithTag("td")[1]).childNodesWithTag("input")[0].value;
|
|
|
|
if (currentValue == neededOptionValue) {
|
|
|
|
stop = true;
|
|
|
|
insertContact($("addr_" + counter), contactName, contactEmail);
|
|
|
|
}
|
|
|
|
counter++;
|
|
|
|
currentRow = $('row_' + counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stop) {
|
2009-10-28 18:48:22 +01:00
|
|
|
fancyAddRow("");
|
2009-08-04 17:42:02 +02:00
|
|
|
var row = $("row_" + currentIndex);
|
|
|
|
var td = $(row.childNodesWithTag("td")[0]);
|
|
|
|
var select = $(td.childNodesWithTag("select")[0]);
|
|
|
|
select.value = neededOptionValue;
|
|
|
|
insertContact($("addr_" + currentIndex), contactName, contactEmail);
|
2011-12-14 04:13:00 +01:00
|
|
|
onWindowResize(null);
|
2009-08-04 17:42:02 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-03 16:38:51 +02:00
|
|
|
}
|
|
|
|
|
2011-12-02 08:22:47 +01:00
|
|
|
function onContactFolderChange(event) {
|
|
|
|
initCriteria();
|
|
|
|
openContactsFolder(this.value);
|
|
|
|
}
|
|
|
|
|
2006-10-03 16:38:51 +02:00
|
|
|
function mailIsRecipient(mailto) {
|
2009-08-04 17:42:02 +02:00
|
|
|
var isRecipient = false;
|
|
|
|
|
|
|
|
var counter = 0;
|
|
|
|
var currentRow = $('row_' + counter);
|
|
|
|
|
|
|
|
var email = extractEmailAddress(mailto).toUpperCase();
|
|
|
|
|
|
|
|
while (currentRow && !isRecipient) {
|
|
|
|
var currentValue = $("addr_"+counter).value.toUpperCase();
|
|
|
|
if (currentValue.indexOf(email) > -1)
|
|
|
|
isRecipient = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
currentRow = $('row_' + counter);
|
|
|
|
}
|
|
|
|
}
|
2006-10-03 16:38:51 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
return isRecipient;
|
2006-10-03 16:38:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function insertContact(inputNode, contactName, contactEmail) {
|
2009-08-04 17:42:02 +02:00
|
|
|
var value = '' + inputNode.value;
|
2006-10-03 16:38:51 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
var newContact = contactName;
|
|
|
|
if (newContact.length > 0)
|
|
|
|
newContact += ' <' + contactEmail + '>';
|
|
|
|
else
|
|
|
|
newContact = contactEmail;
|
2006-10-03 16:38:51 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
if (value.length > 0)
|
|
|
|
value += ", ";
|
|
|
|
value += newContact;
|
2006-10-03 16:38:51 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
inputNode.value = value;
|
2006-09-20 19:58:42 +02:00
|
|
|
}
|
2006-10-18 23:53:47 +02:00
|
|
|
|
2012-09-20 19:46:23 +02:00
|
|
|
function updateWindowTitleFromSubject(event) {
|
|
|
|
if (this.value) {
|
|
|
|
document.title = this.value;
|
|
|
|
}else{
|
2012-09-27 16:03:54 +02:00
|
|
|
document.title = '(' + _("Untitled") + ')';
|
2012-09-20 19:46:23 +02:00
|
|
|
}
|
|
|
|
}
|
2009-08-04 17:42:02 +02:00
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
/* mail editor */
|
|
|
|
|
2012-05-29 16:20:06 +02:00
|
|
|
function onValidate(onSuccess) {
|
|
|
|
if (document.pageform.action != "send") {
|
|
|
|
|
|
|
|
if (!hasRecipients()) {
|
|
|
|
showAlertDialog(_("error_missingrecipients"));
|
|
|
|
}
|
|
|
|
else if (document.pageform.subject.value == "") {
|
2013-01-31 15:44:29 +01:00
|
|
|
showConfirmDialog(_("Warning"), _("error_missingsubject"), onValidateDone.bind(this, onSuccess), null, _("Send Anyway"), _("Cancel"));
|
2012-05-29 16:20:06 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
onValidateDone(onSuccess);
|
|
|
|
}
|
2009-08-04 17:42:02 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2012-05-29 16:20:06 +02:00
|
|
|
function onValidateDone(onSuccess) {
|
2012-09-18 21:05:02 +02:00
|
|
|
// Create "blocking" div to avoid double-clicking on send button
|
|
|
|
var safetyNet = createElement("div", "javascriptSafetyNet");
|
|
|
|
$('pageContent').insert({top: safetyNet});
|
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
if (!document.busyAnim) {
|
|
|
|
var toolbar = document.getElementById("toolbar");
|
2012-05-29 16:20:06 +02:00
|
|
|
document.busyAnim = startAnimation(toolbar);
|
2013-12-18 22:36:49 +01:00
|
|
|
}
|
2012-11-27 16:37:14 +01:00
|
|
|
|
2012-05-29 16:20:06 +02:00
|
|
|
var lastRow = $("lastRow");
|
|
|
|
lastRow.down("select").name = "popup_last";
|
2012-11-27 16:37:14 +01:00
|
|
|
|
2012-05-29 16:20:06 +02:00
|
|
|
window.shouldPreserve = true;
|
2012-11-27 16:37:14 +01:00
|
|
|
|
2012-05-29 16:20:06 +02:00
|
|
|
document.pageform.action = "send";
|
2012-09-18 21:05:02 +02:00
|
|
|
|
2012-05-29 16:20:06 +02:00
|
|
|
if (typeof onSuccess == 'function')
|
|
|
|
onSuccess();
|
2010-08-23 22:58:41 +02:00
|
|
|
|
2012-05-29 16:20:06 +02:00
|
|
|
disposeDialog();
|
2010-08-23 22:58:41 +02:00
|
|
|
|
2012-05-29 16:20:06 +02:00
|
|
|
return true;
|
2010-08-23 22:58:41 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
function onPostComplete(http) {
|
|
|
|
var response = http.responseText;
|
2010-08-23 22:58:41 +02:00
|
|
|
if (response && response.length > 0) {
|
|
|
|
var jsonResponse = response.evalJSON();
|
|
|
|
if (jsonResponse["status"] == "success") {
|
2011-12-02 08:22:47 +01:00
|
|
|
var p;
|
|
|
|
if (window.frameElement && window.frameElement.id)
|
|
|
|
p = parent;
|
|
|
|
if (window.opener && window.opener.refreshMessage)
|
|
|
|
p = window.opener;
|
|
|
|
if (p && p.refreshMessage)
|
|
|
|
p.refreshMessage(jsonResponse["sourceFolder"],
|
2012-09-18 21:05:02 +02:00
|
|
|
jsonResponse["messageID"]);
|
2011-12-02 08:22:47 +01:00
|
|
|
onCloseButtonClick();
|
2010-08-23 22:58:41 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
var message = jsonResponse["message"];
|
|
|
|
document.pageform.action = "";
|
|
|
|
var progressImage = $("progressIndicator");
|
|
|
|
if (progressImage) {
|
|
|
|
progressImage.parentNode.removeChild(progressImage);
|
|
|
|
}
|
|
|
|
showAlertDialog(jsonResponse["message"]);
|
2012-09-18 21:05:02 +02:00
|
|
|
// Remove "blocking" div
|
|
|
|
onFinalLoadHandler(); // from generic.js
|
2010-08-23 22:58:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-12-02 08:22:47 +01:00
|
|
|
onCloseButtonClick();
|
2010-08-23 22:58:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickedEditorSend() {
|
2012-05-29 16:20:06 +02:00
|
|
|
onValidate(function() {
|
2014-01-03 20:33:27 +01:00
|
|
|
if (CKEDITOR.instances.text) CKEDITOR.instances.text.updateElement();
|
2013-12-18 22:36:49 +01:00
|
|
|
triggerAjaxRequest(document.pageform.action,
|
|
|
|
onPostComplete,
|
|
|
|
null,
|
|
|
|
Form.serialize(document.pageform), // excludes the file input
|
|
|
|
{ "Content-type": "application/x-www-form-urlencoded" });
|
2012-05-29 16:20:06 +02:00
|
|
|
});
|
2010-08-24 21:57:44 +02:00
|
|
|
|
|
|
|
return false;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
function formatBytes(bytes, si) {
|
|
|
|
var thresh = si ? 1000 : 1024;
|
|
|
|
if (bytes < thresh) return bytes + ' B';
|
|
|
|
var units = si ? ['KiB','MiB','GiB'] : ['KB','MB','GB'];
|
|
|
|
var u = -1;
|
|
|
|
do {
|
|
|
|
bytes /= thresh;
|
|
|
|
++u;
|
|
|
|
} while (bytes >= thresh);
|
|
|
|
return bytes.toFixed(1) + ' ' + units[u];
|
|
|
|
}
|
|
|
|
|
|
|
|
function createAttachment(file) {
|
|
|
|
var list = $('attachments');
|
|
|
|
var attachment;
|
|
|
|
if (list.select('[data-filename="'+file.name+'"]').length == 0) {
|
|
|
|
// File is not already uploaded
|
|
|
|
var attachment = createElement('li', null, ['muted progress0'], null, { 'data-filename': file.name }, list);
|
|
|
|
attachment.appendChild(new Element('i', { 'class': 'icon-attachment' }));
|
|
|
|
var a = createElement('a', null, null, null, {'href': '#', 'target': '_new' }, attachment);
|
|
|
|
|
|
|
|
a.appendChild(document.createTextNode(file.name));
|
|
|
|
if (file.size)
|
|
|
|
attachment.appendChild(new Element('span', { 'class': 'muted' }).update('(' + formatBytes(file.size, true) + ')'));
|
2009-08-04 17:42:02 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
return attachment;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2010-08-23 22:58:41 +02:00
|
|
|
function clickedEditorSave() {
|
2009-08-04 17:42:02 +02:00
|
|
|
var lastRow = $("lastRow");
|
|
|
|
lastRow.down("select").name = "popup_last";
|
2008-08-15 10:20:34 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
window.shouldPreserve = true;
|
|
|
|
document.pageform.action = "save";
|
2014-01-03 20:33:27 +01:00
|
|
|
if (CKEDITOR.instances.text) CKEDITOR.instances.text.updateElement();
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
triggerAjaxRequest(document.pageform.action, function (http) {
|
|
|
|
if (http.readyState == 4) {
|
|
|
|
if (http.status == 200) {
|
|
|
|
if (window.opener && window.opener.open && !window.opener.closed)
|
|
|
|
window.opener.refreshFolderByType('draft');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var response = http.responseText.evalJSON(true);
|
2014-01-07 17:11:39 +01:00
|
|
|
showAlertDialog(_("Error while saving the draft:") + " " + response.textStatus);
|
2013-12-18 22:36:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
Form.serialize(document.pageform), // excludes the file input
|
|
|
|
{ "Content-type": "application/x-www-form-urlencoded" });
|
2010-07-28 23:17:57 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
return false;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2014-01-23 15:10:17 +01:00
|
|
|
/**
|
|
|
|
* On first focus of textarea, position the caret with respect to user's preferences
|
|
|
|
*/
|
2009-06-16 22:29:25 +02:00
|
|
|
function onTextFocus(event) {
|
2009-08-04 17:42:02 +02:00
|
|
|
if (MailEditor.textFirstFocus) {
|
|
|
|
var content = this.getValue();
|
2009-11-29 05:19:32 +01:00
|
|
|
var replyPlacement = UserDefaults["SOGoMailReplyPlacement"];
|
2014-01-23 15:10:17 +01:00
|
|
|
if (replyPlacement == "above" || !mailIsReply) {
|
|
|
|
// For forwards, place caret at top unconditionally
|
2009-08-04 17:42:02 +02:00
|
|
|
this.setCaretTo(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var caretPosition = this.getValue().length - MailEditor.signatureLength;
|
2014-01-23 15:10:17 +01:00
|
|
|
caretPosition = adjustOffset(this, caretPosition);
|
2009-08-04 17:42:02 +02:00
|
|
|
if (hasSignature())
|
|
|
|
caretPosition -= 2;
|
|
|
|
this.setCaretTo(caretPosition);
|
|
|
|
}
|
|
|
|
MailEditor.textFirstFocus = false;
|
|
|
|
}
|
2007-12-07 00:55:39 +01:00
|
|
|
}
|
|
|
|
|
2014-01-23 15:10:17 +01:00
|
|
|
/**
|
|
|
|
* Change behavior of tab key in textarea (plain-text mail)
|
|
|
|
*/
|
2008-08-28 00:50:12 +02:00
|
|
|
function onTextKeyDown(event) {
|
2009-08-04 17:42:02 +02:00
|
|
|
if (event.keyCode == Event.KEY_TAB) {
|
|
|
|
if (event.shiftKey) {
|
2014-01-23 15:10:17 +01:00
|
|
|
// Shift-tab goes back to subject field
|
2009-08-04 17:42:02 +02:00
|
|
|
var subjectField = $$("div#subjectRow input").first();
|
|
|
|
subjectField.focus();
|
|
|
|
subjectField.selectText(0, subjectField.value.length);
|
|
|
|
preventDefault(event);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!(event.shiftKey || event.metaKey || event.ctrlKey)) {
|
2013-11-20 17:17:42 +01:00
|
|
|
// Convert a tab to 4 spaces
|
2014-01-23 15:10:17 +01:00
|
|
|
if (typeof(this.selectionStart) != "undefined") { // Mozilla and Safari
|
2009-08-04 17:42:02 +02:00
|
|
|
var cursor = this.selectionStart;
|
|
|
|
var startText = ((cursor > 0)
|
|
|
|
? this.value.substr(0, cursor)
|
|
|
|
: "");
|
|
|
|
var endText = this.value.substr(cursor);
|
2013-11-20 17:17:42 +01:00
|
|
|
var newText = startText + " " + endText;
|
2009-08-04 17:42:02 +02:00
|
|
|
this.value = newText;
|
2013-11-20 17:17:42 +01:00
|
|
|
cursor += 4;
|
2009-08-04 17:42:02 +02:00
|
|
|
this.setSelectionRange(cursor, cursor);
|
|
|
|
}
|
|
|
|
else if (this.selectionRange) // IE
|
2013-11-20 17:17:42 +01:00
|
|
|
this.selectionRange.text = " ";
|
2009-08-04 17:42:02 +02:00
|
|
|
preventDefault(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-28 00:50:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTextIEUpdateCursorPos(event) {
|
2009-08-04 17:42:02 +02:00
|
|
|
this.selectionRange = document.selection.createRange().duplicate();
|
2008-08-28 00:50:12 +02:00
|
|
|
}
|
|
|
|
|
2012-11-27 16:37:14 +01:00
|
|
|
function onHTMLFocus(event) {
|
|
|
|
if (MailEditor.textFirstFocus) {
|
|
|
|
var s = event.editor.getSelection();
|
|
|
|
var selected_ranges = s.getRanges();
|
|
|
|
var children = event.editor.document.getBody().getChildren();
|
|
|
|
var node;
|
|
|
|
var caretAtTop = (UserDefaults["SOGoMailReplyPlacement"] == "above")
|
|
|
|
|| !mailIsReply; // for forwards, place caret at top unconditionally
|
|
|
|
|
|
|
|
if (caretAtTop) {
|
|
|
|
node = children.getItem(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Search for signature starting from bottom
|
|
|
|
node = children.getItem(children.count() - 1);
|
|
|
|
while (true) {
|
|
|
|
var x = node.getPrevious();
|
|
|
|
if (x == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (x.getText() == '--') {
|
|
|
|
node = x.getPrevious().getPrevious();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.selectElement(node);
|
|
|
|
|
|
|
|
// Place the caret
|
|
|
|
if (caretAtTop)
|
|
|
|
s.scrollIntoView(); // top
|
|
|
|
selected_ranges = s.getRanges();
|
|
|
|
selected_ranges[0].collapse(true);
|
|
|
|
s.selectRanges(selected_ranges);
|
|
|
|
if (!caretAtTop)
|
|
|
|
s.scrollIntoView(); // bottom
|
|
|
|
|
|
|
|
MailEditor.textFirstFocus = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-21 15:33:45 +02:00
|
|
|
function initAddresses() {
|
|
|
|
var addressList = $("addressList");
|
2009-08-04 17:42:02 +02:00
|
|
|
addressList.select("input.textField").each(function (input) {
|
|
|
|
if (!input.readAttribute("readonly")) {
|
2009-09-01 16:12:53 +02:00
|
|
|
input.addInterface(SOGoAutoCompletionInterface);
|
|
|
|
input.uidField = "c_name";
|
2011-04-21 15:33:45 +02:00
|
|
|
input.on("focus", addressFieldGotFocus.bind(input));
|
|
|
|
input.on("blur", addressFieldLostFocus.bind(input));
|
|
|
|
input.on("autocompletion:changedlist", expandContactList);
|
|
|
|
input.on("autocompletion:changed", addressFieldChanged.bind(input));
|
2009-10-28 18:48:22 +01:00
|
|
|
//input.onListAdded = expandContactList;
|
2009-08-04 17:42:02 +02:00
|
|
|
}
|
|
|
|
});
|
2008-06-30 22:05:48 +02:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:17:25 +01:00
|
|
|
/* Overwrite function of MailerUI.js */
|
2011-12-02 08:22:47 +01:00
|
|
|
function configureDragHandle() {
|
|
|
|
var handle = $("hiddenDragHandle");
|
|
|
|
if (handle) {
|
|
|
|
handle.addInterface(SOGoDragHandlesInterface);
|
2012-03-15 20:17:25 +01:00
|
|
|
handle.leftMargin = 135; // minimum width
|
|
|
|
handle.leftBlock = $("leftPanel");
|
|
|
|
handle.rightBlock = $("rightPanel");
|
|
|
|
handle.enableRightSafety();
|
2011-12-14 04:13:00 +01:00
|
|
|
handle.observe("handle:dragged", onWindowResize);
|
2011-12-02 08:22:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
function configureAttachments() {
|
|
|
|
var list = $("attachments");
|
|
|
|
|
|
|
|
if (!list) return;
|
|
|
|
|
|
|
|
list.on('click', 'a', function (event, element) {
|
2014-01-06 21:09:09 +01:00
|
|
|
// Don't follow links of attachments not yet uploaded
|
|
|
|
if (!element.up('li').hasClassName('progressDone')) {
|
|
|
|
Event.stop(event);
|
2013-12-18 22:36:49 +01:00
|
|
|
return false;
|
2014-01-06 21:09:09 +01:00
|
|
|
}
|
2013-12-18 22:36:49 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
list.on('click', 'i.icon-attachment', function (event, element) {
|
2014-01-06 21:09:09 +01:00
|
|
|
// Delete attachment when clicking on small icon
|
2013-12-18 22:36:49 +01:00
|
|
|
var item = element.up('li');
|
|
|
|
if (item.hasClassName('progressDone')) {
|
|
|
|
var filename = item.readAttribute('data-filename');
|
|
|
|
var url = "" + window.location;
|
|
|
|
var parts = url.split("/");
|
|
|
|
parts[parts.length-1] = "deleteAttachment?filename=" + encodeURIComponent(filename);
|
|
|
|
url = parts.join("/");
|
|
|
|
triggerAjaxRequest(url, attachmentDeleteCallback, item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var dropzone = jQuery('#dropZone');
|
|
|
|
jQuery('#fileUpload').fileupload({
|
|
|
|
// With singleFileUploads option enabled, the 'add' and 'done' (or 'fail') callbacks
|
|
|
|
// are called once for each file in the selection for XHR file uploads
|
|
|
|
singleFileUploads: true,
|
|
|
|
dataType: 'json',
|
|
|
|
add: function (e, data) {
|
|
|
|
var file = data.files[0];
|
|
|
|
var attachment = createAttachment(file);
|
|
|
|
if (attachment) {
|
|
|
|
file.attachment = attachment;
|
|
|
|
data.submit();
|
|
|
|
}
|
|
|
|
if (dropzone.is(":visible"))
|
|
|
|
dropzone.fadeOut('fast');
|
|
|
|
},
|
|
|
|
done: function (e, data) {
|
|
|
|
var attachment = data.files[0].attachment;
|
|
|
|
var attrs = data.result[data.result.length-1];
|
|
|
|
attachment.className = 'progressDone';
|
|
|
|
attachment.down('a').setAttribute('href', attrs.url);
|
|
|
|
if (window.opener && window.opener.open && !window.opener.closed)
|
|
|
|
window.opener.refreshFolderByType('draft');
|
|
|
|
},
|
|
|
|
fail: function (e, data) {
|
|
|
|
var attachment = data.files[0].attachment;
|
|
|
|
var filename = data.files[0].name;
|
2014-01-07 17:11:39 +01:00
|
|
|
var textStatus;
|
|
|
|
try {
|
|
|
|
var response = data.xhr().response.evalJSON();
|
|
|
|
textStatus = response.textStatus;
|
|
|
|
} catch (e) {}
|
|
|
|
if (!textStatus)
|
|
|
|
textStatus = _("Can't contact server");
|
|
|
|
showAlertDialog(_("Error while uploading the file \"%{0}\":").formatted(filename) + " " + textStatus);
|
2013-12-18 22:36:49 +01:00
|
|
|
attachment.remove();
|
|
|
|
},
|
|
|
|
dragover: function (e, data) {
|
|
|
|
if (!dropzone.is(":visible"))
|
|
|
|
dropzone.show();
|
|
|
|
},
|
|
|
|
progress: function (e, data) {
|
|
|
|
var progress = parseInt(data.loaded / data.total * 4, 10);
|
|
|
|
var attachment = data.files[0].attachment;
|
|
|
|
attachment.className = 'muted progress' + progress;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dropzone.on('dragleave', function (e) {
|
|
|
|
dropzone.fadeOut('fast');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
function initMailEditor() {
|
2014-01-23 15:10:17 +01:00
|
|
|
var textarea = $("text");
|
|
|
|
|
2009-08-25 17:05:01 +02:00
|
|
|
if (composeMode != "html" && $("text"))
|
2014-01-23 15:10:17 +01:00
|
|
|
textarea.show();
|
2009-08-25 15:27:03 +02:00
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
configureAttachments();
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2011-04-21 15:33:45 +02:00
|
|
|
initAddresses();
|
2009-08-04 17:42:02 +02:00
|
|
|
|
2012-11-27 16:37:14 +01:00
|
|
|
var focusField = textarea;
|
|
|
|
if (!mailIsReply) {
|
|
|
|
focusField = $("addr_0");
|
|
|
|
focusField.focus();
|
|
|
|
}
|
2009-08-04 17:42:02 +02:00
|
|
|
|
|
|
|
initializePriorityMenu();
|
|
|
|
|
2011-12-02 08:22:47 +01:00
|
|
|
configureDragHandle();
|
|
|
|
|
2012-09-26 17:28:18 +02:00
|
|
|
// Set current subject as window title if not set, use '(Untitled)'
|
|
|
|
if (document.pageform.subject.value == "")
|
|
|
|
document.title = '(' + _("Untitled") + ')';
|
|
|
|
else
|
|
|
|
document.title = _(document.pageform.subject.value);
|
|
|
|
|
2012-09-20 19:46:23 +02:00
|
|
|
// Change the window title when typing the subject
|
|
|
|
$$("div#subjectRow input").first().on("keyup", updateWindowTitleFromSubject);
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
var composeMode = UserDefaults["SOGoMailComposeMessageType"];
|
2009-08-04 17:42:02 +02:00
|
|
|
if (composeMode == "html") {
|
2012-11-27 16:37:14 +01:00
|
|
|
// HTML mode
|
2009-08-04 17:42:02 +02:00
|
|
|
CKEDITOR.replace('text',
|
|
|
|
{
|
2010-06-30 20:37:12 +02:00
|
|
|
language : localeCode,
|
|
|
|
scayt_sLang : localeCode
|
2009-08-26 17:08:56 +02:00
|
|
|
}
|
2009-08-04 17:42:02 +02:00
|
|
|
);
|
2012-11-27 16:37:14 +01:00
|
|
|
CKEDITOR.on('instanceReady', function(event) {
|
|
|
|
if (focusField == textarea)
|
|
|
|
// CKEditor reports being ready but it's still not focusable;
|
|
|
|
// we wait for a few more milliseconds
|
|
|
|
setTimeout("CKEDITOR.instances.text.focus()", 500);
|
|
|
|
});
|
|
|
|
CKEDITOR.instances.text.on('focus', onHTMLFocus);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Plain text mode
|
|
|
|
var textContent = textarea.getValue();
|
|
|
|
if (hasSignature()) {
|
|
|
|
var sigLimit = textContent.lastIndexOf("--");
|
|
|
|
if (sigLimit > -1)
|
|
|
|
MailEditor.signatureLength = (textContent.length - sigLimit);
|
|
|
|
}
|
|
|
|
if (UserDefaults["SOGoMailReplyPlacement"] != "above") {
|
|
|
|
textarea.scrollTop = textarea.scrollHeight;
|
|
|
|
}
|
|
|
|
textarea.observe("focus", onTextFocus);
|
|
|
|
textarea.observe("keydown", onTextKeyDown);
|
|
|
|
|
|
|
|
if (Prototype.Browser.IE) {
|
2014-01-23 15:10:17 +01:00
|
|
|
// Hack to allow to replace the tab by spaces in IE < 9
|
2012-11-27 16:37:14 +01:00
|
|
|
var ieEvents = [ "click", "select", "keyup" ];
|
|
|
|
for (var i = 0; i < ieEvents.length; i++)
|
|
|
|
textarea.observe(ieEvents[i], onTextIEUpdateCursorPos, false);
|
|
|
|
}
|
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
if (focusField == textarea)
|
2012-11-27 16:37:14 +01:00
|
|
|
textarea.focus();
|
2009-08-04 17:42:02 +02:00
|
|
|
}
|
|
|
|
|
2011-12-02 08:22:47 +01:00
|
|
|
$("contactFolder").observe("change", onContactFolderChange);
|
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
Event.observe(window, "beforeunload", onMailEditorClose);
|
2008-09-28 16:02:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function initializePriorityMenu() {
|
2009-08-04 17:42:02 +02:00
|
|
|
var priority = $("priority").value.toUpperCase();
|
2010-08-31 15:49:31 +02:00
|
|
|
var priorityMenu = $("priorityMenu").childNodesWithTag("ul")[0];
|
2009-08-04 17:42:02 +02:00
|
|
|
var menuEntries = $(priorityMenu).childNodesWithTag("li");
|
|
|
|
var chosenNode;
|
|
|
|
if (priority == "HIGHEST")
|
|
|
|
chosenNode = menuEntries[0];
|
|
|
|
else if (priority == "HIGH")
|
|
|
|
chosenNode = menuEntries[1];
|
|
|
|
else if (priority == "LOW")
|
|
|
|
chosenNode = menuEntries[3];
|
|
|
|
else if (priority == "LOWEST")
|
|
|
|
chosenNode = menuEntries[4];
|
|
|
|
else
|
|
|
|
chosenNode = menuEntries[2];
|
|
|
|
priorityMenu.chosenNode = chosenNode;
|
|
|
|
$(chosenNode).addClassName("_chosen");
|
2010-08-31 15:49:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-02 14:31:32 +02:00
|
|
|
function onMenuCheckReturnReceipt(event) {
|
2010-08-31 15:49:31 +02:00
|
|
|
event.cancelBubble = true;
|
|
|
|
|
|
|
|
this.enabled = !this.enabled;
|
|
|
|
var enabled = this.enabled;
|
|
|
|
if (enabled) {
|
|
|
|
this.addClassName("_chosen");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.removeClassName("_chosen");
|
|
|
|
}
|
|
|
|
var receiptInput = $("receipt");
|
|
|
|
receiptInput.value = (enabled ? "true" : "false") ;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getMenus() {
|
2010-08-31 15:49:31 +02:00
|
|
|
return {
|
|
|
|
"optionsMenu": [ onMenuCheckReturnReceipt,
|
|
|
|
"-",
|
|
|
|
"priorityMenu" ],
|
|
|
|
"priorityMenu": [ onMenuSetPriority,
|
|
|
|
onMenuSetPriority,
|
|
|
|
onMenuSetPriority,
|
|
|
|
onMenuSetPriority,
|
|
|
|
onMenuSetPriority ]
|
|
|
|
};
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2007-08-18 22:29:50 +02:00
|
|
|
function attachmentDeleteCallback(http) {
|
2009-08-04 17:42:02 +02:00
|
|
|
if (http.readyState == 4) {
|
|
|
|
if (isHttpStatus204(http.status)) {
|
|
|
|
var node = http.callbackData;
|
|
|
|
node.parentNode.removeChild(node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log("attachmentDeleteCallback: an error occured: " + http.responseText);
|
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2014-01-23 15:10:17 +01:00
|
|
|
/**
|
|
|
|
* Adjust offset when the browser uses two characters for line feeds.
|
|
|
|
*/
|
|
|
|
function adjustOffset(element, offset) {
|
|
|
|
var val = element.value, newOffset = offset;
|
|
|
|
if (val.indexOf("\r\n") > -1) {
|
|
|
|
var matches = val.replace(/\r\n/g, "\n").slice(0, offset).match(/\n/g);
|
|
|
|
newOffset -= matches ? matches.length - 1 : 0;
|
2009-08-04 17:42:02 +02:00
|
|
|
}
|
2014-01-23 15:10:17 +01:00
|
|
|
return newOffset;
|
2008-10-21 23:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function hasSignature() {
|
2009-08-04 17:42:02 +02:00
|
|
|
try {
|
2009-11-29 05:19:32 +01:00
|
|
|
return(UserDefaults["SOGoMailSignature"].length > 0);
|
2009-08-04 17:42:02 +02:00
|
|
|
} catch(e) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-10-21 23:58:59 +02:00
|
|
|
}
|
|
|
|
|
2008-09-28 16:02:40 +02:00
|
|
|
function onMenuSetPriority(event) {
|
2009-08-04 17:42:02 +02:00
|
|
|
event.cancelBubble = true;
|
2008-09-28 16:02:40 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
var priority = this.getAttribute("priority");
|
|
|
|
if (this.parentNode.chosenNode)
|
|
|
|
this.parentNode.chosenNode.removeClassName("_chosen");
|
|
|
|
this.addClassName("_chosen");
|
|
|
|
this.parentNode.chosenNode = this;
|
2008-09-28 16:02:40 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
var priorityInput = $("priority");
|
|
|
|
priorityInput.value = priority;
|
2008-09-28 16:02:40 +02:00
|
|
|
}
|
|
|
|
|
2010-08-31 15:49:31 +02:00
|
|
|
function onSelectOptions(event) {
|
2011-04-21 15:33:45 +02:00
|
|
|
if (event.button == 0 || (isWebKit() && event.button == 1)) {
|
2009-08-04 17:42:02 +02:00
|
|
|
var node = getTarget(event);
|
2009-11-04 23:13:20 +01:00
|
|
|
if (node.tagName != 'A')
|
|
|
|
node = $(node).up("A");
|
2010-08-31 15:49:31 +02:00
|
|
|
popupToolbarMenu(node, "optionsMenu");
|
2009-08-04 17:42:02 +02:00
|
|
|
Event.stop(event);
|
|
|
|
}
|
2008-09-28 16:02:40 +02:00
|
|
|
}
|
|
|
|
|
2014-01-23 15:10:17 +01:00
|
|
|
/**
|
|
|
|
* Overwrite definition of MailerUI.js
|
|
|
|
*/
|
2011-12-14 04:13:00 +01:00
|
|
|
function onWindowResize(event) {
|
2009-08-24 22:26:52 +02:00
|
|
|
if (!document.pageform)
|
|
|
|
return;
|
2009-08-04 17:42:02 +02:00
|
|
|
var textarea = document.pageform.text;
|
|
|
|
var rowheight = (Element.getHeight(textarea) / textarea.rows);
|
|
|
|
var headerarea = $("headerArea");
|
2011-12-02 08:22:47 +01:00
|
|
|
var totalwidth = $("rightPanel").getWidth();
|
2007-09-10 20:46:05 +02:00
|
|
|
|
2010-07-08 06:13:56 +02:00
|
|
|
var subjectfield = headerarea.down("div#subjectRow span.headerField");
|
|
|
|
var subjectinput = headerarea.down("div#subjectRow input.textField");
|
2008-06-30 20:43:57 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
// Resize subject field
|
2011-12-02 08:22:47 +01:00
|
|
|
subjectinput.setStyle({ width: (totalwidth
|
2009-08-04 17:42:02 +02:00
|
|
|
- $(subjectfield).getWidth()
|
2011-12-02 08:22:47 +01:00
|
|
|
- 17) + 'px' });
|
2009-11-04 23:13:20 +01:00
|
|
|
// Resize from field
|
2011-12-02 08:22:47 +01:00
|
|
|
$("fromSelect").setStyle({ width: (totalwidth
|
2009-11-04 23:13:20 +01:00
|
|
|
- $("fromField").getWidth()
|
2011-12-02 08:22:47 +01:00
|
|
|
- 15) + 'px' });
|
2009-08-04 17:42:02 +02:00
|
|
|
|
|
|
|
// Resize address fields
|
2013-12-18 22:36:49 +01:00
|
|
|
// var addresslist = $('addressList');
|
|
|
|
// addresslist.setStyle({ width: (totalwidth - 10) + 'px' });
|
2009-08-04 17:42:02 +02:00
|
|
|
|
|
|
|
// Resize the textarea (message content)
|
2012-02-10 04:17:52 +01:00
|
|
|
var offsetTop = $('rightPanel').offsetTop + headerarea.getHeight();
|
2009-11-29 05:19:32 +01:00
|
|
|
var composeMode = UserDefaults["SOGoMailComposeMessageType"];
|
2009-08-04 17:42:02 +02:00
|
|
|
if (composeMode == "html") {
|
|
|
|
var editor = $('cke_text');
|
|
|
|
if (editor == null) {
|
2011-12-14 04:13:00 +01:00
|
|
|
onWindowResize.defer();
|
2009-08-04 17:42:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-02-10 04:17:52 +01:00
|
|
|
var height = window.height() - offsetTop;
|
|
|
|
CKEDITOR.instances["text"].resize('100%', height);
|
2009-06-25 21:18:02 +02:00
|
|
|
}
|
2009-08-04 17:42:02 +02:00
|
|
|
else
|
2012-02-10 04:17:52 +01:00
|
|
|
textarea.rows = Math.floor((window.height() - offsetTop) / rowheight);
|
2011-12-02 08:22:47 +01:00
|
|
|
|
|
|
|
// Resize search contacts addressbook selector
|
|
|
|
if ($("contacts").visible())
|
|
|
|
$("contactFolder").setStyle({ width: ($("contactsSearch").getWidth() - 10) + "px" });
|
2009-08-04 17:42:02 +02:00
|
|
|
}
|
2009-07-31 15:52:29 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
function onMailEditorClose(event) {
|
2014-01-07 17:11:39 +01:00
|
|
|
var e = event || window.event;
|
|
|
|
|
|
|
|
if (window.shouldPreserve) {
|
2009-08-04 17:42:02 +02:00
|
|
|
window.shouldPreserve = false;
|
2014-01-07 17:11:39 +01:00
|
|
|
if (jQuery('#fileUpload').fileupload('active') > 0) {
|
|
|
|
var msg = _("There is an active file upload. Closing the window will interrupt it.");
|
|
|
|
if (e) {
|
|
|
|
e.returnValue = msg;
|
|
|
|
}
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
}
|
2009-07-31 15:52:29 +02:00
|
|
|
else {
|
2011-12-02 08:22:47 +01:00
|
|
|
var url = "" + window.location;
|
|
|
|
var parts = url.split("/");
|
|
|
|
parts[parts.length-1] = "delete";
|
|
|
|
url = parts.join("/");
|
|
|
|
if (window.frameElement && window.frameElement.id)
|
|
|
|
parent.deleteDraft(url);
|
|
|
|
else if (window.opener && window.opener.open && !window.opener.closed)
|
2009-08-04 17:42:02 +02:00
|
|
|
window.opener.deleteDraft(url);
|
2009-07-31 15:52:29 +02:00
|
|
|
}
|
2007-08-15 00:09:20 +02:00
|
|
|
|
2009-08-04 17:42:02 +02:00
|
|
|
Event.stopObserving(window, "beforeunload", onMailEditorClose);
|
2007-08-18 22:29:50 +02:00
|
|
|
}
|
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initMailEditor);
|