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
35 <var:component className="AnaisAttendeeSelector"
36 selectorID="participant"
44 @interface AnaisAttendeeSelector : UIxComponent
54 #include <NGiCal/NGiCal.h>
55 #include <NGObjWeb/WOContext.h>
58 @implementation AnaisAttendeeSelector
61 [self->division release];
62 [self->selectorID release];
63 [self->attendee release];
64 [self->attendees release];
71 [self->attendee release]; self->attendee = nil;
77 - (void)setAttendees:(NSArray *)_attendees {
78 ASSIGN(self->attendees, _attendees);
80 - (NSArray *)attendees {
81 return self->attendees;
84 - (void)setAttendee:(iCalPerson *)_attendee {
85 ASSIGN(self->attendee, _attendee);
87 - (iCalPerson *)attendee {
88 return self->attendee;
91 - (void)setDivision:(NSString *)_value {
92 ASSIGNCOPY(self->division, _value);
94 - (NSString *)division {
95 return self->division;
100 - (void)setSelectorID:(NSString *)_value {
101 ASSIGNCOPY(self->selectorID, _value);
103 - (NSString *)selectorID {
104 return self->selectorID;
106 - (NSString *)capitalizedSelectorID {
107 return [[self selectorID] capitalizedString];
110 - (NSString *)windowId {
111 /* eg: 'Resources' */
112 return [[self capitalizedSelectorID] stringByAppendingString:@"s"];
114 - (NSString *)callbackName {
115 /* eg: 'addResource' */
116 return [@"add" stringByAppendingString:[self capitalizedSelectorID]];
118 - (NSString *)tableId {
119 /* eg: 'resources' */
120 return [[self selectorID] stringByAppendingString:@"s"];
122 - (NSString *)checkboxId {
123 /* eg: 'resources' */
124 return [self tableId]; /* TODO: znek, is this ok? */
127 /* handling requests */
129 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
130 [self logWithFormat:@"Note: will take values ..."];
131 [super takeValuesFromRequest:_rq inContext:_ctx];
134 /* response generation */
136 - (NSString *)jsCode {
141 ms = [NSMutableString stringWithCapacity:128];
143 ctx = [self context];
144 if (![[ctx valueForKey:@"HasAddTableAnaisAttendeeSelector"] boolValue]) {
145 static NSString *script = \
146 @"function addToTable(tableId, type, cn, dn, email, uid, sn) {\n"
147 @" var test = document.getElementById(email);"
151 @" var table = document.getElementById(tableId);"
152 @" var tr = document.createElement('tr');"
153 @" var td, checkbox, text;"
155 @" td = document.createElement('td');"
156 @" checkbox = document.createElement('input');"
157 @" checkbox.setAttribute('type', 'checkbox');"
158 @" checkbox.setAttribute('checked', 'checked');"
159 @" checkbox.setAttribute('value', email + ';' + cn);"
160 @" checkbox.setAttribute('id', email);"
161 @" checkbox.setAttribute('name', tableId);"
162 @" td.appendChild(checkbox);"
163 @" tr.appendChild(td);"
164 @" td = document.createElement('td');"
165 @" text = document.createTextNode(cn);"
166 @" td.appendChild(text);"
167 @" tr.appendChild(td);"
168 @" table.appendChild(tr);"
170 [ms appendString:script];
172 [ctx takeValue:[NSNumber numberWithBool:YES]
173 forKey:@"HasAddTableAnaisAttendeeSelector"];
177 @"function %@(type, cn, dn, email, uid, sn) {\n"
178 @" addToTable('%@', type, cn, dn, email, uid, sn);\n"
180 [ms appendFormat:s, [self callbackName], [self tableId]];
184 @end /* AnaisAttendeeSelector */