]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/UIxMailEditor.js
initial sync
[scalable-opengroupware.org] / UI / WebServerResources / UIxMailEditor.js
1 var contactSelectorAction = 'mailer-contacts';
2
3 function addContact(tag, fullContactName, contactId, contactName, contactEmail)
4 {
5   if (!mailIsRecipient(contactEmail)) {
6     var neededOptionValue = 0;
7     if (tag == "cc")
8       neededOptionValue = 1;
9     else if (tag == "bcc")
10       neededOptionValue = 2;
11
12     var stop = false;
13     var counter = 0;
14     var currentRow = $('row_' + counter);
15     while (currentRow
16            && !stop) {
17       var currentValue = currentRow.childNodesWithTag("span")[1].childNodesWithTag("input")[0].value;
18       if (currentValue == neededOptionValue) {
19         stop = true;
20         insertContact($("addr_" + counter), contactName, contactEmail);
21       }
22       counter++;
23       currentRow = $('row_' + counter);
24     }
25
26     if (!stop) {
27       fancyAddRow(false, "");
28       $("row_" + counter).childNodesWithTag("span")[0].childNodesWithTag("select")[0].value
29         = neededOptionValue;
30       insertContact($("addr_" + counter), contactName, contactEmail);
31     }
32   }
33 }
34
35 function mailIsRecipient(mailto) {
36   var isRecipient = false;
37
38   var counter = 0;
39   var currentRow = $('row_' + counter);
40
41   var email = extractEmailAddress(mailto).toUpperCase();
42
43   while (currentRow && !isRecipient) {
44     var currentValue = $("addr_"+counter).value.toUpperCase();
45     if (currentValue.indexOf(email) > -1)
46       isRecipient = true;
47     else
48       {
49         counter++;
50         currentRow = $('row_' + counter);
51       }
52   }
53
54   return isRecipient;
55 }
56
57 function insertContact(inputNode, contactName, contactEmail) {
58   var value = '' + inputNode.value;
59
60   var newContact = contactName;
61   if (newContact.length > 0)
62     newContact += ' <' + contactEmail + '>';
63   else
64     newContact = contactEmail;
65
66   if (value.length > 0)
67     value += ", ";
68   value += newContact;
69
70   inputNode.value = value;
71 }
72
73 function toggleAttachments() {
74   var div = $("attachmentsArea");
75   if (div.style.display)
76     div.style.display = "";
77   else
78     div.style.display = "block;";
79
80   return false;
81 }
82
83 function updateInlineAttachmentList(sender, attachments) {
84   var count = 0;
85
86   var div = $("attachmentsArea");
87   if (attachments)
88     count = attachments.length;
89   if (count)
90     {
91       var text  = "";
92       for (var i = 0; i < count; i++) {
93         text = text + attachments[i];
94         text = text + '<br />';
95       }
96
97       var e = $('compose_attachments_list');
98       e.innerHTML = text;
99       if (!div.style.display)
100         div.style.display = "block;";
101     }
102   else
103     div.style.display = "";
104 }