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-07-03 23:26:05 +02:00
|
|
|
addressBook: null,
|
|
|
|
currentField: null,
|
|
|
|
selectedIndex: -1,
|
|
|
|
delay: 500,
|
|
|
|
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() {
|
|
|
|
var selector = null;
|
|
|
|
var selectorURL = '?popup=YES&selectorId=mailer-contacts';
|
|
|
|
|
2007-11-21 16:04:37 +01:00
|
|
|
if (MailEditor.addressBook && MailEditor.addressBook.open && !MailEditor.addressBook.closed)
|
2007-11-20 22:11:23 +01:00
|
|
|
MailEditor.addressBook.focus();
|
|
|
|
else {
|
2007-11-21 16:04:37 +01:00
|
|
|
var urlstr = ApplicationBaseURL
|
2007-11-20 22:11:23 +01:00
|
|
|
+ "../Contacts/"
|
|
|
|
+ contactSelectorAction + selectorURL;
|
|
|
|
MailEditor.addressBook = window.open(urlstr, "_blank",
|
|
|
|
"width=640,height=400,resizable=1,scrollbars=0");
|
|
|
|
MailEditor.addressBook.selector = selector;
|
2007-11-21 16:04:37 +01:00
|
|
|
MailEditor.addressBook.opener = self;
|
2007-11-20 22:11:23 +01:00
|
|
|
MailEditor.addressBook.focus();
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:04:41 +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) {
|
2006-10-03 16:38:51 +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);
|
2007-08-15 00:09:20 +02:00
|
|
|
while (currentRow && !stop) {
|
2007-11-02 19:18:15 +01:00
|
|
|
var currentValue = $(currentRow.childNodesWithTag("td")[1]).childNodesWithTag("input")[0].value;
|
2006-10-03 16:38:51 +02:00
|
|
|
if (currentValue == neededOptionValue) {
|
|
|
|
stop = true;
|
|
|
|
insertContact($("addr_" + counter), contactName, contactEmail);
|
|
|
|
}
|
|
|
|
counter++;
|
|
|
|
currentRow = $('row_' + counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stop) {
|
|
|
|
fancyAddRow(false, "");
|
2007-11-02 19:18:15 +01:00
|
|
|
$($("row_" + counter).childNodesWithTag("td")[0]).childNodesWithTag("select")[0].value
|
2006-10-03 16:38:51 +02:00
|
|
|
= neededOptionValue;
|
|
|
|
insertContact($("addr_" + counter), contactName, contactEmail);
|
2007-11-02 19:18:15 +01:00
|
|
|
onWindowResize(null);
|
2006-10-03 16:38:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mailIsRecipient(mailto) {
|
|
|
|
var isRecipient = false;
|
|
|
|
|
|
|
|
var counter = 0;
|
|
|
|
var currentRow = $('row_' + counter);
|
|
|
|
|
2006-10-03 18:30:11 +02:00
|
|
|
var email = extractEmailAddress(mailto).toUpperCase();
|
2006-10-03 16:38:51 +02:00
|
|
|
|
|
|
|
while (currentRow && !isRecipient) {
|
2006-10-03 18:30:11 +02:00
|
|
|
var currentValue = $("addr_"+counter).value.toUpperCase();
|
2006-10-03 16:38:51 +02:00
|
|
|
if (currentValue.indexOf(email) > -1)
|
|
|
|
isRecipient = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
currentRow = $('row_' + counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return isRecipient;
|
|
|
|
}
|
|
|
|
|
|
|
|
function insertContact(inputNode, contactName, contactEmail) {
|
|
|
|
var value = '' + inputNode.value;
|
|
|
|
|
|
|
|
var newContact = contactName;
|
|
|
|
if (newContact.length > 0)
|
|
|
|
newContact += ' <' + contactEmail + '>';
|
|
|
|
else
|
|
|
|
newContact = contactEmail;
|
|
|
|
|
|
|
|
if (value.length > 0)
|
|
|
|
value += ", ";
|
|
|
|
value += newContact;
|
|
|
|
|
|
|
|
inputNode.value = value;
|
2006-09-20 19:58:42 +02:00
|
|
|
}
|
2006-10-18 23:53:47 +02:00
|
|
|
|
|
|
|
function toggleAttachments() {
|
|
|
|
var div = $("attachmentsArea");
|
2008-05-06 00:30:06 +02:00
|
|
|
var style = "" + div.getStyle("display");
|
|
|
|
if (style.length)
|
|
|
|
div.setStyle({ display: "" });
|
2006-10-18 23:53:47 +02:00
|
|
|
else
|
2008-05-06 00:30:06 +02:00
|
|
|
div.setStyle({ display: "block" });
|
2006-10-18 23:53:47 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateInlineAttachmentList(sender, attachments) {
|
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
var div = $("attachmentsArea");
|
|
|
|
if (attachments)
|
|
|
|
count = attachments.length;
|
|
|
|
|
2008-05-06 00:30:06 +02:00
|
|
|
if (count) {
|
|
|
|
var text = "";
|
|
|
|
for (var i = 0; i < count; i++) {
|
|
|
|
text = text + attachments[i];
|
|
|
|
text = text + '<br />';
|
2006-10-18 23:53:47 +02:00
|
|
|
}
|
2008-05-06 00:30:06 +02:00
|
|
|
|
|
|
|
var e = $('compose_attachments_list');
|
|
|
|
e.innerHTML = text;
|
|
|
|
var style = "" + div.getStyle("display");
|
|
|
|
if (!style.length)
|
|
|
|
div.setStyle({display: "block"});
|
|
|
|
}
|
2006-10-18 23:53:47 +02:00
|
|
|
else
|
2008-05-06 00:30:06 +02:00
|
|
|
div.setStyle({display: ""});
|
2006-10-18 23:53:47 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
/* mail editor */
|
|
|
|
|
|
|
|
function validateEditorInput(sender) {
|
2007-10-25 19:56:47 +02:00
|
|
|
var errortext = "";
|
|
|
|
var field;
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2007-10-25 19:56:47 +02:00
|
|
|
field = document.pageform.subject;
|
|
|
|
if (field.value == "")
|
|
|
|
errortext = errortext + labels["error_missingsubject"] + "\n";
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2007-11-05 15:37:26 +01:00
|
|
|
if (!hasRecipients())
|
2007-10-25 19:56:47 +02:00
|
|
|
errortext = errortext + labels["error_missingrecipients"] + "\n";
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2007-10-25 19:56:47 +02:00
|
|
|
if (errortext.length > 0) {
|
|
|
|
alert(labels["error_validationfailed"] + ":\n" + errortext);
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-22 23:56:27 +02:00
|
|
|
|
2007-10-25 19:56:47 +02:00
|
|
|
return true;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function clickedEditorSend(sender) {
|
2007-10-25 19:56:47 +02:00
|
|
|
if (!validateEditorInput(sender))
|
|
|
|
return false;
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2007-10-25 19:56:47 +02:00
|
|
|
var input = currentAttachmentInput();
|
|
|
|
if (input)
|
|
|
|
input.parentNode.removeChild(input);
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2007-10-25 19:56:47 +02:00
|
|
|
var toolbar = document.getElementById("toolbar");
|
|
|
|
if (!document.busyAnim)
|
|
|
|
document.busyAnim = startAnimation(toolbar);
|
2007-11-20 22:11:23 +01:00
|
|
|
|
2007-10-25 19:56:47 +02:00
|
|
|
window.shouldPreserve = true;
|
|
|
|
document.pageform.action = "send";
|
|
|
|
document.pageform.submit();
|
2007-11-26 22:16:00 +01:00
|
|
|
|
2007-10-25 19:56:47 +02:00
|
|
|
return false;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2007-10-25 19:34:27 +02:00
|
|
|
function currentAttachmentInput() {
|
|
|
|
var input = null;
|
2007-09-10 20:46:05 +02:00
|
|
|
|
2007-10-25 19:34:27 +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
|
|
|
|
2007-10-25 19:34:27 +02:00
|
|
|
return input;
|
|
|
|
}
|
2007-09-10 20:46:05 +02:00
|
|
|
|
2007-10-25 19:34:27 +02:00
|
|
|
function clickedEditorAttach(sender) {
|
|
|
|
var input = currentAttachmentInput();
|
|
|
|
if (!input) {
|
|
|
|
var area = $("attachmentsArea");
|
2007-09-29 02:22:11 +02:00
|
|
|
|
2007-10-25 19:34:27 +02:00
|
|
|
if (!area.style.display) {
|
|
|
|
area.setStyle({ display: "block" });
|
|
|
|
onWindowResize(null);
|
|
|
|
}
|
|
|
|
var inputs = area.getElementsByTagName("input");
|
2007-12-13 00:56:01 +01:00
|
|
|
var attachmentName = "attachment" + attachmentCount;
|
2007-10-25 19:34:27 +02:00
|
|
|
var newAttachment = createElement("input", attachmentName,
|
|
|
|
"currentAttachment", null,
|
|
|
|
{ type: "file",
|
|
|
|
name: attachmentName },
|
2007-10-25 19:56:47 +02:00
|
|
|
area);
|
2007-12-13 00:56:01 +01:00
|
|
|
attachmentCount++;
|
2008-04-15 22:12:51 +02:00
|
|
|
newAttachment.observe("change",
|
2007-10-25 19:34:27 +02:00
|
|
|
onAttachmentChange.bindAsEventListener(newAttachment));
|
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAddAttachment() {
|
2007-09-29 02:22:11 +02:00
|
|
|
return clickedEditorAttach(null);
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onAttachmentChange(event) {
|
|
|
|
if (this.value == "")
|
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
else {
|
|
|
|
this.addClassName("attachment");
|
|
|
|
this.removeClassName("currentAttachment");
|
|
|
|
var list = $("attachments");
|
|
|
|
createAttachment(this, list);
|
2007-12-07 00:55:39 +01:00
|
|
|
clickedEditorAttach(null)
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createAttachment(node, list) {
|
|
|
|
var attachment = createElement("li", null, null, { node: node }, null, list);
|
|
|
|
createElement("img", null, null, { src: ResourcesURL + "/attachment.gif" },
|
|
|
|
null, attachment);
|
2008-04-15 22:12:51 +02:00
|
|
|
attachment.observe("click", onRowClick);
|
2007-07-27 22:03:05 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickedEditorSave(sender) {
|
2007-10-25 19:34:27 +02:00
|
|
|
var input = currentAttachmentInput();
|
|
|
|
if (input)
|
|
|
|
input.parentNode.removeChild(input);
|
2007-10-25 19:56:47 +02:00
|
|
|
|
2007-08-18 22:29:50 +02:00
|
|
|
window.shouldPreserve = true;
|
2007-08-16 23:49:59 +02:00
|
|
|
document.pageform.action = "save";
|
|
|
|
document.pageform.submit();
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2007-10-30 20:56:50 +01:00
|
|
|
if (window.opener && window.open && !window.closed)
|
|
|
|
window.opener.refreshFolderByType('draft');
|
2007-07-27 22:03:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-11-20 18:00:08 +01:00
|
|
|
function onTextFocus() {
|
2007-12-07 00:55:39 +01:00
|
|
|
var input = currentAttachmentInput();
|
|
|
|
if (input)
|
|
|
|
input.parentNode.removeChild(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTextFirstFocus() {
|
2007-11-20 20:15:22 +01:00
|
|
|
var content = this.getValue();
|
|
|
|
if (content.lastIndexOf("--") == 0) {
|
2008-04-29 22:58:35 +02:00
|
|
|
this.insertBefore(document.createTextNode("\r"),
|
2007-11-20 20:15:22 +01:00
|
|
|
this.lastChild);
|
|
|
|
}
|
2007-11-20 18:00:08 +01:00
|
|
|
if (signatureLength > 0) {
|
2008-04-29 22:58:35 +02:00
|
|
|
var length = this.getValue().length - signatureLength - 2;
|
2007-11-27 17:29:57 +01:00
|
|
|
this.setCaretTo(length);
|
2007-11-20 18:00:08 +01:00
|
|
|
}
|
2007-12-07 00:55:39 +01: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) {
|
|
|
|
event.returnValue = true;
|
|
|
|
event.cancelBubble = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTextMouseDown(event) {
|
2008-02-05 16:06:49 +01: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) {
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
this.focussed = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event.keyCode == 9) { // Tab
|
|
|
|
if (this.confirmedValue)
|
|
|
|
this.value = this.confirmedValue;
|
|
|
|
if (document.currentPopupMenu)
|
|
|
|
hideMenu(document.currentPopupMenu);
|
|
|
|
}
|
|
|
|
else if (event.keyCode == 0
|
|
|
|
|| event.keyCode == 8 // Backspace
|
|
|
|
|| event.keyCode == 32 // Space
|
|
|
|
|| event.keyCode > 47) {
|
|
|
|
this.confirmedValue = null;
|
|
|
|
MailEditor.selectedIndex = -1;
|
|
|
|
MailEditor.currentField = this;
|
|
|
|
if (this.value.length > 0 && !MailEditor.delayedSearch) {
|
|
|
|
MailEditor.delayedSearch = true;
|
|
|
|
setTimeout("performSearch()", MailEditor.delay);
|
|
|
|
}
|
|
|
|
else if (this.value.length == 0) {
|
|
|
|
if (document.currentPopupMenu)
|
|
|
|
hideMenu(document.currentPopupMenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event.keyCode == 13) {
|
|
|
|
preventDefault(event);
|
|
|
|
if (this.confirmedValue)
|
|
|
|
this.value = this.confirmedValue;
|
|
|
|
$(this).selectText(0, this.value.length);
|
|
|
|
if (document.currentPopupMenu)
|
|
|
|
hideMenu(document.currentPopupMenu);
|
|
|
|
MailEditor.selectedIndex = -1;
|
|
|
|
}
|
2008-07-04 11:43:28 +02:00
|
|
|
else if ($('contactsMenu').getStyle('visibility') == 'visible') {
|
|
|
|
if (event.keyCode == 38) { // Up arrow
|
|
|
|
if (MailEditor.selectedIndex > 0) {
|
|
|
|
var contacts = $('contactsMenu').select("li");
|
|
|
|
contacts[MailEditor.selectedIndex--].removeClassName("selected");
|
|
|
|
this.value = contacts[MailEditor.selectedIndex].firstChild.nodeValue.trim();
|
|
|
|
contacts[MailEditor.selectedIndex].addClassName("selected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event.keyCode == 40) { // Down arrow
|
|
|
|
var contacts = $('contactsMenu').select("li");
|
|
|
|
if (contacts.size() - 1 > MailEditor.selectedIndex) {
|
|
|
|
if (MailEditor.selectedIndex >= 0)
|
|
|
|
contacts[MailEditor.selectedIndex].removeClassName("selected");
|
|
|
|
MailEditor.selectedIndex++;
|
|
|
|
this.value = contacts[MailEditor.selectedIndex].firstChild.nodeValue.trim();
|
|
|
|
contacts[MailEditor.selectedIndex].addClassName("selected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 23:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function performSearch() {
|
|
|
|
// Perform address completion
|
|
|
|
if (MailEditor.currentField) {
|
|
|
|
if (document.contactLookupAjaxRequest) {
|
|
|
|
// Abort any pending request
|
|
|
|
document.contactLookupAjaxRequest.aborted = true;
|
|
|
|
document.contactLookupAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
if (MailEditor.currentField.value.trim().length > 0) {
|
2008-07-04 11:43:28 +02:00
|
|
|
var urlstr = ( UserFolderURL + "Contacts/allContactSearch?search="
|
2008-07-09 04:01:32 +02:00
|
|
|
+ MailEditor.currentField.value ); log (urlstr);
|
|
|
|
// + escape(MailEditor.currentField.value) ); log (urlstr);
|
2008-07-03 23:26:05 +02:00
|
|
|
document.contactLookupAjaxRequest =
|
|
|
|
triggerAjaxRequest(urlstr, performSearchCallback, MailEditor.currentField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MailEditor.delayedSearch = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function performSearchCallback(http) {
|
|
|
|
if (http.readyState == 4) {
|
|
|
|
var menu = $('contactsMenu');
|
|
|
|
var list = menu.down("ul");
|
|
|
|
|
|
|
|
var input = http.callbackData;
|
|
|
|
|
|
|
|
if (http.status == 200) {
|
2008-07-04 11:43:28 +02:00
|
|
|
var start = input.value.length;
|
2008-07-03 23:26:05 +02:00
|
|
|
var data = http.responseText.evalJSON(true);
|
2008-07-04 11:43:28 +02:00
|
|
|
|
2008-07-03 23:26:05 +02:00
|
|
|
if (data.length > 1) {
|
2008-07-04 11:43:28 +02:00
|
|
|
list.select("li").each(function(item) {
|
2008-07-03 23:26:05 +02:00
|
|
|
item.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Populate popup menu
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
var contact = data[i];
|
2008-07-04 11:43:28 +02:00
|
|
|
var completeEmail = contact["displayName"] + " <" + contact["mail"] + ">";
|
2008-07-03 23:26:05 +02:00
|
|
|
var node = document.createElement("li");
|
|
|
|
list.appendChild(node);
|
2008-07-04 11:43:28 +02:00
|
|
|
node.uid = contact["c_uid"];
|
2008-07-03 23:26:05 +02:00
|
|
|
node.appendChild(document.createTextNode(completeEmail));
|
|
|
|
$(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';
|
2008-07-08 22:14:47 +02:00
|
|
|
var heightDiff = window.height() - offset[1];
|
|
|
|
var nodeHeight = node.getHeight();
|
|
|
|
|
|
|
|
if ((data.length * nodeHeight) > heightDiff)
|
|
|
|
// Limit the size of the popup to the window height, minus 12 pixels
|
|
|
|
height = parseInt(heightDiff/nodeHeight) * nodeHeight - 12 + 'px';
|
|
|
|
|
2008-07-03 23:26:05 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (data.length == 1) {
|
|
|
|
// Single result
|
|
|
|
var contact = data[0];
|
2008-07-04 11:43:28 +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()
|
2008-07-03 23:26:05 +02:00
|
|
|
== 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-07-03 23:26:05 +02:00
|
|
|
var end = input.value.length;
|
|
|
|
$(input).selectText(start, end);
|
2008-07-04 11:43:28 +02:00
|
|
|
|
|
|
|
MailEditor.selectedIndex = -1;
|
2008-07-03 23:26:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (document.currentPopupMenu)
|
|
|
|
hideMenu(document.currentPopupMenu);
|
|
|
|
document.contactLookupAjaxRequest = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAddressResultClick(event) {
|
|
|
|
if (MailEditor.currentField) {
|
|
|
|
MailEditor.currentField.uid = this.uid;
|
|
|
|
MailEditor.currentField.value = this.firstChild.nodeValue.trim();
|
|
|
|
MailEditor.currentField.confirmedValue = currentField.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-30 22:05:48 +02:00
|
|
|
function initTabIndex(addressList, subjectField, msgArea) {
|
|
|
|
|
|
|
|
var i = 1;
|
|
|
|
addressList.select("input.textField").each(function (input) {
|
2008-07-03 23:26:05 +02:00
|
|
|
if (!input.readAttribute("readonly")) {
|
2008-06-30 22:05:48 +02:00
|
|
|
input.writeAttribute("tabindex", i++);
|
2008-07-03 23:26:05 +02:00
|
|
|
input.writeAttribute("autocomplete", "off");
|
|
|
|
input.observe("keydown", onContactKeydown); // bind listener for address completion
|
|
|
|
}
|
2008-06-30 22:05:48 +02:00
|
|
|
});
|
|
|
|
subjectField.writeAttribute("tabindex", i++);
|
|
|
|
msgArea.writeAttribute("tabindex", i);
|
|
|
|
}
|
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
function initMailEditor() {
|
|
|
|
var list = $("attachments");
|
|
|
|
$(list).attachMenu("attachmentsMenu");
|
2008-05-06 00:30:06 +02:00
|
|
|
var elements = $(list).childNodesWithTag("li");
|
2008-03-07 23:10:17 +01:00
|
|
|
for (var i = 0; i < elements.length; i++)
|
|
|
|
elements[i].observe("click", onRowClick);
|
2007-08-18 22:29:50 +02:00
|
|
|
|
|
|
|
var listContent = $("attachments").childNodesWithTag("li");
|
|
|
|
if (listContent.length > 0)
|
|
|
|
$("attachmentsArea").setStyle({ display: "block" });
|
|
|
|
|
2007-11-02 16:09:44 +01:00
|
|
|
var list = $("addressList");
|
|
|
|
TableKit.Resizable.init(list, {'trueResize' : true, 'keepWidth' : true});
|
|
|
|
|
2007-11-20 18:00:08 +01:00
|
|
|
var textarea = $("text");
|
|
|
|
var textContent = textarea.getValue();
|
|
|
|
var sigLimit = textContent.lastIndexOf("--");
|
|
|
|
if (sigLimit > -1)
|
|
|
|
signatureLength = (textContent.length - sigLimit);
|
2007-11-27 17:29:57 +01:00
|
|
|
textarea.scrollTop = textarea.scrollHeight;
|
2007-12-07 00:55:39 +01:00
|
|
|
textarea.observe("focus", onTextFirstFocus);
|
2007-11-20 20:15:22 +01:00
|
|
|
textarea.observe("focus", onTextFocus);
|
2008-02-05 16:06:49 +01:00
|
|
|
// textarea.observe("contextmenu", onTextContextMenu);
|
|
|
|
textarea.observe("mousedown", onTextMouseDown, true);
|
2007-11-20 18:00:08 +01:00
|
|
|
|
2008-06-30 22:05:48 +02:00
|
|
|
initTabIndex(list, $$("div#subjectRow input").first(), textarea);
|
2007-08-15 00:09:20 +02:00
|
|
|
onWindowResize(null);
|
2008-06-30 22:05:48 +02:00
|
|
|
|
2007-08-15 00:09:20 +02:00
|
|
|
Event.observe(window, "resize", onWindowResize);
|
2007-08-18 22:29:50 +02:00
|
|
|
Event.observe(window, "beforeunload", onMailEditorClose);
|
2008-04-15 17:01:16 +02:00
|
|
|
|
|
|
|
var focusField = (mailIsReply ? textarea : $("addr_0"));
|
|
|
|
focusField.focus();
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getMenus() {
|
|
|
|
return { "attachmentsMenu": new Array(null, onRemoveAttachments,
|
|
|
|
onSelectAllAttachments,
|
|
|
|
"-",
|
|
|
|
onAddAttachment, null) };
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRemoveAttachments() {
|
|
|
|
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]);
|
|
|
|
}
|
2007-08-18 22:29:50 +02:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function attachmentDeleteCallback(http) {
|
|
|
|
if (http.readyState == 4) {
|
2007-10-25 21:22:07 +02:00
|
|
|
if (isHttpStatus204(http.status)) {
|
2007-08-18 22:29:50 +02:00
|
|
|
var node = http.callbackData;
|
|
|
|
node.parentNode.removeChild(node);
|
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
else
|
2007-08-18 22:29:50 +02:00
|
|
|
log("attachmentDeleteCallback: an error occured: " + http.responseText);
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSelectAllAttachments() {
|
|
|
|
var list = $("attachments");
|
|
|
|
var nodes = list.childNodesWithTag("li");
|
|
|
|
for (var i = 0; i < nodes.length; i++)
|
2008-02-05 21:00:52 +01:00
|
|
|
nodes[i].selectElement();
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2007-08-15 00:09:20 +02:00
|
|
|
function onWindowResize(event) {
|
|
|
|
var textarea = document.pageform.text;
|
|
|
|
var rowheight = (Element.getHeight(textarea) / textarea.rows);
|
2007-09-10 20:46:05 +02:00
|
|
|
var headerarea = $("headerArea");
|
|
|
|
|
|
|
|
var attachmentsarea = $("attachmentsArea");
|
|
|
|
var attachmentswidth = 0;
|
2007-11-02 16:09:44 +01:00
|
|
|
if (attachmentsarea.style.display) {
|
2007-09-10 20:46:05 +02:00
|
|
|
attachmentswidth = attachmentsarea.getWidth();
|
2007-11-02 16:09:44 +01:00
|
|
|
// Resize of attachment list is b0rken under IE7
|
|
|
|
// fromfield = $(document).getElementsByClassName('headerField',
|
|
|
|
// headerarea)[0];
|
|
|
|
// $("attachments").setStyle({ height: (headerarea.getHeight() - fromfield.getHeight() - 10) + 'px' });
|
|
|
|
}
|
2008-06-30 20:43:57 +02:00
|
|
|
var subjectfield = headerarea.select("div#subjectRow span.headerField").first();
|
|
|
|
var subjectinput = headerarea.select("div#subjectRow input.textField").first();
|
|
|
|
|
2007-09-10 20:46:05 +02:00
|
|
|
// Resize subject field
|
2007-11-20 22:11:23 +01:00
|
|
|
subjectinput.setStyle({ width: (window.width()
|
|
|
|
- $(subjectfield).getWidth()
|
|
|
|
- attachmentswidth
|
|
|
|
- 16) + 'px' });
|
2007-09-10 20:46:05 +02:00
|
|
|
|
|
|
|
// Resize address fields
|
|
|
|
var addresslist = $('addressList');
|
2007-11-02 16:09:44 +01:00
|
|
|
addresslist.setStyle({ width: ($(this).width() - attachmentswidth - 10) + 'px' });
|
|
|
|
|
|
|
|
// Set textarea position
|
|
|
|
textarea.setStyle({ 'top': (headerarea.getHeight() + headerarea.offsetTop) + 'px' });
|
|
|
|
|
|
|
|
var textareaoffset = textarea.offsetTop;
|
|
|
|
|
|
|
|
// Resize the textarea (message content)
|
|
|
|
textarea.rows = Math.round((window.height() - textareaoffset) / rowheight);
|
2007-08-15 00:09:20 +02:00
|
|
|
}
|
|
|
|
|
2007-08-18 22:29:50 +02:00
|
|
|
function onMailEditorClose(event) {
|
|
|
|
if (window.shouldPreserve)
|
|
|
|
window.shouldPreserve = false;
|
|
|
|
else {
|
2007-10-30 20:56:50 +01: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);
|
|
|
|
}
|
2007-08-18 22:29:50 +02:00
|
|
|
}
|
2007-10-22 23:56:27 +02:00
|
|
|
|
2008-06-23 22:44:54 +02:00
|
|
|
if (MailEditor.addressBook && MailEditor.addressBook.open
|
|
|
|
&& !MailEditor.addressBook.closed)
|
2007-11-20 22:11:23 +01:00
|
|
|
MailEditor.addressBook.close();
|
|
|
|
|
2007-09-29 02:22:11 +02:00
|
|
|
Event.stopObserving(window, "beforeunload", onMailEditorClose);
|
2007-08-18 22:29:50 +02:00
|
|
|
}
|
|
|
|
|
2007-11-15 20:02:23 +01:00
|
|
|
FastInit.addOnLoad(initMailEditor);
|