2007-03-18 16:20:38 +01:00
|
|
|
/* UIxTaskEditor.m - this file is part of SOGo
|
|
|
|
*
|
2015-01-22 18:12:51 +01:00
|
|
|
* Copyright (C) 2007-2015 Inverse inc.
|
2007-03-18 16:20:38 +01:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2015-01-22 18:12:51 +01:00
|
|
|
#import <Foundation/NSValue.h>
|
2009-04-22 23:02:11 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
#import <NGObjWeb/SoObject.h>
|
2008-08-10 23:44:25 +02:00
|
|
|
#import <NGObjWeb/SoPermissions.h>
|
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2007-03-18 16:20:38 +01:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-12-17 16:29:06 +01:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2007-03-18 16:20:38 +01:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
#import <NGCards/iCalAlarm.h>
|
2007-11-09 00:18:52 +01:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
2007-03-18 16:20:38 +01:00
|
|
|
#import <NGCards/iCalPerson.h>
|
2009-04-22 23:02:11 +02:00
|
|
|
#import <NGCards/iCalToDo.h>
|
|
|
|
#import <NGCards/iCalTrigger.h>
|
2009-10-26 14:39:28 +01:00
|
|
|
#import <NGCards/iCalTimeZone.h>
|
|
|
|
#import <NGCards/iCalDateTime.h>
|
2007-03-18 16:20:38 +01:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <SOGo/SOGoContentObject.h>
|
|
|
|
#import <SOGo/SOGoDateFormatter.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2014-09-25 15:25:13 +02:00
|
|
|
|
|
|
|
#import <Appointments/iCalEntityObject+SOGo.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <Appointments/SOGoAppointmentFolder.h>
|
|
|
|
#import <Appointments/SOGoTaskObject.h>
|
2007-03-18 16:20:38 +01:00
|
|
|
|
|
|
|
#import "UIxComponentEditor.h"
|
|
|
|
#import "UIxTaskEditor.h"
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
@implementation UIxTaskEditor
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (id) init
|
|
|
|
{
|
2009-07-29 20:46:44 +02:00
|
|
|
SOGoUser *user;
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
taskStartDate = nil;
|
|
|
|
taskDueDate = nil;
|
|
|
|
statusDate = nil;
|
|
|
|
hasStartDate = NO;
|
|
|
|
hasDueDate = NO;
|
|
|
|
status = nil;
|
|
|
|
statusPercent = nil;
|
|
|
|
item = nil;
|
|
|
|
todo = nil;
|
2009-07-29 20:46:44 +02:00
|
|
|
|
|
|
|
user = [[self context] activeUser];
|
|
|
|
ASSIGN (dateFormatter, [user dateFormatterInContext: context]);
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
return self;
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[taskStartDate release];
|
|
|
|
[taskDueDate release];
|
|
|
|
[statusDate release];
|
|
|
|
[status release];
|
|
|
|
[statusPercent release];
|
2009-07-29 20:46:44 +02:00
|
|
|
[dateFormatter release];
|
2009-02-06 21:15:41 +01:00
|
|
|
[[todo parent] release];
|
2007-03-18 16:20:38 +01:00
|
|
|
[super dealloc];
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
/* template values */
|
|
|
|
- (iCalToDo *) todo
|
|
|
|
{
|
2007-11-19 22:07:54 +01:00
|
|
|
if (!todo)
|
|
|
|
{
|
2014-09-12 14:34:15 +02:00
|
|
|
todo = (iCalToDo *) [[self clientObject] occurence];
|
2009-02-06 21:15:41 +01:00
|
|
|
[[todo parent] retain];
|
2007-11-19 22:07:54 +01:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
return todo;
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (NSString *) saveURL
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@/saveAsTask",
|
|
|
|
[[self clientObject] baseURL]];
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
/* icalendar values */
|
|
|
|
- (void) setTaskStartDate: (NSCalendarDate *) newTaskStartDate
|
2006-10-12 18:42:59 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (taskStartDate, newTaskStartDate);
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
2006-10-12 18:42:59 +02:00
|
|
|
|
2006-10-18 16:42:44 +02:00
|
|
|
- (NSCalendarDate *) taskStartDate
|
2006-10-12 18:42:59 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
return taskStartDate;
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) setHasStartDate: (BOOL) newHasStartDate
|
|
|
|
{
|
|
|
|
hasStartDate = newHasStartDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasStartDate
|
2006-10-18 16:42:44 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
return hasStartDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) startDateDisabled
|
|
|
|
{
|
|
|
|
return !hasStartDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTaskDueDate: (NSCalendarDate *) newTaskDueDate
|
|
|
|
{
|
|
|
|
ASSIGN (taskDueDate, newTaskDueDate);
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
|
|
|
|
2006-10-18 16:42:44 +02:00
|
|
|
- (NSCalendarDate *) taskDueDate
|
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
return taskDueDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setHasDueDate: (BOOL) newHasDueDate
|
|
|
|
{
|
|
|
|
hasDueDate = newHasDueDate;
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (BOOL) hasDueDate
|
|
|
|
{
|
|
|
|
return hasDueDate;
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (BOOL) dueDateDisabled
|
2006-10-11 20:15:29 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
return !hasDueDate;
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (NSArray *) statusList
|
2006-10-12 18:42:59 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
static NSArray *statusItems = nil;
|
2006-10-12 18:42:59 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
if (!statusItems)
|
2006-11-07 17:27:46 +01:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
statusItems = [NSArray arrayWithObjects: @"NEEDS-ACTION",
|
|
|
|
@"IN-PROCESS",
|
|
|
|
@"COMPLETED",
|
|
|
|
@"CANCELLED",
|
|
|
|
nil];
|
|
|
|
[statusItems retain];
|
2006-11-07 17:27:46 +01:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
return statusItems;
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (NSString *) itemStatusText
|
2006-10-12 18:42:59 +02:00
|
|
|
{
|
2009-07-29 20:46:44 +02:00
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
item = status;
|
|
|
|
if (!item)
|
|
|
|
item = @"NOT-SPECIFIED";
|
|
|
|
}
|
2007-03-18 16:20:38 +01:00
|
|
|
return [self labelForKey: [NSString stringWithFormat: @"status_%@", item]];
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) setItem: (NSString *) newItem
|
2006-10-11 20:15:29 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
item = newItem;
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (NSString *) item
|
|
|
|
{
|
|
|
|
return item;
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (NSString *) status
|
|
|
|
{
|
|
|
|
return status;
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) setStatus: (NSString *) newStatus
|
|
|
|
{
|
|
|
|
status = newStatus;
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) setStatusDate: (NSCalendarDate *) newStatusDate
|
2006-10-11 20:15:29 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (statusDate, newStatusDate);
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (NSCalendarDate *) statusDate
|
|
|
|
{
|
|
|
|
return statusDate;
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (BOOL) statusDateDisabled
|
|
|
|
{
|
2014-09-25 15:25:13 +02:00
|
|
|
return !([status isEqualToString: @"COMPLETED"] || statusDate);
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (BOOL) statusPercentDisabled
|
|
|
|
{
|
2014-09-25 15:25:13 +02:00
|
|
|
return ([status length] == 0 || [status isEqualToString: @"CANCELLED"]);
|
2006-10-11 20:15:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) setStatusPercent: (NSString *) newStatusPercent
|
2006-10-19 16:40:24 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (statusPercent, newStatusPercent);
|
2006-10-19 16:40:24 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (NSString *) statusPercent
|
2006-10-19 16:40:24 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
return statusPercent;
|
2006-10-19 16:40:24 +02:00
|
|
|
}
|
|
|
|
|
2009-07-29 20:46:44 +02:00
|
|
|
/* viewing read-only tasks */
|
|
|
|
|
|
|
|
- (NSString *) taskStartDateTimeText
|
|
|
|
{
|
|
|
|
return [dateFormatter formattedDateAndTime: taskStartDate];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) taskDueDateTimeText
|
|
|
|
{
|
|
|
|
return [dateFormatter formattedDateAndTime: taskDueDate];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) statusDateText
|
|
|
|
{
|
|
|
|
return [dateFormatter formattedDate: statusDate];
|
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
/* actions */
|
|
|
|
- (NSCalendarDate *) newStartDate
|
2006-10-19 16:40:24 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
NSCalendarDate *newStartDate, *now;
|
2007-04-11 21:08:58 +02:00
|
|
|
NSTimeZone *timeZone;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2011-06-13 22:28:10 +02:00
|
|
|
int hour, minute;
|
2008-07-18 21:25:26 +02:00
|
|
|
unsigned int uStart, uEnd;
|
2007-03-18 16:20:38 +01:00
|
|
|
|
|
|
|
newStartDate = [self selectedDate];
|
2008-07-18 21:25:26 +02:00
|
|
|
if (![[self queryParameterForKey: @"hm"] length])
|
2007-03-18 16:20:38 +01:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
timeZone = [ud timeZone];
|
2007-03-18 16:20:38 +01:00
|
|
|
now = [NSCalendarDate calendarDate];
|
2007-04-11 21:08:58 +02:00
|
|
|
[now setTimeZone: timeZone];
|
2008-07-18 21:25:26 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
uStart = [ud dayStartHour];
|
2007-03-18 16:20:38 +01:00
|
|
|
if ([now isDateOnSameDay: newStartDate])
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
uEnd = [ud dayEndHour];
|
2007-03-18 16:20:38 +01:00
|
|
|
hour = [now hourOfDay];
|
2011-06-13 22:28:10 +02:00
|
|
|
minute = [now minuteOfHour];
|
|
|
|
if (minute % 15)
|
|
|
|
minute += 15 - (minute % 15);
|
2008-07-18 21:25:26 +02:00
|
|
|
if (hour < uStart)
|
|
|
|
newStartDate = [now hour: uStart minute: 0];
|
|
|
|
else if (hour > uEnd)
|
|
|
|
newStartDate = [[now tomorrow] hour: uStart minute: 0];
|
2007-03-18 16:20:38 +01:00
|
|
|
else
|
2011-06-13 22:28:10 +02:00
|
|
|
newStartDate = [now hour: [now hourOfDay] minute: minute];
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
|
|
|
else
|
2008-07-18 21:25:26 +02:00
|
|
|
newStartDate = [newStartDate hour: uStart minute: 0];
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return newStartDate;
|
2006-10-19 16:40:24 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (id <WOActionResults>) defaultAction
|
2006-10-19 16:40:24 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
NSCalendarDate *startDate, *dueDate;
|
|
|
|
NSString *duration;
|
2009-07-29 20:46:44 +02:00
|
|
|
NSTimeZone *timeZone;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2007-03-18 16:20:38 +01:00
|
|
|
unsigned int minutes;
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
timeZone = [ud timeZone];
|
2007-11-26 18:40:44 +01:00
|
|
|
[self todo];
|
2007-03-18 16:20:38 +01:00
|
|
|
if (todo)
|
|
|
|
{
|
|
|
|
startDate = [todo startDate];
|
|
|
|
dueDate = [todo due];
|
2011-06-13 22:28:10 +02:00
|
|
|
if (startDate)
|
|
|
|
hasStartDate = YES;
|
|
|
|
else
|
|
|
|
startDate = [self newStartDate];
|
|
|
|
if (dueDate)
|
|
|
|
hasDueDate = YES;
|
|
|
|
else
|
|
|
|
dueDate = [self newStartDate];
|
2014-09-25 15:25:13 +02:00
|
|
|
|
|
|
|
ASSIGN (statusDate, [todo completed]);
|
|
|
|
[statusDate setTimeZone: timeZone];
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (status, [todo status]);
|
2014-09-25 15:25:13 +02:00
|
|
|
|
|
|
|
if ([status length] == 0 && statusDate)
|
2009-07-29 20:46:44 +02:00
|
|
|
{
|
2014-09-25 15:25:13 +02:00
|
|
|
ASSIGN(status, @"COMPLETED");
|
2009-07-29 20:46:44 +02:00
|
|
|
}
|
2007-03-18 16:20:38 +01:00
|
|
|
else
|
2009-07-29 20:46:44 +02:00
|
|
|
{
|
|
|
|
ASSIGN (statusDate, [self newStartDate]);
|
|
|
|
}
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (statusPercent, [todo percentComplete]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
startDate = [self newStartDate];
|
|
|
|
duration = [self queryParameterForKey:@"dur"];
|
|
|
|
if ([duration length] > 0)
|
|
|
|
minutes = [duration intValue];
|
|
|
|
else
|
|
|
|
minutes = 60;
|
|
|
|
dueDate = [startDate dateByAddingYears: 0 months: 0 days: 0
|
|
|
|
hours: 0 minutes: minutes seconds: 0];
|
|
|
|
hasStartDate = NO;
|
|
|
|
hasDueDate = NO;
|
|
|
|
ASSIGN (statusDate, [self newStartDate]);
|
|
|
|
ASSIGN (status, @"");
|
|
|
|
ASSIGN (statusPercent, @"");
|
|
|
|
}
|
|
|
|
|
2009-07-29 20:46:44 +02:00
|
|
|
[startDate setTimeZone: timeZone];
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (taskStartDate, startDate);
|
2009-07-29 20:46:44 +02:00
|
|
|
|
|
|
|
[dueDate setTimeZone: timeZone];
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (taskDueDate, dueDate);
|
|
|
|
|
|
|
|
/* here comes the code for initializing repeat, reminder and isAllDay... */
|
|
|
|
|
|
|
|
return self;
|
2006-10-19 16:40:24 +02:00
|
|
|
}
|
|
|
|
|
2008-08-10 23:44:25 +02:00
|
|
|
#warning this method could be replaced with a method common with UIxAppointmentEditor...
|
2007-03-18 16:20:38 +01:00
|
|
|
- (id <WOActionResults>) saveAction
|
2006-10-19 16:40:24 +02:00
|
|
|
{
|
2008-08-10 23:44:25 +02:00
|
|
|
NSString *newCalendar;
|
|
|
|
SOGoAppointmentFolder *thisFolder, *newFolder;
|
|
|
|
SOGoTaskObject *co;
|
|
|
|
SoSecurityManager *sm;
|
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
[co saveComponent: todo];
|
|
|
|
|
|
|
|
newCalendar = [self queryParameterForKey: @"moveToCalendar"];
|
|
|
|
if ([newCalendar length])
|
|
|
|
{
|
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
|
|
|
|
|
|
|
thisFolder = [co container];
|
|
|
|
if (![sm validatePermission: SoPerm_DeleteObjects
|
|
|
|
onObject: thisFolder
|
|
|
|
inContext: context])
|
|
|
|
{
|
|
|
|
newFolder = [[thisFolder container] lookupName: newCalendar
|
2012-10-22 16:09:13 +02:00
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
2008-08-10 23:44:25 +02:00
|
|
|
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
onObject: newFolder
|
|
|
|
inContext: context])
|
2012-10-22 16:09:13 +02:00
|
|
|
[co moveToFolder: newFolder];
|
2008-08-10 23:44:25 +02:00
|
|
|
}
|
|
|
|
}
|
2007-03-18 16:20:38 +01:00
|
|
|
|
|
|
|
return [self jsCloseWithRefreshMethod: @"refreshTasks()"];
|
2006-10-19 16:40:24 +02:00
|
|
|
}
|
|
|
|
|
2015-01-22 18:12:51 +01:00
|
|
|
/**
|
|
|
|
* @api {get} /so/:username/Calendar/:calendarId/:todoId/view Get task
|
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName GetTaskView
|
|
|
|
* @apiGroup Calendar
|
|
|
|
* @apiExample {curl} Example usage:
|
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Calendar/personal/1A5-53489200-2D-6BD99880.ics/view
|
|
|
|
*
|
|
|
|
* @apiParam {Number} [resetAlarm] Mark alarm as triggered if set to 1
|
|
|
|
* @apiParam {Number} [snoozeAlarm] Snooze the alarm for this number of minutes
|
|
|
|
*
|
|
|
|
* @apiSuccess (Success 200) {String} id Todo ID
|
|
|
|
* @apiSuccess (Success 200) {String} pid Calendar ID (todo's folder)
|
|
|
|
* @apiSuccess (Success 200) {String} calendar Human readable name of calendar
|
|
|
|
* @apiSuccess (Success 200) {String} startDate Formatted start date
|
|
|
|
* @apiSuccess (Success 200) {String} startTime Formatted start time
|
|
|
|
* @apiSuccess (Success 200) {String} dueDate Formatted due date
|
|
|
|
* @apiSuccess (Success 200) {String} dueTime Formatted due time
|
|
|
|
* @apiSuccess (Success 200) {NSNumber} percentComplete Percent completion
|
|
|
|
*
|
|
|
|
* From [iCalEntityObject+SOGo attributes]
|
|
|
|
*
|
|
|
|
* @apiSuccess (Success 200) {String} component "vtodo"
|
|
|
|
* @apiSuccess (Success 200) {String} summary Summary
|
|
|
|
* @apiSuccess (Success 200) {String} location Location
|
|
|
|
* @apiSuccess (Success 200) {String} comment Comment
|
|
|
|
* @apiSuccess (Success 200) {String} createdBy Value of custom header X-SOGo-Component-Created-By or organizer's "SENT-BY"
|
|
|
|
* @apiSuccess (Success 200) {Number} priority Priority
|
|
|
|
* @apiSuccess (Success 200) {String[]} [categories] Categories
|
|
|
|
* @apiSuccess (Success 200) {Object} [organizer] Appointment organizer
|
|
|
|
* @apiSuccess (Success 200) {String} organizer.name Organizer's name
|
|
|
|
* @apiSuccess (Success 200) {String} organizer.email Organizer's email address
|
|
|
|
* @apiSuccess (Success 200) {Object[]} [attendees] List of attendees
|
|
|
|
* @apiSuccess (Success 200) {String} [attendees.name] Attendee's name
|
|
|
|
* @apiSuccess (Success 200) {String} attendees.email Attendee's email address
|
|
|
|
* @apiSuccess (Success 200) {String} [attendees.uid] System user ID
|
|
|
|
* @apiSuccess (Success 200) {String} attendees.status Attendee's participation status
|
|
|
|
* @apiSuccess (Success 200) {String} [attendees.role] Attendee's role
|
|
|
|
* @apiSuccess (Success 200) {String} [attendees.delegatedTo] User that the original request was delegated to
|
|
|
|
* @apiSuccess (Success 200) {String} [attendees.delegatedFrom] User the request was delegated from
|
|
|
|
* @apiSuccess (Success 200) {Object[]} [alarm] Alarm definition
|
|
|
|
* @apiSuccess (Success 200) {String} alarm.action Either display or email
|
|
|
|
* @apiSuccess (Success 200) {String} alarm.quantity Quantity of units
|
|
|
|
* @apiSuccess (Success 200) {String} alarm.unit Either MINUTES, HOURS, or DAYS
|
|
|
|
* @apiSuccess (Success 200) {String} alarm.reference Either BEFORE or AFTER
|
|
|
|
* @apiSuccess (Success 200) {String} alarm.relation Either START or END
|
|
|
|
* @apiSuccess (Success 200) {Object[]} [alarm.attendees] List of attendees
|
|
|
|
* @apiSuccess (Success 200) {String} [alarm.attendees.name] Attendee's name
|
|
|
|
* @apiSuccess (Success 200) {String} alarm.attendees.email Attendee's email address
|
|
|
|
* @apiSuccess (Success 200) {String} [alarm.attendees.uid] System user ID
|
|
|
|
*
|
|
|
|
* From [iCalRepeatableEntityObject+SOGo attributes]
|
|
|
|
*
|
|
|
|
* @apiSuccess (Success 200) {Object} [repeat] Recurrence rule definition
|
|
|
|
* @apiSuccess (Success 200) {String} repeat.frequency Either daily, (every weekday), weekly, (bi-weekly), monthly, or yearly
|
|
|
|
* @apiSuccess (Success 200) {Number} repeat.interval Intervals the recurrence rule repeats
|
|
|
|
* @apiSuccess (Success 200) {String} [repeat.count] Number of occurrences at which to range-bound the recurrence
|
|
|
|
* @apiSuccess (Success 200) {String} [repeat.until] A Unix epoch value that bounds the recurrence rule in an inclusive manner
|
|
|
|
* @apiSuccess (Success 200) {Number[]} [repeat.days] List of days of the week
|
|
|
|
* @apiSuccess (Success 200) {String} repeat.days.day Day of the week (SU, MO, TU, WE, TH, FR, SA)
|
|
|
|
* @apiSuccess (Success 200) {Number} [repeat.days.occurence] Occurrence of a specific day within the monthly or yearly rule (valures are -5 to 5)
|
|
|
|
* @apiSuccess (Success 200) {Number[]} [repeat.months] List of months of the year (values are 1 to 12)
|
|
|
|
* @apiSuccess (Success 200) {Number[]} [repeat.monthdays] Days of the month (values are 1 to 31)
|
|
|
|
*/
|
2009-04-22 23:02:11 +02:00
|
|
|
- (id <WOActionResults>) viewAction
|
|
|
|
{
|
2015-01-22 18:12:51 +01:00
|
|
|
NSMutableDictionary *data;
|
2009-04-22 23:02:11 +02:00
|
|
|
NSCalendarDate *startDate, *dueDate;
|
|
|
|
NSTimeZone *timeZone;
|
2015-01-22 18:12:51 +01:00
|
|
|
SOGoCalendarComponent *co;
|
|
|
|
SOGoAppointmentFolder *thisFolder;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2014-09-12 14:34:15 +02:00
|
|
|
iCalAlarm *anAlarm;
|
2009-04-22 23:02:11 +02:00
|
|
|
BOOL resetAlarm;
|
2014-09-12 14:34:15 +02:00
|
|
|
BOOL snoozeAlarm;
|
2009-04-22 23:02:11 +02:00
|
|
|
|
|
|
|
[self todo];
|
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
co = [self clientObject];
|
2015-01-22 18:12:51 +01:00
|
|
|
thisFolder = [co container];
|
2014-09-12 14:34:15 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
timeZone = [ud timeZone];
|
2009-04-22 23:02:11 +02:00
|
|
|
startDate = [todo startDate];
|
|
|
|
[startDate setTimeZone: timeZone];
|
|
|
|
dueDate = [todo due];
|
|
|
|
[dueDate setTimeZone: timeZone];
|
2014-09-12 14:34:15 +02:00
|
|
|
|
|
|
|
// resetAlarm=yes is set only when we are about to show the alarm popup in the Web
|
|
|
|
// interface of SOGo. See generic.js for details. snoozeAlarm=X is called when the
|
|
|
|
// user clicks on "Snooze for" X minutes, when the popup is being displayed.
|
|
|
|
// If either is set to yes, we must find the right alarm.
|
2009-04-22 23:02:11 +02:00
|
|
|
resetAlarm = [[[context request] formValueForKey: @"resetAlarm"] boolValue];
|
2014-09-12 14:34:15 +02:00
|
|
|
snoozeAlarm = [[[context request] formValueForKey: @"snoozeAlarm"] intValue];
|
|
|
|
|
|
|
|
if (resetAlarm || snoozeAlarm)
|
2009-04-22 23:02:11 +02:00
|
|
|
{
|
2014-09-12 14:34:15 +02:00
|
|
|
iCalToDo *master;
|
|
|
|
|
|
|
|
master = todo;
|
2015-01-22 18:12:51 +01:00
|
|
|
[thisFolder findEntityForClosestAlarm: &todo
|
|
|
|
timezone: timeZone
|
|
|
|
startDate: &startDate
|
|
|
|
endDate: &dueDate];
|
2014-09-12 20:09:28 +02:00
|
|
|
|
|
|
|
anAlarm = [todo firstDisplayOrAudioAlarm];
|
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
if (resetAlarm)
|
|
|
|
{
|
|
|
|
iCalTrigger *aTrigger;
|
|
|
|
|
|
|
|
aTrigger = [anAlarm trigger];
|
|
|
|
[aTrigger setValue: 0 ofAttribute: @"x-webstatus" to: @"triggered"];
|
|
|
|
|
|
|
|
[co saveComponent: master];
|
|
|
|
}
|
|
|
|
else if (snoozeAlarm)
|
|
|
|
{
|
2014-09-12 20:09:28 +02:00
|
|
|
[co snoozeAlarm: snoozeAlarm];
|
2014-09-12 14:34:15 +02:00
|
|
|
}
|
2009-04-22 23:02:11 +02:00
|
|
|
}
|
2014-09-12 14:34:15 +02:00
|
|
|
resetAlarm = [[[context request] formValueForKey: @"resetAlarm"] boolValue];
|
2009-04-22 23:02:11 +02:00
|
|
|
|
2015-01-22 18:12:51 +01:00
|
|
|
data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[co nameInContainer], @"id",
|
|
|
|
[thisFolder nameInContainer], @"pid",
|
|
|
|
[thisFolder displayName], @"calendar",
|
2009-10-26 14:39:28 +01:00
|
|
|
(startDate? (id)[dateFormatter formattedDate: startDate] : (id)@""), @"startDate",
|
|
|
|
(startDate? (id)[dateFormatter formattedTime: startDate] : (id)@""), @"startTime",
|
|
|
|
(dueDate? (id)[dateFormatter formattedDate: dueDate] : (id)@""), @"dueDate",
|
|
|
|
(dueDate? (id)[dateFormatter formattedTime: dueDate] : (id)@""), @"dueTime",
|
2015-01-22 18:12:51 +01:00
|
|
|
[NSNumber numberWithInt: [[todo percentComplete] intValue]], @"percentComplete",
|
2009-04-22 23:02:11 +02:00
|
|
|
nil];
|
|
|
|
|
2015-01-22 18:12:51 +01:00
|
|
|
// Add attributes from iCalEntityObject+SOGo and iCalRepeatableEntityObject+SOGo
|
|
|
|
[data addEntriesFromDictionary: [todo attributes]];
|
2009-04-22 23:02:11 +02:00
|
|
|
|
2015-01-22 18:12:51 +01:00
|
|
|
// Return JSON representation
|
|
|
|
return [self responseWithStatus: 200 andJSONRepresentation: data];
|
2009-04-22 23:02:11 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
|
|
|
|
inContext: (WOContext*) context
|
2006-10-19 16:40:24 +02:00
|
|
|
{
|
2007-08-24 00:13:27 +02:00
|
|
|
NSString *actionName;
|
|
|
|
|
|
|
|
actionName = [[request requestHandlerPath] lastPathComponent];
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
return ([[self clientObject] conformsToProtocol: @protocol (SOGoComponentOccurence)]
|
2007-08-24 00:13:27 +02:00
|
|
|
&& [actionName hasPrefix: @"save"]);
|
2006-10-19 16:40:24 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) takeValuesFromRequest: (WORequest *) _rq
|
|
|
|
inContext: (WOContext *) _ctx
|
2006-10-19 16:40:24 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
iCalTimeZone *tz;
|
|
|
|
|
2007-11-26 18:40:44 +01:00
|
|
|
[self todo];
|
2007-03-18 16:20:38 +01:00
|
|
|
|
|
|
|
[super takeValuesFromRequest: _rq inContext: _ctx];
|
|
|
|
|
|
|
|
if (hasStartDate)
|
|
|
|
[todo setStartDate: taskStartDate];
|
2007-07-10 16:19:02 +02:00
|
|
|
else
|
2011-12-22 19:02:59 +01:00
|
|
|
{
|
|
|
|
[todo setStartDate: nil];
|
|
|
|
[todo removeAllAlarms];
|
|
|
|
}
|
2007-07-10 16:19:02 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
if (hasDueDate)
|
|
|
|
[todo setDue: taskDueDate];
|
2007-07-10 16:19:02 +02:00
|
|
|
else
|
2009-04-21 16:34:22 +02:00
|
|
|
[todo setDue: nil];
|
2007-07-10 16:19:02 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
if ([status isEqualToString: @"COMPLETED"])
|
|
|
|
[todo setCompleted: statusDate];
|
|
|
|
else
|
|
|
|
[todo setCompleted: nil];
|
|
|
|
if ([status length] > 0)
|
|
|
|
{
|
|
|
|
[todo setStatus: status];
|
|
|
|
[todo setPercentComplete: statusPercent];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[todo setStatus: @""];
|
|
|
|
[todo setPercentComplete: @""];
|
|
|
|
}
|
2009-10-15 20:43:28 +02:00
|
|
|
|
|
|
|
if ([[self clientObject] isNew])
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
tz = [iCalTimeZone timeZoneForName: [ud timeZoneName]];
|
2009-10-15 20:43:28 +02:00
|
|
|
|
|
|
|
if (hasStartDate || hasDueDate)
|
|
|
|
{
|
|
|
|
[[todo parent] addTimeZone: tz];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasStartDate)
|
2009-10-26 14:39:28 +01:00
|
|
|
[(iCalDateTime *)[todo uniqueChildWithTag: @"dtstart"] setTimeZone: tz];
|
2009-10-15 20:43:28 +02:00
|
|
|
|
|
|
|
if (hasDueDate)
|
2009-10-26 14:39:28 +01:00
|
|
|
[(iCalDateTime *)[todo uniqueChildWithTag: @"due"] setTimeZone: tz];
|
2009-10-15 20:43:28 +02:00
|
|
|
}
|
|
|
|
|
2006-10-19 16:40:24 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 16:37:37 +01:00
|
|
|
- (id) changeStatusAction
|
2007-03-18 20:19:44 +01:00
|
|
|
{
|
2007-11-19 20:17:44 +01:00
|
|
|
NSString *newStatus;
|
2007-03-19 16:37:37 +01:00
|
|
|
|
2007-11-26 18:40:44 +01:00
|
|
|
[self todo];
|
2007-03-19 16:37:37 +01:00
|
|
|
if (todo)
|
|
|
|
{
|
|
|
|
newStatus = [self queryParameterForKey: @"status"];
|
|
|
|
if ([newStatus intValue])
|
|
|
|
[todo setCompleted: [NSCalendarDate date]];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[todo setCompleted: nil];
|
2007-03-23 18:41:39 +01:00
|
|
|
[todo setPercentComplete: @"0"];
|
2007-03-19 16:37:37 +01:00
|
|
|
[todo setStatus: @"IN-PROCESS"];
|
|
|
|
}
|
2007-11-26 18:40:44 +01:00
|
|
|
[[self clientObject] saveComponent: todo];
|
2007-03-19 16:37:37 +01:00
|
|
|
}
|
2007-03-18 20:19:44 +01:00
|
|
|
|
2007-11-19 20:17:44 +01:00
|
|
|
return [self responseWith204];
|
2007-03-18 20:19:44 +01:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
@end
|