]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Anais/AnaisAttendeeSelector.m
attendee selector
[scalable-opengroupware.org] / SOGo / UI / Anais / AnaisAttendeeSelector.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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: AnaisSelector.m 184 2004-08-11 17:46:10Z znek $
22
23 #include <SOGoUI/UIxComponent.h>
24
25 /*
26   AnaisAttendeeSelector
27   
28   Select a set of attendees using Anais.
29   
30   Bindings:
31     attendees    - array of iCalPerson objects
32     selectorID   - string to be used as the identifier for form/JS elements
33     withCN       - show CN of person (eg disabled for resources)
34     division     - Anais division
35     emailForUser - default EMail
36     cnForUser    - default CN
37
38   Sample:
39     <var:component className="AnaisAttendeeSelector"
40                    selectorID="participant"
41                    attendees="attendees"
42                    const:division="CC"
43                   />
44 */
45
46 @class iCalPerson;
47
48 @interface AnaisAttendeeSelector : UIxComponent
49 {
50   NSString   *selectorID;
51   NSString   *division;
52   NSArray    *attendees;
53   iCalPerson *attendee;
54   NSString   *emailForUser;
55   NSString   *cnForUser;
56   struct {
57     int withCN:1;
58     int reserved:31;
59   } flags;
60 }
61
62 @end
63
64 #include <NGiCal/NGiCal.h>
65 #include <Scheduler/iCalPerson+UIx.h>
66 #include <NGObjWeb/WOContext.h>
67 #include "common.h"
68
69 @implementation AnaisAttendeeSelector
70
71 - (void)dealloc {
72   [self->emailForUser release];
73   [self->cnForUser    release];
74   [self->division     release];
75   [self->selectorID   release];
76   [self->attendee     release];
77   [self->attendees    release];
78   [super dealloc];
79 }
80
81 /* notifications */
82
83 - (void)sleep {
84   [self->attendee release]; self->attendee = nil;
85   [super sleep];
86 }
87
88 /* accessors */
89
90 - (void)setAttendees:(NSArray *)_attendees {
91   ASSIGN(self->attendees, _attendees);
92 }
93 - (NSArray *)attendees {
94   return self->attendees;
95 }
96 - (BOOL)hasAttendees {
97   return [[self attendees] count] > 0 ? YES : NO;
98 }
99 - (BOOL)hasNoAttendees {
100   return [[self attendees] count] == 0 ? YES : NO;
101 }
102
103 - (void)setWithCN:(BOOL)_flag {
104   self->flags.withCN = _flag ? 1 : 0;
105 }
106 - (BOOL)withCN {
107   return self->flags.withCN ? YES : NO;
108 }
109
110 - (void)setAttendee:(iCalPerson *)_attendee {
111   ASSIGN(self->attendee, _attendee);
112 }
113 - (iCalPerson *)attendee {
114   return self->attendee;
115 }
116
117 - (void)setDivision:(NSString *)_value {
118   ASSIGNCOPY(self->division, _value);
119 }
120 - (NSString *)division {
121   return self->division;
122 }
123
124 - (void)setEmailForUser:(NSString *)_value {
125   ASSIGNCOPY(self->emailForUser, _value);
126 }
127 - (NSString *)emailForUser {
128   return self->emailForUser;
129 }
130
131 - (void)setCnForUser:(NSString *)_value {
132   ASSIGNCOPY(self->cnForUser, _value);
133 }
134 - (NSString *)cnForUser {
135   return self->cnForUser;
136 }
137
138 - (BOOL)showDefaultAttendees {
139   return [self hasNoAttendees] && [[self emailForUser] length] > 0 ? YES : NO;
140 }
141
142 /* email, cn */
143
144 - (NSString *)combinedCNAndEmailForUser {
145   NSString *e, *c;
146
147   e = [self emailForUser];
148   c = [self cnForUser];
149   return [[e stringByAppendingString:@";"] stringByAppendingString:c];
150 }
151
152 - (NSString *)combinedCNAndEmail {
153   NSString *e, *c;
154   
155   e = [[self attendee] rfc822Email];
156   c = [[self attendee] cnForDisplay];
157   return [[e stringByAppendingString:@";"] stringByAppendingString:c];
158 }
159
160 /* id accessors */
161
162 - (void)setSelectorID:(NSString *)_value {
163   ASSIGNCOPY(self->selectorID, _value);
164 }
165 - (NSString *)selectorID {
166   return self->selectorID;
167 }
168 - (NSString *)capitalizedSelectorID {
169   return [[self selectorID] capitalizedString];
170 }
171
172 - (NSString *)windowId {
173   /* eg: 'Resources' */
174   return [[self capitalizedSelectorID] stringByAppendingString:@"s"];
175 }
176 - (NSString *)callbackName {
177   /* eg: 'addResource' */
178   return [@"add" stringByAppendingString:[self capitalizedSelectorID]];
179 }
180 - (NSString *)tableId {
181   /* eg: 'resources' */
182   return [[self selectorID] stringByAppendingString:@"s"];
183 }
184 - (NSString *)checkboxId {
185   /* eg: 'resources' */
186   return [self tableId]; /* TODO: znek, is this ok? */
187 }
188
189 /* handling requests */
190
191 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
192   [self logWithFormat:@"Note: will take values ..."];
193   [super takeValuesFromRequest:_rq inContext:_ctx];
194 }
195
196 /* response generation */
197
198 - (NSString *)jsCode {
199   NSMutableString *ms;
200   WOContext *ctx;
201   NSString *s;
202
203   ms = [NSMutableString stringWithCapacity:128];
204   
205   ctx = [self context];
206   if (![[ctx valueForKey:@"HasAddTableAnaisAttendeeSelector"] boolValue]) {
207     static NSString *script = \
208       @"function addToTable(tableId, type, cn, dn, email, uid, sn) {\n"
209       @"  var test = document.getElementById(email);"
210       @"  if(test)"
211       @"    return;"
212       @""
213       @"  var table = document.getElementById(tableId);"
214       @"  var tr = document.createElement('tr');"
215       @"  var td, checkbox, text;"
216       @""
217       @"  td = document.createElement('td');"
218       @"  checkbox = document.createElement('input');"
219       @"  checkbox.setAttribute('type', 'checkbox');"
220       @"  checkbox.setAttribute('checked', 'checked');"
221       @"  checkbox.setAttribute('value', email + ';' + cn);"
222       @"  checkbox.setAttribute('id', email);"
223       @"  checkbox.setAttribute('name', tableId);"
224       @"  td.appendChild(checkbox);"
225       @"  tr.appendChild(td);"
226       @"  td = document.createElement('td');"
227       @"  text = document.createTextNode(cn);"
228       @"  td.appendChild(text);"
229       @"  tr.appendChild(td);"
230       @"  table.appendChild(tr);"
231       @"}\n";
232     [ms appendString:script];
233     
234     [ctx takeValue:[NSNumber numberWithBool:YES]
235          forKey:@"HasAddTableAnaisAttendeeSelector"];
236   }
237   
238   s = 
239     @"function %@(type, cn, dn, email, uid, sn) {\n"
240     @"  addToTable('%@', type, cn, dn, email, uid, sn);\n"
241     @"}\n";
242   [ms appendFormat:s, [self callbackName], [self tableId]];
243   return ms;
244 }
245
246 @end /* AnaisAttendeeSelector */