2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Dependencies:
|
|
|
|
* It's required that "currentIndex" is defined in a top level context.
|
|
|
|
*
|
|
|
|
* Exports:
|
|
|
|
* defines UIxRecipientSelectorHasRecipients() returning a bool for the
|
|
|
|
* surrounding context to check.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var lastIndex = currentIndex;
|
|
|
|
|
|
|
|
function sanitizedCn(cn) {
|
|
|
|
var parts;
|
|
|
|
parts = cn.split(', ');
|
|
|
|
if(parts.length == 1)
|
|
|
|
return cn;
|
|
|
|
return parts[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
function hasAddress(email) {
|
2006-09-20 19:56:36 +02:00
|
|
|
var e = $(email);
|
2006-06-15 21:34:10 +02:00
|
|
|
if(e)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function rememberAddress(email) {
|
|
|
|
var list, span, idx;
|
|
|
|
|
2006-09-20 19:56:36 +02:00
|
|
|
list = $('addr_addresses');
|
2006-06-15 21:34:10 +02:00
|
|
|
span = document.createElement('span');
|
|
|
|
span.id = email;
|
|
|
|
idx = document.createTextNode(currentIndex);
|
|
|
|
span.appendChild(idx);
|
|
|
|
list.appendChild(span);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAddresses() {
|
|
|
|
alert("addressCount: " + this.getAddressCount() + " currentIndex: " + currentIndex + " lastIndex: " + lastIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addAddress(type, email, uid, sn, cn, dn) {
|
|
|
|
var shouldAddRow, s, e;
|
|
|
|
|
|
|
|
shouldAddRow = true;
|
|
|
|
if (cn)
|
|
|
|
s = this.sanitizedCn(cn) + ' <' + email + '>';
|
|
|
|
else
|
|
|
|
s = email;
|
|
|
|
|
|
|
|
if(this.hasAddress(email))
|
|
|
|
return;
|
|
|
|
|
2006-09-20 19:56:36 +02:00
|
|
|
e = $('addr_0');
|
2006-06-15 21:34:10 +02:00
|
|
|
if(e.value == '') {
|
|
|
|
e.value = s;
|
|
|
|
shouldAddRow = false;
|
|
|
|
}
|
|
|
|
if(shouldAddRow) {
|
|
|
|
this.fancyAddRow(false, s);
|
|
|
|
}
|
|
|
|
this.rememberAddress(email);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fancyAddRow(shouldEdit, text) {
|
2006-09-20 19:56:36 +02:00
|
|
|
var addr, addressList, lastChild, proto, row, select, input;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-20 19:56:36 +02:00
|
|
|
addr = $('addr_' + lastIndex);
|
2006-06-15 21:34:10 +02:00
|
|
|
if (addr && addr.value == '') {
|
2006-09-20 19:56:36 +02:00
|
|
|
input = $('compose_subject_input');
|
2006-06-15 21:34:10 +02:00
|
|
|
if (input && input.value != '') {
|
|
|
|
input.focus();
|
|
|
|
input.select();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-09-20 19:56:36 +02:00
|
|
|
addressList = $("addressList");
|
|
|
|
lastChild = $('row_last');
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
currentIndex++;
|
|
|
|
|
2006-09-20 19:56:36 +02:00
|
|
|
proto = $('row_' + lastIndex);
|
2006-06-15 21:34:10 +02:00
|
|
|
row = proto.cloneNode(true);
|
|
|
|
row.id = 'row_' + currentIndex;
|
2006-09-20 19:56:36 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
// select popup
|
2006-09-20 19:56:36 +02:00
|
|
|
select = row.childNodes[0].childNodes[0];
|
2006-06-15 21:34:10 +02:00
|
|
|
select.name = 'popup_' + currentIndex;
|
2006-09-20 19:56:36 +02:00
|
|
|
select.value = proto.childNodes[0].childNodes[0].value;
|
|
|
|
input = row.childNodes[1];
|
2006-06-15 21:34:10 +02:00
|
|
|
input.name = 'addr_' + currentIndex;
|
2006-09-20 19:56:36 +02:00
|
|
|
input.id = 'addr_' + currentIndex;
|
2006-06-15 21:34:10 +02:00
|
|
|
input.value = text;
|
|
|
|
|
2006-09-20 19:56:36 +02:00
|
|
|
addressList.insertBefore(row, lastChild);
|
|
|
|
|
|
|
|
if (shouldEdit) {
|
|
|
|
input.setAttribute('autocomplete', 'off');
|
2006-06-15 21:34:10 +02:00
|
|
|
input.focus();
|
|
|
|
input.select();
|
2006-09-20 19:56:36 +02:00
|
|
|
input.setAttribute('autocomplete', 'on');
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-09-20 19:56:36 +02:00
|
|
|
// this.adjustInlineAttachmentListHeight(this);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addressFieldGotFocus(sender) {
|
|
|
|
var idx;
|
|
|
|
|
|
|
|
idx = this.getIndexFromIdentifier(sender.id);
|
|
|
|
if ((lastIndex == idx) || (idx == 0)) return;
|
|
|
|
this.removeLastEditedRowIfEmpty();
|
2006-07-13 21:13:18 +02:00
|
|
|
|
|
|
|
return false;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-13 21:13:18 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
function addressFieldLostFocus(sender) {
|
|
|
|
lastIndex = this.getIndexFromIdentifier(sender.id);
|
2006-07-13 21:13:18 +02:00
|
|
|
|
|
|
|
return false;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeLastEditedRowIfEmpty() {
|
2006-09-20 19:56:36 +02:00
|
|
|
var idx, addr, addressList, senderRow;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
idx = lastIndex;
|
|
|
|
if (idx == 0) return;
|
2006-09-20 19:56:36 +02:00
|
|
|
addr = $('addr_' + idx);
|
2006-06-15 21:34:10 +02:00
|
|
|
if (!addr) return;
|
|
|
|
if (addr.value != '') return;
|
|
|
|
addr = this.findAddressWithIndex(idx);
|
|
|
|
if(addr) {
|
2006-09-20 19:56:36 +02:00
|
|
|
var addresses = $('addr_addresses');
|
2006-06-15 21:34:10 +02:00
|
|
|
addresses.removeChild(addr);
|
|
|
|
}
|
2006-09-20 19:56:36 +02:00
|
|
|
addressList = $("addressList");
|
2006-06-15 21:34:10 +02:00
|
|
|
senderRow = this.findRowWithIndex(idx);
|
2006-09-20 19:56:36 +02:00
|
|
|
addressList.removeChild(senderRow);
|
2006-06-15 21:34:10 +02:00
|
|
|
this.adjustInlineAttachmentListHeight(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function findAddressWithIndex(idx) {
|
|
|
|
var list, i, count, addr, idx
|
2006-09-20 19:56:36 +02:00
|
|
|
list = $('addr_addresses').childNodes;
|
2006-06-15 21:34:10 +02:00
|
|
|
count = list.length;
|
|
|
|
for(i = 0; i < count; i++) {
|
|
|
|
addr = list[i];
|
|
|
|
if(addr.innerHTML == idx)
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function findRowWithIndex(idx) {
|
|
|
|
var id = 'row_' + idx;
|
2006-09-20 19:56:36 +02:00
|
|
|
return $(id);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getIndexFromIdentifier(id) {
|
|
|
|
return id.split('_')[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAddressIDs() {
|
2006-09-20 19:56:36 +02:00
|
|
|
var addressList, rows, i, count, addressIDs;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
addressIDs = new Array();
|
|
|
|
|
2006-09-20 19:56:36 +02:00
|
|
|
addressList = $("addressList");
|
|
|
|
rows = addressList.childNodes;
|
2006-06-15 21:34:10 +02:00
|
|
|
count = rows.length;
|
2006-09-20 19:56:36 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
var row, rowId;
|
|
|
|
|
2006-09-20 19:56:36 +02:00
|
|
|
row = addressList.childNodes[i];
|
2006-06-15 21:34:10 +02:00
|
|
|
rowId = row.id;
|
|
|
|
if (rowId && rowId != 'row_last') {
|
|
|
|
var idx;
|
|
|
|
|
|
|
|
idx = this.getIndexFromIdentifier(rowId);
|
|
|
|
addressIDs.push(idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return addressIDs;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAddressCount() {
|
|
|
|
var addressCount, addressIDs, i, count;
|
|
|
|
|
|
|
|
addressCount = 0;
|
|
|
|
addressIDs = this.getAddressIDs();
|
|
|
|
count = addressIDs.length;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
var idx, input;
|
|
|
|
|
|
|
|
idx = addressIDs[i];
|
2006-09-20 19:56:36 +02:00
|
|
|
input = $('addr_' + idx);
|
2006-06-15 21:34:10 +02:00
|
|
|
if (input.value != '')
|
|
|
|
addressCount++;
|
|
|
|
}
|
|
|
|
return addressCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
function UIxRecipientSelectorHasRecipients() {
|
|
|
|
var count;
|
|
|
|
|
|
|
|
count = this.getAddressCount();
|
|
|
|
if (count > 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2006-09-20 19:56:36 +02:00
|
|
|
|
|
|
|
function adjustInlineAttachmentListHeight(sender) {
|
|
|
|
var e;
|
|
|
|
|
|
|
|
e = $('attachmentsArea');
|
|
|
|
if (e.style.display != 'none') {
|
|
|
|
/* need to lower left size first, because left auto-adjusts to right! */
|
|
|
|
xHeight('compose_attachments_list', 10);
|
|
|
|
|
|
|
|
var leftHeight, rightHeaderHeight;
|
|
|
|
leftHeight = xHeight('compose_leftside');
|
|
|
|
rightHeaderHeight = xHeight('compose_attachments_header');
|
|
|
|
xHeight('compose_attachments_list',
|
|
|
|
(leftHeight - rightHeaderHeight) - 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideInlineAttachmentList(sender) {
|
|
|
|
var e;
|
|
|
|
|
|
|
|
// xVisibility('compose_rightside', false);
|
|
|
|
e = $('compose_rightside');
|
|
|
|
e.style.display = 'none';
|
|
|
|
e = $('compose_leftside');
|
|
|
|
e.style.width = "100%";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* addressbook helpers */
|
|
|
|
|