]> err.no Git - scalable-opengroupware.org/blob - UI/Contacts/UIxContactSelector.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1026 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Contacts / UIxContactSelector.m
1 /*
2  Copyright (C) 2000-2004 SKYRIX Software AG
3  
4  This file is part of OGo
5  
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
9  later version.
10  
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.
15  
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
19  02111-1307, USA.
20  */
21 // $Id$
22
23 #import <NGExtensions/NGExtensions.h>
24 #import <NGCards/iCalPerson.h>
25
26 #import <SOGoUI/UIxComponent.h>
27 #import <SOGo/AgenorUserManager.h>
28
29 #import "common.h"
30
31 #import "UIxContactSelector.h"
32
33 @implementation UIxContactSelector
34
35 - (id)init {
36   if ((self = [super init])) {
37     [self setTitle:@"UIxContacts"];
38     [self setWindowId:@"UIxContacts"];
39     [self setCallback:@"undefined"];
40     checkedBoxes = nil;
41     userColors = nil;
42   }
43   return self;
44 }
45
46 - (void)dealloc {
47   [self->title    release];
48   [self->windowId release];
49   [self->callback release];
50   [super dealloc];
51 }
52
53 /* accessors */
54
55 - (void)setTitle:(NSString *)_title {
56   ASSIGNCOPY(self->title, _title);
57 }
58 - (NSString *)title {
59   return self->title;
60 }
61
62 - (void)setWindowId:(NSString *)_winId {
63   ASSIGNCOPY(self->windowId, _winId);
64 }
65 - (NSString *)windowId {
66   return self->windowId;
67 }
68
69 - (void)setSelectorId:(NSString *)_selId {
70   ASSIGNCOPY(selectorId, _selId);
71 }
72
73 - (NSString *)selectorId {
74   return selectorId;
75 }
76
77 - (NSString *)selectorIdList {
78   return [NSString stringWithFormat: @"uixselector-%@-uidList", selectorId];
79 }
80
81 - (NSString *)selectorIdDisplay {
82   return [NSString stringWithFormat: @"uixselector-%@-display", selectorId];
83 }
84
85 - (void)setCallback:(NSString *)_callback {
86   ASSIGNCOPY(self->callback, _callback);
87 }
88 - (NSString *)callback {
89   return self->callback;
90 }
91
92 /* Helper */
93
94 - (NSString *)relativeContactsPath {
95   return [self relativePathToUserFolderSubPath:@"Contacts/select"];
96 }
97
98 /* JavaScript */
99
100 - (NSString *)jsFunctionName {
101   return [NSString stringWithFormat:@"openUIxContactsListViewWindowWithId%@",
102     [self windowId]];
103 }
104
105 - (NSString *)jsFunctionHref {
106   return [NSString stringWithFormat:@"javascript:%@()",
107     [self jsFunctionName]];
108 }
109
110 - (NSString *)jsCode {
111   static NSString *codeFmt = \
112   @"function %@() {\n"
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"
116   @"}";
117   return [NSString stringWithFormat:codeFmt,
118     [self jsFunctionName],
119     [self relativeContactsPath],
120     [self callback],
121     [self windowId]];
122 }
123
124 - (void) setContacts: (NSArray *) _contacts
125 {
126   contacts = _contacts;
127 }
128
129 - (NSArray *) contacts
130 {
131   return contacts;
132 }
133
134 - (NSArray *) getICalPersonsFromValue: (NSString *) selectorValue
135 {
136   NSMutableArray *persons;
137   NSEnumerator *uids;
138   NSString *uid;
139   AgenorUserManager *um;
140
141   um = [AgenorUserManager sharedUserManager];
142
143   persons = [NSMutableArray new];
144   [persons autorelease];
145
146   if ([selectorValue length] > 0)
147     {
148       uids = [[selectorValue componentsSeparatedByString: @","]
149                objectEnumerator];
150       uid = [uids nextObject];
151       while (uid)
152         {
153           [persons addObject: [um iCalPersonWithUid: uid]];
154           uid = [uids nextObject];
155         }
156     }
157
158   return persons;
159 }
160
161 - (void) takeValuesFromRequest: (WORequest *) _rq
162                      inContext: (WOContext *) _ctx
163 {
164   contacts = [self getICalPersonsFromValue: [_rq formValueForKey: selectorId]];
165   if ([contacts count] > 0)
166     NSLog (@"got %i attendees: %@", [contacts count], contacts);
167   else
168     NSLog (@"got no attendees!");
169 }
170
171 - (void) setCurrentContact: (iCalPerson *) aContact
172 {
173   currentContact = aContact;
174 }
175
176 - (NSString *) initialContactsAsString
177 {
178   NSEnumerator *persons;
179   iCalPerson *person;
180   NSMutableArray *participants;
181
182   participants = [NSMutableArray arrayWithCapacity: [contacts count]];
183   persons = [contacts objectEnumerator];
184   person = [persons nextObject];
185   while (person)
186     {
187       [participants addObject: [person cn]];
188       person = [persons nextObject];
189     }
190
191   return [participants componentsJoinedByString: @","];
192 }
193
194 - (NSString *) currentContactId
195 {
196   return [currentContact cn];
197 }
198
199 - (NSString *) currentContactName
200 {
201   return [currentContact cn];
202 }
203
204 - (void) setCheckedBoxes: (NSArray *) boxes
205 {
206   checkedBoxes = boxes;
207 }
208
209 - (void) setHasCheckBoxes: (BOOL) aBool
210 {
211   hasCheckBoxes = aBool;
212 }
213
214 - (BOOL) hasCheckBoxes
215 {
216   return hasCheckBoxes;
217 }
218
219 - (BOOL) isCheckBoxChecked
220 {
221   return (checkedBoxes != nil
222           && [checkedBoxes containsObject: currentContact]);
223 }
224
225 - (void) setCheckBoxOnChange: (NSString *) aString
226 {
227   checkBoxOnChange = aString;
228 }
229
230 - (NSString *) checkBoxOnChange
231 {
232   return  checkBoxOnChange;
233 }
234
235 - (void) setColors: (NSDictionary *) colors
236 {
237   userColors = colors;
238 }
239
240 - (BOOL) hasColors
241 {
242   return (userColors != nil);
243 }
244
245 - (NSString *) currentContactStyle
246 {
247   return [NSString stringWithFormat: @"background-color: %@;",
248                    [userColors objectForKey: [currentContact cn]]];
249 }
250
251 @end /* UIxContactSelector */