1 var contactSelectorAction = 'mailer-contacts';
3 function onContactAdd() {
5 var selectorURL = '?popup=YES&selectorId=mailer-contacts';
7 urlstr = ApplicationBaseURL;
8 if (urlstr[urlstr.length-1] != '/')
10 urlstr += ("../../" + UserLogin + "/Contacts/"
11 + contactSelectorAction + selectorURL);
12 var w = window.open(urlstr, "Addressbook",
13 "width=640,height=400,resizable=1,scrollbars=0");
14 w.selector = selector;
21 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
22 if (!mailIsRecipient(contactEmail)) {
23 var neededOptionValue = 0;
25 neededOptionValue = 1;
26 else if (tag == "bcc")
27 neededOptionValue = 2;
31 var currentRow = $('row_' + counter);
32 while (currentRow && !stop) {
33 var currentValue = $(currentRow.childNodesWithTag("td")[1]).childNodesWithTag("input")[0].value;
34 if (currentValue == neededOptionValue) {
36 insertContact($("addr_" + counter), contactName, contactEmail);
39 currentRow = $('row_' + counter);
43 fancyAddRow(false, "");
44 $($("row_" + counter).childNodesWithTag("td")[0]).childNodesWithTag("select")[0].value
46 insertContact($("addr_" + counter), contactName, contactEmail);
52 function mailIsRecipient(mailto) {
53 var isRecipient = false;
56 var currentRow = $('row_' + counter);
58 var email = extractEmailAddress(mailto).toUpperCase();
60 while (currentRow && !isRecipient) {
61 var currentValue = $("addr_"+counter).value.toUpperCase();
62 if (currentValue.indexOf(email) > -1)
67 currentRow = $('row_' + counter);
74 function insertContact(inputNode, contactName, contactEmail) {
75 var value = '' + inputNode.value;
77 var newContact = contactName;
78 if (newContact.length > 0)
79 newContact += ' <' + contactEmail + '>';
81 newContact = contactEmail;
87 inputNode.value = value;
90 function toggleAttachments() {
91 var div = $("attachmentsArea");
92 if (div.style.display)
93 div.style.display = "";
95 div.style.display = "block;";
100 function updateInlineAttachmentList(sender, attachments) {
103 var div = $("attachmentsArea");
105 count = attachments.length;
109 for (var i = 0; i < count; i++) {
110 text = text + attachments[i];
111 text = text + '<br />';
114 var e = $('compose_attachments_list');
116 if (!div.style.display)
117 div.style.display = "block;";
120 div.style.display = "";
124 function validateEditorInput(sender) {
128 field = document.pageform.subject;
129 if (field.value == "")
130 errortext = errortext + labels["error_missingsubject"] + "\n";
132 if (!hasRecipients())
133 errortext = errortext + labels["error_missingrecipients"] + "\n";
135 if (errortext.length > 0) {
136 alert(labels["error_validationfailed"] + ":\n" + errortext);
143 function clickedEditorSend(sender) {
144 if (!validateEditorInput(sender))
147 var input = currentAttachmentInput();
149 input.parentNode.removeChild(input);
151 var toolbar = document.getElementById("toolbar");
152 if (!document.busyAnim)
153 document.busyAnim = startAnimation(toolbar);
155 window.shouldPreserve = true;
156 document.pageform.action = "send";
157 document.pageform.submit();
162 function currentAttachmentInput() {
165 var inputs = $("attachmentsArea").getElementsByTagName("input");
167 while (!input && i < inputs.length)
168 if ($(inputs[i]).hasClassName("currentAttachment"))
176 function clickedEditorAttach(sender) {
177 var input = currentAttachmentInput();
179 var area = $("attachmentsArea");
181 if (!area.style.display) {
182 area.setStyle({ display: "block" });
183 onWindowResize(null);
185 var inputs = area.getElementsByTagName("input");
186 var attachmentName = "attachment" + inputs.length;
187 var newAttachment = createElement("input", attachmentName,
188 "currentAttachment", null,
190 name: attachmentName },
192 Event.observe(newAttachment, "change",
193 onAttachmentChange.bindAsEventListener(newAttachment));
199 function onAddAttachment() {
200 return clickedEditorAttach(null);
203 function onAttachmentChange(event) {
204 if (this.value == "")
205 this.parentNode.removeChild(this);
207 this.addClassName("attachment");
208 this.removeClassName("currentAttachment");
209 var list = $("attachments");
210 createAttachment(this, list);
214 function createAttachment(node, list) {
215 var attachment = createElement("li", null, null, { node: node }, null, list);
216 createElement("img", null, null, { src: ResourcesURL + "/attachment.gif" },
218 Event.observe(attachment, "click", onRowClick);
220 var filename = node.value;
222 if (navigator.appVersion.indexOf("Windows") > -1)
226 var fileArray = filename.split(separator);
227 var attachmentName = document.createTextNode(fileArray[fileArray.length-1]);
228 attachment.appendChild(attachmentName);
231 function clickedEditorSave(sender) {
232 var input = currentAttachmentInput();
234 input.parentNode.removeChild(input);
236 window.shouldPreserve = true;
237 document.pageform.action = "save";
238 document.pageform.submit();
240 if (window.opener && window.open && !window.closed)
241 window.opener.refreshFolderByType('draft');
245 function initMailEditor() {
246 var list = $("attachments");
247 $(list).attachMenu("attachmentsMenu");
248 var elements = list.childNodesWithTag("li");
249 for (var i = 0; i < elements.length; i++) {
250 Event.observe(elements[i], "click",
251 onRowClick.bindAsEventListener(elements[i]));
254 var listContent = $("attachments").childNodesWithTag("li");
255 if (listContent.length > 0)
256 $("attachmentsArea").setStyle({ display: "block" });
258 var list = $("addressList");
259 TableKit.Resizable.init(list, {'trueResize' : true, 'keepWidth' : true});
261 onWindowResize(null);
262 Event.observe(window, "resize", onWindowResize);
263 Event.observe(window, "beforeunload", onMailEditorClose);
266 function getMenus() {
267 return { "attachmentsMenu": new Array(null, onRemoveAttachments,
268 onSelectAllAttachments,
270 onAddAttachment, null) };
273 function onRemoveAttachments() {
274 var list = $("attachments");
275 var nodes = list.getSelectedNodes();
276 for (var i = nodes.length-1; i > -1; i--) {
277 var input = $(nodes[i]).node;
279 input.parentNode.removeChild(input);
280 list.removeChild(nodes[i]);
284 var childNodes = nodes[i].childNodes;
285 for (var j = 0; j < childNodes.length; j++) {
286 if (childNodes[j].nodeType == 3)
287 filename += childNodes[j].nodeValue;
289 var url = "" + window.location;
290 var parts = url.split("/");
291 parts[parts.length-1] = "deleteAttachment?filename=" + encodeURIComponent(filename);
292 url = parts.join("/");
293 triggerAjaxRequest(url, attachmentDeleteCallback,
299 function attachmentDeleteCallback(http) {
300 if (http.readyState == 4) {
301 if (isHttpStatus204(http.status)) {
302 var node = http.callbackData;
303 node.parentNode.removeChild(node);
306 log("attachmentDeleteCallback: an error occured: " + http.responseText);
310 function onSelectAllAttachments() {
311 var list = $("attachments");
312 var nodes = list.childNodesWithTag("li");
313 for (var i = 0; i < nodes.length; i++)
317 function onWindowResize(event) {
318 var textarea = document.pageform.text;
319 var rowheight = (Element.getHeight(textarea) / textarea.rows);
320 var headerarea = $("headerArea");
322 var attachmentsarea = $("attachmentsArea");
323 var attachmentswidth = 0;
324 if (attachmentsarea.style.display) {
325 attachmentswidth = attachmentsarea.getWidth();
326 // Resize of attachment list is b0rken under IE7
327 // fromfield = $(document).getElementsByClassName('headerField',
329 // $("attachments").setStyle({ height: (headerarea.getHeight() - fromfield.getHeight() - 10) + 'px' });
331 // var subjectfield = $(document).getElementsByClassName('headerField',
332 // $('subjectRow'))[0];
333 // var subjectinput = $(document).getElementsByClassName('textField',
334 // $('subjectRow'))[0];
336 // Resize subject field
337 // subjectinput.setStyle({ width: (window.width()
338 // - $(subjectfield).getWidth()
339 // - attachmentswidth
340 // - 4 - 30) + 'px' });
342 // Resize address fields
343 var addresslist = $('addressList');
344 addresslist.setStyle({ width: ($(this).width() - attachmentswidth - 10) + 'px' });
346 // Set textarea position
347 textarea.setStyle({ 'top': (headerarea.getHeight() + headerarea.offsetTop) + 'px' });
349 var textareaoffset = textarea.offsetTop;
351 // Resize the textarea (message content)
352 textarea.rows = Math.round((window.height() - textareaoffset) / rowheight);
355 function onMailEditorClose(event) {
356 if (window.shouldPreserve)
357 window.shouldPreserve = false;
359 if (window.opener && window.opener.open && !window.opener.closed) {
360 var url = "" + window.location;
361 var parts = url.split("/");
362 parts[parts.length-1] = "delete";
363 url = parts.join("/");
364 window.opener.deleteDraft(url);
368 Event.stopObserving(window, "beforeunload", onMailEditorClose);
371 addEvent(window, 'load', initMailEditor);