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 "UIxTaskView.h"
23 #import <NGCards/NGCards.h>
24 #import <SOGo/WOContext+Agenor.h>
25 #import <Appointments/SOGoTaskObject.h>
26 #import <SOGoUI/SOGoDateFormatter.h>
27 #import "UIxComponent+Agenor.h"
30 @interface UIxTaskView (PrivateAPI)
31 - (BOOL)isAttendeeActiveUser;
34 @implementation UIxTaskView
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
100 NSCalendarDate *date;
101 NSTimeZone *timeZone;
103 timeZone = [[context activeUser] timeZone];
104 date = [[self task] startDate];
105 [date setTimeZone: timeZone];
110 - (NSCalendarDate *) endTime
112 NSCalendarDate *date;
113 NSTimeZone *timeZone;
115 timeZone = [[context activeUser] timeZone];
116 date = [[self task] due];
117 [date setTimeZone: timeZone];
122 - (NSString *)resourcesAsString {
123 NSArray *resources, *cns;
125 resources = [[self task] resources];
126 cns = [resources valueForKey:@"cnForDisplay"];
127 return [cns componentsJoinedByString:@"<br />"];
130 - (NSString *) categoriesAsString
132 NSEnumerator *categories;
133 NSArray *rawCategories;
134 NSMutableArray *l10nCategories;
135 NSString *currentCategory, *l10nCategory;
138 = [[task categories] componentsSeparatedByString: @","];
139 l10nCategories = [NSMutableArray arrayWithCapacity: [rawCategories count]];
140 categories = [rawCategories objectEnumerator];
141 currentCategory = [categories nextObject];
142 while (currentCategory)
145 = [self labelForKey: [currentCategory stringByTrimmingSpaces]];
147 [l10nCategories addObject: l10nCategory];
148 currentCategory = [categories nextObject];
151 return [l10nCategories componentsJoinedByString: @", "];
154 // task.organizer.cnForDisplay
155 - (NSString *) eventOrganizer
157 CardElement *organizer;
159 organizer = [[self task] uniqueChildWithTag: @"organizer"];
161 return [organizer value: 0 ofAttribute: @"cn"];
164 - (NSString *) priorityLabelKey
166 return [NSString stringWithFormat: @"prio_%@", [task priority]];
173 SOGoTaskObject *clientObject;
177 clientObject = [self clientObject];
178 task = (iCalToDo *) [clientObject component: NO];
187 - (NSString *)attributesTabLink {
188 return [self completeHrefForMethod:[self ownMethodName]
189 withParameter:@"attributes"
193 - (NSString *)participantsTabLink {
194 return [self completeHrefForMethod:[self ownMethodName]
195 withParameter:@"participants"
199 - (NSString *)debugTabLink {
200 return [self completeHrefForMethod:[self ownMethodName]
201 withParameter:@"debug"
205 - (NSString *)completeHrefForMethod:(NSString *)_method
206 withParameter:(NSString *)_param
207 forKey:(NSString *)_key
211 [self setQueryParameter:_param forKey:_key];
212 href = [self completeHrefForMethod:[self ownMethodName]];
213 [self setQueryParameter:nil forKey:_key];
222 iCalPerson *organizer;
224 email = [[[self context] activeUser] email];
225 organizer = [[self task] organizer];
226 if (!organizer) return YES; // assume this is correct to do, right?
227 return [[organizer rfc822Email] isEqualToString:email];
230 - (BOOL)canAccessApt {
237 /* not my apt - can access if it's public */
238 if ([[[self task] accessClass] isEqualToString: @"PUBLIC"])
241 /* can access it if I'm invited :-) */
242 email = [[[self context] activeUser] email];
243 partMails = [[[self task] participants] valueForKey:@"rfc822Email"];
244 return [partMails containsObject:email];
248 return [self isMyApt];
254 - (id<WOActionResults>)defaultAction {
255 if ([self task] == nil) {
256 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
257 reason:@"could not locate task"];
263 - (BOOL)isDeletableClientObject {
264 return [[self clientObject] respondsToSelector:@selector(delete)];
271 if ([self task] == nil) {
272 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
273 reason:@"could not locate task"];
276 if (![self isDeletableClientObject]) {
277 /* return 400 == Bad Request */
278 return [NSException exceptionWithHTTPStatus:400
279 reason:@"method cannot be invoked on "
280 @"the specified object"];
283 if ((ex = [[self clientObject] delete]) != nil) {
284 // TODO: improve error handling
285 [self debugWithFormat:@"failed to delete: %@", ex];
289 url = [[[self clientObject] container] baseURLInContext:[self context]];
290 return [self redirectToLocation:url];
293 @end /* UIxTaskView */