]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/UIxMailToSelection.js
added default to disable etag caching in mail objects
[scalable-opengroupware.org] / UI / WebServerResources / UIxMailToSelection.js
1 /*
2  Copyright (C) 2005 SKYRIX Software AG
3  
4  This file is part of OpenGroupware.org.
5  
6  OGo is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License as published by the
8  Free Software Foundation; either version 2, or (at your option) any
9  later version.
10  
11  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12  WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14  License for more details.
15  
16  You should have received a copy of the GNU Lesser General Public
17  License along with OGo; see the file COPYING.  If not, write to the
18  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19  02111-1307, USA.
20 */
21
22 /* Dependencies:
23  * It's required that "currentIndex" is defined in a top level context.
24  *
25  * Exports:
26  * defines UIxRecipientSelectorHasRecipients() returning a bool for the
27  * surrounding context to check.
28  */
29
30 var lastIndex = currentIndex;
31
32 function sanitizedCn(cn) {
33   var parts;
34   parts = cn.split(', ');
35   if(parts.length == 1)
36     return cn;
37   return parts[0];
38 }
39
40 function hasAddress(email) {
41   var e = document.getElementById(email);
42   if(e)
43     return true;
44   return false;
45 }
46
47 function rememberAddress(email) {
48   var list, span, idx;
49   
50   list    = document.getElementById('addr_addresses');
51   span    = document.createElement('span');
52   span.id = email;
53   idx     = document.createTextNode(currentIndex);
54   span.appendChild(idx);
55   list.appendChild(span);
56 }
57
58 function checkAddresses() {
59   alert("addressCount: " + this.getAddressCount() + " currentIndex: " + currentIndex + " lastIndex: " + lastIndex);
60 }
61
62 function addAddress(type, email, uid, sn, cn, dn) {
63   var shouldAddRow, s, e;
64   
65   shouldAddRow = true;
66   if (cn)
67     s = this.sanitizedCn(cn) + ' <' + email + '>';
68   else
69     s = email;
70
71   if(this.hasAddress(email))
72     return;
73   
74   e = document.getElementById('addr_0');
75   if(e.value == '') {
76     e.value = s;
77     shouldAddRow = false;
78   }
79   if(shouldAddRow) {
80     this.fancyAddRow(false, s);
81   }
82   this.rememberAddress(email);
83 }
84
85 function fancyAddRow(shouldEdit, text) {
86   var addr, table, lastChild, proto, row, select, input;
87   
88   addr = document.getElementById('addr_' + lastIndex);
89   if (addr && addr.value == '') {
90     input = document.getElementById('compose_subject_input');
91     if (input && input.value != '') {
92       input.focus();
93       input.select();
94       return;
95     }
96   }
97   table = this.getTable();
98   lastChild = document.getElementById('row_last');
99   
100   currentIndex++;
101   
102   proto = document.getElementById('row_' + lastIndex);
103   row = proto.cloneNode(true);
104   row.id = 'row_' + currentIndex;
105   
106   // select popup
107   select = row.childNodes[1].childNodes[1];
108   select.name = 'popup_' + currentIndex;
109   select.value = proto.childNodes[1].childNodes[1].value;
110   input = row.childNodes[3].childNodes[1];
111   input.name  = 'addr_' + currentIndex;
112   input.id    = 'addr_' + currentIndex;
113   input.value = text;
114   
115   table.insertBefore(row, lastChild);
116
117   if(shouldEdit) {
118     input.focus();
119     input.select();
120   }
121   this.adjustInlineAttachmentListHeight(this);
122 }
123
124 function addressFieldGotFocus(sender) {
125   var idx;
126   
127   idx = this.getIndexFromIdentifier(sender.id);
128   if ((lastIndex == idx) || (idx == 0)) return;
129   this.removeLastEditedRowIfEmpty();
130 }
131 function addressFieldLostFocus(sender) {
132   lastIndex = this.getIndexFromIdentifier(sender.id);
133 }
134
135 function removeLastEditedRowIfEmpty() {
136   var idx, addr, table, senderRow;
137   
138   idx = lastIndex;
139   if (idx == 0) return;
140   addr = document.getElementById('addr_' + idx);
141   if (!addr) return;
142   if (addr.value != '') return;
143   addr = this.findAddressWithIndex(idx);
144   if(addr) {
145     var addresses = document.getElementById('addr_addresses');
146     addresses.removeChild(addr);
147   }
148   table = this.getTable();
149   senderRow = this.findRowWithIndex(idx);
150   table.removeChild(senderRow);
151   this.adjustInlineAttachmentListHeight(this);
152 }
153
154 function findAddressWithIndex(idx) {
155   var list, i, count, addr, idx
156   list = document.getElementById('addr_addresses').childNodes;
157   count = list.length;
158   for(i = 0; i < count; i++) {
159     addr = list[i];
160     if(addr.innerHTML == idx)
161       return addr;
162   }
163   return null;
164 }
165
166 function findRowWithIndex(idx) {
167   var id = 'row_' + idx;
168   return document.getElementById(id);
169 }
170
171 function getIndexFromIdentifier(id) {
172   return id.split('_')[1];
173 }
174
175 function getTable() {
176   return document.getElementById('addr_table').childNodes[1];
177 };
178
179 function getAddressIDs() {
180   var table, rows, i, count, addressIDs;
181
182   addressIDs = new Array();
183
184   table = this.getTable();
185   rows  = table.childNodes;
186   count = rows.length;
187   
188   for (i = 0; i < count; i++) {
189     var row, rowId;
190     
191     row   = table.childNodes[i];
192     rowId = row.id;
193     if (rowId && rowId != 'row_last') {
194       var idx;
195
196       idx = this.getIndexFromIdentifier(rowId);
197       addressIDs.push(idx);
198     }
199   }
200   return addressIDs;
201 }
202
203 function getAddressCount() {
204   var addressCount, addressIDs, i, count;
205   
206   addressCount = 0;
207   addressIDs   = this.getAddressIDs();
208   count        = addressIDs.length;
209   for (i = 0; i < count; i++) {
210     var idx, input;
211
212     idx   = addressIDs[i];
213     input = document.getElementById('addr_' + idx);
214     if (input.value != '')
215       addressCount++;
216   }
217   return addressCount;
218 }
219
220 function UIxRecipientSelectorHasRecipients() {
221   var count;
222   
223   count = this.getAddressCount();
224   if (count > 0)
225     return true;
226   return false;
227 }