]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Anais/AnaisAttendeeSelector.m
7bcc8a748eea7b80a4bb0db681f2c9c4420ffdbe
[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
34   Sample:
35     <var:component className="AnaisAttendeeSelector"
36                    selectorID="participant"
37                    attendees="attendees"
38                    const:division="CC"
39                   />
40 */
41
42 @class iCalPerson;
43
44 @interface AnaisAttendeeSelector : UIxComponent
45 {
46   NSString   *selectorID;
47   NSString   *division;
48   NSArray    *attendees;
49   iCalPerson *attendee;
50 }
51
52 @end
53
54 #include <NGiCal/NGiCal.h>
55 #include <NGObjWeb/WOContext.h>
56 #include "common.h"
57
58 @implementation AnaisAttendeeSelector
59
60 - (void)dealloc {
61   [self->division   release];
62   [self->selectorID release];
63   [self->attendee   release];
64   [self->attendees  release];
65   [super dealloc];
66 }
67
68 /* notifications */
69
70 - (void)sleep {
71   [self->attendee release]; self->attendee = nil;
72   [super sleep];
73 }
74
75 /* accessors */
76
77 - (void)setAttendees:(NSArray *)_attendees {
78   ASSIGN(self->attendees, _attendees);
79 }
80 - (NSArray *)attendees {
81   return self->attendees;
82 }
83
84 - (void)setAttendee:(iCalPerson *)_attendee {
85   ASSIGN(self->attendee, _attendee);
86 }
87 - (iCalPerson *)attendee {
88   return self->attendee;
89 }
90
91 - (void)setDivision:(NSString *)_value {
92   ASSIGNCOPY(self->division, _value);
93 }
94 - (NSString *)division {
95   return self->division;
96 }
97
98 /* id accessors */
99
100 - (void)setSelectorID:(NSString *)_value {
101   ASSIGNCOPY(self->selectorID, _value);
102 }
103 - (NSString *)selectorID {
104   return self->selectorID;
105 }
106 - (NSString *)capitalizedSelectorID {
107   return [[self selectorID] capitalizedString];
108 }
109
110 - (NSString *)windowId {
111   /* eg: 'Resources' */
112   return [[self capitalizedSelectorID] stringByAppendingString:@"s"];
113 }
114 - (NSString *)callbackName {
115   /* eg: 'addResource' */
116   return [@"add" stringByAppendingString:[self capitalizedSelectorID]];
117 }
118 - (NSString *)tableId {
119   /* eg: 'resources' */
120   return [[self selectorID] stringByAppendingString:@"s"];
121 }
122 - (NSString *)checkboxId {
123   /* eg: 'resources' */
124   return [self tableId]; /* TODO: znek, is this ok? */
125 }
126
127 /* handling requests */
128
129 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
130   [self logWithFormat:@"Note: will take values ..."];
131   [super takeValuesFromRequest:_rq inContext:_ctx];
132 }
133
134 /* response generation */
135
136 - (NSString *)jsCode {
137   NSMutableString *ms;
138   WOContext *ctx;
139   NSString *s;
140
141   ms = [NSMutableString stringWithCapacity:128];
142   
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);"
148       @"  if(test)"
149       @"    return;"
150       @""
151       @"  var table = document.getElementById(tableId);"
152       @"  var tr = document.createElement('tr');"
153       @"  var td, checkbox, text;"
154       @""
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);"
169       @"}\n";
170     [ms appendString:script];
171     
172     [ctx takeValue:[NSNumber numberWithBool:YES]
173          forKey:@"HasAddTableAnaisAttendeeSelector"];
174   }
175   
176   s = 
177     @"function %@(type, cn, dn, email, uid, sn) {\n"
178     @"  addToTable('%@', type, cn, dn, email, uid, sn);\n"
179     @"}\n";
180   [ms appendFormat:s, [self callbackName], [self tableId]];
181   return ms;
182 }
183
184 @end /* AnaisAttendeeSelector */