2006-10-03 18:21:25 +02:00
|
|
|
var contactSelectorAction = 'mailer-contacts';
|
|
|
|
|
2007-03-29 20:04:41 +02:00
|
|
|
function onContactAdd() {
|
|
|
|
var selector = null;
|
|
|
|
var selectorURL = '?popup=YES&selectorId=mailer-contacts';
|
|
|
|
|
|
|
|
urlstr = ApplicationBaseURL;
|
|
|
|
if (urlstr[urlstr.length-1] != '/')
|
|
|
|
urlstr += '/';
|
|
|
|
urlstr += ("../../" + UserLogin + "/Contacts/"
|
|
|
|
+ contactSelectorAction + selectorURL);
|
|
|
|
// log (urlstr);
|
|
|
|
var w = window.open(urlstr, "Addressbook",
|
|
|
|
"width=640,height=400,resizable=1,scrollbars=0");
|
|
|
|
w.selector = selector;
|
|
|
|
w.opener = this;
|
|
|
|
w.focus();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
var currentValue = $(currentRow.childNodesWithTag("span")[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, "");
|
2006-10-18 23:53:47 +02:00
|
|
|
$("row_" + counter).childNodesWithTag("span")[0].childNodesWithTag("select")[0].value
|
2006-10-03 16:38:51 +02:00
|
|
|
= neededOptionValue;
|
|
|
|
insertContact($("addr_" + counter), contactName, contactEmail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
if (div.style.display)
|
|
|
|
div.style.display = "";
|
|
|
|
else
|
|
|
|
div.style.display = "block;";
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateInlineAttachmentList(sender, attachments) {
|
|
|
|
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;
|
|
|
|
if (!div.style.display)
|
|
|
|
div.style.display = "block;";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
div.style.display = "";
|
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
/* mail editor */
|
|
|
|
|
|
|
|
function validateEditorInput(sender) {
|
|
|
|
var errortext = "";
|
|
|
|
var field;
|
|
|
|
|
|
|
|
field = document.pageform.subject;
|
|
|
|
if (field.value == "")
|
|
|
|
errortext = errortext + labels.error_missingsubject + "\n";
|
|
|
|
|
|
|
|
if (!UIxRecipientSelectorHasRecipients())
|
|
|
|
errortext = errortext + labels.error_missingrecipients + "\n";
|
|
|
|
|
|
|
|
if (errortext.length > 0) {
|
2007-09-14 23:54:19 +02:00
|
|
|
alert(labels.error_validationfailed + ":\n" + errortext);
|
2007-07-27 22:03:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickedEditorSend(sender) {
|
|
|
|
if (!validateEditorInput(sender))
|
|
|
|
return false;
|
|
|
|
|
2007-08-18 22:29:50 +02:00
|
|
|
window.shouldPreserve = true;
|
2007-07-27 22:03:05 +02:00
|
|
|
document.pageform.action = "send";
|
|
|
|
document.pageform.submit();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickedEditorAttach(sender) {
|
|
|
|
var area = $("attachmentsArea");
|
2007-09-10 20:46:05 +02:00
|
|
|
|
|
|
|
if (!area.style.display) {
|
|
|
|
area.setStyle({ display: "block" });
|
|
|
|
onWindowResize(null);
|
|
|
|
}
|
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
var inputs = area.getElementsByTagName("input");
|
|
|
|
var attachmentName = "attachment" + inputs.length;
|
|
|
|
var newAttachment = createElement("input", attachmentName,
|
|
|
|
"currentAttachment", null,
|
|
|
|
{ type: "file",
|
|
|
|
name: attachmentName },
|
|
|
|
area);
|
|
|
|
Event.observe(newAttachment, "change",
|
|
|
|
onAttachmentChange.bindAsEventListener(newAttachment));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAddAttachment() {
|
|
|
|
var area = $("attachmentsArea");
|
|
|
|
var inputs = area.getElementsByTagName("input");
|
|
|
|
var attachmentName = "attachment" + inputs.length;
|
|
|
|
var newAttachment = createElement("input", attachmentName,
|
|
|
|
"currentAttachment", null,
|
|
|
|
{ type: "file",
|
|
|
|
name: attachmentName },
|
|
|
|
area);
|
|
|
|
Event.observe(newAttachment, "change",
|
|
|
|
onAttachmentChange.bindAsEventListener(newAttachment));
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAttachmentChange(event) {
|
|
|
|
if (this.value == "")
|
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
else {
|
|
|
|
this.addClassName("attachment");
|
|
|
|
this.removeClassName("currentAttachment");
|
|
|
|
var list = $("attachments");
|
|
|
|
createAttachment(this, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createAttachment(node, list) {
|
|
|
|
var attachment = createElement("li", null, null, { node: node }, null, list);
|
|
|
|
createElement("img", null, null, { src: ResourcesURL + "/attachment.gif" },
|
|
|
|
null, attachment);
|
|
|
|
Event.observe(attachment, "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);
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickedEditorSave(sender) {
|
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
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function initMailEditor() {
|
|
|
|
var list = $("attachments");
|
|
|
|
$(list).attachMenu("attachmentsMenu");
|
|
|
|
var elements = list.childNodesWithTag("li");
|
2007-08-15 00:09:20 +02:00
|
|
|
for (var i = 0; i < elements.length; i++) {
|
2007-07-27 22:03:05 +02:00
|
|
|
Event.observe(elements[i], "click",
|
|
|
|
onRowClick.bindAsEventListener(elements[i]));
|
2007-08-15 00:09:20 +02:00
|
|
|
}
|
2007-08-18 22:29:50 +02:00
|
|
|
|
|
|
|
var listContent = $("attachments").childNodesWithTag("li");
|
|
|
|
if (listContent.length > 0)
|
|
|
|
$("attachmentsArea").setStyle({ display: "block" });
|
|
|
|
|
2007-08-15 00:09:20 +02:00
|
|
|
onWindowResize(null);
|
|
|
|
Event.observe(window, "resize", onWindowResize);
|
2007-08-18 22:29:50 +02:00
|
|
|
Event.observe(window, "beforeunload", onMailEditorClose);
|
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) {
|
|
|
|
if (http.status == 204) {
|
|
|
|
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++)
|
|
|
|
nodes[i].select();
|
|
|
|
}
|
|
|
|
|
2007-08-15 00:09:20 +02:00
|
|
|
function onWindowResize(event) {
|
|
|
|
var textarea = document.pageform.text;
|
|
|
|
var windowheight = (typeof self.innerHeight == "number" ? self.innerHeight : document.body.clientHeight);
|
|
|
|
var rowheight = (Element.getHeight(textarea) / textarea.rows);
|
2007-09-10 20:46:05 +02:00
|
|
|
var headerarea = $("headerArea");
|
|
|
|
|
|
|
|
// Set textarea position
|
|
|
|
textarea.setStyle({ 'top': (headerarea.getHeight() + headerarea.offsetTop) + 'px' });
|
2007-08-15 00:09:20 +02:00
|
|
|
|
2007-09-10 20:46:05 +02:00
|
|
|
var textareaoffset = textarea.offsetTop;
|
|
|
|
|
|
|
|
// Resize the textarea (message content)
|
2007-08-15 00:09:20 +02:00
|
|
|
textarea.rows = Math.round((windowheight - textareaoffset) / rowheight);
|
2007-09-10 20:46:05 +02:00
|
|
|
|
|
|
|
var attachmentsarea = $("attachmentsArea");
|
|
|
|
var attachmentswidth = 0;
|
|
|
|
if (attachmentsarea.style.display)
|
|
|
|
attachmentswidth = attachmentsarea.getWidth();
|
|
|
|
var windowwidth = (typeof self.innerWidth == "number" ? self.innerWidth : document.body.clientWidth);
|
|
|
|
var subjectfield = $(document).getElementsByClassName('headerField', $('subjectRow'))[0];
|
|
|
|
var subjectinput = $(document).getElementsByClassName('textField', $('subjectRow'))[0];
|
|
|
|
|
|
|
|
// Resize subject field
|
|
|
|
subjectinput.setStyle({ width: (windowwidth
|
|
|
|
- $(subjectfield).getWidth()
|
|
|
|
- attachmentswidth
|
|
|
|
- 4 - 30
|
|
|
|
) + 'px' });
|
|
|
|
|
|
|
|
// Resize address fields
|
|
|
|
var addresslist = $('addressList');
|
|
|
|
var firstselect = document.getElementsByClassName('headerField', addresslist)[0];
|
|
|
|
var inputwidth = windowwidth - $(firstselect).getWidth() - attachmentswidth - 24 - 30;
|
|
|
|
var addresses = document.getElementsByClassName('textField', addresslist);
|
|
|
|
for (var i = 0; i < addresses.length; i++) {
|
|
|
|
addresses[i].setStyle({ width: inputwidth + 'px' });
|
|
|
|
}
|
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 {
|
|
|
|
var url = "" + window.location;
|
|
|
|
var parts = url.split("/");
|
|
|
|
parts[parts.length-1] = "delete";
|
|
|
|
url = parts.join("/");
|
|
|
|
|
|
|
|
http = createHTTPClient();
|
|
|
|
http.open("POST", url, false /* not async */);
|
|
|
|
http.send("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-08 23:06:51 +02:00
|
|
|
addEvent(window, 'load', initMailEditor);
|