* It's required that "currentIndex" is defined in a top level context.
*
* Exports:
- * defines UIxRecipientSelectorHasRecipients() returning a bool for the
+ * defines hasRecipients() returning a bool for the
* surrounding context to check.
*/
}
function hasAddress(email) {
- var e = document.getElementById(email);
+ var e = $(email);
if(e)
return true;
return false;
}
-function rememberAddress(email) {
- var list, span, idx;
-
- list = document.getElementById('addr_addresses');
- 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;
-
- e = document.getElementById('addr_0');
- if(e.value == '') {
- e.value = s;
- shouldAddRow = false;
- }
- if(shouldAddRow) {
- this.fancyAddRow(false, s);
- }
- this.rememberAddress(email);
-}
-
-function fancyAddRow(shouldEdit, text) {
- var addr, table, lastChild, proto, row, select, input;
+function fancyAddRow(shouldEdit, text, type) {
+ var addr, addressList, lastChild, proto, row, select, input;
- addr = document.getElementById('addr_' + lastIndex);
+ addr = $('addr_' + lastIndex);
if (addr && addr.value == '') {
- input = document.getElementById('compose_subject_input');
+ input = $('subjectField');
if (input && input.value != '') {
input.focus();
input.select();
return;
}
}
- table = this.getTable();
- lastChild = document.getElementById('row_last');
+ addressList = $("addressList").tBodies[0];
+ lastChild = $("lastRow");
currentIndex++;
-
- proto = document.getElementById('row_' + lastIndex);
+ proto = lastChild.previous("tr");
row = proto.cloneNode(true);
- row.id = 'row_' + currentIndex;
-
+ row.setAttribute("id", 'row_' + currentIndex);
+
// select popup
- select = row.childNodes[1].childNodes[1];
+ var rowNodes = row.childNodesWithTag("td");
+ select = $(rowNodes[0]).childNodesWithTag("select")[0];
select.name = 'popup_' + currentIndex;
- select.value = proto.childNodes[1].childNodes[1].value;
- input = row.childNodes[3].childNodes[1];
+ select.value = (type? type : proto.down("select").value);
+ input = $(rowNodes[1]).childNodesWithTag("input")[0];
input.name = 'addr_' + currentIndex;
- input.id = 'addr_' + currentIndex;
+ input.id = 'addr_' + currentIndex;
input.value = text;
-
- table.insertBefore(row, lastChild);
- if(shouldEdit) {
+ addressList.insertBefore(row, lastChild);
+
+ if (shouldEdit) {
+ input.setAttribute('autocomplete', 'off');
input.focus();
input.select();
+ input.setAttribute('autocomplete', 'on');
}
- this.adjustInlineAttachmentListHeight(this);
}
function addressFieldGotFocus(sender) {
var idx;
idx = this.getIndexFromIdentifier(sender.id);
- if ((lastIndex == idx) || (idx == 0)) return;
+ if (lastIndex == idx) return;
this.removeLastEditedRowIfEmpty();
+ onWindowResize(null);
+
+ return false;
}
+
function addressFieldLostFocus(sender) {
lastIndex = this.getIndexFromIdentifier(sender.id);
-}
-
-function removeLastEditedRowIfEmpty() {
- var idx, addr, table, senderRow;
- idx = lastIndex;
- if (idx == 0) return;
- addr = document.getElementById('addr_' + idx);
- if (!addr) return;
- if (addr.value != '') return;
- addr = this.findAddressWithIndex(idx);
- if(addr) {
- var addresses = document.getElementById('addr_addresses');
- addresses.removeChild(addr);
+ 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)
+ fancyAddRow(false, addr, $(sender).up("tr").down("select").value);
+ }
}
- table = this.getTable();
- senderRow = this.findRowWithIndex(idx);
- table.removeChild(senderRow);
- this.adjustInlineAttachmentListHeight(this);
-}
-function findAddressWithIndex(idx) {
- var list, i, count, addr, idx
- list = document.getElementById('addr_addresses').childNodes;
- count = list.length;
- for(i = 0; i < count; i++) {
- addr = list[i];
- if(addr.innerHTML == idx)
- return addr;
- }
- return null;
+ return false;
}
-function findRowWithIndex(idx) {
- var id = 'row_' + idx;
- return document.getElementById(id);
+function removeLastEditedRowIfEmpty() {
+ var addr, addressList, senderRow;
+
+ addressList = $("addressList").tBodies[0];
+
+ 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);
}
function getIndexFromIdentifier(id) {
return id.split('_')[1];
}
-function getTable() {
- return document.getElementById('addr_table').childNodes[1];
-};
-
function getAddressIDs() {
- var table, rows, i, count, addressIDs;
+ var addressList, rows, i, count, addressIDs;
addressIDs = new Array();
- table = this.getTable();
- rows = table.childNodes;
+ addressList = $("addressList").tBodies[0];
+ rows = addressList.childNodes;
count = rows.length;
-
+
for (i = 0; i < count; i++) {
var row, rowId;
- row = table.childNodes[i];
+ row = rows[i];
rowId = row.id;
- if (rowId && rowId != 'row_last') {
+ if (rowId && rowId != 'lastRow') {
var idx;
idx = this.getIndexFromIdentifier(rowId);
var idx, input;
idx = addressIDs[i];
- input = document.getElementById('addr_' + idx);
- if (input.value != '')
+ input = $('addr_' + idx);
+ if (input && input.value != '')
addressCount++;
}
return addressCount;
}
-function UIxRecipientSelectorHasRecipients() {
+function hasRecipients() {
var count;
count = this.getAddressCount();
- if (count > 0)
- return true;
- return false;
+
+ return (count > 0)
+}
+
+function initMailToSelection() {
+ currentIndex = lastIndex = $$("table#addressList tr").length - 2;
}
+
+FastInit.addOnLoad(initMailToSelection);