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 <SOGo/SOGoUser.h>
26 #import <Appointments/SOGoAppointmentObject.h>
27 #import <SOGoUI/SOGoDateFormatter.h>
28 #import "UIxComponent+Scheduler.h"
31 @interface UIxAppointmentView (PrivateAPI)
32 - (BOOL)isAttendeeActiveUser;
35 @implementation UIxAppointmentView
38 [appointment release];
40 [dateFormatter release];
47 - (NSString *)tabSelection {
50 selection = [self queryParameterForKey:@"tab"];
52 selection = @"attributes";
56 - (void)setAttendee:(id)_attendee {
57 ASSIGN(attendee, _attendee);
63 - (BOOL)isAttendeeActiveUser {
64 NSString *email, *attEmail;
66 email = [[[self context] activeUser] primaryEmail];
67 attendee = [self attendee];
68 attEmail = [attendee rfc822Email];
70 return [email isEqualToString: attEmail];
73 - (BOOL)showAcceptButton {
74 return [[self attendee] participationStatus] != iCalPersonPartStatAccepted;
76 - (BOOL)showRejectButton {
77 return [[self attendee] participationStatus] != iCalPersonPartStatDeclined;
79 - (NSString *)attendeeStatusColspan {
80 return [self isAttendeeActiveUser] ? @"1" : @"2";
83 - (void)setItem:(id)_item {
90 - (SOGoDateFormatter *)dateFormatter {
91 if (dateFormatter == nil) {
93 [[SOGoDateFormatter alloc] initWithLocale:[self locale]];
94 [dateFormatter setFullWeekdayNameAndDetails];
99 - (NSCalendarDate *)startTime {
100 NSCalendarDate *date;
101 NSTimeZone *timeZone;
103 timeZone = [[context activeUser] timeZone];
104 date = [[self appointment] startDate];
105 [date setTimeZone: timeZone];
110 - (NSCalendarDate *)endTime {
111 NSCalendarDate *date;
112 NSTimeZone *timeZone;
114 timeZone = [[context activeUser] timeZone];
115 date = [[self appointment] endDate];
116 [date setTimeZone: timeZone];
121 - (NSString *)resourcesAsString {
122 NSArray *resources, *cns;
124 resources = [[self appointment] resources];
125 cns = [resources valueForKey:@"cnForDisplay"];
126 return [cns componentsJoinedByString:@"<br />"];
129 - (NSString *) categoriesAsString
131 NSEnumerator *categories;
132 NSArray *rawCategories;
133 NSMutableArray *l10nCategories;
134 NSString *currentCategory, *l10nCategory;
137 = [[appointment categories] componentsSeparatedByString: @","];
138 l10nCategories = [NSMutableArray arrayWithCapacity: [rawCategories count]];
139 categories = [rawCategories objectEnumerator];
140 currentCategory = [categories nextObject];
141 while (currentCategory)
144 = [self labelForKey: [currentCategory stringByTrimmingSpaces]];
146 [l10nCategories addObject: l10nCategory];
147 currentCategory = [categories nextObject];
150 return [l10nCategories componentsJoinedByString: @", "];
153 // appointment.organizer.cnForDisplay
154 - (NSString *) eventOrganizer
156 CardElement *organizer;
158 organizer = [[self appointment] uniqueChildWithTag: @"organizer"];
160 return [organizer value: 0 ofAttribute: @"cn"];
163 - (NSString *) priorityLabelKey
165 return [NSString stringWithFormat: @"prio_%@", [appointment priority]];
170 - (iCalEvent *) appointment
172 SOGoAppointmentObject *clientObject;
176 clientObject = [self clientObject];
177 appointment = (iCalEvent *) [clientObject component: NO];
178 [appointment retain];
186 - (NSString *)attributesTabLink {
187 return [self completeHrefForMethod:[self ownMethodName]
188 withParameter:@"attributes"
192 - (NSString *)participantsTabLink {
193 return [self completeHrefForMethod:[self ownMethodName]
194 withParameter:@"participants"
198 - (NSString *)debugTabLink {
199 return [self completeHrefForMethod:[self ownMethodName]
200 withParameter:@"debug"
204 - (NSString *)completeHrefForMethod:(NSString *)_method
205 withParameter:(NSString *)_param
206 forKey:(NSString *)_key
210 [self setQueryParameter:_param forKey:_key];
211 href = [self completeHrefForMethod:[self ownMethodName]];
212 [self setQueryParameter:nil forKey:_key];
221 iCalPerson *organizer;
223 email = [[[self context] activeUser] primaryEmail];
224 organizer = [[self appointment] organizer];
225 if (!organizer) return YES; // assume this is correct to do, right?
226 return [[organizer rfc822Email] isEqualToString:email];
229 - (BOOL)canAccessApt {
236 /* not my apt - can access if it's public */
237 if ([[[self appointment] accessClass] isEqualToString: @"PUBLIC"])
240 /* can access it if I'm invited :-) */
241 email = [[[self context] activeUser] primaryEmail];
242 partMails = [[[self appointment] participants] valueForKey:@"rfc822Email"];
243 return [partMails containsObject:email];
247 return [self isMyApt];
253 - (id<WOActionResults>)defaultAction {
254 if ([self appointment] == nil) {
255 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
256 reason:@"could not locate appointment"];
262 - (BOOL)isDeletableClientObject {
263 return [[self clientObject] respondsToSelector:@selector(delete)];
270 if ([self appointment] == nil) {
271 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
272 reason:@"could not locate appointment"];
275 if (![self isDeletableClientObject]) {
276 /* return 400 == Bad Request */
277 return [NSException exceptionWithHTTPStatus:400
278 reason:@"method cannot be invoked on "
279 @"the specified object"];
282 if ((ex = [[self clientObject] delete]) != nil) {
283 // TODO: improve error handling
284 [self debugWithFormat:@"failed to delete: %@", ex];
288 url = [[[self clientObject] container] baseURLInContext:[self context]];
289 return [self redirectToLocation:url];
292 @end /* UIxAppointmentView */