2007-03-18 16:20:38 +01:00
|
|
|
/* UIxTaskEditor.m - this file is part of SOGo
|
|
|
|
*
|
2014-07-30 20:51:00 +02:00
|
|
|
* Copyright (C) 2007-2014 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>
|
|
|
|
|
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>
|
|
|
|
#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
|
|
|
|
{
|
|
|
|
return ![status isEqualToString: @"COMPLETED"];
|
|
|
|
}
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (BOOL) statusPercentDisabled
|
|
|
|
{
|
|
|
|
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];
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (status, [todo status]);
|
|
|
|
if ([status isEqualToString: @"COMPLETED"])
|
2009-07-29 20:46:44 +02:00
|
|
|
{
|
|
|
|
ASSIGN (statusDate, [todo completed]);
|
|
|
|
[statusDate setTimeZone: timeZone];
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (id <WOActionResults>) newAction
|
2006-10-19 16:40:24 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
NSString *objectId, *method, *uri;
|
|
|
|
id <WOActionResults> result;
|
2007-09-15 00:01:02 +02:00
|
|
|
SOGoAppointmentFolder *co;
|
2008-08-25 21:13:18 +02:00
|
|
|
SoSecurityManager *sm;
|
2007-03-18 16:20:38 +01:00
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
co = [self clientObject];
|
|
|
|
objectId = [co globallyUniqueObjectId];
|
2007-03-18 16:20:38 +01:00
|
|
|
if ([objectId length] > 0)
|
|
|
|
{
|
2008-08-25 21:13:18 +02:00
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
|
|
|
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
onObject: co
|
|
|
|
inContext: context])
|
|
|
|
{
|
|
|
|
method = [NSString stringWithFormat:@"%@/%@.ics/editAsTask",
|
|
|
|
[co soURL], objectId];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
method = [NSString stringWithFormat: @"%@/Calendar/personal/%@.vcf/editAsTask",
|
|
|
|
[self userFolderPath], objectId];
|
|
|
|
}
|
2007-03-18 16:20:38 +01:00
|
|
|
uri = [self completeHrefForMethod: method];
|
|
|
|
result = [self redirectToLocation: uri];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
|
|
|
|
reason: @"could not create a unique ID"];
|
|
|
|
|
|
|
|
return result;
|
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
|
|
|
}
|
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
- (id <WOActionResults>) viewAction
|
|
|
|
{
|
|
|
|
WOResponse *result;
|
|
|
|
NSDictionary *data;
|
|
|
|
NSCalendarDate *startDate, *dueDate;
|
2014-09-12 14:34:15 +02:00
|
|
|
SOGoCalendarComponent *co;
|
2009-04-22 23:02:11 +02:00
|
|
|
NSTimeZone *timeZone;
|
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];
|
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
result = [self responseWithStatus: 200];
|
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;
|
|
|
|
[[co container] 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
|
|
|
|
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[todo tag], @"component",
|
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",
|
2009-04-22 23:02:11 +02:00
|
|
|
([todo hasRecurrenceRules]? @"1": @"0"), @"isReccurent",
|
|
|
|
[todo summary], @"summary",
|
|
|
|
[todo location], @"location",
|
|
|
|
[todo comment], @"description",
|
|
|
|
nil];
|
|
|
|
|
|
|
|
[result appendContentString: [data jsonRepresentation]];
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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
|