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("span")[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("span")[0].childNodesWithTag("select")[0].value
46 insertContact($("addr_" + counter), contactName, contactEmail);
51 function mailIsRecipient(mailto) {
52 var isRecipient = false;
55 var currentRow = $('row_' + counter);
57 var email = extractEmailAddress(mailto).toUpperCase();
59 while (currentRow && !isRecipient) {
60 var currentValue = $("addr_"+counter).value.toUpperCase();
61 if (currentValue.indexOf(email) > -1)
66 currentRow = $('row_' + counter);
73 function insertContact(inputNode, contactName, contactEmail) {
74 var value = '' + inputNode.value;
76 var newContact = contactName;
77 if (newContact.length > 0)
78 newContact += ' <' + contactEmail + '>';
80 newContact = contactEmail;
86 inputNode.value = value;
89 function toggleAttachments() {
90 var div = $("attachmentsArea");
91 if (div.style.display)
92 div.style.display = "";
94 div.style.display = "block;";
99 function updateInlineAttachmentList(sender, attachments) {
102 var div = $("attachmentsArea");
104 count = attachments.length;
108 for (var i = 0; i < count; i++) {
109 text = text + attachments[i];
110 text = text + '<br />';
113 var e = $('compose_attachments_list');
115 if (!div.style.display)
116 div.style.display = "block;";
119 div.style.display = "";
123 function validateEditorInput(sender) {
127 field = document.pageform.subject;
128 if (field.value == "")
129 errortext = errortext + labels["error_missingsubject"] + "\n";
131 if (!UIxRecipientSelectorHasRecipients())
132 errortext = errortext + labels["error_missingrecipients"] + "\n";
134 if (errortext.length > 0) {
135 alert(labels["error_validationfailed"] + ":\n" + errortext);
142 function clickedEditorSend(sender) {
143 if (!validateEditorInput(sender))
146 var input = currentAttachmentInput();
148 input.parentNode.removeChild(input);
150 var toolbar = document.getElementById("toolbar");
151 if (!document.busyAnim)
152 document.busyAnim = startAnimation(toolbar);
154 window.shouldPreserve = true;
155 document.pageform.action = "send";
156 document.pageform.submit();
161 function currentAttachmentInput() {
164 var inputs = $("attachmentsArea").getElementsByTagName("input");
166 while (!input && i < inputs.length)
167 if ($(inputs[i]).hasClassName("currentAttachment"))
175 function clickedEditorAttach(sender) {
176 var input = currentAttachmentInput();
178 var area = $("attachmentsArea");
180 if (!area.style.display) {
181 area.setStyle({ display: "block" });
182 onWindowResize(null);
184 var inputs = area.getElementsByTagName("input");
185 var attachmentName = "attachment" + inputs.length;
186 var newAttachment = createElement("input", attachmentName,
187 "currentAttachment", null,
189 name: attachmentName },
191 Event.observe(newAttachment, "change",
192 onAttachmentChange.bindAsEventListener(newAttachment));
198 function onAddAttachment() {
199 return clickedEditorAttach(null);
202 function onAttachmentChange(event) {
203 if (this.value == "")
204 this.parentNode.removeChild(this);
206 this.addClassName("attachment");
207 this.removeClassName("currentAttachment");
208 var list = $("attachments");
209 createAttachment(this, list);
213 function createAttachment(node, list) {
214 var attachment = createElement("li", null, null, { node: node }, null, list);
215 createElement("img", null, null, { src: ResourcesURL + "/attachment.gif" },
217 Event.observe(attachment, "click", onRowClick);
219 var filename = node.value;
221 if (navigator.appVersion.indexOf("Windows") > -1)
225 var fileArray = filename.split(separator);
226 var attachmentName = document.createTextNode(fileArray[fileArray.length-1]);
227 attachment.appendChild(attachmentName);
230 function clickedEditorSave(sender) {
231 var input = currentAttachmentInput();
233 input.parentNode.removeChild(input);
235 var toolbar = document.getElementById("toolbar");
236 if (!document.busyAnim)
237 document.busyAnim = startAnimation(toolbar);
239 window.shouldPreserve = true;
240 document.pageform.action = "save";
241 document.pageform.submit();
247 function initMailEditor() {
248 var list = $("attachments");
249 $(list).attachMenu("attachmentsMenu");
250 var elements = list.childNodesWithTag("li");
251 for (var i = 0; i < elements.length; i++) {
252 Event.observe(elements[i], "click",
253 onRowClick.bindAsEventListener(elements[i]));
256 var listContent = $("attachments").childNodesWithTag("li");
257 if (listContent.length > 0)
258 $("attachmentsArea").setStyle({ display: "block" });
260 onWindowResize(null);
261 Event.observe(window, "resize", onWindowResize);
262 Event.observe(window, "beforeunload", onMailEditorClose);
265 function getMenus() {
266 return { "attachmentsMenu": new Array(null, onRemoveAttachments,
267 onSelectAllAttachments,
269 onAddAttachment, null) };
272 function onRemoveAttachments() {
273 var list = $("attachments");
274 var nodes = list.getSelectedNodes();
275 for (var i = nodes.length-1; i > -1; i--) {
276 var input = $(nodes[i]).node;
278 input.parentNode.removeChild(input);
279 list.removeChild(nodes[i]);
283 var childNodes = nodes[i].childNodes;
284 for (var j = 0; j < childNodes.length; j++) {
285 if (childNodes[j].nodeType == 3)
286 filename += childNodes[j].nodeValue;
288 var url = "" + window.location;
289 var parts = url.split("/");
290 parts[parts.length-1] = "deleteAttachment?filename=" + encodeURIComponent(filename);
291 url = parts.join("/");
292 triggerAjaxRequest(url, attachmentDeleteCallback,
298 function attachmentDeleteCallback(http) {
299 if (http.readyState == 4) {
300 if (isHttpStatus204(http.status)) {
301 var node = http.callbackData;
302 node.parentNode.removeChild(node);
305 log("attachmentDeleteCallback: an error occured: " + http.responseText);
309 function onSelectAllAttachments() {
310 var list = $("attachments");
311 var nodes = list.childNodesWithTag("li");
312 for (var i = 0; i < nodes.length; i++)
316 function onWindowResize(event) {
317 var textarea = document.pageform.text;
318 var rowheight = (Element.getHeight(textarea) / textarea.rows);
319 var headerarea = $("headerArea");
321 // Set textarea position
322 textarea.setStyle({ 'top': (headerarea.getHeight() + headerarea.offsetTop) + 'px' });
324 var textareaoffset = textarea.offsetTop;
326 // Resize the textarea (message content)
327 textarea.rows = Math.round((window.height() - textareaoffset) / rowheight);
329 var attachmentsarea = $("attachmentsArea");
330 var attachmentswidth = 0;
331 if (attachmentsarea.style.display)
332 attachmentswidth = attachmentsarea.getWidth();
333 var subjectfield = $(document).getElementsByClassName('headerField',
335 var subjectinput = $(document).getElementsByClassName('textField',
338 // Resize subject field
339 subjectinput.setStyle({ width: (window.width()
340 - $(subjectfield).getWidth()
344 // Resize address fields
345 var addresslist = $('addressList');
346 var firstselect = document.getElementsByClassName('headerField', addresslist)[0];
347 var inputwidth = ($(this).width() - $(firstselect).getWidth()
348 - attachmentswidth - 24 - 30);
349 var addresses = document.getElementsByClassName('textField', addresslist);
350 for (var i = 0; i < addresses.length; i++)
351 addresses[i].setStyle({ width: inputwidth + 'px' });
354 function onMailEditorClose(event) {
355 if (window.shouldPreserve)
356 window.shouldPreserve = false;
358 var url = "" + window.location;
359 var parts = url.split("/");
360 parts[parts.length-1] = "delete";
361 url = parts.join("/");
362 http = createHTTPClient();
363 http.open("POST", url, false /* not async */);
367 Event.stopObserving(window, "beforeunload", onMailEditorClose);
370 addEvent(window, 'load', initMailEditor);