1 /* UIxTaskEditor.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <NGObjWeb/SoObject.h>
24 #import <NGObjWeb/WORequest.h>
25 #import <NGObjWeb/NSException+HTTP.h>
26 #import <NGExtensions/NSCalendarDate+misc.h>
28 #import <NGCards/iCalToDo.h>
29 #import <NGCards/iCalPerson.h>
31 #import <SoObjects/SOGo/SOGoUser.h>
32 #import <SoObjects/SOGo/SOGoContentObject.h>
33 #import <SoObjects/Appointments/SOGoAppointmentFolder.h>
34 #import <SoObjects/Appointments/SOGoTaskObject.h>
36 #import "UIxComponentEditor.h"
37 #import "UIxTaskEditor.h"
39 @implementation UIxTaskEditor
43 if ((self = [super init]))
61 [taskStartDate release];
62 [taskDueDate release];
65 [statusPercent release];
75 - (NSString *) saveURL
77 return [NSString stringWithFormat: @"%@/saveAsTask",
78 [[self clientObject] baseURL]];
81 /* icalendar values */
82 - (void) setTaskStartDate: (NSCalendarDate *) newTaskStartDate
84 ASSIGN (taskStartDate, newTaskStartDate);
87 - (NSCalendarDate *) taskStartDate
92 - (void) setHasStartDate: (BOOL) newHasStartDate
94 hasStartDate = newHasStartDate;
102 - (BOOL) startDateDisabled
104 return !hasStartDate;
107 - (void) setTaskDueDate: (NSCalendarDate *) newTaskDueDate
109 ASSIGN (taskDueDate, newTaskDueDate);
112 - (NSCalendarDate *) taskDueDate
117 - (void) setHasDueDate: (BOOL) newHasDueDate
119 hasDueDate = newHasDueDate;
127 - (BOOL) dueDateDisabled
132 - (NSArray *) repeatList
134 static NSArray *repeatItems = nil;
138 repeatItems = [NSArray arrayWithObjects: @"DAILY",
147 [repeatItems retain];
153 - (NSString *) itemRepeatText
157 if ([item isEqualToString: @"-"])
160 text = [self labelForKey: [NSString stringWithFormat: @"repeat_%@", item]];
165 - (NSArray *) statusList
167 static NSArray *statusItems = nil;
171 statusItems = [NSArray arrayWithObjects: @"NEEDS-ACTION",
176 [statusItems retain];
182 - (NSString *) itemStatusText
184 return [self labelForKey: [NSString stringWithFormat: @"status_%@", item]];
187 - (void) setItem: (NSString *) newItem
197 - (NSString *) repeat
202 - (void) setRepeat: (NSString *) newRepeat
206 - (NSString *) status
211 - (void) setStatus: (NSString *) newStatus
216 - (void) setStatusDate: (NSCalendarDate *) newStatusDate
218 ASSIGN (statusDate, newStatusDate);
221 - (NSCalendarDate *) statusDate
226 - (BOOL) statusDateDisabled
228 return ![status isEqualToString: @"COMPLETED"];
231 - (BOOL) statusPercentDisabled
233 NSLog (@"status: '%@'", status);
234 return ([status length] == 0
235 || [status isEqualToString: @"CANCELLED"]);
238 - (void) setStatusPercent: (NSString *) newStatusPercent
240 ASSIGN (statusPercent, newStatusPercent);
243 - (NSString *) statusPercent
245 return statusPercent;
249 - (NSCalendarDate *) newStartDate
251 NSCalendarDate *newStartDate, *now;
253 NSTimeZone *timeZone;
255 timeZone = [[context activeUser] timeZone];
257 newStartDate = [self selectedDate];
258 if ([[self queryParameterForKey: @"hm"] length] == 0)
260 now = [NSCalendarDate calendarDate];
261 [now setTimeZone: timeZone];
262 if ([now isDateOnSameDay: newStartDate])
264 hour = [now hourOfDay];
266 newStartDate = [now hour: 8 minute: 0];
268 newStartDate = [[now tomorrow] hour: 8 minute: 0];
273 newStartDate = [newStartDate hour: 8 minute: 0];
279 - (id <WOActionResults>) defaultAction
281 NSCalendarDate *startDate, *dueDate;
283 unsigned int minutes;
285 todo = (iCalToDo *) [[self clientObject] component: NO];
288 startDate = [todo startDate];
289 dueDate = [todo due];
290 hasStartDate = (startDate != nil);
291 hasDueDate = (dueDate != nil);
292 ASSIGN (status, [todo status]);
293 if ([status isEqualToString: @"COMPLETED"])
294 ASSIGN (statusDate, [todo completed]);
296 ASSIGN (statusDate, [self newStartDate]);
297 ASSIGN (statusPercent, [todo percentComplete]);
301 startDate = [self newStartDate];
302 duration = [self queryParameterForKey:@"dur"];
303 if ([duration length] > 0)
304 minutes = [duration intValue];
307 dueDate = [startDate dateByAddingYears: 0 months: 0 days: 0
308 hours: 0 minutes: minutes seconds: 0];
311 ASSIGN (statusDate, [self newStartDate]);
312 ASSIGN (status, @"");
313 ASSIGN (statusPercent, @"");
316 ASSIGN (taskStartDate, startDate);
317 ASSIGN (taskDueDate, dueDate);
319 /* here comes the code for initializing repeat, reminder and isAllDay... */
324 - (id <WOActionResults>) newAction
326 NSString *objectId, *method, *uri;
327 id <WOActionResults> result;
330 clientKlazz = [[self clientObject] class];
331 objectId = [clientKlazz globallyUniqueObjectId];
332 if ([objectId length] > 0)
334 method = [NSString stringWithFormat:@"%@/Calendar/%@/editAsTask",
335 [self userFolderPath], objectId];
336 uri = [self completeHrefForMethod: method];
337 result = [self redirectToLocation: uri];
340 result = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
341 reason: @"could not create a unique ID"];
346 - (id <WOActionResults>) saveAction
348 SOGoTaskObject *clientObject;
349 NSString *iCalString;
351 clientObject = [self clientObject];
352 iCalString = [[clientObject calendar: NO] versitString];
353 [clientObject saveContentString: iCalString];
355 return [self jsCloseWithRefreshMethod: @"refreshTasks()"];
358 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
359 inContext: (WOContext*) context
361 return ([[self clientObject] isKindOfClass: [SOGoTaskObject class]]
362 && [[request method] isEqualToString: @"POST"]);
365 - (void) takeValuesFromRequest: (WORequest *) _rq
366 inContext: (WOContext *) _ctx
368 SOGoTaskObject *clientObject;
370 clientObject = [self clientObject];
371 todo = (iCalToDo *) [clientObject component: YES];
373 [super takeValuesFromRequest: _rq inContext: _ctx];
376 [todo setStartDate: taskStartDate];
378 [todo setDue: taskDueDate];
379 if ([status isEqualToString: @"COMPLETED"])
380 [todo setCompleted: statusDate];
382 [todo setCompleted: nil];
383 if ([status length] > 0)
385 [todo setStatus: status];
386 [todo setPercentComplete: statusPercent];
390 [todo setStatus: @""];
391 [todo setPercentComplete: @""];
395 // TODO: add tentatively
397 - (id) acceptOrDeclineAction: (BOOL) _accept
399 [[self clientObject] changeParticipationStatus:
400 _accept ? @"ACCEPTED" : @"DECLINED"];
407 return [self acceptOrDeclineAction: YES];
412 return [self acceptOrDeclineAction: NO];
415 - (id) changeStatusAction
417 SOGoTaskObject *clientObject;
418 NSString *newStatus, *iCalString;
420 clientObject = [self clientObject];
421 todo = (iCalToDo *) [clientObject component: NO];
424 newStatus = [self queryParameterForKey: @"status"];
425 if ([newStatus intValue])
426 [todo setCompleted: [NSCalendarDate date]];
429 [todo setCompleted: nil];
430 [todo setPercentComplete: @"0"];
431 [todo setStatus: @"IN-PROCESS"];
434 iCalString = [[clientObject calendar: NO] versitString];
435 [clientObject saveContentString: iCalString];