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
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
#import <SOGo/NSCalendarDate+SOGo.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
2015-02-18 22:44:09 +01:00
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#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]))
|
|
|
|
{
|
2015-02-19 03:39:18 +01:00
|
|
|
// item = 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
|
|
|
|
{
|
2009-07-29 20:46:44 +02:00
|
|
|
[dateFormatter 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
|
|
|
|
{
|
2015-02-18 22:44:09 +01:00
|
|
|
return (iCalToDo *) component;
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
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 */
|
2006-10-11 20:15:29 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// - (NSArray *) statusList
|
|
|
|
// {
|
|
|
|
// static NSArray *statusItems = nil;
|
|
|
|
|
|
|
|
// if (!statusItems)
|
|
|
|
// {
|
|
|
|
// statusItems = [NSArray arrayWithObjects: @"NEEDS-ACTION",
|
|
|
|
// @"IN-PROCESS",
|
|
|
|
// @"COMPLETED",
|
|
|
|
// @"CANCELLED",
|
|
|
|
// nil];
|
|
|
|
// [statusItems retain];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return statusItems;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSString *) itemStatusText
|
|
|
|
// {
|
|
|
|
// if (!item)
|
|
|
|
// {
|
|
|
|
// item = status;
|
|
|
|
// if (!item)
|
|
|
|
// item = @"NOT-SPECIFIED";
|
|
|
|
// }
|
|
|
|
// return [self labelForKey: [NSString stringWithFormat: @"status_%@", item]];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (BOOL) statusDateDisabled
|
|
|
|
// {
|
|
|
|
// return !([status isEqualToString: @"COMPLETED"] || statusDate);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (BOOL) statusPercentDisabled
|
|
|
|
// {
|
|
|
|
// return ([status length] == 0 || [status isEqualToString: @"CANCELLED"]);
|
|
|
|
// }
|
2006-10-19 16:40:24 +02:00
|
|
|
|
2009-07-29 20:46:44 +02:00
|
|
|
/* viewing read-only tasks */
|
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// - (NSString *) taskStartDateTimeText
|
|
|
|
// {
|
|
|
|
// return [dateFormatter formattedDateAndTime: taskStartDate];
|
|
|
|
// }
|
2009-07-29 20:46:44 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// - (NSString *) taskDueDateTimeText
|
|
|
|
// {
|
|
|
|
// return [dateFormatter formattedDateAndTime: taskDueDate];
|
|
|
|
// }
|
2009-07-29 20:46:44 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// - (NSString *) statusDateText
|
|
|
|
// {
|
|
|
|
// return [dateFormatter formattedDate: statusDate];
|
|
|
|
// }
|
2009-07-29 20:46:44 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// - (id <WOActionResults>) defaultAction
|
|
|
|
// {
|
|
|
|
// NSCalendarDate *startDate, *dueDate;
|
|
|
|
// NSString *duration;
|
|
|
|
// NSTimeZone *timeZone;
|
|
|
|
// SOGoUserDefaults *ud;
|
|
|
|
// iCalToDo *todo;
|
|
|
|
// unsigned int minutes;
|
|
|
|
|
|
|
|
// ud = [[context activeUser] userDefaults];
|
|
|
|
// timeZone = [ud timeZone];
|
|
|
|
// todo = [self todo];
|
|
|
|
// if (todo)
|
|
|
|
// {
|
|
|
|
// startDate = [todo startDate];
|
|
|
|
// dueDate = [todo due];
|
|
|
|
// if (startDate)
|
|
|
|
// hasStartDate = YES;
|
|
|
|
// else
|
|
|
|
// startDate = [self newStartDate];
|
|
|
|
// if (dueDate)
|
|
|
|
// hasDueDate = YES;
|
|
|
|
// else
|
|
|
|
// dueDate = [self newStartDate];
|
2014-09-25 15:25:13 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// ASSIGN (statusDate, [todo completed]);
|
|
|
|
// [statusDate setTimeZone: timeZone];
|
2014-09-25 15:25:13 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// ASSIGN (status, [todo status]);
|
2014-09-25 15:25:13 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// if ([status length] == 0 && statusDate)
|
|
|
|
// {
|
|
|
|
// ASSIGN(status, @"COMPLETED");
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// ASSIGN (statusDate, [self newStartDate]);
|
|
|
|
// }
|
|
|
|
// 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, @"");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// /* here comes the code for initializing repeat, reminder and isAllDay... */
|
|
|
|
|
|
|
|
// return self;
|
|
|
|
// }
|
2007-03-18 16:20:38 +01:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
/**
|
|
|
|
* @api {post} /so/:username/Calendar/:calendarId/:todoId/save Save todo
|
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName PostToDoSave
|
|
|
|
* @apiGroup Calendar
|
|
|
|
* @apiExample {curl} Example usage:
|
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Calendar/personal/2142-54198E00-F-821E450.ics/save \
|
|
|
|
* -H 'Content-Type: application/json' \
|
|
|
|
* -d '{ "Summary": "Todo", "startDate": "2015-01-28", "startTime": "10:00", \
|
|
|
|
* "dueDate": "2015-01-28", "status": "in-process", "percentComplete": 25 }'
|
|
|
|
*
|
2015-06-25 17:23:18 +02:00
|
|
|
* @apiParam {_} . _Save in [iCalToDo+SOGo setAttributes:inContext:]_
|
|
|
|
*
|
2015-02-18 22:44:09 +01:00
|
|
|
* @apiParam {String} [startDate] Start date (YYYY-MM-DD)
|
|
|
|
* @apiParam {String} [startTime] Start time (HH:MM)
|
|
|
|
* @apiParam {String} [dueDate] End date (YYYY-MM-DD)
|
|
|
|
* @apiParam {String} [dueTime] End time (HH:MM)
|
|
|
|
* @apiParam {String} [completedDate] End date (YYYY-MM-DD)
|
|
|
|
* @apiParam {String} [completedTime] End time (HH:MM)
|
|
|
|
* @apiParam {Number} percentComplete Percent completion (0-100)
|
|
|
|
*
|
2015-06-25 17:23:18 +02:00
|
|
|
* @apiParam {_} .. _Save in [iCalEntityObject+SOGo setAttributes:inContext:]_
|
2015-02-18 22:44:09 +01:00
|
|
|
*
|
|
|
|
* @apiParam {Number} [sendAppointmentNotifications] 0 if notifications must not be sent
|
|
|
|
* @apiParam {String} [summary] Summary
|
|
|
|
* @apiParam {String} [location] Location
|
|
|
|
* @apiParam {String} [comment] Comment
|
|
|
|
* @apiParam {String} [status] Status (needs-action, in-process, completed, or cancelled)
|
|
|
|
* @apiParam {String} [attachUrl] Attached URL
|
|
|
|
* @apiParam {Number} [priority] Priority
|
|
|
|
* @apiParam {NSString} [classification] Either public, confidential or private
|
|
|
|
* @apiParam {String[]} [categories] Categories
|
|
|
|
* @apiParam {Object[]} [attendees] List of attendees
|
|
|
|
* @apiParam {String} [attendees.name] Attendee's name
|
|
|
|
* @apiParam {String} attendees.email Attendee's email address
|
|
|
|
* @apiParam {String} [attendees.uid] System user ID
|
|
|
|
* @apiParam {String} attendees.status Attendee's participation status
|
|
|
|
* @apiParam {String} [attendees.role] Either CHAIR, REQ-PARTICIPANT, OPT-PARTICIPANT, or NON-PARTICIPANT
|
|
|
|
* @apiParam {String} [attendees.delegatedTo] User that the original request was delegated to
|
|
|
|
* @apiParam {String} [attendees.delegatedFrom] User the request was delegated from
|
|
|
|
* @apiParam {Object[]} [alarm] Alarm definition
|
|
|
|
* @apiParam {String} alarm.action Either display or email
|
|
|
|
* @apiParam {Number} alarm.quantity Quantity of units
|
|
|
|
* @apiParam {String} alarm.unit Either MINUTES, HOURS, or DAYS
|
|
|
|
* @apiParam {String} alarm.reference Either BEFORE or AFTER
|
|
|
|
* @apiParam {String} alarm.relation Either START or END
|
|
|
|
* @apiParam {Boolean} [alarm.attendees] Alert attendees by email if true and action is email
|
|
|
|
* @apiParam {Object} [alarm.organizer] Alert organizer at this email address if action is email
|
|
|
|
* @apiParam {String} [alarm.organizer.name] Attendee's name
|
|
|
|
* @apiParam {String} alarm.organizer.email Attendee's email address
|
|
|
|
*
|
2015-06-25 17:23:18 +02:00
|
|
|
* @apiParam {_} ... _Save in [iCalRepeatbleEntityObject+SOGo setAttributes:inContext:]_
|
2015-02-18 22:44:09 +01:00
|
|
|
*
|
|
|
|
* @apiParam {Object} [repeat] Recurrence rule definition
|
|
|
|
* @apiParam {String} repeat.frequency Either daily, every weekday, weekly, bi-weekly, monthly, or yearly
|
|
|
|
* @apiParam {Number} repeat.interval Intervals the recurrence rule repeats
|
|
|
|
* @apiParam {String} [repeat.count] Number of occurrences at which to range-bound the recurrence
|
|
|
|
* @apiParam {String} [repeat.until] A date (YYYY-MM-DD) that bounds the recurrence rule in an inclusive manner
|
|
|
|
* @apiParam {Object[]} [repeat.days] List of days of the week (by day mask)
|
|
|
|
* @apiParam {String} [repeat.days.day] Day of the week (SU, MO, TU, WE, TH, FR, SA)
|
|
|
|
* @apiParam {Number} [repeat.days.occurence] Occurrence of a specific day within the monthly or yearly rule (values are -5 to 5)
|
|
|
|
* @apiParam {Number[]} [repeat.months] List of months of the year (values are 1 to 12)
|
|
|
|
* @apiParam {Number[]} [repeat.monthdays] Days of the month (values are 1 to 31)
|
|
|
|
*
|
2015-06-25 17:23:18 +02:00
|
|
|
* @apiParam {_} .... _Save in [UIxComponentEditor setAttributes:]_
|
2015-02-18 22:44:09 +01:00
|
|
|
*
|
|
|
|
* @apiParam {Object} [organizer] Appointment organizer
|
|
|
|
* @apiParam {String} organizer.name Organizer's name
|
|
|
|
* @apiParam {String} organizer.email Organizer's email address
|
|
|
|
*
|
|
|
|
* @apiError (Error 500) {Object} error The error message
|
|
|
|
*/
|
2007-03-18 16:20:38 +01:00
|
|
|
- (id <WOActionResults>) saveAction
|
2006-10-19 16:40:24 +02:00
|
|
|
{
|
2015-02-18 22:44:09 +01:00
|
|
|
NSDictionary *params;
|
|
|
|
NSException *ex;
|
|
|
|
NSString *newCalendar, *jsonResponse;
|
2008-08-10 23:44:25 +02:00
|
|
|
SOGoAppointmentFolder *thisFolder, *newFolder;
|
|
|
|
SOGoTaskObject *co;
|
|
|
|
SoSecurityManager *sm;
|
2015-02-18 22:44:09 +01:00
|
|
|
WORequest *request;
|
|
|
|
iCalToDo *todo;
|
2008-08-10 23:44:25 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
todo = [self todo];
|
2008-08-10 23:44:25 +02:00
|
|
|
co = [self clientObject];
|
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
ex = nil;
|
|
|
|
request = [context request];
|
|
|
|
params = [[request contentAsString] objectFromJSONString];
|
|
|
|
if (params == nil)
|
2008-08-10 23:44:25 +02:00
|
|
|
{
|
2015-02-18 22:44:09 +01:00
|
|
|
ex = [NSException exceptionWithName: @"JSONParsingException"
|
|
|
|
reason: @"Can't parse JSON string"
|
|
|
|
userInfo: nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setAttributes: params];
|
|
|
|
ex = [co saveComponent: todo];
|
2008-08-10 23:44:25 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
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
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
onObject: newFolder
|
|
|
|
inContext: context])
|
|
|
|
[co moveToFolder: newFolder];
|
|
|
|
}
|
|
|
|
}
|
2008-08-10 23:44:25 +02:00
|
|
|
}
|
2007-03-18 16:20:38 +01:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
if (ex)
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"failure", @"status",
|
|
|
|
[ex reason],
|
|
|
|
@"message",
|
|
|
|
nil];
|
|
|
|
else
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"success", @"status", nil];
|
|
|
|
|
|
|
|
return [self responseWithStatus: 200
|
|
|
|
andJSONRepresentation: jsonResponse];
|
2006-10-19 16:40:24 +02:00
|
|
|
}
|
|
|
|
|
2015-01-22 18:12:51 +01:00
|
|
|
/**
|
2015-02-18 22:44:09 +01:00
|
|
|
* @api {get} /so/:username/Calendar/:calendarId/:todoId/view Get todo
|
2015-01-22 18:12:51 +01:00
|
|
|
* @apiVersion 1.0.0
|
2015-02-18 22:44:09 +01:00
|
|
|
* @apiName GetToDoView
|
2015-01-22 18:12:51 +01:00
|
|
|
* @apiGroup Calendar
|
|
|
|
* @apiExample {curl} Example usage:
|
2015-02-18 22:44:09 +01:00
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Calendar/personal/2142-54198E00-F-821E450.ics/view
|
2015-01-22 18:12:51 +01:00
|
|
|
*
|
|
|
|
* @apiParam {Number} [resetAlarm] Mark alarm as triggered if set to 1
|
|
|
|
* @apiParam {Number} [snoozeAlarm] Snooze the alarm for this number of minutes
|
|
|
|
*
|
2015-07-04 03:38:37 +02:00
|
|
|
* @apiSuccess {_} . _From [UIxTaskEditor viewAction]_
|
|
|
|
*
|
2015-01-22 18:12:51 +01:00
|
|
|
* @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
|
2015-02-18 22:44:09 +01:00
|
|
|
* @apiSuccess (Success 200) {String} localizedStartDate Formatted start date
|
|
|
|
* @apiSuccess (Success 200) {String} localizedStartTime Formatted start time
|
|
|
|
* @apiSuccess (Success 200) {String} localizedDueDate Formatted due date
|
|
|
|
* @apiSuccess (Success 200) {String} localizedDueTime Formatted due time
|
2015-06-25 17:23:18 +02:00
|
|
|
* @apiSuccess (Success 200) {String} localizedCompletedDate Formatted completed date
|
|
|
|
* @apiSuccess (Success 200) {String} localizedCompletedTime Formatted completed time
|
|
|
|
* @apiSuccess (Success 200) {Number} isReadOnly 1 if task is read-only
|
2015-07-04 03:38:37 +02:00
|
|
|
* @apiSuccess (Success 200) {Object[]} [attachUrls] Attached URLs
|
|
|
|
* @apiSuccess (Success 200) {String} attachUrls.value URL
|
2015-06-25 17:23:18 +02:00
|
|
|
*
|
2015-07-04 03:38:37 +02:00
|
|
|
* @apiSuccess {_} .. _From [iCalToDo+SOGo attributesInContext:]_
|
2015-06-25 17:23:18 +02:00
|
|
|
*
|
|
|
|
* @apiSuccess (Success 200) {String} startDate Start date (ISO8601)
|
|
|
|
* @apiSuccess (Success 200) {String} dueDate Due date (ISO8601)
|
2015-02-18 22:44:09 +01:00
|
|
|
* @apiSuccess (Success 200) {String} completedDate Completed date (ISO8601)
|
|
|
|
* @apiSuccess (Success 200) {Number} percentComplete Percent completion
|
2015-01-22 18:12:51 +01:00
|
|
|
*
|
2015-07-04 03:38:37 +02:00
|
|
|
* @apiSuccess {_} ... _From [UIxComponentEdtiror alarm]_
|
2015-06-25 17:23:18 +02:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*
|
2015-07-04 03:38:37 +02:00
|
|
|
* @apiSuccess {_} .... _From [iCalEntityObject+SOGo attributesInContext:]_
|
2015-01-22 18:12:51 +01:00
|
|
|
*
|
|
|
|
* @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
|
2015-06-25 17:23:18 +02:00
|
|
|
* @apiSuccess (Success 200) {String} status Status (needs-action, in-process, completed, or cancelled)
|
2015-01-22 18:12:51 +01:00
|
|
|
* @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
|
|
|
|
*
|
2015-07-04 03:38:37 +02:00
|
|
|
* @apiSuccess {_} ..... _From [iCalRepeatableEntityObject+SOGo attributesInContext:]_
|
2015-01-22 18:12:51 +01:00
|
|
|
*
|
|
|
|
* @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-07-04 03:38:37 +02:00
|
|
|
NSArray *attachUrls;
|
2015-01-22 18:12:51 +01:00
|
|
|
NSMutableDictionary *data;
|
2015-02-18 22:44:09 +01:00
|
|
|
NSCalendarDate *startDate, *dueDate, *completedDate;
|
2009-04-22 23:02:11 +02:00
|
|
|
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;
|
2015-02-18 22:44:09 +01:00
|
|
|
iCalToDo *todo;
|
|
|
|
BOOL resetAlarm, snoozeAlarm;
|
|
|
|
BOOL isAllDayStartDate, isAllDayDueDate;
|
2009-04-22 23:02:11 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
todo = [self todo];
|
2009-04-22 23:02:11 +02:00
|
|
|
|
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];
|
2015-02-18 22:44:09 +01:00
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
startDate = [todo startDate];
|
2015-02-18 22:44:09 +01:00
|
|
|
isAllDayStartDate = [(iCalDateTime *) [todo uniqueChildWithTag: @"dtstart"] isAllDay];
|
|
|
|
if (!isAllDayStartDate)
|
|
|
|
[startDate setTimeZone: timeZone];
|
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
dueDate = [todo due];
|
2015-02-18 22:44:09 +01:00
|
|
|
isAllDayDueDate = [(iCalDateTime *) [todo uniqueChildWithTag: @"due"] isAllDay];
|
|
|
|
if (!isAllDayDueDate)
|
|
|
|
[dueDate setTimeZone: timeZone];
|
|
|
|
|
|
|
|
completedDate = [todo completed];
|
|
|
|
[completedDate 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
|
|
|
}
|
|
|
|
|
2015-01-22 18:12:51 +01:00
|
|
|
data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[co nameInContainer], @"id",
|
|
|
|
[thisFolder nameInContainer], @"pid",
|
|
|
|
[thisFolder displayName], @"calendar",
|
2015-04-24 20:25:04 +02:00
|
|
|
[NSNumber numberWithBool: [self isReadOnly]], @"isReadOnly",
|
2015-07-01 20:34:35 +02:00
|
|
|
[self alarm], @"alarm",
|
2009-04-22 23:02:11 +02:00
|
|
|
nil];
|
2009-11-29 05:19:32 +01:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
if (startDate)
|
2011-12-22 19:02:59 +01:00
|
|
|
{
|
2015-02-18 22:44:09 +01:00
|
|
|
[data setObject: [dateFormatter formattedDate: startDate] forKey: @"localizedStartDate"];
|
|
|
|
if (!isAllDayStartDate)
|
|
|
|
[data setObject: [dateFormatter formattedTime: startDate] forKey: @"localizedStartTime"];
|
2011-12-22 19:02:59 +01:00
|
|
|
}
|
2015-02-18 22:44:09 +01:00
|
|
|
if (dueDate)
|
2007-03-18 16:20:38 +01:00
|
|
|
{
|
2015-02-18 22:44:09 +01:00
|
|
|
[data setObject: [dateFormatter formattedDate: dueDate] forKey: @"localizedDueDate"];
|
|
|
|
if (!isAllDayDueDate)
|
|
|
|
[data setObject: [dateFormatter formattedTime: dueDate] forKey: @"localizedDueTime"];
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
2015-02-18 22:44:09 +01:00
|
|
|
|
|
|
|
if (completedDate)
|
2007-03-18 16:20:38 +01:00
|
|
|
{
|
2015-02-18 22:44:09 +01:00
|
|
|
[data setObject: [dateFormatter formattedDate: completedDate] forKey: @"localizedCompletedDate"];
|
|
|
|
[data setObject: [dateFormatter formattedTime: completedDate] forKey: @"localizedCompletedTime"];
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2015-07-04 03:38:37 +02:00
|
|
|
attachUrls = [self attachUrls];
|
|
|
|
if ([attachUrls count]) [data setObject: attachUrls forKey: @"attachUrls"];
|
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// Add attributes from iCalToDo+SOGo, iCalEntityObject+SOGo and iCalRepeatableEntityObject+SOGo
|
|
|
|
[data addEntriesFromDictionary: [todo attributesInContext: context]];
|
|
|
|
|
|
|
|
// Return JSON representation
|
|
|
|
return [self responseWithStatus: 200 andJSONRepresentation: data];
|
|
|
|
}
|
|
|
|
|
|
|
|
// - (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
|
|
|
|
// inContext: (WOContext*) context
|
|
|
|
// {
|
|
|
|
// NSString *actionName;
|
|
|
|
|
|
|
|
// actionName = [[request requestHandlerPath] lastPathComponent];
|
|
|
|
|
|
|
|
// return ([[self clientObject] conformsToProtocol: @protocol (SOGoComponentOccurence)]
|
|
|
|
// && [actionName hasPrefix: @"save"]);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (void) takeValuesFromRequest: (WORequest *) _rq
|
|
|
|
// inContext: (WOContext *) _ctx
|
|
|
|
// {
|
|
|
|
// SOGoUserDefaults *ud;
|
|
|
|
// iCalTimeZone *tz;
|
|
|
|
// iCalToDo *todo;
|
|
|
|
|
|
|
|
// todo = [self todo];
|
|
|
|
|
|
|
|
// [super takeValuesFromRequest: _rq inContext: _ctx];
|
|
|
|
|
|
|
|
// if (hasStartDate)
|
|
|
|
// [todo setStartDate: taskStartDate];
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// [todo setStartDate: nil];
|
|
|
|
// [todo removeAllAlarms];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (hasDueDate)
|
|
|
|
// [todo setDue: taskDueDate];
|
|
|
|
// else
|
|
|
|
// [todo setDue: nil];
|
|
|
|
|
|
|
|
// 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: @""];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if ([[self clientObject] isNew])
|
|
|
|
// {
|
|
|
|
// ud = [[context activeUser] userDefaults];
|
|
|
|
// tz = [iCalTimeZone timeZoneForName: [ud timeZoneName]];
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// if (hasStartDate || hasDueDate)
|
|
|
|
// {
|
|
|
|
// [[todo parent] addTimeZone: tz];
|
|
|
|
// }
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// if (hasStartDate)
|
|
|
|
// [(iCalDateTime *)[todo uniqueChildWithTag: @"dtstart"] setTimeZone: tz];
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
// if (hasDueDate)
|
|
|
|
// [(iCalDateTime *)[todo uniqueChildWithTag: @"due"] setTimeZone: tz];
|
|
|
|
// }
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2015-02-18 22:44:09 +01: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;
|
2015-02-18 22:44:09 +01:00
|
|
|
iCalToDo *todo;
|
2007-03-19 16:37:37 +01:00
|
|
|
|
2015-02-18 22:44:09 +01:00
|
|
|
todo = [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
|