]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Scheduler/UIxAppointmentView.m
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@237 d1b88da0-ebda-0310-925b-ed51d...
[scalable-opengroupware.org] / SOGo / UI / Scheduler / UIxAppointmentView.m
1 // $Id$
2
3 #include "UIxAppointmentView.h"
4 #include <NGiCal/NGiCal.h>
5 #include <SOGoLogic/SOGoAppointment.h>
6 #include <Appointments/SOGoAppointmentObject.h>
7 #include <SOGoUI/SOGoDateFormatter.h>
8 #include "common.h"
9
10 @implementation UIxAppointmentView
11
12 - (void)dealloc {
13   [self->appointment release];
14   [self->attendee    release];
15   [self->dateFormatter release];
16   [super dealloc];
17 }
18
19 /* accessors */
20
21 - (NSString *)tabSelection {
22   NSString *selection;
23     
24   selection = [self queryParameterForKey:@"tab"];
25   if (selection == nil)
26     selection = @"attributes";
27   return selection;
28 }
29
30 - (void)setAttendee:(id)_attendee {
31   ASSIGN(self->attendee, _attendee);
32 }
33 - (id)attendee {
34   return self->attendee;
35 }
36
37 - (SOGoDateFormatter *)dateFormatter {
38     if(self->dateFormatter == nil) {
39         self->dateFormatter = \
40         [[SOGoDateFormatter alloc] initWithLocale:[self locale]];
41         [self->dateFormatter setFullWeekdayNameAndDetails];
42     }
43     return self->dateFormatter;
44 }
45
46 - (NSCalendarDate *)startTime {
47   NSCalendarDate *date;
48     
49   date = [[self appointment] startDate];
50   [date setTimeZone:[self viewTimeZone]];
51   return date;
52 }
53
54 - (NSCalendarDate *)endTime {
55   NSCalendarDate *date;
56   
57   date = [[self appointment] endDate];
58   [date setTimeZone:[self viewTimeZone]];
59   return date;
60 }
61
62 - (NSString *)resourcesAsString {
63     NSArray *resources, *cns;
64
65     resources = [[self appointment] resources];
66     cns = [resources valueForKey:@"cnForDisplay"];
67     return [cns componentsJoinedByString:@"<br />"];
68 }
69
70
71 /* backend */
72
73 - (SOGoAppointment *)appointment {
74     NSString *iCalString;
75     
76     if (self->appointment)
77         return self->appointment;
78     
79     iCalString = [[self clientObject] valueForKey:@"iCalString"];
80     if (![iCalString isNotNull] || [iCalString length] == 0) {
81         [self debugWithFormat:@"ERROR(%s): missing iCal string!", 
82             __PRETTY_FUNCTION__];
83         return nil;
84     }
85     
86     self->appointment = [[SOGoAppointment alloc] initWithICalString:iCalString];
87     return self->appointment;
88 }
89
90
91 /* hrefs */
92
93 - (NSString *)attributesTabLink {
94   return [self completeHrefForMethod:[self ownMethodName]
95                withParameter:@"attributes"
96                forKey:@"tab"];
97 }
98
99 - (NSString *)participantsTabLink {
100     return [self completeHrefForMethod:[self ownMethodName]
101                  withParameter:@"participants"
102                  forKey:@"tab"];
103 }
104
105 - (NSString *)debugTabLink {
106   return [self completeHrefForMethod:[self ownMethodName]
107                withParameter:@"debug"
108                forKey:@"tab"];
109 }
110
111 - (NSString *)completeHrefForMethod:(NSString *)_method
112   withParameter:(NSString *)_param
113   forKey:(NSString *)_key
114 {
115   NSString *href;
116
117   [self setQueryParameter:_param forKey:_key];
118   href = [self completeHrefForMethod:[self ownMethodName]];
119   [self setQueryParameter:nil forKey:_key];
120   return href;
121 }
122
123 /* action */
124
125 - (id)defaultAction {
126   if ([self appointment] == nil) {
127     return [NSException exceptionWithHTTPStatus:404 /* Not Found */
128                         reason:@"could not locate appointment"];
129   }
130   
131   return self;
132 }
133
134 - (BOOL)isDeletableClientObject {
135   return [[self clientObject] respondsToSelector:@selector(delete)];
136 }
137
138 - (id)deleteAction {
139   NSException *ex;
140   
141   if ([self appointment] == nil) {
142     return [NSException exceptionWithHTTPStatus:404 /* Not Found */
143                         reason:@"could not locate appointment"];
144   }
145
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"];
151   }
152   
153   if ((ex = [[self clientObject] delete]) != nil) {
154     // TODO: improve error handling
155     [self debugWithFormat:@"failed to delete: %@", ex];
156     return ex;
157   }
158   
159 #warning TODO: fix redirect
160   return [[[self clientObject] container] baseURLInContext:[self context]];
161 }
162
163 @end /* UIxAppointmentView */