2 Copyright (C) 2004-2005 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
22 #import "UIxAppointmentView.h"
23 #import <NGCards/NGCards.h>
24 #import <SOGo/WOContext+Agenor.h>
25 #import <Appointments/SOGoAppointmentObject.h>
26 #import <SOGoUI/SOGoDateFormatter.h>
27 #import "UIxComponent+Agenor.h"
30 @interface UIxAppointmentView (PrivateAPI)
31 - (BOOL)isAttendeeActiveUser;
34 @implementation UIxAppointmentView
37 [appointment release];
39 [dateFormatter release];
46 - (NSString *)tabSelection {
49 selection = [self queryParameterForKey:@"tab"];
51 selection = @"attributes";
55 - (void)setAttendee:(id)_attendee {
56 ASSIGN(attendee, _attendee);
62 - (BOOL)isAttendeeActiveUser {
63 NSString *email, *attEmail;
65 email = [[[self context] activeUser] email];
66 attendee = [self attendee];
67 attEmail = [attendee rfc822Email];
69 return [email isEqualToString: attEmail];
72 - (BOOL)showAcceptButton {
73 return [[self attendee] participationStatus] != iCalPersonPartStatAccepted;
75 - (BOOL)showRejectButton {
76 return [[self attendee] participationStatus] != iCalPersonPartStatDeclined;
78 - (NSString *)attendeeStatusColspan {
79 return [self isAttendeeActiveUser] ? @"1" : @"2";
82 - (void)setItem:(id)_item {
89 - (SOGoDateFormatter *)dateFormatter {
90 if (dateFormatter == nil) {
92 [[SOGoDateFormatter alloc] initWithLocale:[self locale]];
93 [dateFormatter setFullWeekdayNameAndDetails];
98 - (NSCalendarDate *)startTime {
101 date = [[self appointment] startDate];
102 [date setTimeZone:[[self clientObject] userTimeZone]];
106 - (NSCalendarDate *)endTime {
107 NSCalendarDate *date;
109 date = [[self appointment] endDate];
110 [date setTimeZone:[[self clientObject] userTimeZone]];
114 - (NSString *)resourcesAsString {
115 NSArray *resources, *cns;
117 resources = [[self appointment] resources];
118 cns = [resources valueForKey:@"cnForDisplay"];
119 return [cns componentsJoinedByString:@"<br />"];
122 - (NSString *) categoriesAsString
124 NSEnumerator *categories;
125 NSArray *rawCategories;
126 NSMutableArray *l10nCategories;
127 NSString *currentCategory, *l10nCategory;
130 = [[appointment categories] componentsSeparatedByString: @","];
131 l10nCategories = [NSMutableArray arrayWithCapacity: [rawCategories count]];
132 categories = [rawCategories objectEnumerator];
133 currentCategory = [categories nextObject];
134 while (currentCategory)
137 = [self labelForKey: [currentCategory stringByTrimmingSpaces]];
139 [l10nCategories addObject: l10nCategory];
140 currentCategory = [categories nextObject];
143 return [l10nCategories componentsJoinedByString: @", "];
146 // appointment.organizer.cnForDisplay
147 - (NSString *) eventOrganizer
149 CardElement *organizer;
151 organizer = [[self appointment] uniqueChildWithTag: @"organizer"];
153 return [organizer value: 0 ofAttribute: @"cn"];
156 - (NSString *) priorityLabelKey
158 return [NSString stringWithFormat: @"prio_%@", [appointment priority]];
163 - (iCalEvent *) appointment
165 NSString *iCalString;
166 iCalCalendar *calendar;
167 SOGoAppointmentObject *clientObject;
169 if (appointment != nil)
172 clientObject = [self clientObject];
174 iCalString = [[self clientObject] valueForKey:@"iCalString"];
175 if (![iCalString isNotNull] || [iCalString length] == 0) {
176 [self errorWithFormat:@"(%s): missing iCal string!",
177 __PRETTY_FUNCTION__];
181 calendar = [iCalCalendar parseSingleFromSource: iCalString];
182 appointment = [clientObject firstEventFromCalendar: calendar];
183 [appointment retain];
190 - (NSString *)attributesTabLink {
191 return [self completeHrefForMethod:[self ownMethodName]
192 withParameter:@"attributes"
196 - (NSString *)participantsTabLink {
197 return [self completeHrefForMethod:[self ownMethodName]
198 withParameter:@"participants"
202 - (NSString *)debugTabLink {
203 return [self completeHrefForMethod:[self ownMethodName]
204 withParameter:@"debug"
208 - (NSString *)completeHrefForMethod:(NSString *)_method
209 withParameter:(NSString *)_param
210 forKey:(NSString *)_key
214 [self setQueryParameter:_param forKey:_key];
215 href = [self completeHrefForMethod:[self ownMethodName]];
216 [self setQueryParameter:nil forKey:_key];
225 iCalPerson *organizer;
227 email = [[[self context] activeUser] email];
228 organizer = [[self appointment] organizer];
229 if (!organizer) return YES; // assume this is correct to do, right?
230 return [[organizer rfc822Email] isEqualToString:email];
233 - (BOOL)canAccessApt {
240 /* not my apt - can access if it's public */
241 if ([[[self appointment] accessClass] isEqualToString: @"PUBLIC"])
244 /* can access it if I'm invited :-) */
245 email = [[[self context] activeUser] email];
246 partMails = [[[self appointment] participants] valueForKey:@"rfc822Email"];
247 return [partMails containsObject:email];
251 return [self isMyApt];
257 - (id<WOActionResults>)defaultAction {
258 if ([self appointment] == nil) {
259 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
260 reason:@"could not locate appointment"];
266 - (BOOL)isDeletableClientObject {
267 return [[self clientObject] respondsToSelector:@selector(delete)];
274 if ([self appointment] == nil) {
275 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
276 reason:@"could not locate appointment"];
279 if (![self isDeletableClientObject]) {
280 /* return 400 == Bad Request */
281 return [NSException exceptionWithHTTPStatus:400
282 reason:@"method cannot be invoked on "
283 @"the specified object"];
286 if ((ex = [[self clientObject] delete]) != nil) {
287 // TODO: improve error handling
288 [self debugWithFormat:@"failed to delete: %@", ex];
292 url = [[[self clientObject] container] baseURLInContext:[self context]];
293 return [self redirectToLocation:url];
296 @end /* UIxAppointmentView */