From 6e606f86cfcb465d989e9f39c09fd40adc7b8bea Mon Sep 17 00:00:00 2001 From: znek Date: Tue, 12 Oct 2004 19:22:35 +0000 Subject: [PATCH] work in progress git-svn-id: http://svn.opengroupware.org/SOGo/trunk@388 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/UI/Mailer/ChangeLog | 3 + SOGo/UI/Mailer/UIxMailToSelection.m | 370 ++++++++++++++++++-------- SOGo/UI/Mailer/UIxMailToSelection.wox | 40 ++- SOGo/UI/Mailer/Version | 2 +- 4 files changed, 293 insertions(+), 122 deletions(-) diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index 3f9a2bde..9a9e6dd6 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,5 +1,8 @@ 2004-10-12 Marcus Mueller + * 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 diff --git a/SOGo/UI/Mailer/UIxMailToSelection.m b/SOGo/UI/Mailer/UIxMailToSelection.m index e10f290b..b41ec79b 100644 --- a/SOGo/UI/Mailer/UIxMailToSelection.m +++ b/SOGo/UI/Mailer/UIxMailToSelection.m @@ -45,9 +45,13 @@ @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; @@ -57,49 +61,195 @@ - (void)setBcc:(NSArray *)_bcc; - (NSArray *)bcc; +- (NSArray *)properlySplitAddresses:(NSArray *)_addresses; + - (NSArray *)getAddressesOfType:(NSString *)_type fromFormValues:(NSArray *)_values; @end #include "common.h" +#include @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 */ @@ -107,109 +257,113 @@ - (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 diff --git a/SOGo/UI/Mailer/UIxMailToSelection.wox b/SOGo/UI/Mailer/UIxMailToSelection.wox index 3eb95359..678d5226 100644 --- a/SOGo/UI/Mailer/UIxMailToSelection.wox +++ b/SOGo/UI/Mailer/UIxMailToSelection.wox @@ -11,22 +11,35 @@ - - - - + + + + + + + + +
- - - -
+ + + +
@@ -36,4 +49,5 @@
+ \ No newline at end of file diff --git a/SOGo/UI/Mailer/Version b/SOGo/UI/Mailer/Version index 8d1e9bd6..941f0d4d 100644 --- a/SOGo/UI/Mailer/Version +++ b/SOGo/UI/Mailer/Version @@ -1,3 +1,3 @@ # $Id$ -SUBMINOR_VERSION:=34 +SUBMINOR_VERSION:=35 -- 2.39.5