]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/UIxMailEditor.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1037 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / UIxMailEditor.js
1 var contactSelectorAction = 'mailer-contacts';
2
3 function onContactAdd() {
4   var selector = null;
5   var selectorURL = '?popup=YES&selectorId=mailer-contacts';
6  
7   urlstr = ApplicationBaseURL;
8   if (urlstr[urlstr.length-1] != '/')
9     urlstr += '/';
10   urlstr += ("../../" + UserLogin + "/Contacts/"
11              + contactSelectorAction + selectorURL);
12 //   log (urlstr);
13   var w = window.open(urlstr, "Addressbook",
14                       "width=640,height=400,resizable=1,scrollbars=0");
15   w.selector = selector;
16   w.opener = this;
17   w.focus();
18
19   return false;
20  }
21
22 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
23   if (!mailIsRecipient(contactEmail)) {
24     var neededOptionValue = 0;
25     if (tag == "cc")
26       neededOptionValue = 1;
27     else if (tag == "bcc")
28       neededOptionValue = 2;
29
30     var stop = false;
31     var counter = 0;
32     var currentRow = $('row_' + counter);
33     while (currentRow
34            && !stop) {
35       var currentValue = currentRow.childNodesWithTag("span")[1].childNodesWithTag("input")[0].value;
36       if (currentValue == neededOptionValue) {
37         stop = true;
38         insertContact($("addr_" + counter), contactName, contactEmail);
39       }
40       counter++;
41       currentRow = $('row_' + counter);
42     }
43
44     if (!stop) {
45       fancyAddRow(false, "");
46       $("row_" + counter).childNodesWithTag("span")[0].childNodesWithTag("select")[0].value
47         = neededOptionValue;
48       insertContact($("addr_" + counter), contactName, contactEmail);
49     }
50   }
51 }
52
53 function mailIsRecipient(mailto) {
54   var isRecipient = false;
55
56   var counter = 0;
57   var currentRow = $('row_' + counter);
58
59   var email = extractEmailAddress(mailto).toUpperCase();
60
61   while (currentRow && !isRecipient) {
62     var currentValue = $("addr_"+counter).value.toUpperCase();
63     if (currentValue.indexOf(email) > -1)
64       isRecipient = true;
65     else
66       {
67         counter++;
68         currentRow = $('row_' + counter);
69       }
70   }
71
72   return isRecipient;
73 }
74
75 function insertContact(inputNode, contactName, contactEmail) {
76   var value = '' + inputNode.value;
77
78   var newContact = contactName;
79   if (newContact.length > 0)
80     newContact += ' <' + contactEmail + '>';
81   else
82     newContact = contactEmail;
83
84   if (value.length > 0)
85     value += ", ";
86   value += newContact;
87
88   inputNode.value = value;
89 }
90
91 function toggleAttachments() {
92   var div = $("attachmentsArea");
93   if (div.style.display)
94     div.style.display = "";
95   else
96     div.style.display = "block;";
97
98   return false;
99 }
100
101 function updateInlineAttachmentList(sender, attachments) {
102   var count = 0;
103
104   var div = $("attachmentsArea");
105   if (attachments)
106     count = attachments.length;
107   if (count)
108     {
109       var text  = "";
110       for (var i = 0; i < count; i++) {
111         text = text + attachments[i];
112         text = text + '<br />';
113       }
114
115       var e = $('compose_attachments_list');
116       e.innerHTML = text;
117       if (!div.style.display)
118         div.style.display = "block;";
119     }
120   else
121     div.style.display = "";
122 }