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);
13 var w = window.open(urlstr, "Addressbook",
14 "width=640,height=400,resizable=1,scrollbars=0");
15 w.selector = selector;
22 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
23 if (!mailIsRecipient(contactEmail)) {
24 var neededOptionValue = 0;
26 neededOptionValue = 1;
27 else if (tag == "bcc")
28 neededOptionValue = 2;
32 var currentRow = $('row_' + counter);
33 while (currentRow && !stop) {
34 var currentValue = $(currentRow.childNodesWithTag("span")[1]).childNodesWithTag("input")[0].value;
35 if (currentValue == neededOptionValue) {
37 insertContact($("addr_" + counter), contactName, contactEmail);
40 currentRow = $('row_' + counter);
44 fancyAddRow(false, "");
45 $("row_" + counter).childNodesWithTag("span")[0].childNodesWithTag("select")[0].value
47 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 (!UIxRecipientSelectorHasRecipients())
133 errortext = errortext + labels.error_missingrecipients + "\n";
135 if (errortext.length > 0) {
136 alert(labels.error_validationfailed.decodeEntities() + ":\n"
137 + errortext.decodeEntities());
143 function clickedEditorSend(sender) {
144 if (!validateEditorInput(sender))
147 document.pageform.action = "send";
148 document.pageform.submit();
153 function clickedEditorAttach(sender) {
154 var area = $("attachmentsArea");
156 area.setStyle({ display: "block" });
158 var inputs = area.getElementsByTagName("input");
159 var attachmentName = "attachment" + inputs.length;
160 var newAttachment = createElement("input", attachmentName,
161 "currentAttachment", null,
163 name: attachmentName },
165 Event.observe(newAttachment, "change",
166 onAttachmentChange.bindAsEventListener(newAttachment));
171 function onAddAttachment() {
172 var area = $("attachmentsArea");
173 var inputs = area.getElementsByTagName("input");
174 var attachmentName = "attachment" + inputs.length;
175 var newAttachment = createElement("input", attachmentName,
176 "currentAttachment", null,
178 name: attachmentName },
180 Event.observe(newAttachment, "change",
181 onAttachmentChange.bindAsEventListener(newAttachment));
184 function onAttachmentChange(event) {
185 if (this.value == "")
186 this.parentNode.removeChild(this);
188 this.addClassName("attachment");
189 this.removeClassName("currentAttachment");
190 var list = $("attachments");
191 createAttachment(this, list);
195 function createAttachment(node, list) {
196 var attachment = createElement("li", null, null, { node: node }, null, list);
197 createElement("img", null, null, { src: ResourcesURL + "/attachment.gif" },
199 Event.observe(attachment, "click", onRowClick);
201 var filename = node.value;
203 if (navigator.appVersion.indexOf("Windows") > -1)
207 var fileArray = filename.split(separator);
208 var attachmentName = document.createTextNode(fileArray[fileArray.length-1]);
209 attachment.appendChild(attachmentName);
212 function clickedEditorSave(sender) {
213 document.pageform.action = "save";
214 document.pageform.submit();
219 function clickedEditorDelete(sender) {
220 document.pageform.action = "delete";
221 document.pageform.submit();
227 function initMailEditor() {
228 var list = $("attachments");
229 $(list).attachMenu("attachmentsMenu");
230 var elements = list.childNodesWithTag("li");
231 for (var i = 0; i < elements.length; i++) {
232 Event.observe(elements[i], "click",
233 onRowClick.bindAsEventListener(elements[i]));
235 onWindowResize(null);
236 Event.observe(window, "resize", onWindowResize);
239 function getMenus() {
240 return { "attachmentsMenu": new Array(null, onRemoveAttachments,
241 onSelectAllAttachments,
243 onAddAttachment, null) };
246 function onRemoveAttachments() {
247 var list = $("attachments");
248 var nodes = list.getSelectedNodes();
249 for (var i = nodes.length-1; i > -1; i--) {
250 var input = $(nodes[i]).node;
252 input.parentNode.removeChild(input);
253 list.removeChild(nodes[i]);
256 window.alert("Server attachments not handled");
260 function onSelectAllAttachments() {
261 var list = $("attachments");
262 var nodes = list.childNodesWithTag("li");
263 for (var i = 0; i < nodes.length; i++)
267 function onWindowResize(event) {
268 var textarea = document.pageform.text;
269 var windowheight = (typeof self.innerHeight == "number" ? self.innerHeight : document.body.clientHeight);
270 var textareaoffset = textarea.offsetTop;
271 var rowheight = (Element.getHeight(textarea) / textarea.rows);
273 textarea.rows = Math.round((windowheight - textareaoffset) / rowheight);
274 log ("onWindowResize new number of rows = " + textarea.rows);
277 addEvent(window, 'load', initMailEditor);