2008-08-28 16:48:45 +02:00
|
|
|
/* -*- Mode: java; tab-width: 2; c-tab-always-indent: t; indent-tabs-mode: t; c-basic-offset: 2 -*- */
|
|
|
|
|
2006-10-03 18:21:25 +02:00
|
|
|
var contactSelectorAction = 'mailer-contacts';
|
2007-11-20 18:00:08 +01:00
|
|
|
var signatureLength = 0;
|
2007-12-13 00:56:01 +01:00
|
|
|
|
|
|
|
var attachmentCount = 0;
|
2007-11-20 22:11:23 +01:00
|
|
|
var MailEditor = {
|
2008-08-28 16:48:45 +02:00
|
|
|
addressBook: null,
|
|
|
|
currentField: null,
|
|
|
|
selectedIndex: -1,
|
2008-09-02 20:44:48 +02:00
|
|
|
delay: 750,
|
2008-08-28 16:48:45 +02:00
|
|
|
delayedSearch: false
|
2007-11-20 22:11:23 +01:00
|
|
|
};
|
2006-10-03 18:21:25 +02:00
|
|
|
|
2007-03-29 20:04:41 +02:00
|
|
|
function onContactAdd() {
|
2008-08-28 16:48:45 +02:00
|
|
|
var selector = null;
|
|
|
|
var selectorURL = '?popup=YES&selectorId=mailer-contacts';
|
2007-03-29 20:04:41 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
if (MailEditor.addressBook && MailEditor.addressBook.open && !MailEditor.addressBook.closed)
|
|
|
|
MailEditor.addressBook.focus();
|
|
|
|
else {
|
|
|
|
var urlstr = ApplicationBaseURL
|
|
|
|
+ "../Contacts/"
|
|
|
|
+ contactSelectorAction + selectorURL;
|
|
|
|
MailEditor.addressBook = window.open(urlstr, "_blank",
|
|
|
|
"width=640,height=400,resizable=1,scrollbars=0");
|
|
|
|
MailEditor.addressBook.selector = selector;
|
|
|
|
MailEditor.addressBook.opener = self;
|
|
|
|
MailEditor.addressBook.focus();
|
|
|
|
}
|
2007-11-20 22:11:23 +01:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
return false;
|
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) {
|
2008-08-28 16:48:45 +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) {
|
|
|
|
fancyAddRow(false, "");
|
2008-09-09 20:44:25 +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);
|
2008-08-28 16:48:45 +02:00
|
|
|
onWindowResize(null);
|
|
|
|
}
|
|
|
|
}
|
2006-10-03 16:38:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function mailIsRecipient(mailto) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var isRecipient = false;
|
2006-10-03 16:38:51 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var counter = 0;
|
|
|
|
var currentRow = $('row_' + counter);
|
2006-10-03 16:38:51 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var email = extractEmailAddress(mailto).toUpperCase();
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
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
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
return isRecipient;
|
2006-10-03 16:38:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function insertContact(inputNode, contactName, contactEmail) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var value = '' + inputNode.value;
|
2006-10-03 16:38:51 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var newContact = contactName;
|
|
|
|
if (newContact.length > 0)
|
|
|
|
newContact += ' <' + contactEmail + '>';
|
|
|
|
else
|
|
|
|
newContact = contactEmail;
|
2006-10-03 16:38:51 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
if (value.length > 0)
|
|
|
|
value += ", ";
|
|
|
|
value += newContact;
|
2006-10-03 16:38:51 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
inputNode.value = value;
|
2006-09-20 19:58:42 +02:00
|
|
|
}
|
2006-10-18 23:53:47 +02:00
|
|
|
|
|
|
|
function toggleAttachments() {
|
2008-08-28 16:48:45 +02:00
|
|
|
var div = $("attachmentsArea");
|
|
|
|
var style = "" + div.getStyle("display");
|
|
|
|
if (style.length)
|
|
|
|
div.setStyle({ display: "" });
|
|
|
|
else
|
|
|
|
div.setStyle({ display: "block" });
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
return false;
|
2006-10-18 23:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateInlineAttachmentList(sender, attachments) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
var div = $("attachmentsArea");
|
|
|
|
if (attachments)
|
|
|
|
count = attachments.length;
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
var text = "";
|
|
|
|
for (var i = 0; i < count; i++) {
|
|
|
|
text = text + attachments[i];
|
|
|
|
text = text + '<br />';
|
|
|
|
}
|
|
|
|
|
|
|
|
var e = $('compose_attachments_list');
|
|
|
|
e.innerHTML = text;
|
|
|
|
var style = "" + div.getStyle("display");
|
|
|
|
if (!style.length)
|
|
|
|
div.setStyle({display: "block"});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
div.setStyle({display: ""});
|
2006-10-18 23:53:47 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
/* mail editor */
|
|
|
|
|
|
|
|
function validateEditorInput(sender) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var errortext = "";
|
|
|
|
var field;
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
field = document.pageform.subject;
|
|
|
|
if (field.value == "")
|
|
|
|
errortext = errortext + labels["error_missingsubject"] + "\n";
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
if (!hasRecipients())
|
|
|
|
errortext = errortext + labels["error_missingrecipients"] + "\n";
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
if (errortext.length > 0) {
|
|
|
|
alert(labels["error_validationfailed"] + ":\n" + errortext);
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-22 23:56:27 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
return true;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function clickedEditorSend(sender) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (!validateEditorInput(sender))
|
|
|
|
return false;
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var input = currentAttachmentInput();
|
|
|
|
if (input)
|
|
|
|
input.parentNode.removeChild(input);
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var toolbar = document.getElementById("toolbar");
|
|
|
|
if (!document.busyAnim)
|
|
|
|
document.busyAnim = startAnimation(toolbar);
|
2007-11-20 22:11:23 +01:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var lastRow = $("lastRow");
|
|
|
|
lastRow.down("select").name = "popup_last";
|
2008-08-15 10:20:34 +02:00
|
|
|
|
2008-10-16 20:07:09 +02:00
|
|
|
//window.shouldPreserve = true;
|
2008-08-28 16:48:45 +02:00
|
|
|
document.pageform.action = "send";
|
|
|
|
document.pageform.submit();
|
2007-11-26 22:16:00 +01:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
return false;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2007-10-25 19:34:27 +02:00
|
|
|
function currentAttachmentInput() {
|
2008-08-28 16:48:45 +02:00
|
|
|
var input = null;
|
2007-09-10 20:46:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var inputs = $("attachmentsArea").getElementsByTagName("input");
|
|
|
|
var i = 0;
|
|
|
|
while (!input && i < inputs.length)
|
|
|
|
if ($(inputs[i]).hasClassName("currentAttachment"))
|
|
|
|
input = inputs[i];
|
|
|
|
else
|
|
|
|
i++;
|
2007-09-10 20:46:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
return input;
|
2007-10-25 19:34:27 +02:00
|
|
|
}
|
2007-09-10 20:46:05 +02:00
|
|
|
|
2007-10-25 19:34:27 +02:00
|
|
|
function clickedEditorAttach(sender) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var input = currentAttachmentInput();
|
|
|
|
if (!input) {
|
|
|
|
var area = $("attachmentsArea");
|
|
|
|
|
|
|
|
if (!area.style.display) {
|
|
|
|
area.setStyle({ display: "block" });
|
|
|
|
onWindowResize(null);
|
|
|
|
}
|
|
|
|
var inputs = area.getElementsByTagName("input");
|
|
|
|
var attachmentName = "attachment" + attachmentCount;
|
|
|
|
var newAttachment = createElement("input", attachmentName,
|
|
|
|
"currentAttachment", null,
|
|
|
|
{ type: "file",
|
|
|
|
name: attachmentName },
|
|
|
|
area);
|
|
|
|
attachmentCount++;
|
|
|
|
newAttachment.observe("change",
|
|
|
|
onAttachmentChange.bindAsEventListener(newAttachment));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onAddAttachment() {
|
2008-08-28 16:48:45 +02:00
|
|
|
return clickedEditorAttach(null);
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onAttachmentChange(event) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (this.value == "")
|
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
else {
|
|
|
|
this.addClassName("attachment");
|
|
|
|
this.removeClassName("currentAttachment");
|
|
|
|
var list = $("attachments");
|
|
|
|
createAttachment(this, list);
|
|
|
|
clickedEditorAttach(null);
|
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function createAttachment(node, list) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var attachment = createElement("li", null, null, { node: node }, null, list);
|
|
|
|
createElement("img", null, null, { src: ResourcesURL + "/attachment.gif" },
|
|
|
|
null, attachment);
|
|
|
|
attachment.observe("click", onRowClick);
|
|
|
|
|
|
|
|
var filename = node.value;
|
|
|
|
var separator;
|
|
|
|
if (navigator.appVersion.indexOf("Windows") > -1)
|
|
|
|
separator = "\\";
|
|
|
|
else
|
|
|
|
separator = "/";
|
|
|
|
var fileArray = filename.split(separator);
|
|
|
|
var attachmentName = document.createTextNode(fileArray[fileArray.length-1]);
|
|
|
|
attachment.appendChild(attachmentName);
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function clickedEditorSave(sender) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var input = currentAttachmentInput();
|
|
|
|
if (input)
|
|
|
|
input.parentNode.removeChild(input);
|
2007-10-25 19:56:47 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var lastRow = $("lastRow");
|
|
|
|
lastRow.down("select").name = "popup_last";
|
2008-08-15 10:20:34 +02:00
|
|
|
|
2008-10-16 20:07:09 +02:00
|
|
|
//window.shouldPreserve = true;
|
2008-08-28 16:48:45 +02:00
|
|
|
document.pageform.action = "save";
|
|
|
|
document.pageform.submit();
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
if (window.opener && window.open && !window.closed)
|
|
|
|
window.opener.refreshFolderByType('draft');
|
|
|
|
return false;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2007-11-20 18:00:08 +01:00
|
|
|
function onTextFocus() {
|
2008-08-28 16:48:45 +02:00
|
|
|
var input = currentAttachmentInput();
|
|
|
|
if (input)
|
|
|
|
input.parentNode.removeChild(input);
|
2007-12-07 00:55:39 +01:00
|
|
|
}
|
|
|
|
|
2008-08-28 00:50:12 +02:00
|
|
|
function onTextKeyDown(event) {
|
2008-09-02 20:44:48 +02:00
|
|
|
if (event.keyCode == Event.KEY_TAB) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (event.shiftKey) {
|
|
|
|
var nodes = $("subjectRow").childNodesWithTag("input");
|
|
|
|
var objectInput = $(nodes[0]);
|
|
|
|
objectInput.focus();
|
|
|
|
objectInput.selectText(0, objectInput.value.length);
|
|
|
|
preventDefault(event);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!(event.shiftKey || event.metaKey || event.ctrlKey)) {
|
2008-08-29 04:49:43 +02:00
|
|
|
if (typeof(this.selectionStart)
|
|
|
|
!= "undefined") { // For Mozilla and Safari
|
|
|
|
var cursor = this.selectionStart;
|
|
|
|
var startText = ((cursor > 0)
|
|
|
|
? this.value.substr(0, cursor)
|
|
|
|
: "");
|
|
|
|
var endText = this.value.substr(cursor);
|
|
|
|
var newText = startText + " " + endText;
|
|
|
|
this.value = newText;
|
|
|
|
cursor += 3;
|
|
|
|
this.setSelectionRange(cursor, cursor);
|
2008-08-28 16:48:45 +02:00
|
|
|
}
|
|
|
|
else if (this.selectionRange) // IE
|
|
|
|
this.selectionRange.text = " ";
|
|
|
|
else { // others ?
|
|
|
|
}
|
|
|
|
preventDefault(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-28 00:50:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTextIEUpdateCursorPos(event) {
|
2008-08-28 16:48:45 +02:00
|
|
|
this.selectionRange = document.selection.createRange().duplicate();
|
2008-08-28 00:50:12 +02:00
|
|
|
}
|
|
|
|
|
2007-12-07 00:55:39 +01:00
|
|
|
function onTextFirstFocus() {
|
2008-08-28 16:48:45 +02:00
|
|
|
var content = this.getValue();
|
2008-09-28 21:49:17 +02:00
|
|
|
var signaturePlacement = userDefaults["SignaturePlacement"];
|
|
|
|
if ( typeof(signaturePlacement) == "undefined" ) {
|
|
|
|
signaturePlacement = "below";
|
|
|
|
}
|
|
|
|
var replyPlacement = userDefaults["ReplyPlacement"];
|
|
|
|
if ( typeof(replyPlacement) == "undefined" ) {
|
|
|
|
replyPlacement = signaturePlacement;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( replyPlacement == "above" ) {
|
2008-10-06 17:44:05 +02:00
|
|
|
this.insertBefore(document.createTextNode("\r\r"), this.lastChild);
|
2008-09-28 21:49:17 +02:00
|
|
|
this.setCaretTo(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.setCaretTo(this.getValue().length - signatureLength - 2);
|
|
|
|
}
|
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
Event.stopObserving(this, "focus", onTextFirstFocus);
|
2007-11-20 18:00:08 +01:00
|
|
|
}
|
|
|
|
|
2008-01-31 17:07:09 +01:00
|
|
|
function onTextContextMenu(event) {
|
2008-08-28 16:48:45 +02:00
|
|
|
event.returnValue = true;
|
|
|
|
event.cancelBubble = true;
|
2008-01-31 17:07:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTextMouseDown(event) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (event.button == 0) {
|
|
|
|
event.returnValue = false;
|
|
|
|
event.cancelBubble = false;
|
|
|
|
}
|
2008-01-31 17:07:09 +01:00
|
|
|
}
|
|
|
|
|
2008-07-04 11:43:28 +02:00
|
|
|
/* address completion */
|
|
|
|
|
2008-07-03 23:26:05 +02:00
|
|
|
function onContactKeydown(event) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
this.focussed = true;
|
|
|
|
return;
|
|
|
|
}
|
2008-09-02 20:44:48 +02:00
|
|
|
if (event.keyCode == Event.KEY_TAB) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (this.confirmedValue)
|
|
|
|
this.value = this.confirmedValue;
|
|
|
|
if (document.currentPopupMenu)
|
|
|
|
hideMenu(document.currentPopupMenu);
|
|
|
|
}
|
|
|
|
else if (event.keyCode == 0
|
2008-09-02 20:44:48 +02:00
|
|
|
|| event.keyCode == Event.KEY_BACKSPACE
|
2008-08-28 16:48:45 +02:00
|
|
|
|| event.keyCode == 32 // Space
|
|
|
|
|| event.keyCode > 47) {
|
|
|
|
this.confirmedValue = null;
|
|
|
|
MailEditor.selectedIndex = -1;
|
|
|
|
MailEditor.currentField = this;
|
2008-09-02 21:15:58 +02:00
|
|
|
if (this.value.length > 1) {
|
|
|
|
if (MailEditor.delayedSearch) window.clearTimeout(MailEditor.delayedSearch);
|
|
|
|
MailEditor.delayedSearch = window.setTimeout("performSearch()", MailEditor.delay);
|
2008-08-28 16:48:45 +02:00
|
|
|
}
|
2008-09-02 21:15:58 +02:00
|
|
|
else if (this.value.length <= 1) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (document.currentPopupMenu)
|
|
|
|
hideMenu(document.currentPopupMenu);
|
|
|
|
}
|
|
|
|
}
|
2008-09-02 20:44:48 +02:00
|
|
|
else if (event.keyCode == Event.KEY_RETURN) {
|
2008-08-28 16:48:45 +02:00
|
|
|
preventDefault(event);
|
|
|
|
if (this.confirmedValue)
|
|
|
|
this.value = this.confirmedValue;
|
2008-09-02 20:44:48 +02:00
|
|
|
$(this).select();
|
2008-08-28 16:48:45 +02:00
|
|
|
if (document.currentPopupMenu)
|
|
|
|
hideMenu(document.currentPopupMenu);
|
|
|
|
MailEditor.selectedIndex = -1;
|
|
|
|
}
|
|
|
|
else if ($('contactsMenu').getStyle('visibility') == 'visible') {
|
2008-09-02 20:44:48 +02:00
|
|
|
if (event.keyCode == Event.KEY_UP) { // Up arrow
|
2008-08-28 16:48:45 +02:00
|
|
|
if (MailEditor.selectedIndex > 0) {
|
|
|
|
var contacts = $('contactsMenu').select("li");
|
|
|
|
contacts[MailEditor.selectedIndex--].removeClassName("selected");
|
2008-10-04 01:12:11 +02:00
|
|
|
this.value = contacts[MailEditor.selectedIndex].readAttribute("address");
|
2008-08-28 16:48:45 +02:00
|
|
|
contacts[MailEditor.selectedIndex].addClassName("selected");
|
|
|
|
}
|
|
|
|
}
|
2008-09-02 20:44:48 +02:00
|
|
|
else if (event.keyCode == Event.KEY_DOWN) { // Down arrow
|
2008-08-28 16:48:45 +02:00
|
|
|
var contacts = $('contactsMenu').select("li");
|
|
|
|
if (contacts.size() - 1 > MailEditor.selectedIndex) {
|
|
|
|
if (MailEditor.selectedIndex >= 0)
|
|
|
|
contacts[MailEditor.selectedIndex].removeClassName("selected");
|
|
|
|
MailEditor.selectedIndex++;
|
2008-10-04 01:12:11 +02:00
|
|
|
this.value = contacts[MailEditor.selectedIndex].readAttribute("address");
|
2008-08-28 16:48:45 +02:00
|
|
|
contacts[MailEditor.selectedIndex].addClassName("selected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 23:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function performSearch() {
|
2008-08-28 16:48:45 +02:00
|
|
|
// Perform address completion
|
|
|
|
if (MailEditor.currentField) {
|
|
|
|
if (document.contactLookupAjaxRequest) {
|
|
|
|
// Abort any pending request
|
|
|
|
document.contactLookupAjaxRequest.aborted = true;
|
|
|
|
document.contactLookupAjaxRequest.abort();
|
|
|
|
}
|
2008-09-02 20:44:48 +02:00
|
|
|
if (MailEditor.currentField.value.trim().length > 1) {
|
2008-09-09 21:50:22 +02:00
|
|
|
var urlstr = (UserFolderURL + "Contacts/allContactSearch?search="
|
|
|
|
+ encodeURIComponent(MailEditor.currentField.value));
|
2008-08-28 16:48:45 +02:00
|
|
|
document.contactLookupAjaxRequest =
|
|
|
|
triggerAjaxRequest(urlstr, performSearchCallback, MailEditor.currentField);
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 23:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function performSearchCallback(http) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (http.readyState == 4) {
|
|
|
|
var menu = $('contactsMenu');
|
|
|
|
var list = menu.down("ul");
|
2008-07-03 23:26:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var input = http.callbackData;
|
2008-07-03 23:26:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
if (http.status == 200) {
|
|
|
|
var start = input.value.length;
|
|
|
|
var data = http.responseText.evalJSON(true);
|
2008-10-04 01:12:11 +02:00
|
|
|
|
|
|
|
if (data.contacts.length > 1) {
|
2008-08-28 16:48:45 +02:00
|
|
|
list.select("li").each(function(item) {
|
|
|
|
item.remove();
|
|
|
|
});
|
2008-07-03 23:26:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
// Populate popup menu
|
2008-10-04 01:12:11 +02:00
|
|
|
for (var i = 0; i < data.contacts.length; i++) {
|
|
|
|
var contact = data.contacts[i];
|
2008-08-28 16:48:45 +02:00
|
|
|
var completeEmail = contact["displayName"] + " <" + contact["mail"] + ">";
|
2008-10-04 01:12:11 +02:00
|
|
|
var node = new Element('li', { 'address': completeEmail });
|
|
|
|
var matchPosition = completeEmail.toLowerCase().indexOf(data.searchText.toLowerCase());
|
|
|
|
var matchBefore = completeEmail.substring(0, matchPosition);
|
|
|
|
var matchText = completeEmail.substring(matchPosition, matchPosition + data.searchText.length);
|
|
|
|
var matchAfter = completeEmail.substring(matchPosition + data.searchText.length);
|
2008-08-28 16:48:45 +02:00
|
|
|
list.appendChild(node);
|
|
|
|
node.uid = contact["c_uid"];
|
2008-10-04 01:12:11 +02:00
|
|
|
node.appendChild(document.createTextNode(matchBefore));
|
|
|
|
node.appendChild(new Element('strong').update(matchText));
|
|
|
|
node.appendChild(document.createTextNode(matchAfter));
|
|
|
|
if (contact["contactInfo"])
|
|
|
|
node.appendChild(document.createTextNode(" (" + contact["contactInfo"] + ")"));
|
2008-08-28 16:48:45 +02:00
|
|
|
$(node).observe("mousedown", onAddressResultClick);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show popup menu
|
|
|
|
var offsetScroll = Element.cumulativeScrollOffset(MailEditor.currentField);
|
|
|
|
var offset = Element.cumulativeOffset(MailEditor.currentField);
|
|
|
|
var top = offset[1] - offsetScroll[1] + node.offsetHeight + 3;
|
|
|
|
var height = 'auto';
|
|
|
|
var heightDiff = window.height() - offset[1];
|
|
|
|
var nodeHeight = node.getHeight();
|
|
|
|
|
2008-10-04 01:12:11 +02:00
|
|
|
if ((data.contacts.length * nodeHeight) > heightDiff)
|
2008-08-28 16:48:45 +02:00
|
|
|
// Limit the size of the popup to the window height, minus 12 pixels
|
|
|
|
height = parseInt(heightDiff/nodeHeight) * nodeHeight - 12 + 'px';
|
|
|
|
|
|
|
|
menu.setStyle({ top: top + "px",
|
|
|
|
left: offset[0] + "px",
|
|
|
|
height: height,
|
|
|
|
visibility: "visible" });
|
|
|
|
menu.scrollTop = 0;
|
|
|
|
|
|
|
|
document.currentPopupMenu = menu;
|
|
|
|
$(document.body).observe("click", onBodyClickMenuHandler);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (document.currentPopupMenu)
|
|
|
|
hideMenu(document.currentPopupMenu);
|
|
|
|
|
2008-10-04 01:12:11 +02:00
|
|
|
if (data.contacts.length == 1) {
|
2008-08-28 16:48:45 +02:00
|
|
|
// Single result
|
2008-10-04 01:12:11 +02:00
|
|
|
var contact = data.contacts[0];
|
2008-08-28 16:48:45 +02:00
|
|
|
if (contact["c_uid"].length > 0)
|
|
|
|
input.uid = contact["c_uid"];
|
|
|
|
var completeEmail = contact["displayName"] + " <" + contact["mail"] + ">";
|
|
|
|
if (contact["displayName"].substring(0, input.value.length).toUpperCase()
|
|
|
|
== input.value.toUpperCase())
|
|
|
|
input.value = completeEmail;
|
|
|
|
else
|
|
|
|
// The result matches email address, not user name
|
|
|
|
input.value += ' >> ' + completeEmail;
|
|
|
|
input.confirmedValue = completeEmail;
|
2008-07-04 11:43:28 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var end = input.value.length;
|
|
|
|
$(input).selectText(start, end);
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
MailEditor.selectedIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (document.currentPopupMenu)
|
|
|
|
hideMenu(document.currentPopupMenu);
|
|
|
|
document.contactLookupAjaxRequest = null;
|
|
|
|
}
|
2008-07-03 23:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onAddressResultClick(event) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (MailEditor.currentField) {
|
|
|
|
MailEditor.currentField.uid = this.uid;
|
2008-10-04 01:12:11 +02:00
|
|
|
MailEditor.currentField.value = $(this).readAttribute("address");
|
2008-08-28 16:48:45 +02:00
|
|
|
MailEditor.currentField.confirmedValue = MailEditor.currentField.value;
|
|
|
|
}
|
2008-07-03 23:26:05 +02:00
|
|
|
}
|
|
|
|
|
2008-06-30 22:05:48 +02:00
|
|
|
function initTabIndex(addressList, subjectField, msgArea) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var i = 1;
|
|
|
|
addressList.select("input.textField").each(function (input) {
|
|
|
|
if (!input.readAttribute("readonly")) {
|
|
|
|
input.writeAttribute("tabindex", i++);
|
|
|
|
input.writeAttribute("autocomplete", "off");
|
|
|
|
input.observe("keydown", onContactKeydown); // bind listener for address completion
|
|
|
|
}
|
|
|
|
});
|
|
|
|
subjectField.writeAttribute("tabindex", i++);
|
|
|
|
msgArea.writeAttribute("tabindex", i);
|
2008-06-30 22:05:48 +02:00
|
|
|
}
|
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
function initMailEditor() {
|
2008-08-28 16:48:45 +02:00
|
|
|
var list = $("attachments");
|
|
|
|
$(list).attachMenu("attachmentsMenu");
|
|
|
|
var elements = $(list).childNodesWithTag("li");
|
|
|
|
for (var i = 0; i < elements.length; i++)
|
|
|
|
elements[i].observe("click", onRowClick);
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var listContent = $("attachments").childNodesWithTag("li");
|
|
|
|
if (listContent.length > 0)
|
|
|
|
$("attachmentsArea").setStyle({ display: "block" });
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var textarea = $("text");
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var textContent = textarea.getValue();
|
|
|
|
var sigLimit = textContent.lastIndexOf("--");
|
|
|
|
if (sigLimit > -1)
|
|
|
|
signatureLength = (textContent.length - sigLimit);
|
2008-09-30 15:42:48 +02:00
|
|
|
if ( userDefaults["ReplyPlacement"] != "above" ) {
|
2008-09-30 00:01:44 +02:00
|
|
|
textarea.scrollTop = textarea.scrollHeight;
|
|
|
|
}
|
2008-08-28 16:48:45 +02:00
|
|
|
textarea.observe("focus", onTextFirstFocus);
|
|
|
|
textarea.observe("focus", onTextFocus);
|
|
|
|
// textarea.observe("contextmenu", onTextContextMenu);
|
|
|
|
textarea.observe("mousedown", onTextMouseDown, true);
|
|
|
|
textarea.observe("keydown", onTextKeyDown);
|
2008-08-28 00:50:12 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
if (Prototype.Browser.IE) {
|
|
|
|
var ieEvents = [ "click", "select", "keyup" ];
|
|
|
|
for (var i = 0; i < ieEvents.length; i++)
|
|
|
|
textarea.observe(ieEvents[i], onTextIEUpdateCursorPos, false);
|
|
|
|
}
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2008-09-02 20:44:48 +02:00
|
|
|
var subjectField = $$("div#subjectRow input").first();
|
|
|
|
initTabIndex($("addressList"), subjectField, textarea);
|
2008-08-28 16:48:45 +02:00
|
|
|
onWindowResize(null);
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
Event.observe(window, "resize", onWindowResize);
|
|
|
|
Event.observe(window, "beforeunload", onMailEditorClose);
|
2008-08-28 00:01:41 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var focusField = (mailIsReply ? textarea : $("addr_0"));
|
|
|
|
focusField.focus();
|
2008-09-28 16:02:40 +02:00
|
|
|
|
|
|
|
initializePriorityMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
function initializePriorityMenu() {
|
|
|
|
var priority = $("priority").value.toUpperCase();
|
|
|
|
var priorityMenu = $("priority-menu").childNodesWithTag("ul")[0];
|
|
|
|
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");
|
|
|
|
|
|
|
|
var menuItems = $("itemPriorityList").childNodesWithTag("li");
|
|
|
|
for (var i = 0; i < menuItems.length; i++)
|
|
|
|
menuItems[i].observe("mousedown",
|
|
|
|
onMenuSetPriority.bindAsEventListener(menuItems[i]),
|
|
|
|
false);
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getMenus() {
|
2008-08-28 16:48:45 +02:00
|
|
|
return { "attachmentsMenu": new Array(null, onRemoveAttachments,
|
|
|
|
onSelectAllAttachments,
|
|
|
|
"-",
|
|
|
|
onAddAttachment, null) };
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onRemoveAttachments() {
|
2008-08-28 16:48:45 +02:00
|
|
|
var list = $("attachments");
|
|
|
|
var nodes = list.getSelectedNodes();
|
|
|
|
for (var i = nodes.length-1; i > -1; i--) {
|
|
|
|
var input = $(nodes[i]).node;
|
|
|
|
if (input) {
|
|
|
|
input.parentNode.removeChild(input);
|
|
|
|
list.removeChild(nodes[i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var filename = "";
|
|
|
|
var childNodes = nodes[i].childNodes;
|
|
|
|
for (var j = 0; j < childNodes.length; j++) {
|
|
|
|
if (childNodes[j].nodeType == 3)
|
|
|
|
filename += childNodes[j].nodeValue;
|
|
|
|
}
|
|
|
|
var url = "" + window.location;
|
|
|
|
var parts = url.split("/");
|
|
|
|
parts[parts.length-1] = "deleteAttachment?filename=" + encodeURIComponent(filename);
|
|
|
|
url = parts.join("/");
|
|
|
|
triggerAjaxRequest(url, attachmentDeleteCallback,
|
|
|
|
nodes[i]);
|
|
|
|
}
|
|
|
|
}
|
2007-08-18 22:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function attachmentDeleteCallback(http) {
|
2008-08-28 16:48:45 +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
|
|
|
}
|
|
|
|
|
2008-09-28 16:02:40 +02:00
|
|
|
function onMenuSetPriority(event) {
|
|
|
|
event.cancelBubble = true;
|
|
|
|
|
|
|
|
var priority = this.getAttribute("priority");
|
|
|
|
if (this.parentNode.chosenNode)
|
|
|
|
this.parentNode.chosenNode.removeClassName("_chosen");
|
|
|
|
this.addClassName("_chosen");
|
|
|
|
this.parentNode.chosenNode = this;
|
|
|
|
|
|
|
|
var priorityInput = $("priority");
|
|
|
|
priorityInput.value = priority;
|
|
|
|
}
|
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
function onSelectAllAttachments() {
|
2008-08-28 16:48:45 +02:00
|
|
|
var list = $("attachments");
|
|
|
|
var nodes = list.childNodesWithTag("li");
|
|
|
|
for (var i = 0; i < nodes.length; i++)
|
|
|
|
nodes[i].selectElement();
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2008-09-28 16:02:40 +02:00
|
|
|
function onSelectPriority(event) {
|
|
|
|
if (event.button == 0 || (isSafari() && event.button == 1)) {
|
|
|
|
var node = getTarget(event);
|
|
|
|
if (node.tagName != 'BUTTON')
|
|
|
|
node = $(node).up("button");
|
|
|
|
popupToolbarMenu(node, "priority-menu");
|
|
|
|
Event.stop(event);
|
|
|
|
// preventDefault(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-15 00:09:20 +02:00
|
|
|
function onWindowResize(event) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var textarea = document.pageform.text;
|
|
|
|
var rowheight = (Element.getHeight(textarea) / textarea.rows);
|
|
|
|
var headerarea = $("headerArea");
|
2007-09-10 20:46:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var attachmentsarea = $("attachmentsArea");
|
|
|
|
var attachmentswidth = 0;
|
|
|
|
if (attachmentsarea.style.display) {
|
|
|
|
attachmentswidth = attachmentsarea.getWidth();
|
|
|
|
// Resize of attachment list is b0rken under IE7
|
|
|
|
// fromfield = $(document).getElementsByClassName('headerField',
|
|
|
|
// headerarea)[0];
|
|
|
|
// $("attachments").setStyle({ height: (headerarea.getHeight() - fromfield.getHeight() - 10) + 'px' });
|
|
|
|
}
|
|
|
|
var subjectfield = headerarea.down("div#subjectRow span.headerField");
|
|
|
|
var subjectinput = headerarea.down("div#subjectRow input.textField");
|
2008-06-30 20:43:57 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
// Resize subject field
|
|
|
|
subjectinput.setStyle({ width: (window.width()
|
|
|
|
- $(subjectfield).getWidth()
|
|
|
|
- attachmentswidth
|
|
|
|
- 16) + 'px' });
|
2007-09-10 20:46:05 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
// Resize address fields
|
|
|
|
var addresslist = $('addressList');
|
|
|
|
addresslist.setStyle({ width: ($(this).width() - attachmentswidth - 10) + 'px' });
|
2007-11-02 16:09:44 +01:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
// Set textarea position
|
2008-09-02 20:44:48 +02:00
|
|
|
var hr = headerarea.select("hr").first();
|
|
|
|
textarea.setStyle({ 'top': hr.offsetTop + 'px' });
|
2007-11-02 16:09:44 +01:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
// Resize the textarea (message content)
|
2008-09-02 20:44:48 +02:00
|
|
|
textarea.rows = Math.floor((window.height() - textarea.offsetTop) / rowheight);
|
2007-08-15 00:09:20 +02:00
|
|
|
}
|
|
|
|
|
2007-08-18 22:29:50 +02:00
|
|
|
function onMailEditorClose(event) {
|
2008-10-16 20:07:09 +02:00
|
|
|
// if (window.shouldPreserve)
|
|
|
|
// window.shouldPreserve = false;
|
|
|
|
// else {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (window.opener && window.opener.open && !window.opener.closed) {
|
|
|
|
var url = "" + window.location;
|
|
|
|
var parts = url.split("/");
|
|
|
|
parts[parts.length-1] = "delete";
|
|
|
|
url = parts.join("/");
|
|
|
|
window.opener.deleteDraft(url);
|
|
|
|
}
|
2008-10-16 20:07:09 +02:00
|
|
|
// }
|
2008-08-28 16:48:45 +02:00
|
|
|
|
|
|
|
if (MailEditor.addressBook && MailEditor.addressBook.open
|
|
|
|
&& !MailEditor.addressBook.closed)
|
|
|
|
MailEditor.addressBook.close();
|
|
|
|
|
|
|
|
Event.stopObserving(window, "beforeunload", onMailEditorClose);
|
2007-08-18 22:29:50 +02:00
|
|
|
}
|
|
|
|
|
2007-11-15 20:02:23 +01:00
|
|
|
FastInit.addOnLoad(initMailEditor);
|