]> err.no Git - scalable-opengroupware.org/blobdiff - UI/WebServerResources/UIxMailToSelection.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1292 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / UIxMailToSelection.js
index 1966931bac547fb0830d0d37ad5a65a808293770..8a9a686f378fc75fb15749db12c2533dc5b137fc 100644 (file)
@@ -23,7 +23,7 @@
  * 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.
  */
 
@@ -38,159 +38,115 @@ function sanitizedCn(cn) {
 }
 
 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);
@@ -210,18 +166,23 @@ function getAddressCount() {
     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);