]> err.no Git - scalable-opengroupware.org/commitdiff
work in progress
authorznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 12 Oct 2004 19:22:35 +0000 (19:22 +0000)
committerznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 12 Oct 2004 19:22:35 +0000 (19:22 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@388 d1b88da0-ebda-0310-925b-ed51d893ca5b

SOGo/UI/Mailer/ChangeLog
SOGo/UI/Mailer/UIxMailToSelection.m
SOGo/UI/Mailer/UIxMailToSelection.wox
SOGo/UI/Mailer/Version

index 3f9a2bde0bb68e8408c3e1246bc0d96df58b4065..9a9e6dd688e31e15f44a74b7624d2959495e6536 100644 (file)
@@ -1,5 +1,8 @@
 2004-10-12  Marcus Mueller  <znek@mulle-kybernetik.com>
 
+        * UIxMailToSelection.[m|wox]: parse given arguments and conditionally
+         split lists. Dynamically create tables and JavaScript. (v0.9.35)
+
         * UIxMailToSelection.wox: minor update (v0.9.34)
 
         * v0.9.33
index e10f290b98a1187a270485bb4d48b9c656406df3..b41ec79b455b8bc92b054877ea82afccad041d52 100644 (file)
 
 @interface UIxMailToSelection : UIxComponent
 {
-    NSArray *to;
-    NSArray *cc;
-    NSArray *bcc;
+  NSArray *to;
+  NSArray *cc;
+  NSArray *bcc;
+  id item;
+  id address;
+  NSArray *addressList;
+  int currentIndex;
 }
 
 - (void)setTo:(NSArray *)_to;
 - (void)setBcc:(NSArray *)_bcc;
 - (NSArray *)bcc;
 
+- (NSArray *)properlySplitAddresses:(NSArray *)_addresses;
+
 - (NSArray *)getAddressesOfType:(NSString *)_type
                  fromFormValues:(NSArray *)_values;
 
 @end
 
 #include "common.h"
+#include <NGMail/NGMail.h>
 
 @implementation UIxMailToSelection
 
+static NSArray *headers = nil;
+
++ (void)initialize {
+  static BOOL didInit = NO;
+  if(didInit)
+    return;
+
+  didInit = YES;
+  headers = [[NSArray alloc] initWithObjects:@"to", @"cc", @"bcc", nil];
+}
+
+- (id)init {
+  self = [super init];
+  if(self) {
+    self->currentIndex = 0;
+  }
+  return self;
+}
+
 - (void)dealloc {
-    [self->to  release];
-    [self->cc  release];
-    [self->bcc release];
-    [super dealloc];
+  [self->to   release];
+  [self->cc   release];
+  [self->bcc  release];
+
+  [self->item        release];
+  [self->address     release];
+  [self->addressList release];
+  [super dealloc];
 }
 
 /* notifications */
 
+- (void)awake {
+  [super awake];
+  NSLog(@"%s", __PRETTY_FUNCTION__);
+}
+
 - (void)sleep {
-    [super sleep];
+  [super sleep];
 }
 
 /* accessors */
 
 - (void)setTo:(NSArray *)_to {
-    ASSIGN(self->to, _to);
+  _to = [self properlySplitAddresses:_to];
+  ASSIGN(self->to, _to);
 }
 - (NSArray *)to {
-    return self->to;
+  return self->to;
 }
 
 - (void)setCc:(NSArray *)_cc {
-    ASSIGN(self->cc, _cc);
+  _cc = [self properlySplitAddresses:_cc];
+  ASSIGN(self->cc, _cc);
 }
 - (NSArray *)cc {
-    return self->cc;
+  return self->cc;
 }
 
 - (void)setBcc:(NSArray *)_bcc {
-    ASSIGN(self->bcc, _bcc);
+  _bcc = [self properlySplitAddresses:_bcc];
+  ASSIGN(self->bcc, _bcc);
 }
 - (NSArray *)bcc {
-    return self->bcc;
+  return self->bcc;
+}
+
+- (void)setAddressList:(NSArray *)_addressList {
+  ASSIGN(self->addressList, _addressList);
+}
+- (NSArray *)addressList {
+  return self->addressList;
+}
+
+- (void)setAddress:(id)_address {
+  ASSIGN(self->address, _address);
+}
+- (id)address {
+  return self->address;
+}
+
+- (void)setItem:(id)_item {
+  ASSIGN(self->item, _item);
+}
+- (id)item {
+  return self->item;
+}
+
+- (NSArray *)addressLists {
+  NSMutableArray *ma;
+  
+  ma = [NSMutableArray arrayWithCapacity:3];
+  if(self->to)
+    [ma addObject:self->to];
+  if(self->cc)
+    [ma addObject:self->cc];
+  if(self->bcc)
+    [ma addObject:self->bcc];
+  return ma;
+}
+
+- (NSArray *)headers {
+  return headers;
+}
+
+- (NSString *)currentHeader {
+  if(self->addressList == self->to)
+    return @"to";
+  else if(self->addressList == self->cc)
+    return @"cc";
+  return @"bcc";
+}
+
+/* identifiers */
+
+- (NSString *)currentRowId {
+  if(currentIndex == 0)
+    return @"addr_proto";
+  return [NSString stringWithFormat:@"row_%d", self->currentIndex];
+}
+
+- (NSString *)currentPopUpId {
+  return [NSString stringWithFormat:@"popup_%d", self->currentIndex];
+}
+
+- (NSString *)currentAddressId {
+  return [NSString stringWithFormat:@"addr_%d", self->currentIndex];
+}
+
+- (NSString *)nextId {
+  self->currentIndex++;
+  return @"";
+}
+
+/* address handling */
+
+- (NSArray *)properlySplitAddresses:(NSArray *)_addresses {
+  NSString *addrs;
+  NGMailAddressParser *parser;
+  NSArray *result;
+  NSMutableArray *ma;
+  unsigned i, count;
+
+  if(!_addresses || [_addresses count] == 0)
+    return nil;
+
+  /* create one huge string, then split it using the parser */
+  addrs = [_addresses componentsJoinedByString:@","];
+  parser = [NGMailAddressParser mailAddressParserWithString:addrs];
+  result = [parser parseAddressList];
+  if(result == nil) {
+    [self debugWithFormat:@"Couldn't parse given addresses:%@", _addresses];
+    return _addresses;
+  }
+
+  count = [result count];
+  ma = [NSMutableArray arrayWithCapacity:count];
+  for(i = 0; i < count; i++) {
+    NGMailAddress *addr;
+    NSMutableString *s;
+    BOOL hasName = NO;
+
+    s = [[NSMutableString alloc] init];
+    addr = [result objectAtIndex:i];
+    if([addr displayName]) {
+      [s appendString:[addr displayName]];
+      [s appendString:@" "];
+      hasName = YES;
+    }
+    if(hasName)
+      [s appendString:@"<"];
+    [s appendString:[addr address]];
+    if(hasName)
+      [s appendString:@">"];
+    [ma addObject:s];
+  }
+  return ma;
 }
 
 /* handling requests */
 - (NSArray *)getAddressesOfType:(NSString *)_type
                  fromFormValues:(NSArray *)_values
 {
-    unsigned i, count;
-    NSMutableArray *result;
+  unsigned i, count;
+  NSMutableArray *result;
+  
+  count = [_values count];
+  result = [NSMutableArray arrayWithCapacity:count];
+  for (i = 0; i < count; i++) {
+    NSString *s;
     
-    count = [_values count];
-    result = [NSMutableArray arrayWithCapacity:count];
-    for (i = 0; i < count; i++) {
-        NSString *s;
-        
-        s = [_values objectAtIndex:i];
-        if ([s length] == 0)
-            continue;
-    }
-    return result;
+    s = [_values objectAtIndex:i];
+    if ([s length] == 0)
+      continue;
+  }
+  return result;
 }
 
 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
-    /* OK, we have a special form value processor */
-    NSArray *tmp;
-    
-    [self debugWithFormat:@"Note: will take values ..."];
-    
-    NSLog(@"formValues: %@", [_rq formValues]);
-
-    tmp = [self getAddressesOfType:@"to"
-                    fromFormValues:[_rq formValuesForKey:@"to"]];
-    [self setTo:tmp];
-    tmp = [self getAddressesOfType:@"cc"
-                    fromFormValues:[_rq formValuesForKey:@"cc"]];
-    [self setCc:tmp];
-    tmp = [self getAddressesOfType:@"bcc"
-                    fromFormValues:[_rq formValuesForKey:@"bcc"]];
-    [self setBcc:tmp];
+  /* OK, we have a special form value processor */
+  NSArray *tmp;
+  
+  [self debugWithFormat:@"Note: will take values ..."];
+  
+  NSLog(@"%s formValues: %@",
+        __PRETTY_FUNCTION__,
+        [_rq formValues]);
+  
+  tmp = [self getAddressesOfType:@"to"
+                  fromFormValues:[_rq formValuesForKey:@"to"]];
+  [self setTo:tmp];
+  tmp = [self getAddressesOfType:@"cc"
+                  fromFormValues:[_rq formValuesForKey:@"cc"]];
+  [self setCc:tmp];
+  tmp = [self getAddressesOfType:@"bcc"
+                  fromFormValues:[_rq formValuesForKey:@"bcc"]];
+  [self setBcc:tmp];
 }
 
 /* response generation */
 
 - (NSString *)jsCode {
-    static NSString *script = \
-    @"var currentIndex = 0;\n"
-    @"\n"
-    @"function hasAddress(email) {\n"
-    @"  var e = document.getElementById(email);\n"
-    @"  if(e)\n"
-    @"    return true;\n"
-    @"  return false;\n"
-    @"}\n"
-    @"\n"
-    @"function rememberAddress(email) {\n"
-    @"  var list, e;\n"
-    @"  \n"
-    @"  list = document.getElementById(\"addr_addresses\");\n"
-    @"  e = document.createElement(\"span\");\n"
-    @"  e.id = email;\n"
-    @"  list.appendChild(e);\n"
-    @"}\n"
-    @"\n"
-    @"function addAddress(type, cn, dn, email, uid, sn) {\n"
-    @"  var shouldAddRow, s;\n"
-    @"  \n"
-    @"  shouldAddRow = true;\n"
-    @"  s = cn + \" <\" + email + \">\";\n"
-    @"\n"
-    @"  if(this.hasAddress(email))\n"
-    @"    return;\n"
-    @"\n"
-    @"  this.rememberAddress(email);\n"
-    @"\n"
-    @"  var e = document.getElementById(\"addr_0\");\n"
-    @"  if(e.value == '') {\n"
-    @"    e.value = s;\n"
-    @"    shouldAddRow = false;\n"
-    @"  }\n"
-    @"  if(shouldAddRow) {\n"
-    @"    this.fancyAddRow(false, s);\n"
-    @"  }\n"
-    @"}\n"
-    @"\n"
-    @"function fancyAddRow(shouldEdit, text) {\n"
-    @"  var table = document.getElementById(\"addr_table\").childNodes[1];\n"
-    @"  var lastChild = document.getElementById(\"addr_lastentry\");\n"
-    @"  var proto, row, select, input;\n"
-    @"\n"
-    @"  currentIndex++;\n"
-    @"\n"
-    @"  proto = document.getElementById(\"addr_proto\");\n"
-    @"  row = proto.cloneNode(true);\n"
-    @"  row.id = \"\";\n"
-    @"\n"
-    @"  select = row.childNodes[1].childNodes[1];\n"
-    @"  select.name = \"popup_\" + currentIndex;\n"
-    @"  input = row.childNodes[3].childNodes[1];\n"
-    @"  input.name = \"addr_\" + currentIndex;\n"
-    @"  input.id = \"addr_\" + currentIndex;\n"
-    @"  input.value = text;\n"
-    @"\n"
-    @"  table.insertBefore(row, lastChild);\n"
-    @"  if(shouldEdit) {\n"
-    @"    input.focus();\n"
-    @"    input.select();\n"
-    @"  }\n"
-    @"}\n"
-    @"\n";
-    return script;
+  static NSString *script = \
+  @"var currentIndex = %d;\n"
+  @"\n"
+  @"function hasAddress(email) {\n"
+  @"  var e = document.getElementById(email);\n"
+  @"  if(e)\n"
+  @"    return true;\n"
+  @"  return false;\n"
+  @"}\n"
+  @"\n"
+  @"function rememberAddress(email) {\n"
+  @"  var list, e;\n"
+  @"  \n"
+  @"  list = document.getElementById(\"addr_addresses\");\n"
+  @"  e = document.createElement(\"span\");\n"
+  @"  e.id = email;\n"
+  @"  list.appendChild(e);\n"
+  @"}\n"
+  @"\n"
+  @"function addAddress(type, cn, dn, email, uid, sn) {\n"
+  @"  var shouldAddRow, s;\n"
+  @"  \n"
+  @"  shouldAddRow = true;\n"
+  @"  s = cn + \" <\" + email + \">\";\n"
+  @"\n"
+  @"  if(this.hasAddress(email))\n"
+  @"    return;\n"
+  @"\n"
+  @"  this.rememberAddress(email);\n"
+  @"\n"
+  @"  var e = document.getElementById(\"addr_0\");\n"
+  @"  if(e.value == '') {\n"
+  @"    e.value = s;\n"
+  @"    shouldAddRow = false;\n"
+  @"  }\n"
+  @"  if(shouldAddRow) {\n"
+  @"    this.fancyAddRow(false, s);\n"
+  @"  }\n"
+  @"}\n"
+  @"\n"
+  @"function fancyAddRow(shouldEdit, text) {\n"
+  @"  var table = document.getElementById(\"addr_table\").childNodes[1];\n"
+  @"  var lastChild = document.getElementById(\"addr_lastentry\");\n"
+  @"  var proto, row, select, input;\n"
+  @"\n"
+  @"  currentIndex++;\n"
+  @"\n"
+  @"  proto = document.getElementById(\"addr_proto\");\n"
+  @"  row = proto.cloneNode(true);\n"
+  @"  row.id = \"\";\n"
+  @"\n"
+  @"  select = row.childNodes[1].childNodes[1];\n"
+  @"  select.name = \"popup_\" + currentIndex;\n"
+  @"  input = row.childNodes[3].childNodes[1];\n"
+  @"  input.name = \"addr_\" + currentIndex;\n"
+  @"  input.id = \"addr_\" + currentIndex;\n"
+  @"  input.value = text;\n"
+  @"\n"
+  @"  table.insertBefore(row, lastChild);\n"
+  @"  if(shouldEdit) {\n"
+  @"    input.focus();\n"
+  @"    input.select();\n"
+  @"  }\n"
+  @"}\n"
+  @"\n";
+  return [NSString stringWithFormat:
+    script,
+    self->currentIndex];
 }
 
 @end
index 3eb953591023fef4f79ce87ac56986644b3cd011..678d5226f3bf218cc28a23aa75de834c08a74f96 100644 (file)
     <var:string value="jsCode" const:escapeHTML="NO" />
   </script>
   <table id="addr_table">
-    <tr id="addr_proto">
-      <td width="20%">
-        <select id="popup_0" name="popup_0" style="width: 100%;">
-          <option value="to" ><var:string label:value="TO" />:</option>
-          <option value="cc" ><var:string label:value="CC" />:</option>
-          <option value="bcc"><var:string label:value="BCC" />:</option>
-        </select>
-      </td>
-      <td width="80%">
-        <input id="addr_0" name="addr_0" type="text" style="width: 100%;"/>
-      </td>
-    </tr>
+    <var:foreach list="addressLists" item="addressList">
+      <var:foreach list="addressList" item="address">
+        <tr var:id="currentRowId">
+          <td width="20%">
+            <var:popup id="currentPopUpId"
+                       name="currentPopUpId"
+                       list="headers"
+                       item="item"
+                       label:string="$item"
+                       selection="currentHeader"
+                       const:style="width: 100%;"
+            />
+          </td>
+          <td width="80%">
+            <input var:id="currentAddressId"
+                   var:name="currentAddressId"
+                   type="text"
+                   var:value="address"
+                   style="width: 100%;"
+            />
+          </td>
+        </tr>
+        <var:string value="nextId" />
+      </var:foreach>
+    </var:foreach>
     <tr id="addr_lastentry">
       <td width="20%">
         <select style="width: 100%;" disabled="1">
-          <option value="to" ><var:string label:value="TO" />:</option>
+          <option value="to" ><var:string label:value="to" />:</option>
         </select>
       </td>
       <td width="80%">
@@ -36,4 +49,5 @@
   </table>
   <span id="addr_addresses" style="visibility: hidden;">
   </span>
+  <input type="submit" label:value="Test" name="test:method" />
 </span>
\ No newline at end of file
index 8d1e9bd6bf0563028ada61e19a231d8cfede140f..941f0d4d5677280a5b28760e3f32942b31598979 100644 (file)
@@ -1,3 +1,3 @@
 # $Id$
 
-SUBMINOR_VERSION:=34
+SUBMINOR_VERSION:=35