diff --git a/ChangeLog b/ChangeLog index 5b67140d0..b53e0ea24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-03-29 Wolfgang Sourdeau + * UI/Scheduler/UIxCalendarSelector.m: new template module derived + from a simplified version of the old UIxContactEditor (removed). + * UI/Contacts/UIxContactsUserFolders.m: new template module for selecting users or user folders through an LDAP search of which the results are displayed as a tree. diff --git a/UI/Contacts/UIxContactSelector.h b/UI/Contacts/UIxContactSelector.h deleted file mode 100644 index 81b20751b..000000000 --- a/UI/Contacts/UIxContactSelector.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - Copyright (C) 2000-2004 SKYRIX Software AG - - This file is part of OGo - - OGo is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - OGo is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with OGo; see the file COPYING. If not, write to the - Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. - */ - -#ifndef UIXCONTACTSELECTOR_H -#define UIXCONTACTSELECTOR_H - -@class NSArray; -@class NSDictionary; -@class NSString; -@class iCalPerson; - -@interface UIxContactSelector : UIxComponent -{ - NSString *title; - NSString *windowId; - NSString *selectorId; - NSString *callback; - - NSArray *contacts; - NSArray *checkedBoxes; - iCalPerson *currentContact; - - BOOL hasCheckBoxes; - NSString *checkBoxOnChange; - - NSDictionary *userColors; -} - -- (void) setHasCheckBoxes: (BOOL) aBool; -- (BOOL) hasCheckBoxes; -- (void) setCheckBoxOnChange: (NSString *) aString; -- (NSString *) checkBoxOnChange; - -- (void)setTitle:(NSString *)_title; -- (NSString *)title; -- (void)setWindowId:(NSString *)_winId; -- (NSString *)windowId; -- (void)setSelectorId:(NSString *)_selId; -- (NSString *)selectorId; -- (void)setCallback:(NSString *)_callback; -- (NSString *)callback; - -- (void) setContacts: (NSArray *) _contacts; -- (NSArray *) contacts; - -- (void) setCurrentContact: (iCalPerson *) aContact; -- (NSString *) currentContactId; -- (NSString *) currentContactName; -- (NSString *) initialContactsAsString; - -- (NSString *)relativeContactsPath; - -- (NSString *)jsFunctionName; -- (NSString *)jsFunctionHref; -- (NSString *)jsCode; -@end - -#endif /* UIXCONTACTSELECTOR_H */ diff --git a/UI/Contacts/UIxContactSelector.m b/UI/Contacts/UIxContactSelector.m deleted file mode 100644 index 041fe52eb..000000000 --- a/UI/Contacts/UIxContactSelector.m +++ /dev/null @@ -1,251 +0,0 @@ -/* - Copyright (C) 2000-2004 SKYRIX Software AG - - This file is part of OGo - - OGo is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - OGo is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with OGo; see the file COPYING. If not, write to the - Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. - */ -// $Id: UIxContactSelector.m 394 2004-10-14 08:47:35Z znek $ - -#import -#import - -#import -#import - -#import "common.h" - -#import "UIxContactSelector.h" - -@implementation UIxContactSelector - -- (id)init { - if ((self = [super init])) { - [self setTitle:@"UIxContacts"]; - [self setWindowId:@"UIxContacts"]; - [self setCallback:@"undefined"]; - checkedBoxes = nil; - userColors = nil; - } - return self; -} - -- (void)dealloc { - [self->title release]; - [self->windowId release]; - [self->callback release]; - [super dealloc]; -} - -/* accessors */ - -- (void)setTitle:(NSString *)_title { - ASSIGNCOPY(self->title, _title); -} -- (NSString *)title { - return self->title; -} - -- (void)setWindowId:(NSString *)_winId { - ASSIGNCOPY(self->windowId, _winId); -} -- (NSString *)windowId { - return self->windowId; -} - -- (void)setSelectorId:(NSString *)_selId { - ASSIGNCOPY(selectorId, _selId); -} - -- (NSString *)selectorId { - return selectorId; -} - -- (NSString *)selectorIdList { - return [NSString stringWithFormat: @"uixselector-%@-uidList", selectorId]; -} - -- (NSString *)selectorIdDisplay { - return [NSString stringWithFormat: @"uixselector-%@-display", selectorId]; -} - -- (void)setCallback:(NSString *)_callback { - ASSIGNCOPY(self->callback, _callback); -} -- (NSString *)callback { - return self->callback; -} - -/* Helper */ - -- (NSString *)relativeContactsPath { - return [self relativePathToUserFolderSubPath:@"Contacts/select"]; -} - -/* JavaScript */ - -- (NSString *)jsFunctionName { - return [NSString stringWithFormat:@"openUIxContactsListViewWindowWithId%@", - [self windowId]]; -} - -- (NSString *)jsFunctionHref { - return [NSString stringWithFormat:@"javascript:%@()", - [self jsFunctionName]]; -} - -- (NSString *)jsCode { - static NSString *codeFmt = \ - @"function %@() {\n" - @" var url = '%@?callback=%@';\n" - @" var contactsWindow = window.open(url, '%@', 'width=600, height=400, left=10, top=10, toolbar=no, dependent=yes, menubar=no, location=no, resizable=yes, scrollbars=yes, directories=no, status=no');\n" - @" contactsWindow.focus();\n" - @"}"; - return [NSString stringWithFormat:codeFmt, - [self jsFunctionName], - [self relativeContactsPath], - [self callback], - [self windowId]]; -} - -- (void) setContacts: (NSArray *) _contacts -{ - contacts = _contacts; -} - -- (NSArray *) contacts -{ - return contacts; -} - -- (NSArray *) getICalPersonsFromValue: (NSString *) selectorValue -{ - NSMutableArray *persons; - NSEnumerator *uids; - NSString *uid; - AgenorUserManager *um; - - um = [AgenorUserManager sharedUserManager]; - - persons = [NSMutableArray new]; - [persons autorelease]; - - if ([selectorValue length] > 0) - { - uids = [[selectorValue componentsSeparatedByString: @","] - objectEnumerator]; - uid = [uids nextObject]; - while (uid) - { - [persons addObject: [um iCalPersonWithUid: uid]]; - uid = [uids nextObject]; - } - } - - return persons; -} - -- (void) takeValuesFromRequest: (WORequest *) _rq - inContext: (WOContext *) _ctx -{ - contacts = [self getICalPersonsFromValue: [_rq formValueForKey: selectorId]]; - if ([contacts count] > 0) - NSLog (@"got %i attendees: %@", [contacts count], contacts); - else - NSLog (@"got no attendees!"); -} - -- (void) setCurrentContact: (iCalPerson *) aContact -{ - currentContact = aContact; -} - -- (NSString *) initialContactsAsString -{ - NSEnumerator *persons; - iCalPerson *person; - NSMutableArray *participants; - - participants = [NSMutableArray arrayWithCapacity: [contacts count]]; - persons = [contacts objectEnumerator]; - person = [persons nextObject]; - while (person) - { - [participants addObject: [person cn]]; - person = [persons nextObject]; - } - - return [participants componentsJoinedByString: @","]; -} - -- (NSString *) currentContactId -{ - return [currentContact cn]; -} - -- (NSString *) currentContactName -{ - return [currentContact cn]; -} - -- (void) setCheckedBoxes: (NSArray *) boxes -{ - checkedBoxes = boxes; -} - -- (void) setHasCheckBoxes: (BOOL) aBool -{ - hasCheckBoxes = aBool; -} - -- (BOOL) hasCheckBoxes -{ - return hasCheckBoxes; -} - -- (BOOL) isCheckBoxChecked -{ - return (checkedBoxes != nil - && [checkedBoxes containsObject: currentContact]); -} - -- (void) setCheckBoxOnChange: (NSString *) aString -{ - checkBoxOnChange = aString; -} - -- (NSString *) checkBoxOnChange -{ - return checkBoxOnChange; -} - -- (void) setColors: (NSDictionary *) colors -{ - userColors = colors; -} - -- (BOOL) hasColors -{ - return (userColors != nil); -} - -- (NSString *) currentContactStyle -{ - return [NSString stringWithFormat: @"background-color: %@;", - [userColors objectForKey: [currentContact cn]]]; -} - -@end /* UIxContactSelector */ diff --git a/UI/Scheduler/UIxCalendarSelector.h b/UI/Scheduler/UIxCalendarSelector.h new file mode 100644 index 000000000..3d15fc774 --- /dev/null +++ b/UI/Scheduler/UIxCalendarSelector.h @@ -0,0 +1,52 @@ +/* UIxCalendarSelector.h - this file is part of SOGo + * + * Copyright (C) 2007 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef UIXCALENDARSELECTOR_H +#define UIXCALENDARSELECTOR_H + +@class NSArray; +@class NSMutableArray; +@class NSDictionary; +@class NSMutableDictionary; +@class NSString; +@class iCalPerson; + +@interface UIxCalendarSelector : UIxComponent +{ + NSMutableArray *calendarFolders; + NSMutableDictionary *colors; + + NSDictionary *currentCalendarFolder; + NSString *currentCalendarLogin; +} + +- (NSArray *) calendarFolders; +- (void) setCurrentCalendarFolder: (NSDictionary *) newCurrentCalendarFolder; +- (NSDictionary *) currentCalendarFolder; + +- (NSString *) currentCalendarSpanBG; +- (NSString *) currentCalendarLogin; +- (NSString *) currentCalendarStyle; + +@end + +#endif /* UIXCALENDARSELECTOR_H */ diff --git a/UI/Scheduler/UIxCalendarSelector.m b/UI/Scheduler/UIxCalendarSelector.m new file mode 100644 index 000000000..ab6b124a1 --- /dev/null +++ b/UI/Scheduler/UIxCalendarSelector.m @@ -0,0 +1,175 @@ +/* UIxCalendarSelector.m - this file is part of SOGo + * + * Copyright (C) 2007 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import +#import +#import + +#import +#import + +#import +#import +#import + +#import "UIxCalendarSelector.h" + +static inline char +darkenedColor (const char value) +{ + char newValue; + + if (value >= '0' && value <= '9') + newValue = ((value - '0') / 2) + '0'; + else if (value >= 'a' && value <= 'f') + newValue = ((value + 10 - 'a') / 2) + '0'; + else if (value >= 'A' && value <= 'F') + newValue = ((value + 10 - 'A') / 2) + '0'; + else + newValue = value; + + return newValue; +} + +static inline NSString * +colorForNumber (unsigned int number) +{ + unsigned int index, currentValue; + unsigned char colorTable[] = { 1, 1, 1 }; + NSString *color; + + if (number == 0) + color = @"#ccf"; + else if (number == NSNotFound) + color = @"#f00"; + else + { + currentValue = number; + index = 0; + while (currentValue) + { + if (currentValue & 1) + colorTable[index]++; + if (index == 3) + index = 0; + currentValue >>= 1; + index++; + } + color = [NSString stringWithFormat: @"#%2x%2x%2x", + (255 / colorTable[2]) - 1, + (255 / colorTable[1]) - 1, + (255 / colorTable[0]) - 1]; + } + + return color; +} + +@implementation UIxCalendarSelector + +- (id) init +{ + if ((self = [super init])) + { + colors = [NSMutableDictionary new]; + calendarFolders = nil; + currentCalendarFolder = nil; + } + + return self; +} + +- (void) dealloc +{ + [calendarFolders release]; + [currentCalendarFolder release]; + [colors release]; + [super dealloc]; +} + +- (void) setCalendarFolders: (NSArray *) newCalendarFolders +{ + NSEnumerator *newFolders; + NSDictionary *currentFolder; + unsigned int count; + + ASSIGN (calendarFolders, newCalendarFolders); + + newFolders = [calendarFolders objectEnumerator]; + currentFolder = [newFolders nextObject]; + count = 0; + while (currentFolder) + { + [colors setObject: colorForNumber (count) + forKey: [currentFolder objectForKey: @"folder"]]; + count++; + currentFolder = [newFolders nextObject]; + } +} + +- (NSArray *) calendarFolders +{ + return calendarFolders; +} + +- (void) setCurrentCalendarFolder: (NSDictionary *) newCurrentCalendarFolder +{ + ASSIGN (currentCalendarFolder, newCurrentCalendarFolder); +} + +- (NSDictionary *) currentCalendarFolder +{ + return currentCalendarFolder; +} + +- (NSString *) currentCalendarSpanBG +{ + NSString *colorKey; + + colorKey = [currentCalendarFolder objectForKey: @"folder"]; + + return [colors objectForKey: colorKey]; +} + +- (NSString *) currentCalendarLogin +{ + NSArray *parts; + + parts = [[currentCalendarFolder objectForKey: @"folder"] + componentsSeparatedByString: @":"]; + + return (([parts count] > 1) + ? [parts objectAtIndex: 0] + : [[context activeUser] login]); +} + +- (NSString *) currentCalendarStyle +{ + NSString *color; + + color = [self currentCalendarSpanBG]; + + return [NSString stringWithFormat: @"color: %@; background-color: %@;", + color, color]; +} + +@end /* UIxCalendarSelector */