2009-07-19 18:41:42 +02:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-08-28 16:48:45 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2008-08-28 16:48:45 +02:00
|
|
|
Copyright (C) 2005 SKYRIX Software AG
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
This file is part of OpenGroupware.org.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
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.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
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.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
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.
|
2006-06-15 21:34:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Dependencies:
|
|
|
|
* It's required that "currentIndex" is defined in a top level context.
|
|
|
|
*
|
|
|
|
* Exports:
|
2007-11-05 15:37:26 +01:00
|
|
|
* defines hasRecipients() returning a bool for the
|
2006-06-15 21:34:10 +02:00
|
|
|
* 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 checkAddresses() {
|
|
|
|
alert("addressCount: " + this.getAddressCount() + " currentIndex: " + currentIndex + " lastIndex: " + lastIndex);
|
|
|
|
}
|
|
|
|
|
2007-12-06 20:35:19 +01:00
|
|
|
function fancyAddRow(shouldEdit, text, type) {
|
2008-09-09 20:44:25 +02:00
|
|
|
var addr = $('addr_' + lastIndex);
|
2006-06-15 21:34:10 +02:00
|
|
|
if (addr && addr.value == '') {
|
2008-09-09 20:44:25 +02:00
|
|
|
var input = $('subjectField');
|
2006-06-15 21:34:10 +02:00
|
|
|
if (input && input.value != '') {
|
|
|
|
input.focus();
|
|
|
|
input.select();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 20:44:25 +02:00
|
|
|
var addressList = $("addressList").tBodies[0];
|
|
|
|
var lastChild = $("lastRow");
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
currentIndex++;
|
2008-09-09 20:44:25 +02:00
|
|
|
var proto = lastChild.previous("tr");
|
|
|
|
var row = proto.cloneNode(true);
|
2008-08-09 12:18:45 +02:00
|
|
|
row.writeAttribute("id", 'row_' + currentIndex);
|
2007-11-02 16:09:44 +01:00
|
|
|
var rowNodes = row.childNodesWithTag("td");
|
2008-09-09 20:44:25 +02:00
|
|
|
var select = $(rowNodes[0]).childNodesWithTag("select")[0];
|
2006-06-15 21:34:10 +02:00
|
|
|
select.name = 'popup_' + currentIndex;
|
2007-12-06 20:35:19 +01:00
|
|
|
select.value = (type? type : proto.down("select").value);
|
2008-09-09 20:44:25 +02:00
|
|
|
var input = $(rowNodes[1]).childNodesWithTag("input")[0];
|
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;
|
2008-10-16 19:57:49 +02:00
|
|
|
input.stopObserving("keydown", onContactKeydown);
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-20 19:56:36 +02:00
|
|
|
addressList.insertBefore(row, lastChild);
|
|
|
|
|
|
|
|
if (shouldEdit) {
|
2008-08-09 12:18:45 +02:00
|
|
|
input.writeAttribute("autocomplete", "off");
|
2008-07-03 23:26:05 +02:00
|
|
|
input.observe("keydown", onContactKeydown); // bind listener for address completion
|
2009-02-20 00:05:31 +01:00
|
|
|
input.observe("blur", onContactBlur);
|
2006-06-15 21:34:10 +02:00
|
|
|
input.focus();
|
|
|
|
input.select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addressFieldGotFocus(sender) {
|
|
|
|
var idx;
|
|
|
|
|
|
|
|
idx = this.getIndexFromIdentifier(sender.id);
|
2007-09-10 20:46:05 +02:00
|
|
|
if (lastIndex == idx) return;
|
2006-06-15 21:34:10 +02:00
|
|
|
this.removeLastEditedRowIfEmpty();
|
2007-09-10 20:46:05 +02:00
|
|
|
onWindowResize(null);
|
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);
|
2008-09-05 23:02:42 +02:00
|
|
|
|
2008-10-16 19:57:49 +02:00
|
|
|
if (sender.confirmedValue) {
|
|
|
|
sender.value = sender.confirmedValue;
|
|
|
|
sender.confirmedValue = false;
|
|
|
|
}
|
|
|
|
|
2007-12-06 20:35:19 +01:00
|
|
|
var addresses = sender.value.split(',');
|
|
|
|
if (addresses.length > 0) {
|
|
|
|
sender.value = addresses[0].strip();
|
|
|
|
for (var i = 1; i < addresses.length; i++) {
|
|
|
|
var addr = addresses[i].strip();
|
|
|
|
if (addr.length > 0)
|
2008-08-28 16:48:45 +02:00
|
|
|
fancyAddRow(false, addr, $(sender).up("tr").down("select").value);
|
2007-12-06 20:35:19 +01:00
|
|
|
}
|
|
|
|
}
|
2008-06-23 22:44:54 +02:00
|
|
|
onWindowResize(null);
|
2007-12-06 20:35:19 +01:00
|
|
|
|
2006-07-13 21:13:18 +02:00
|
|
|
return false;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeLastEditedRowIfEmpty() {
|
2007-12-05 18:07:40 +01:00
|
|
|
var addr, addressList, senderRow;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-12-05 18:07:40 +01:00
|
|
|
addressList = $("addressList").tBodies[0];
|
|
|
|
|
|
|
|
if (lastIndex == 0 && addressList.childNodes.length <= 2) return;
|
|
|
|
addr = $('addr_' + lastIndex);
|
2006-06-15 21:34:10 +02:00
|
|
|
if (!addr) return;
|
2007-12-04 23:47:41 +01:00
|
|
|
if (addr.value.strip() != '') return;
|
2007-12-05 18:07:40 +01:00
|
|
|
senderRow = $("row_" + lastIndex);
|
2008-10-16 19:57:49 +02:00
|
|
|
addressList.removeChild(senderRow);
|
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();
|
|
|
|
|
2007-11-05 15:37:26 +01:00
|
|
|
addressList = $("addressList").tBodies[0];
|
2006-09-20 19:56:36 +02:00
|
|
|
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;
|
|
|
|
|
2007-11-05 15:37:26 +01:00
|
|
|
row = rows[i];
|
2006-06-15 21:34:10 +02:00
|
|
|
rowId = row.id;
|
2007-11-05 15:37:26 +01:00
|
|
|
if (rowId && rowId != 'lastRow') {
|
2006-06-15 21:34:10 +02:00
|
|
|
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-10-19 18:55:42 +02:00
|
|
|
if (input && input.value != '')
|
2006-06-15 21:34:10 +02:00
|
|
|
addressCount++;
|
|
|
|
}
|
|
|
|
return addressCount;
|
|
|
|
}
|
|
|
|
|
2007-11-05 15:37:26 +01:00
|
|
|
function hasRecipients() {
|
2006-06-15 21:34:10 +02:00
|
|
|
var count;
|
|
|
|
|
|
|
|
count = this.getAddressCount();
|
2007-11-17 00:02:21 +01:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
return (count > 0);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-09-20 19:56:36 +02:00
|
|
|
|
2007-12-04 23:47:41 +01:00
|
|
|
function initMailToSelection() {
|
|
|
|
currentIndex = lastIndex = $$("table#addressList tr").length - 2;
|
|
|
|
}
|
2006-09-20 19:56:36 +02:00
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initMailToSelection);
|