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) {
|
2009-09-01 16:12:53 +02:00
|
|
|
var parts;
|
|
|
|
parts = cn.split(', ');
|
|
|
|
if(parts.length == 1)
|
|
|
|
return cn;
|
|
|
|
return parts[0];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function hasAddress(email) {
|
2009-09-01 16:12:53 +02:00
|
|
|
var e = $(email);
|
|
|
|
if(e)
|
|
|
|
return true;
|
|
|
|
return false;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkAddresses() {
|
2009-09-01 16:12:53 +02:00
|
|
|
alert("addressCount: " + this.getAddressCount() + " currentIndex: " + currentIndex + " lastIndex: " + lastIndex);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
function fancyAddRow(text, type) {
|
2009-09-01 16:12:53 +02:00
|
|
|
var addr = $('addr_' + lastIndex);
|
|
|
|
if (addr && addr.value == '') {
|
2009-09-11 21:30:22 +02:00
|
|
|
var sub = $('subjectField');
|
|
|
|
if (sub && sub.value != '') {
|
|
|
|
sub.focus();
|
|
|
|
sub.select();
|
2009-09-01 16:12:53 +02:00
|
|
|
return;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2009-09-01 16:12:53 +02:00
|
|
|
var addressList = $("addressList").tBodies[0];
|
|
|
|
var lastChild = $("lastRow");
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
currentIndex++;
|
|
|
|
var proto = lastChild.previous("tr");
|
|
|
|
var row = proto.cloneNode(true);
|
|
|
|
row.writeAttribute("id", 'row_' + currentIndex);
|
|
|
|
var rowNodes = row.childNodesWithTag("td");
|
|
|
|
var select = $(rowNodes[0]).childNodesWithTag("select")[0];
|
|
|
|
select.name = 'popup_' + currentIndex;
|
|
|
|
select.value = (type? type : proto.down("select").value);
|
2010-10-14 21:34:31 +02:00
|
|
|
var cell = $(rowNodes[1]);
|
|
|
|
var input = cell.childNodesWithTag("input")[0];
|
|
|
|
if (Prototype.Browser.IE) {
|
|
|
|
cell.removeChild(input);
|
|
|
|
input = new Element("input");
|
|
|
|
cell.appendChild(input);
|
|
|
|
}
|
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
input.name = 'addr_' + currentIndex;
|
|
|
|
input.id = 'addr_' + currentIndex;
|
|
|
|
input.value = text;
|
2010-10-14 21:34:31 +02:00
|
|
|
input.stopObserving();
|
2009-09-01 16:12:53 +02:00
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
input.addInterface(SOGoAutoCompletionInterface);
|
|
|
|
input.focus();
|
|
|
|
input.select();
|
2010-10-14 21:34:31 +02:00
|
|
|
input.observe("focus", addressFieldGotFocus.bind(input));
|
|
|
|
input.observe("blur", addressFieldLostFocus.bind(input));
|
2009-10-28 18:48:22 +01:00
|
|
|
input.observe("autocompletion:changedlist", expandContactList);
|
2010-10-14 21:34:31 +02:00
|
|
|
|
|
|
|
addressList.insertBefore(row, lastChild);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2009-09-11 21:30:22 +02:00
|
|
|
function expandContactList (e) {
|
2009-10-28 18:48:22 +01:00
|
|
|
var container = $(e).memo;
|
|
|
|
var url = UserFolderURL + "Contacts/" + container + "/"
|
|
|
|
+ this.readAttribute("uid") + "/properties";
|
2009-09-11 21:30:22 +02:00
|
|
|
triggerAjaxRequest (url, expandContactListCallback, this);
|
|
|
|
}
|
2009-09-23 16:08:37 +02:00
|
|
|
|
2009-09-11 21:30:22 +02:00
|
|
|
function expandContactListCallback (http) {
|
|
|
|
if (http.readyState == 4) {
|
|
|
|
var input = http.callbackData;
|
|
|
|
if (http.status == 200) {
|
|
|
|
var data = http.responseText.evalJSON(true);
|
2009-10-28 18:48:22 +01:00
|
|
|
// TODO: Should check for duplicated entries
|
2009-09-11 21:30:22 +02:00
|
|
|
if (data.length >= 1) {
|
|
|
|
var text = data[0][2];
|
|
|
|
if (data[0][1].length)
|
|
|
|
text = data[0][1] + " <" + data[0][2] + ">";
|
|
|
|
input.value = text;
|
2010-06-17 23:38:12 +02:00
|
|
|
input.writeAttribute("container", null);
|
2009-09-11 21:30:22 +02:00
|
|
|
}
|
|
|
|
if (data.length > 1) {
|
|
|
|
for (var i = 1; i < data.length; i++) {
|
|
|
|
var text = data[i][2];
|
|
|
|
if (data[i][1].length)
|
|
|
|
text = data[i][1] + " <" + data[i][2] + ">";
|
2009-10-28 18:48:22 +01:00
|
|
|
fancyAddRow(text, $(input).up("tr").down("select").value);
|
2009-09-11 21:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 21:34:31 +02:00
|
|
|
function addressFieldGotFocus(event) {
|
2009-09-01 16:12:53 +02:00
|
|
|
var idx;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-10-14 21:34:31 +02:00
|
|
|
idx = getIndexFromIdentifier(this.id);
|
2009-09-01 16:12:53 +02:00
|
|
|
if (lastIndex == idx) return;
|
2010-10-14 21:34:31 +02:00
|
|
|
removeLastEditedRowIfEmpty();
|
2009-09-01 16:12:53 +02:00
|
|
|
onWindowResize(null);
|
2006-07-13 21:13:18 +02:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
return false;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-13 21:13:18 +02:00
|
|
|
|
2010-10-14 21:34:31 +02:00
|
|
|
function addressFieldLostFocus(event) {
|
|
|
|
lastIndex = getIndexFromIdentifier(this.id);
|
2009-10-28 18:48:22 +01:00
|
|
|
|
2010-10-14 21:34:31 +02:00
|
|
|
var addresses = this.value.split(',');
|
2009-09-01 16:12:53 +02:00
|
|
|
if (addresses.length > 0) {
|
2010-06-17 23:38:12 +02:00
|
|
|
var first = true;
|
|
|
|
for (var i = 0; i < addresses.length; i++) {
|
|
|
|
var words = addresses[i].split(' ');
|
|
|
|
var phrase = new Array();
|
|
|
|
for (var j = 0; j < words.length; j++) {
|
|
|
|
var word = words[j].strip().replace(/<(.+)>/, "$1");
|
|
|
|
if (word.length > 0) {
|
2010-06-30 19:26:06 +02:00
|
|
|
// Use the regexp defined in generic.js
|
2010-06-17 23:38:12 +02:00
|
|
|
if (emailRE.test(word)) {
|
|
|
|
phrase.push('<' + word + '>');
|
|
|
|
if (first) {
|
2010-10-14 21:34:31 +02:00
|
|
|
this.value = phrase.join(' ');
|
2010-06-17 23:38:12 +02:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
else
|
2010-10-14 21:34:31 +02:00
|
|
|
fancyAddRow(phrase.join(' '), $(this).up("tr").down("select").value);
|
2010-06-17 23:38:12 +02:00
|
|
|
|
|
|
|
phrase = new Array();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
phrase.push(word);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (phrase.length > 0) {
|
|
|
|
if (first) {
|
2010-10-14 21:34:31 +02:00
|
|
|
this.value = phrase.join(' ');
|
2010-06-17 23:38:12 +02:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
else
|
2010-10-14 21:34:31 +02:00
|
|
|
fancyAddRow(phrase.join(' '), $(this).up("tr").down("select").value);
|
2010-06-17 23:38:12 +02:00
|
|
|
|
|
|
|
phrase = new Array();
|
|
|
|
}
|
2009-09-01 16:12:53 +02:00
|
|
|
}
|
2007-12-06 20:35:19 +01:00
|
|
|
}
|
2009-09-01 16:12:53 +02:00
|
|
|
onWindowResize(null);
|
2007-12-06 20:35:19 +01:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
return false;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeLastEditedRowIfEmpty() {
|
2009-09-01 16:12:53 +02:00
|
|
|
var addr, addressList, senderRow;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
addressList = $("addressList").tBodies[0];
|
2007-12-05 18:07:40 +01:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
if (lastIndex == 0 && addressList.childNodes.length <= 2) return;
|
|
|
|
addr = $('addr_' + lastIndex);
|
|
|
|
if (!addr) return;
|
|
|
|
if (addr.value.strip() != '') return;
|
|
|
|
senderRow = $("row_" + lastIndex);
|
|
|
|
addressList.removeChild(senderRow);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getIndexFromIdentifier(id) {
|
2009-09-01 16:12:53 +02:00
|
|
|
return id.split('_')[1];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAddressIDs() {
|
2009-09-01 16:12:53 +02:00
|
|
|
var addressList, rows, i, count, addressIDs;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
addressIDs = new Array();
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
addressList = $("addressList").tBodies[0];
|
|
|
|
rows = addressList.childNodes;
|
|
|
|
count = rows.length;
|
2006-09-20 19:56:36 +02:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
var row, rowId;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
row = rows[i];
|
|
|
|
rowId = row.id;
|
|
|
|
if (rowId && rowId != 'lastRow') {
|
|
|
|
var idx;
|
|
|
|
|
|
|
|
idx = this.getIndexFromIdentifier(rowId);
|
|
|
|
addressIDs.push(idx);
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2009-09-01 16:12:53 +02:00
|
|
|
return addressIDs;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAddressCount() {
|
2009-09-01 16:12:53 +02:00
|
|
|
var addressCount, addressIDs, i, count;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
addressCount = 0;
|
|
|
|
addressIDs = this.getAddressIDs();
|
|
|
|
count = addressIDs.length;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
var idx, input;
|
|
|
|
|
|
|
|
idx = addressIDs[i];
|
|
|
|
input = $('addr_' + idx);
|
|
|
|
if (input && input.value != '')
|
|
|
|
addressCount++;
|
|
|
|
}
|
|
|
|
return addressCount;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-05 15:37:26 +01:00
|
|
|
function hasRecipients() {
|
2009-09-01 16:12:53 +02:00
|
|
|
var count;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-09-01 16:12:53 +02:00
|
|
|
count = this.getAddressCount();
|
2007-11-17 00:02:21 +01:00
|
|
|
|
2009-09-01 16:12:53 +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() {
|
2009-09-01 16:12:53 +02:00
|
|
|
currentIndex = lastIndex = $$("table#addressList tr").length - 2;
|
2007-12-04 23:47:41 +01:00
|
|
|
}
|
2006-09-20 19:56:36 +02:00
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initMailToSelection);
|