2 Copyright (C) 2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
23 * It's required that "currentIndex" is defined in a top level context.
26 * defines hasRecipients() returning a bool for the
27 * surrounding context to check.
30 var lastIndex = currentIndex;
32 function sanitizedCn(cn) {
34 parts = cn.split(', ');
40 function hasAddress(email) {
47 function rememberAddress(email) {
50 list = $('addr_addresses');
51 span = document.createElement('span');
53 idx = document.createTextNode(currentIndex);
54 span.appendChild(idx);
55 list.appendChild(span);
58 function checkAddresses() {
59 alert("addressCount: " + this.getAddressCount() + " currentIndex: " + currentIndex + " lastIndex: " + lastIndex);
62 function addAddress(type, email, uid, sn, cn, dn) {
63 var shouldAddRow, s, e;
67 s = this.sanitizedCn(cn) + ' <' + email + '>';
71 if(this.hasAddress(email))
80 this.fancyAddRow(false, s);
82 this.rememberAddress(email);
85 function fancyAddRow(shouldEdit, text) {
86 var addr, addressList, lastChild, proto, row, select, input;
88 addr = $('addr_' + lastIndex);
89 if (addr && addr.value == '') {
90 input = $('subjectField');
91 if (input && input.value != '') {
97 addressList = $("addressList").tBodies[0];
98 lastChild = $("lastRow");
102 proto = $('row_' + lastIndex);
103 row = proto.cloneNode(true);
104 row.id = 'row_' + currentIndex;
107 var rowNodes = row.childNodesWithTag("td");
108 select = $(rowNodes[0]).childNodesWithTag("select")[0];
109 select.name = 'popup_' + currentIndex;
110 // select.value = row.childNodesWithTag("span")[0].childNodesWithTag("select")[0].value;
111 input = $(rowNodes[1]).childNodesWithTag("input")[0];
112 input.name = 'addr_' + currentIndex;
113 input.id = 'addr_' + currentIndex;
116 addressList.insertBefore(row, lastChild);
119 input.setAttribute('autocomplete', 'off');
122 input.setAttribute('autocomplete', 'on');
126 function addressFieldGotFocus(sender) {
129 idx = this.getIndexFromIdentifier(sender.id);
130 if (lastIndex == idx) return;
131 this.removeLastEditedRowIfEmpty();
132 onWindowResize(null);
137 function addressFieldLostFocus(sender) {
138 lastIndex = this.getIndexFromIdentifier(sender.id);
143 function removeLastEditedRowIfEmpty() {
144 var idx, addr, addressList, senderRow;
147 if (idx == 0) return;
148 addr = $('addr_' + idx);
150 if (addr.value != '') return;
151 addr = this.findAddressWithIndex(idx);
153 var addresses = $('addr_addresses');
154 addresses.removeChild(addr);
156 addressList = $("addressList").tBodies[0];
157 senderRow = $("row_" + idx);
158 addressList.removeChild(senderRow);
161 function findAddressWithIndex(idx) {
162 var list, i, count, addr, idx
163 list = $('addr_addresses').childNodes;
165 for(i = 0; i < count; i++) {
167 if(addr.innerHTML == idx)
173 function getIndexFromIdentifier(id) {
174 return id.split('_')[1];
177 function getAddressIDs() {
178 var addressList, rows, i, count, addressIDs;
180 addressIDs = new Array();
182 addressList = $("addressList").tBodies[0];
183 rows = addressList.childNodes;
186 for (i = 0; i < count; i++) {
191 if (rowId && rowId != 'lastRow') {
194 idx = this.getIndexFromIdentifier(rowId);
195 addressIDs.push(idx);
201 function getAddressCount() {
202 var addressCount, addressIDs, i, count;
205 addressIDs = this.getAddressIDs();
206 count = addressIDs.length;
207 for (i = 0; i < count; i++) {
211 input = $('addr_' + idx);
212 if (input && input.value != '')
218 function hasRecipients() {
221 count = this.getAddressCount();
227 /* addressbook helpers */