1 var contactSelectorAction = 'mailer-contacts';
3 function onContactAdd() {
5 var selectorURL = '?popup=YES&selectorId=mailer-contacts';
7 urlstr = ApplicationBaseURL
9 + contactSelectorAction + selectorURL;
10 var w = window.open(urlstr, "Addressbook",
11 "width=640,height=400,resizable=1,scrollbars=0");
12 w.selector = selector;
19 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
20 if (!mailIsRecipient(contactEmail)) {
21 var neededOptionValue = 0;
23 neededOptionValue = 1;
24 else if (tag == "bcc")
25 neededOptionValue = 2;
29 var currentRow = $('row_' + counter);
30 while (currentRow && !stop) {
31 var currentValue = $(currentRow.childNodesWithTag("td")[1]).childNodesWithTag("input")[0].value;
32 if (currentValue == neededOptionValue) {
34 insertContact($("addr_" + counter), contactName, contactEmail);
37 currentRow = $('row_' + counter);
41 fancyAddRow(false, "");
42 $($("row_" + counter).childNodesWithTag("td")[0]).childNodesWithTag("select")[0].value
44 insertContact($("addr_" + counter), contactName, contactEmail);
50 function mailIsRecipient(mailto) {
51 var isRecipient = false;
54 var currentRow = $('row_' + counter);
56 var email = extractEmailAddress(mailto).toUpperCase();
58 while (currentRow && !isRecipient) {
59 var currentValue = $("addr_"+counter).value.toUpperCase();
60 if (currentValue.indexOf(email) > -1)
65 currentRow = $('row_' + counter);
72 function insertContact(inputNode, contactName, contactEmail) {
73 var value = '' + inputNode.value;
75 var newContact = contactName;
76 if (newContact.length > 0)
77 newContact += ' <' + contactEmail + '>';
79 newContact = contactEmail;
85 inputNode.value = value;
88 function toggleAttachments() {
89 var div = $("attachmentsArea");
90 if (div.style.display)
91 div.style.display = "";
93 div.style.display = "block;";
98 function updateInlineAttachmentList(sender, attachments) {
101 var div = $("attachmentsArea");
103 count = attachments.length;
107 for (var i = 0; i < count; i++) {
108 text = text + attachments[i];
109 text = text + '<br />';
112 var e = $('compose_attachments_list');
114 if (!div.style.display)
115 div.style.display = "block;";
118 div.style.display = "";
122 function validateEditorInput(sender) {
126 field = document.pageform.subject;
127 if (field.value == "")
128 errortext = errortext + labels["error_missingsubject"] + "\n";
130 if (!hasRecipients())
131 errortext = errortext + labels["error_missingrecipients"] + "\n";
133 if (errortext.length > 0) {
134 alert(labels["error_validationfailed"] + ":\n" + errortext);
141 function clickedEditorSend(sender) {
142 if (!validateEditorInput(sender))
145 var input = currentAttachmentInput();
147 input.parentNode.removeChild(input);
149 var toolbar = document.getElementById("toolbar");
150 if (!document.busyAnim)
151 document.busyAnim = startAnimation(toolbar);
153 window.shouldPreserve = true;
154 document.pageform.action = "send";
155 document.pageform.submit();
160 function currentAttachmentInput() {
163 var inputs = $("attachmentsArea").getElementsByTagName("input");
165 while (!input && i < inputs.length)
166 if ($(inputs[i]).hasClassName("currentAttachment"))
174 function clickedEditorAttach(sender) {
175 var input = currentAttachmentInput();
177 var area = $("attachmentsArea");
179 if (!area.style.display) {
180 area.setStyle({ display: "block" });
181 onWindowResize(null);
183 var inputs = area.getElementsByTagName("input");
184 var attachmentName = "attachment" + inputs.length;
185 var newAttachment = createElement("input", attachmentName,
186 "currentAttachment", null,
188 name: attachmentName },
190 Event.observe(newAttachment, "change",
191 onAttachmentChange.bindAsEventListener(newAttachment));
197 function onAddAttachment() {
198 return clickedEditorAttach(null);
201 function onAttachmentChange(event) {
202 if (this.value == "")
203 this.parentNode.removeChild(this);
205 this.addClassName("attachment");
206 this.removeClassName("currentAttachment");
207 var list = $("attachments");
208 createAttachment(this, list);
212 function createAttachment(node, list) {
213 var attachment = createElement("li", null, null, { node: node }, null, list);
214 createElement("img", null, null, { src: ResourcesURL + "/attachment.gif" },
216 Event.observe(attachment, "click", onRowClick);
218 var filename = node.value;
220 if (navigator.appVersion.indexOf("Windows") > -1)
224 var fileArray = filename.split(separator);
225 var attachmentName = document.createTextNode(fileArray[fileArray.length-1]);
226 attachment.appendChild(attachmentName);
229 function clickedEditorSave(sender) {
230 var input = currentAttachmentInput();
232 input.parentNode.removeChild(input);
234 window.shouldPreserve = true;
235 document.pageform.action = "save";
236 document.pageform.submit();
238 if (window.opener && window.open && !window.closed)
239 window.opener.refreshFolderByType('draft');
243 function initMailEditor() {
244 var list = $("attachments");
245 $(list).attachMenu("attachmentsMenu");
246 var elements = list.childNodesWithTag("li");
247 for (var i = 0; i < elements.length; i++) {
248 Event.observe(elements[i], "click",
249 onRowClick.bindAsEventListener(elements[i]));
252 var listContent = $("attachments").childNodesWithTag("li");
253 if (listContent.length > 0)
254 $("attachmentsArea").setStyle({ display: "block" });
256 var list = $("addressList");
257 TableKit.Resizable.init(list, {'trueResize' : true, 'keepWidth' : true});
259 onWindowResize(null);
260 Event.observe(window, "resize", onWindowResize);
261 Event.observe(window, "beforeunload", onMailEditorClose);
264 function getMenus() {
265 return { "attachmentsMenu": new Array(null, onRemoveAttachments,
266 onSelectAllAttachments,
268 onAddAttachment, null) };
271 function onRemoveAttachments() {
272 var list = $("attachments");
273 var nodes = list.getSelectedNodes();
274 for (var i = nodes.length-1; i > -1; i--) {
275 var input = $(nodes[i]).node;
277 input.parentNode.removeChild(input);
278 list.removeChild(nodes[i]);
282 var childNodes = nodes[i].childNodes;
283 for (var j = 0; j < childNodes.length; j++) {
284 if (childNodes[j].nodeType == 3)
285 filename += childNodes[j].nodeValue;
287 var url = "" + window.location;
288 var parts = url.split("/");
289 parts[parts.length-1] = "deleteAttachment?filename=" + encodeURIComponent(filename);
290 url = parts.join("/");
291 triggerAjaxRequest(url, attachmentDeleteCallback,
297 function attachmentDeleteCallback(http) {
298 if (http.readyState == 4) {
299 if (isHttpStatus204(http.status)) {
300 var node = http.callbackData;
301 node.parentNode.removeChild(node);
304 log("attachmentDeleteCallback: an error occured: " + http.responseText);
308 function onSelectAllAttachments() {
309 var list = $("attachments");
310 var nodes = list.childNodesWithTag("li");
311 for (var i = 0; i < nodes.length; i++)
315 function onWindowResize(event) {
316 var textarea = document.pageform.text;
317 var rowheight = (Element.getHeight(textarea) / textarea.rows);
318 var headerarea = $("headerArea");
320 var attachmentsarea = $("attachmentsArea");
321 var attachmentswidth = 0;
322 if (attachmentsarea.style.display) {
323 attachmentswidth = attachmentsarea.getWidth();
324 // Resize of attachment list is b0rken under IE7
325 // fromfield = $(document).getElementsByClassName('headerField',
327 // $("attachments").setStyle({ height: (headerarea.getHeight() - fromfield.getHeight() - 10) + 'px' });
329 // var subjectfield = $(document).getElementsByClassName('headerField',
330 // $('subjectRow'))[0];
331 // var subjectinput = $(document).getElementsByClassName('textField',
332 // $('subjectRow'))[0];
334 // Resize subject field
335 // subjectinput.setStyle({ width: (window.width()
336 // - $(subjectfield).getWidth()
337 // - attachmentswidth
338 // - 4 - 30) + 'px' });
340 // Resize address fields
341 var addresslist = $('addressList');
342 addresslist.setStyle({ width: ($(this).width() - attachmentswidth - 10) + 'px' });
344 // Set textarea position
345 textarea.setStyle({ 'top': (headerarea.getHeight() + headerarea.offsetTop) + 'px' });
347 var textareaoffset = textarea.offsetTop;
349 // Resize the textarea (message content)
350 textarea.rows = Math.round((window.height() - textareaoffset) / rowheight);
353 function onMailEditorClose(event) {
354 if (window.shouldPreserve)
355 window.shouldPreserve = false;
357 if (window.opener && window.opener.open && !window.opener.closed) {
358 var url = "" + window.location;
359 var parts = url.split("/");
360 parts[parts.length-1] = "delete";
361 url = parts.join("/");
362 window.opener.deleteDraft(url);
366 Event.stopObserving(window, "beforeunload", onMailEditorClose);
369 FastInit.addOnLoad(initMailEditor);