From 21799d8e1f9dff7b02503a44be0f7072e88757e9 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 26 Oct 2006 00:15:12 +0000 Subject: [PATCH] Monotone-Parent: ef9dde1efccc6f2049760614ab6add61bb302de5 Monotone-Revision: eb3a293c7b6e644d0c97e3f1954550bb78ebb5ef Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2006-10-26T00:15:12 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 5 ++ UI/Contacts/UIxContactFoldersView.m | 96 ++++++++++++++++++++++++++++- UI/Contacts/product.plist | 19 +++--- 3 files changed, 111 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index b535c7ae7..4a03c67c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2006-10-25 Wolfgang Sourdeau + * UI/Contacts/UIxContactFoldersView.m ([UIxContactFoldersView + -contactSearchAction]): new action that returns the uid and the + username + email of the user whose name contain the value of the + "search" url parameter. + * SoObjects/Appointments/SOGoAppointmentFolder.m ([SOGoAppointmentFolder -fetchFreebusyInfosFrom:_startDateto:_endDate]): added fields diff --git a/UI/Contacts/UIxContactFoldersView.m b/UI/Contacts/UIxContactFoldersView.m index 661301d38..f6bef241d 100644 --- a/UI/Contacts/UIxContactFoldersView.m +++ b/UI/Contacts/UIxContactFoldersView.m @@ -21,9 +21,13 @@ */ #import -#import +#import +#import +#import -#import +#import +#import +#import #import "common.h" @@ -76,4 +80,92 @@ return [self _selectActionForApplication: @"calendars-contacts"]; } + +- (NSArray *) _searchResults: (NSString *) contact +{ + NSMutableArray *results; + SOGoContactFolders *topFolder; + NSEnumerator *sogoContactFolders; + id currentFolder; + + results = [NSMutableArray new]; + [results autorelease]; + + topFolder = [self clientObject]; + sogoContactFolders = [[topFolder contactFolders] objectEnumerator]; + currentFolder = [sogoContactFolders nextObject]; + while (currentFolder) + { + [results addObjectsFromArray: [currentFolder + lookupContactsWithFilter: contact + sortBy: @"cn" + ordering: NSOrderedAscending]]; + currentFolder = [sogoContactFolders nextObject]; + } + [topFolder release]; + + return results; +} + +- (NSString *) _emailForResult: (NSDictionary *) result +{ + NSMutableString *email; + NSString *name, *mail; + + email = [NSMutableString string]; + name = [result objectForKey: @"displayName"]; + if (![name length]) + name = [result objectForKey: @"cn"]; + mail = [result objectForKey: @"mail"]; + if ([name length]) + [email appendFormat: @"%@ <%@>", name, mail]; + else + [email appendString: mail]; + + NSLog(@"email: '%@'", email); + + return email; +} + +- (WOResponse *) _responseForResults: (NSArray *) results +{ + WOResponse *response; + NSString *email, *responseString; + NSDictionary *result; + + response = [context response]; + + if ([results count]) + { + result = [results objectAtIndex: 0]; + email = [self _emailForResult: result]; + responseString = [NSString stringWithFormat: @"%@:%@", + [result objectForKey: @"c_uid"], + email]; + [response setStatus: 200]; + [response setHeader: @"text/plain; charset=iso-8859-1" + forKey: @"Content-Type"]; + [response appendContentString: responseString]; + } + else + [response setStatus: 404]; + + return response; +} + +- (id ) contactSearchAction +{ + NSString *contact; + id result; + + contact = [self queryParameterForKey: @"search"]; + if ([contact length]) + result = [self _responseForResults: [self _searchResults: contact]]; + else + result = [NSException exceptionWithHTTPStatus: 400 + reason: @"missing 'search' parameter"]; + + return result; +} + @end diff --git a/UI/Contacts/product.plist b/UI/Contacts/product.plist index 6c08cd8b7..76a35de07 100644 --- a/UI/Contacts/product.plist +++ b/UI/Contacts/product.plist @@ -12,28 +12,33 @@ methods = { view = { protectedBy = "View"; - pageName = "UIxContactFoldersView"; + pageName = "UIxContactFoldersView"; }; new = { protectedBy = "View"; - pageName = "UIxContactFoldersView"; + pageName = "UIxContactFoldersView"; actionName = "new"; }; scheduler-contacts = { protectedBy = "View"; - pageName = "UIxContactFoldersView"; + pageName = "UIxContactFoldersView"; actionName = "selectForScheduler"; }; mailer-contacts = { protectedBy = "View"; - pageName = "UIxContactFoldersView"; + pageName = "UIxContactFoldersView"; actionName = "selectForMailer"; }; calendars-contacts = { protectedBy = "View"; - pageName = "UIxContactFoldersView"; + pageName = "UIxContactFoldersView"; actionName = "selectForCalendars"; }; + contactSearch = { + protectedBy = "View"; + pageName = "UIxContactFoldersView"; + actionName = "contactSearch"; + }; }; }; @@ -47,11 +52,11 @@ methods = { view = { protectedBy = "View"; - pageName = "UIxContactsListView"; + pageName = "UIxContactsListView"; }; new = { protectedBy = "View"; - pageName = "UIxContactEditor"; + pageName = "UIxContactEditor"; actionName = "new"; }; mailer-contacts = {