3 #include "UIxAppointmentView.h"
4 #include <NGiCal/NGiCal.h>
5 #include <SOGoLogic/SOGoAppointment.h>
6 #include <Appointments/SOGoAppointmentObject.h>
7 #include <SOGoUI/SOGoDateFormatter.h>
10 @implementation UIxAppointmentView
13 [self->appointment release];
14 [self->attendee release];
15 [self->dateFormatter release];
21 - (NSString *)tabSelection {
24 selection = [self queryParameterForKey:@"tab"];
26 selection = @"attributes";
30 - (void)setAttendee:(id)_attendee {
31 ASSIGN(self->attendee, _attendee);
34 return self->attendee;
37 - (SOGoDateFormatter *)dateFormatter {
38 if(self->dateFormatter == nil) {
39 self->dateFormatter = \
40 [[SOGoDateFormatter alloc] initWithLocale:[self locale]];
41 [self->dateFormatter setFullWeekdayNameAndDetails];
43 return self->dateFormatter;
46 - (NSCalendarDate *)startTime {
49 date = [[self appointment] startDate];
50 [date setTimeZone:[self viewTimeZone]];
54 - (NSCalendarDate *)endTime {
57 date = [[self appointment] endDate];
58 [date setTimeZone:[self viewTimeZone]];
62 - (NSString *)resourcesAsString {
63 NSArray *resources, *cns;
65 resources = [[self appointment] resources];
66 cns = [resources valueForKey:@"cnForDisplay"];
67 return [cns componentsJoinedByString:@"<br />"];
73 - (SOGoAppointment *)appointment {
76 if (self->appointment)
77 return self->appointment;
79 iCalString = [[self clientObject] valueForKey:@"iCalString"];
80 if (![iCalString isNotNull] || [iCalString length] == 0) {
81 [self debugWithFormat:@"ERROR(%s): missing iCal string!",
86 self->appointment = [[SOGoAppointment alloc] initWithICalString:iCalString];
87 return self->appointment;
93 - (NSString *)attributesTabLink {
94 return [self completeHrefForMethod:[self ownMethodName]
95 withParameter:@"attributes"
99 - (NSString *)participantsTabLink {
100 return [self completeHrefForMethod:[self ownMethodName]
101 withParameter:@"participants"
105 - (NSString *)debugTabLink {
106 return [self completeHrefForMethod:[self ownMethodName]
107 withParameter:@"debug"
111 - (NSString *)completeHrefForMethod:(NSString *)_method
112 withParameter:(NSString *)_param
113 forKey:(NSString *)_key
117 [self setQueryParameter:_param forKey:_key];
118 href = [self completeHrefForMethod:[self ownMethodName]];
119 [self setQueryParameter:nil forKey:_key];
125 - (id)defaultAction {
126 if ([self appointment] == nil) {
127 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
128 reason:@"could not locate appointment"];
134 - (BOOL)isDeletableClientObject {
135 return [[self clientObject] respondsToSelector:@selector(delete)];
141 if ([self appointment] == nil) {
142 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
143 reason:@"could not locate appointment"];
146 if (![self isDeletableClientObject]) {
147 /* return 400 == Bad Request */
148 return [NSException exceptionWithHTTPStatus:400
149 reason:@"method cannot be invoked on "
150 @"the specified object"];
153 if ((ex = [[self clientObject] delete]) != nil) {
154 // TODO: improve error handling
155 [self debugWithFormat:@"failed to delete: %@", ex];
159 #warning TODO: fix redirect
160 return [[[self clientObject] container] baseURLInContext:[self context]];
163 @end /* UIxAppointmentView */