2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #import <NGExtensions/NGExtensions.h>
24 #import <NGCards/iCalPerson.h>
26 #import <SOGoUI/UIxComponent.h>
27 #import <SOGo/AgenorUserManager.h>
31 #import "UIxContactSelector.h"
33 @implementation UIxContactSelector
36 if ((self = [super init])) {
37 [self setTitle:@"UIxContacts"];
38 [self setWindowId:@"UIxContacts"];
39 [self setCallback:@"undefined"];
47 [self->title release];
48 [self->windowId release];
49 [self->callback release];
55 - (void)setTitle:(NSString *)_title {
56 ASSIGNCOPY(self->title, _title);
62 - (void)setWindowId:(NSString *)_winId {
63 ASSIGNCOPY(self->windowId, _winId);
65 - (NSString *)windowId {
66 return self->windowId;
69 - (void)setSelectorId:(NSString *)_selId {
70 ASSIGNCOPY(selectorId, _selId);
73 - (NSString *)selectorId {
77 - (NSString *)selectorIdList {
78 return [NSString stringWithFormat: @"uixselector-%@-uidList", selectorId];
81 - (NSString *)selectorIdDisplay {
82 return [NSString stringWithFormat: @"uixselector-%@-display", selectorId];
85 - (void)setCallback:(NSString *)_callback {
86 ASSIGNCOPY(self->callback, _callback);
88 - (NSString *)callback {
89 return self->callback;
94 - (NSString *)relativeContactsPath {
95 return [self relativePathToUserFolderSubPath:@"Contacts/select"];
100 - (NSString *)jsFunctionName {
101 return [NSString stringWithFormat:@"openUIxContactsListViewWindowWithId%@",
105 - (NSString *)jsFunctionHref {
106 return [NSString stringWithFormat:@"javascript:%@()",
107 [self jsFunctionName]];
110 - (NSString *)jsCode {
111 static NSString *codeFmt = \
113 @" var url = '%@?callback=%@';\n"
114 @" 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"
115 @" contactsWindow.focus();\n"
117 return [NSString stringWithFormat:codeFmt,
118 [self jsFunctionName],
119 [self relativeContactsPath],
124 - (void) setContacts: (NSArray *) _contacts
126 contacts = _contacts;
129 - (NSArray *) contacts
134 - (NSArray *) getICalPersonsFromValue: (NSString *) selectorValue
136 NSMutableArray *persons;
139 AgenorUserManager *um;
141 um = [AgenorUserManager sharedUserManager];
143 persons = [NSMutableArray new];
144 [persons autorelease];
146 if ([selectorValue length] > 0)
148 uids = [[selectorValue componentsSeparatedByString: @","]
150 uid = [uids nextObject];
153 [persons addObject: [um iCalPersonWithUid: uid]];
154 uid = [uids nextObject];
161 - (void) takeValuesFromRequest: (WORequest *) _rq
162 inContext: (WOContext *) _ctx
164 contacts = [self getICalPersonsFromValue: [_rq formValueForKey: selectorId]];
165 if ([contacts count] > 0)
166 NSLog (@"got %i attendees: %@", [contacts count], contacts);
168 NSLog (@"got no attendees!");
171 - (void) setCurrentContact: (iCalPerson *) aContact
173 currentContact = aContact;
176 - (NSString *) initialContactsAsString
178 NSEnumerator *persons;
180 NSMutableArray *participants;
182 participants = [NSMutableArray arrayWithCapacity: [contacts count]];
183 persons = [contacts objectEnumerator];
184 person = [persons nextObject];
187 [participants addObject: [person cn]];
188 person = [persons nextObject];
191 return [participants componentsJoinedByString: @","];
194 - (NSString *) currentContactId
196 return [currentContact cn];
199 - (NSString *) currentContactName
201 return [currentContact cn];
204 - (void) setCheckedBoxes: (NSArray *) boxes
206 checkedBoxes = boxes;
209 - (void) setHasCheckBoxes: (BOOL) aBool
211 hasCheckBoxes = aBool;
214 - (BOOL) hasCheckBoxes
216 return hasCheckBoxes;
219 - (BOOL) isCheckBoxChecked
221 return (checkedBoxes != nil
222 && [checkedBoxes containsObject: currentContact]);
225 - (void) setCheckBoxOnChange: (NSString *) aString
227 checkBoxOnChange = aString;
230 - (NSString *) checkBoxOnChange
232 return checkBoxOnChange;
235 - (void) setColors: (NSDictionary *) colors
242 return (userColors != nil);
245 - (NSString *) currentContactStyle
247 return [NSString stringWithFormat: @"background-color: %@;",
248 [userColors objectForKey: [currentContact cn]]];
251 @end /* UIxContactSelector */