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 <SOGo/SOGoUser.h>
26 #import <Appointments/SOGoTaskObject.h>
27 #import <SOGoUI/SOGoDateFormatter.h>
28 #import "UIxComponent+Scheduler.h"
31 @interface UIxTaskView (PrivateAPI)
32 - (BOOL)isAttendeeActiveUser;
35 @implementation UIxTaskView
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
101 NSCalendarDate *date;
102 NSTimeZone *timeZone;
104 timeZone = [[context activeUser] timeZone];
105 date = [[self task] startDate];
106 [date setTimeZone: timeZone];
111 - (NSCalendarDate *) endTime
113 NSCalendarDate *date;
114 NSTimeZone *timeZone;
116 timeZone = [[context activeUser] timeZone];
117 date = [[self task] due];
118 [date setTimeZone: timeZone];
123 - (NSString *)resourcesAsString {
124 NSArray *resources, *cns;
126 resources = [[self task] resources];
127 cns = [resources valueForKey:@"cnForDisplay"];
128 return [cns componentsJoinedByString:@"<br />"];
131 - (NSString *) categoriesAsString
133 NSEnumerator *categories;
134 NSArray *rawCategories;
135 NSMutableArray *l10nCategories;
136 NSString *currentCategory, *l10nCategory;
139 = [[task categories] componentsSeparatedByString: @","];
140 l10nCategories = [NSMutableArray arrayWithCapacity: [rawCategories count]];
141 categories = [rawCategories objectEnumerator];
142 currentCategory = [categories nextObject];
143 while (currentCategory)
146 = [self labelForKey: [currentCategory stringByTrimmingSpaces]];
148 [l10nCategories addObject: l10nCategory];
149 currentCategory = [categories nextObject];
152 return [l10nCategories componentsJoinedByString: @", "];
155 // task.organizer.cnForDisplay
156 - (NSString *) eventOrganizer
158 CardElement *organizer;
160 organizer = [[self task] uniqueChildWithTag: @"organizer"];
162 return [organizer value: 0 ofAttribute: @"cn"];
165 - (NSString *) priorityLabelKey
167 return [NSString stringWithFormat: @"prio_%@", [task priority]];
174 SOGoTaskObject *clientObject;
178 clientObject = [self clientObject];
179 task = (iCalToDo *) [clientObject component: NO];
188 - (NSString *)attributesTabLink {
189 return [self completeHrefForMethod:[self ownMethodName]
190 withParameter:@"attributes"
194 - (NSString *)participantsTabLink {
195 return [self completeHrefForMethod:[self ownMethodName]
196 withParameter:@"participants"
200 - (NSString *)debugTabLink {
201 return [self completeHrefForMethod:[self ownMethodName]
202 withParameter:@"debug"
206 - (NSString *)completeHrefForMethod:(NSString *)_method
207 withParameter:(NSString *)_param
208 forKey:(NSString *)_key
212 [self setQueryParameter:_param forKey:_key];
213 href = [self completeHrefForMethod:[self ownMethodName]];
214 [self setQueryParameter:nil forKey:_key];
223 iCalPerson *organizer;
225 email = [[[self context] activeUser] primaryEmail];
226 organizer = [[self task] organizer];
227 if (!organizer) return YES; // assume this is correct to do, right?
228 return [[organizer rfc822Email] isEqualToString:email];
231 - (BOOL)canAccessApt {
238 /* not my apt - can access if it's public */
239 if ([[[self task] accessClass] isEqualToString: @"PUBLIC"])
242 /* can access it if I'm invited :-) */
243 email = [[[self context] activeUser] primaryEmail];
244 partMails = [[[self task] participants] valueForKey:@"rfc822Email"];
245 return [partMails containsObject: email];
249 return [self isMyApt];
255 - (id<WOActionResults>)defaultAction {
256 if ([self task] == nil) {
257 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
258 reason:@"could not locate task"];
264 - (BOOL)isDeletableClientObject {
265 return [[self clientObject] respondsToSelector:@selector(delete)];
272 if ([self task] == nil) {
273 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
274 reason:@"could not locate task"];
277 if (![self isDeletableClientObject]) {
278 /* return 400 == Bad Request */
279 return [NSException exceptionWithHTTPStatus:400
280 reason:@"method cannot be invoked on "
281 @"the specified object"];
284 if ((ex = [[self clientObject] delete]) != nil) {
285 // TODO: improve error handling
286 [self debugWithFormat:@"failed to delete: %@", ex];
290 url = [[[self clientObject] container] baseURLInContext:[self context]];
291 return [self redirectToLocation:url];
294 @end /* UIxTaskView */