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 #include "UIxAppointmentView.h"
23 #include <NGiCal/NGiCal.h>
24 #include <SOGo/SOGoAppointment.h>
25 #include <SOGo/WOContext+Agenor.h>
26 #include <Appointments/SOGoAppointmentObject.h>
27 #include <SOGoUI/SOGoDateFormatter.h>
28 #include "UIxComponent+Agenor.h"
31 @interface UIxAppointmentView (PrivateAPI)
32 - (BOOL)isAttendeeActiveUser;
35 @implementation UIxAppointmentView
38 [self->appointment release];
39 [self->attendee release];
40 [self->dateFormatter release];
47 - (NSString *)tabSelection {
50 selection = [self queryParameterForKey:@"tab"];
52 selection = @"attributes";
56 - (void)setAttendee:(id)_attendee {
57 ASSIGN(self->attendee, _attendee);
60 return self->attendee;
63 - (BOOL)isAttendeeActiveUser {
64 NSString *email, *attEmail;
66 email = [[[self context] activeUser] email];
67 attEmail = [[self attendee] rfc822Email];
68 return [email isEqualToString:attEmail];
70 - (BOOL)showAcceptButton {
71 return [[self attendee] participationStatus] != iCalPersonPartStatAccepted;
73 - (BOOL)showRejectButton {
74 return [[self attendee] participationStatus] != iCalPersonPartStatDeclined;
76 - (NSString *)attendeeStatusColspan {
77 return [self isAttendeeActiveUser] ? @"1" : @"2";
80 - (void)setItem:(id)_item {
81 ASSIGN(self->item, _item);
87 - (SOGoDateFormatter *)dateFormatter {
88 if (self->dateFormatter == nil) {
90 [[SOGoDateFormatter alloc] initWithLocale:[self locale]];
91 [self->dateFormatter setFullWeekdayNameAndDetails];
93 return self->dateFormatter;
96 - (NSCalendarDate *)startTime {
99 date = [[self appointment] startDate];
100 [date setTimeZone:[self viewTimeZone]];
104 - (NSCalendarDate *)endTime {
105 NSCalendarDate *date;
107 date = [[self appointment] endDate];
108 [date setTimeZone:[self viewTimeZone]];
112 - (NSString *)resourcesAsString {
113 NSArray *resources, *cns;
115 resources = [[self appointment] resources];
116 cns = [resources valueForKey:@"cnForDisplay"];
117 return [cns componentsJoinedByString:@"<br />"];
120 - (NSString *)categoriesAsString {
125 s = [NSMutableString stringWithCapacity:32];
126 cats = [((SOGoAppointment *)self->appointment) categories];
127 count = [cats count];
128 for(i = 0; i < count; i++) {
129 NSString *cat, *label;
131 cat = [cats objectAtIndex:i];
132 label = [self labelForKey:cat];
133 [s appendString:label];
135 [s appendString:@", "];
142 - (SOGoAppointment *)appointment {
143 NSString *iCalString;
145 if (self->appointment != nil)
146 return self->appointment;
148 iCalString = [[self clientObject] valueForKey:@"iCalString"];
149 if (![iCalString isNotNull] || [iCalString length] == 0) {
150 [self errorWithFormat:@"(%s): missing iCal string!",
151 __PRETTY_FUNCTION__];
155 self->appointment = [[SOGoAppointment alloc] initWithICalString:iCalString];
156 return self->appointment;
162 - (NSString *)attributesTabLink {
163 return [self completeHrefForMethod:[self ownMethodName]
164 withParameter:@"attributes"
168 - (NSString *)participantsTabLink {
169 return [self completeHrefForMethod:[self ownMethodName]
170 withParameter:@"participants"
174 - (NSString *)debugTabLink {
175 return [self completeHrefForMethod:[self ownMethodName]
176 withParameter:@"debug"
180 - (NSString *)completeHrefForMethod:(NSString *)_method
181 withParameter:(NSString *)_param
182 forKey:(NSString *)_key
186 [self setQueryParameter:_param forKey:_key];
187 href = [self completeHrefForMethod:[self ownMethodName]];
188 [self setQueryParameter:nil forKey:_key];
197 iCalPerson *organizer;
199 email = [[[self context] activeUser] email];
200 organizer = [[self appointment] organizer];
201 if (!organizer) return YES; // assume this is correct to do, right?
202 return [[organizer rfc822Email] isEqualToString:email];
205 - (BOOL)canAccessApt {
212 /* not my apt - can access if it's public */
213 if ([[self appointment] isPublic])
216 /* can access it if I'm invited :-) */
217 email = [[[self context] activeUser] email];
218 partMails = [[[self appointment] participants] valueForKey:@"rfc822Email"];
219 return [partMails containsObject:email];
223 return [self isMyApt];
229 - (id<WOActionResults>)defaultAction {
230 if ([self appointment] == nil) {
231 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
232 reason:@"could not locate appointment"];
238 - (BOOL)isDeletableClientObject {
239 return [[self clientObject] respondsToSelector:@selector(delete)];
246 if ([self appointment] == nil) {
247 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
248 reason:@"could not locate appointment"];
251 if (![self isDeletableClientObject]) {
252 /* return 400 == Bad Request */
253 return [NSException exceptionWithHTTPStatus:400
254 reason:@"method cannot be invoked on "
255 @"the specified object"];
258 if ((ex = [[self clientObject] delete]) != nil) {
259 // TODO: improve error handling
260 [self debugWithFormat:@"failed to delete: %@", ex];
264 url = [[[self clientObject] container] baseURLInContext:[self context]];
265 return [self redirectToLocation:url];
268 @end /* UIxAppointmentView */