2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
21 // $Id: AnaisSelector.m 184 2004-08-11 17:46:10Z znek $
23 #include <SOGoUI/UIxComponent.h>
28 Select a set of attendees using Anais.
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
39 <var:component className="AnaisAttendeeSelector"
40 selectorID="participant"
48 @interface AnaisAttendeeSelector : UIxComponent
54 NSString *emailForUser;
64 #include <NGiCal/NGiCal.h>
65 #include <Scheduler/iCalPerson+UIx.h>
66 #include <NGObjWeb/WOContext.h>
69 @implementation AnaisAttendeeSelector
72 [self->emailForUser release];
73 [self->cnForUser release];
74 [self->division release];
75 [self->selectorID release];
76 [self->attendee release];
77 [self->attendees release];
84 [self->attendee release]; self->attendee = nil;
90 - (void)setAttendees:(NSArray *)_attendees {
91 ASSIGN(self->attendees, _attendees);
93 - (NSArray *)attendees {
94 return self->attendees;
96 - (BOOL)hasAttendees {
97 return [[self attendees] count] > 0 ? YES : NO;
99 - (BOOL)hasNoAttendees {
100 return [[self attendees] count] == 0 ? YES : NO;
103 - (void)setWithCN:(BOOL)_flag {
104 self->flags.withCN = _flag ? 1 : 0;
107 return self->flags.withCN ? YES : NO;
110 - (void)setAttendee:(iCalPerson *)_attendee {
111 ASSIGN(self->attendee, _attendee);
113 - (iCalPerson *)attendee {
114 return self->attendee;
117 - (void)setDivision:(NSString *)_value {
118 ASSIGNCOPY(self->division, _value);
120 - (NSString *)division {
121 return self->division;
124 - (void)setEmailForUser:(NSString *)_value {
125 ASSIGNCOPY(self->emailForUser, _value);
127 - (NSString *)emailForUser {
128 return self->emailForUser;
131 - (void)setCnForUser:(NSString *)_value {
132 ASSIGNCOPY(self->cnForUser, _value);
134 - (NSString *)cnForUser {
135 return self->cnForUser;
138 - (BOOL)showDefaultAttendees {
139 return [self hasNoAttendees] && [[self emailForUser] length] > 0 ? YES : NO;
144 - (NSString *)combinedCNAndEmailForUser {
147 e = [self emailForUser];
148 c = [self cnForUser];
149 return [[e stringByAppendingString:@";"] stringByAppendingString:c];
152 - (NSString *)combinedCNAndEmail {
155 e = [[self attendee] rfc822Email];
156 c = [[self attendee] cnForDisplay];
157 return [[e stringByAppendingString:@";"] stringByAppendingString:c];
162 - (void)setSelectorID:(NSString *)_value {
163 ASSIGNCOPY(self->selectorID, _value);
165 - (NSString *)selectorID {
166 return self->selectorID;
168 - (NSString *)capitalizedSelectorID {
169 return [[self selectorID] capitalizedString];
172 - (NSString *)windowId {
173 /* eg: 'Resources' */
174 return [[self capitalizedSelectorID] stringByAppendingString:@"s"];
176 - (NSString *)callbackName {
177 /* eg: 'addResource' */
178 return [@"add" stringByAppendingString:[self capitalizedSelectorID]];
180 - (NSString *)tableId {
181 /* eg: 'resources' */
182 return [[self selectorID] stringByAppendingString:@"s"];
184 - (NSString *)checkboxId {
185 /* eg: 'resources' */
186 return [self tableId]; /* TODO: znek, is this ok? */
189 /* handling requests */
191 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
192 [self logWithFormat:@"Note: will take values ..."];
193 [super takeValuesFromRequest:_rq inContext:_ctx];
196 /* response generation */
198 - (NSString *)jsCode {
203 ms = [NSMutableString stringWithCapacity:128];
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);"
213 @" var table = document.getElementById(tableId);"
214 @" var tr = document.createElement('tr');"
215 @" var td, checkbox, text;"
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);"
232 [ms appendString:script];
234 [ctx takeValue:[NSNumber numberWithBool:YES]
235 forKey:@"HasAddTableAnaisAttendeeSelector"];
239 @"function %@(type, cn, dn, email, uid, sn) {\n"
240 @" addToTable('%@', type, cn, dn, email, uid, sn);\n"
242 [ms appendFormat:s, [self callbackName], [self tableId]];
246 @end /* AnaisAttendeeSelector */