2007-03-18 16:20:38 +01:00
|
|
|
/* UIxAppointmentEditor.m - this file is part of SOGo
|
|
|
|
*
|
2009-07-29 20:46:44 +02:00
|
|
|
* Copyright (C) 2007-2009 Inverse inc.
|
2007-03-18 16:20:38 +01:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-06-07 20:12:20 +02:00
|
|
|
#include <math.h>
|
|
|
|
|
2008-08-19 00:45:59 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2008-12-23 19:39:36 +01:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2008-12-30 15:47:58 +01:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2008-08-19 00:45:59 +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/iCalEvent.h>
|
|
|
|
#import <NGCards/iCalPerson.h>
|
2009-04-22 23:02:11 +02:00
|
|
|
#import <NGCards/iCalTrigger.h>
|
2007-10-09 19:19:20 +02:00
|
|
|
#import <NGCards/iCalRecurrenceRule.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/SOGoPermissions.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
|
|
|
#import <Appointments/iCalPerson+SOGo.h>
|
|
|
|
#import <Appointments/SOGoAppointmentFolder.h>
|
|
|
|
#import <Appointments/SOGoAppointmentObject.h>
|
|
|
|
#import <Appointments/SOGoAppointmentOccurence.h>
|
|
|
|
|
|
|
|
#import <Appointments/SOGoComponentOccurence.h>
|
2008-07-17 23:12:43 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
#import "UIxComponentEditor.h"
|
|
|
|
#import "UIxAppointmentEditor.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
@implementation UIxAppointmentEditor
|
2006-09-28 19:26:02 +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]))
|
|
|
|
{
|
|
|
|
aptStartDate = nil;
|
|
|
|
aptEndDate = nil;
|
|
|
|
item = nil;
|
|
|
|
event = nil;
|
2007-06-07 20:12:20 +02:00
|
|
|
isAllDay = NO;
|
2008-12-01 23:46:31 +01:00
|
|
|
isTransparent = NO;
|
2008-12-17 15:32:13 +01:00
|
|
|
componentCalendar = 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-06-15 21:34:10 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
return self;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-10-09 19:19:20 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-10-17 16:53:21 +02:00
|
|
|
[item release];
|
2009-02-06 21:15:41 +01:00
|
|
|
[[event parent] release];
|
2007-10-17 16:53:21 +02:00
|
|
|
[aptStartDate release];
|
|
|
|
[aptEndDate release];
|
2009-07-29 20:46:44 +02:00
|
|
|
[dateFormatter release];
|
2008-12-17 15:32:13 +01:00
|
|
|
[componentCalendar release];
|
2007-10-09 19:19:20 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
/* template values */
|
|
|
|
- (iCalEvent *) event
|
|
|
|
{
|
2007-11-19 22:07:54 +01:00
|
|
|
if (!event)
|
|
|
|
{
|
2008-07-17 23:12:43 +02:00
|
|
|
event = (iCalEvent *) [[self clientObject] occurence];
|
2009-02-06 21:15:41 +01:00
|
|
|
[[event parent] retain];
|
2007-11-19 22:07:54 +01:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
return event;
|
|
|
|
}
|
2006-10-12 18:42:59 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (NSString *) saveURL
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@/saveAsAppointment",
|
2008-03-07 23:18:01 +01:00
|
|
|
[[self clientObject] baseURL]];
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
2006-10-12 18:42:59 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
/* icalendar values */
|
|
|
|
- (BOOL) isAllDay
|
2006-10-18 16:42:44 +02:00
|
|
|
{
|
2007-06-11 23:25:43 +02:00
|
|
|
NSString *hm;
|
|
|
|
|
|
|
|
hm = [self queryParameterForKey: @"hm"];
|
|
|
|
|
|
|
|
return (isAllDay
|
2008-07-11 19:26:11 +02:00
|
|
|
|| [hm isEqualToString: @"allday"]);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) setIsAllDay: (BOOL) newIsAllDay
|
|
|
|
{
|
2007-06-07 20:12:20 +02:00
|
|
|
isAllDay = newIsAllDay;
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-12-01 23:46:31 +01:00
|
|
|
- (BOOL) isTransparent
|
2008-11-06 18:19:14 +01:00
|
|
|
{
|
2008-12-01 23:46:31 +01:00
|
|
|
return isTransparent;
|
2008-11-06 18:19:14 +01:00
|
|
|
}
|
|
|
|
|
2008-12-01 23:46:31 +01:00
|
|
|
- (void) setIsTransparent: (BOOL) newIsTransparent
|
2008-11-06 18:19:14 +01:00
|
|
|
{
|
2008-12-01 23:46:31 +01:00
|
|
|
isTransparent = newIsTransparent;
|
2008-11-06 18:19:14 +01:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) setAptStartDate: (NSCalendarDate *) newAptStartDate
|
2006-10-18 16:42:44 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (aptStartDate, newAptStartDate);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-10-18 16:42:44 +02:00
|
|
|
- (NSCalendarDate *) aptStartDate
|
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
return aptStartDate;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) setAptEndDate: (NSCalendarDate *) newAptEndDate
|
2006-10-18 16:42:44 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (aptEndDate, newAptEndDate);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-10-18 16:42:44 +02:00
|
|
|
- (NSCalendarDate *) aptEndDate
|
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
return aptEndDate;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) setItem: (NSString *) newItem
|
|
|
|
{
|
2007-10-17 16:53:21 +02:00
|
|
|
ASSIGN (item, newItem);
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) item
|
|
|
|
{
|
|
|
|
return item;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-08-22 08:44:27 +02:00
|
|
|
- (SOGoAppointmentFolder *) componentCalendar
|
|
|
|
{
|
|
|
|
return componentCalendar;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setComponentCalendar: (SOGoAppointmentFolder *) _componentCalendar
|
|
|
|
{
|
|
|
|
ASSIGN (componentCalendar, _componentCalendar);
|
|
|
|
}
|
|
|
|
|
2009-07-29 20:46:44 +02:00
|
|
|
/* read-only event */
|
|
|
|
- (NSString *) aptStartDateText
|
|
|
|
{
|
|
|
|
return [dateFormatter formattedDate: aptStartDate];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) aptStartDateTimeText
|
|
|
|
{
|
|
|
|
return [dateFormatter formattedDateAndTime: aptStartDate];
|
|
|
|
}
|
|
|
|
|
2009-10-19 17:22:36 +02:00
|
|
|
- (NSString *) aptEndDateText
|
|
|
|
{
|
|
|
|
return [dateFormatter formattedDate: aptEndDate];
|
|
|
|
}
|
|
|
|
|
2009-07-29 20:46:44 +02:00
|
|
|
- (NSString *) aptEndDateTimeText
|
|
|
|
{
|
|
|
|
return [dateFormatter formattedDateAndTime: aptEndDate];
|
|
|
|
}
|
|
|
|
|
2009-10-19 17:22:36 +02:00
|
|
|
- (BOOL) startDateIsEqualToEndDate
|
|
|
|
{
|
|
|
|
return [aptStartDate isEqualToDate: aptEndDate];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* actions */
|
2007-03-18 16:20:38 +01:00
|
|
|
- (NSCalendarDate *) newStartDate
|
2006-10-18 16:42:44 +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;
|
2007-03-18 16:20:38 +01:00
|
|
|
int hour;
|
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-11 19:26:11 +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];
|
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
|
|
|
|
newStartDate = now;
|
|
|
|
}
|
|
|
|
else
|
2008-07-18 21:25:26 +02:00
|
|
|
newStartDate = [newStartDate hour: uStart minute: 0];
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
2006-09-28 19:26:02 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
return newStartDate;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (id <WOActionResults>) defaultAction
|
2006-10-18 16:42:44 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
NSCalendarDate *startDate, *endDate;
|
2008-12-01 23:46:31 +01:00
|
|
|
NSString *duration;
|
2009-07-29 20:46:44 +02:00
|
|
|
NSTimeZone *timeZone;
|
2010-02-11 03:36:43 +01:00
|
|
|
unsigned int total, hours, minutes;
|
2008-07-17 23:12:43 +02:00
|
|
|
SOGoObject <SOGoComponentOccurence> *co;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2007-03-18 16:20:38 +01:00
|
|
|
|
2007-11-26 18:40:44 +01:00
|
|
|
[self event];
|
2008-07-17 23:12:43 +02:00
|
|
|
co = [self clientObject];
|
2009-11-29 05:19:32 +01:00
|
|
|
|
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
timeZone = [ud timeZone];
|
2009-07-29 20:46:44 +02:00
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
if ([co isNew]
|
|
|
|
&& [co isKindOfClass: [SOGoCalendarComponent class]])
|
2007-03-18 16:20:38 +01:00
|
|
|
{
|
|
|
|
startDate = [self newStartDate];
|
2010-02-11 03:36:43 +01:00
|
|
|
duration = [self queryParameterForKey:@"duration"];
|
2007-03-18 16:20:38 +01:00
|
|
|
if ([duration length] > 0)
|
2010-02-11 03:36:43 +01:00
|
|
|
{
|
|
|
|
total = [duration intValue];
|
|
|
|
hours = total / 100;
|
|
|
|
minutes = total % 100;
|
|
|
|
}
|
2007-03-18 16:20:38 +01:00
|
|
|
else
|
2010-02-11 03:36:43 +01:00
|
|
|
{
|
|
|
|
hours = 1;
|
|
|
|
minutes = 0;
|
|
|
|
}
|
2007-03-18 16:20:38 +01:00
|
|
|
endDate
|
2009-07-14 19:17:06 +02:00
|
|
|
= [startDate dateByAddingYears: 0 months: 0 days: 0
|
2010-02-11 03:36:43 +01:00
|
|
|
hours: hours minutes: minutes seconds: 0];
|
2007-03-18 16:20:38 +01:00
|
|
|
}
|
2007-11-27 17:00:18 +01:00
|
|
|
else
|
|
|
|
{
|
2008-12-30 15:47:58 +01:00
|
|
|
NSCalendarDate *firstDate;
|
|
|
|
iCalEvent *master;
|
|
|
|
signed int daylightOffset;
|
|
|
|
|
2007-11-27 17:00:18 +01:00
|
|
|
startDate = [event startDate];
|
2008-12-30 15:47:58 +01:00
|
|
|
daylightOffset = 0;
|
2009-07-14 19:17:06 +02:00
|
|
|
|
2008-12-30 15:47:58 +01:00
|
|
|
if ([co isNew] && [co isKindOfClass: [SOGoAppointmentOccurence class]])
|
2009-07-14 19:17:06 +02:00
|
|
|
{
|
|
|
|
// We are creating a new exception in a recurrent event -- compute the daylight
|
|
|
|
// saving time with respect to the first occurrence of the recurrent event.
|
|
|
|
master = (iCalEvent*)[[event parent] firstChildWithTag: @"vevent"];
|
|
|
|
firstDate = [master startDate];
|
|
|
|
|
|
|
|
if ([timeZone isDaylightSavingTimeForDate: startDate] != [timeZone isDaylightSavingTimeForDate: firstDate])
|
|
|
|
{
|
|
|
|
daylightOffset = (signed int)[timeZone secondsFromGMTForDate: firstDate]
|
|
|
|
- (signed int)[timeZone secondsFromGMTForDate: startDate];
|
|
|
|
startDate = [startDate dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:daylightOffset];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-27 17:00:18 +01:00
|
|
|
isAllDay = [event isAllDay];
|
|
|
|
if (isAllDay)
|
2009-07-14 19:17:06 +02:00
|
|
|
endDate = [[event endDate] dateByAddingYears: 0 months: 0 days: -1];
|
2007-11-27 17:00:18 +01:00
|
|
|
else
|
2009-07-14 19:17:06 +02:00
|
|
|
endDate = [[event endDate] dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:daylightOffset];
|
2008-12-01 23:46:31 +01:00
|
|
|
isTransparent = ![event isOpaque];
|
2007-11-27 17:00:18 +01:00
|
|
|
}
|
2007-03-18 16:20:38 +01:00
|
|
|
|
2009-07-29 20:46:44 +02:00
|
|
|
[startDate setTimeZone: timeZone];
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (aptStartDate, startDate);
|
2009-07-29 20:46:44 +02:00
|
|
|
|
|
|
|
[endDate setTimeZone: timeZone];
|
2007-03-18 16:20:38 +01:00
|
|
|
ASSIGN (aptEndDate, endDate);
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (id <WOActionResults>) newAction
|
2006-10-12 18:42:59 +02:00
|
|
|
{
|
2007-03-18 16:20:38 +01:00
|
|
|
NSString *objectId, *method, *uri;
|
2006-10-12 18:42:59 +02:00
|
|
|
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];
|
2008-07-11 19:26:11 +02:00
|
|
|
if ([objectId length])
|
2007-03-18 16:20:38 +01:00
|
|
|
{
|
2008-08-25 21:13:18 +02:00
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
|
|
|
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
|
2009-07-14 19:15:03 +02:00
|
|
|
onObject: co
|
|
|
|
inContext: context])
|
2010-01-06 21:29:54 +01:00
|
|
|
method = [NSString stringWithFormat:@"%@/%@.ics/editAsAppointment",
|
2010-01-22 17:33:35 +01:00
|
|
|
[co soURL], objectId] ;
|
2008-08-25 21:13:18 +02:00
|
|
|
else
|
2010-01-06 21:32:24 +01:00
|
|
|
method = [NSString stringWithFormat: @"%@/Calendar/personal/%@.ics/editAsAppointment",
|
2010-01-06 21:29:54 +01:00
|
|
|
[self userFolderPath], objectId];
|
2007-03-18 16:20:38 +01:00
|
|
|
uri = [self completeHrefForMethod: method];
|
|
|
|
result = [self redirectToLocation: uri];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-10-12 18:42:59 +02:00
|
|
|
else
|
2007-03-18 16:20:38 +01:00
|
|
|
result = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
|
|
|
|
reason: @"could not create a unique ID"];
|
2006-10-12 18:42:59 +02:00
|
|
|
|
|
|
|
return result;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-12-23 19:39:36 +01:00
|
|
|
- (void) _adjustRecurrentRules
|
|
|
|
{
|
|
|
|
iCalRecurrenceRule *rule;
|
|
|
|
NSEnumerator *rules;
|
|
|
|
NSCalendarDate *untilDate;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
NSTimeZone *timeZone;
|
2008-12-23 19:39:36 +01:00
|
|
|
|
|
|
|
rules = [[event recurrenceRules] objectEnumerator];
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
timeZone = [ud timeZone];
|
|
|
|
|
2008-12-23 19:39:36 +01:00
|
|
|
while ((rule = [rules nextObject]))
|
|
|
|
{
|
|
|
|
untilDate = [rule untilDate];
|
|
|
|
if (untilDate)
|
|
|
|
{
|
|
|
|
// The until date must match the time of the start date
|
2009-01-07 19:32:24 +01:00
|
|
|
NSCalendarDate *date;
|
|
|
|
|
|
|
|
date = [[event startDate] copy];
|
2009-11-29 05:19:32 +01:00
|
|
|
[date setTimeZone: timeZone];
|
2009-01-07 19:32:24 +01:00
|
|
|
untilDate = [untilDate dateByAddingYears:0
|
|
|
|
months:0
|
|
|
|
days:0
|
|
|
|
hours:[date hourOfDay]
|
|
|
|
minutes:[date minuteOfHour]
|
|
|
|
seconds:0];
|
2008-12-23 19:39:36 +01:00
|
|
|
[rule setUntilDate: untilDate];
|
2009-01-07 19:40:25 +01:00
|
|
|
[date release];
|
2008-12-23 19:39:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (id <WOActionResults>) saveAction
|
2006-10-11 20:56:04 +02:00
|
|
|
{
|
2008-12-12 19:44:07 +01:00
|
|
|
SOGoAppointmentFolder *previousCalendar;
|
2008-08-10 23:44:25 +02:00
|
|
|
SOGoAppointmentObject *co;
|
|
|
|
SoSecurityManager *sm;
|
|
|
|
NSException *ex;
|
|
|
|
|
|
|
|
co = [self clientObject];
|
2008-12-12 19:44:07 +01:00
|
|
|
if ([co isKindOfClass: [SOGoAppointmentOccurence class]])
|
|
|
|
co = [co container];
|
|
|
|
previousCalendar = [co container];
|
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
2008-11-26 17:26:32 +01:00
|
|
|
|
2009-01-07 17:23:18 +01:00
|
|
|
if ([event hasRecurrenceRules])
|
|
|
|
[self _adjustRecurrentRules];
|
|
|
|
|
2008-12-12 19:44:07 +01:00
|
|
|
if ([co isNew])
|
2008-11-26 17:26:32 +01:00
|
|
|
{
|
2008-12-12 19:44:07 +01:00
|
|
|
if (componentCalendar && componentCalendar != previousCalendar)
|
2008-11-26 17:26:32 +01:00
|
|
|
{
|
2008-12-12 19:44:07 +01:00
|
|
|
// New event in a different calendar -- make sure the user can
|
|
|
|
// write to the selected calendar since the rights were verified
|
|
|
|
// on the calendar specified in the URL, not on the selected
|
|
|
|
// calendar of the popup menu.
|
|
|
|
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
onObject: componentCalendar
|
|
|
|
inContext: context])
|
|
|
|
co = [componentCalendar lookupName: [co nameInContainer]
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
2008-11-26 17:26:32 +01:00
|
|
|
}
|
2008-12-12 19:44:07 +01:00
|
|
|
|
|
|
|
// Save the event.
|
|
|
|
[co saveComponent: event];
|
2008-11-26 17:26:32 +01:00
|
|
|
}
|
2008-12-12 19:44:07 +01:00
|
|
|
else
|
2008-08-10 23:44:25 +02:00
|
|
|
{
|
2008-12-12 19:44:07 +01:00
|
|
|
// The event was modified -- save it.
|
|
|
|
[co saveComponent: event];
|
2008-08-10 23:44:25 +02:00
|
|
|
|
2008-12-12 19:44:07 +01:00
|
|
|
if (componentCalendar && componentCalendar != previousCalendar)
|
|
|
|
{
|
|
|
|
// The event was moved to a different calendar.
|
|
|
|
if (![sm validatePermission: SoPerm_DeleteObjects
|
|
|
|
onObject: previousCalendar
|
|
|
|
inContext: context])
|
|
|
|
{
|
|
|
|
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
onObject: componentCalendar
|
|
|
|
inContext: context])
|
|
|
|
ex = [co moveToFolder: componentCalendar];
|
|
|
|
}
|
|
|
|
}
|
2008-08-10 23:44:25 +02:00
|
|
|
}
|
2008-12-12 19:44:07 +01:00
|
|
|
|
2007-06-11 23:25:43 +02:00
|
|
|
return [self jsCloseWithRefreshMethod: @"refreshEventsAndDisplay()"];
|
2006-10-11 20:56:04 +02:00
|
|
|
}
|
|
|
|
|
2008-08-19 00:45:59 +02:00
|
|
|
- (id <WOActionResults>) viewAction
|
|
|
|
{
|
2008-08-19 16:48:30 +02:00
|
|
|
WOResponse *result;
|
2008-08-19 00:45:59 +02:00
|
|
|
NSDictionary *data;
|
2008-12-30 15:47:58 +01:00
|
|
|
NSCalendarDate *firstDate, *eventDate;
|
|
|
|
NSTimeZone *timeZone;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2008-12-30 15:47:58 +01:00
|
|
|
SOGoCalendarComponent *co;
|
|
|
|
iCalEvent *master;
|
2009-04-22 23:02:11 +02:00
|
|
|
BOOL resetAlarm;
|
2008-12-30 15:47:58 +01:00
|
|
|
signed int daylightOffset;
|
|
|
|
|
|
|
|
[self event];
|
2008-08-19 00:45:59 +02:00
|
|
|
|
2009-02-27 20:09:08 +01:00
|
|
|
result = [self responseWithStatus: 200];
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
timeZone = [ud timeZone];
|
2008-12-30 15:47:58 +01:00
|
|
|
eventDate = [event startDate];
|
|
|
|
[eventDate setTimeZone: timeZone];
|
|
|
|
co = [self clientObject];
|
|
|
|
|
2009-12-22 22:07:06 +01:00
|
|
|
if (!componentCalendar)
|
|
|
|
{
|
|
|
|
componentCalendar = [co container];
|
|
|
|
if ([componentCalendar isKindOfClass: [SOGoCalendarComponent class]])
|
|
|
|
componentCalendar = [componentCalendar container];
|
|
|
|
[componentCalendar retain];
|
|
|
|
}
|
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
resetAlarm = [[[context request] formValueForKey: @"resetAlarm"] boolValue];
|
|
|
|
if (resetAlarm && [event hasAlarms] && ![event hasRecurrenceRules])
|
|
|
|
{
|
|
|
|
iCalAlarm *anAlarm;
|
|
|
|
iCalTrigger *aTrigger;
|
|
|
|
|
|
|
|
anAlarm = [[event alarms] objectAtIndex: 0];
|
|
|
|
aTrigger = [anAlarm trigger];
|
|
|
|
[aTrigger setValue: 0 ofAttribute: @"x-webstatus" to: @"triggered"];
|
|
|
|
|
|
|
|
[co saveComponent: event];
|
|
|
|
}
|
|
|
|
|
2008-12-30 15:47:58 +01:00
|
|
|
if ([co isNew] && [co isKindOfClass: [SOGoAppointmentOccurence class]])
|
|
|
|
{
|
|
|
|
// This is a new exception in a recurrent event -- compute the daylight
|
|
|
|
// saving time with respect to the first occurrence of the recurrent event.
|
|
|
|
master = (iCalEvent*)[[event parent] firstChildWithTag: @"vevent"];
|
|
|
|
firstDate = [master startDate];
|
2008-08-19 16:48:30 +02:00
|
|
|
|
2008-12-30 15:47:58 +01:00
|
|
|
if ([timeZone isDaylightSavingTimeForDate: eventDate] != [timeZone isDaylightSavingTimeForDate: firstDate])
|
|
|
|
{
|
|
|
|
daylightOffset = (signed int)[timeZone secondsFromGMTForDate: firstDate]
|
|
|
|
- (signed int)[timeZone secondsFromGMTForDate: eventDate];
|
|
|
|
eventDate = [eventDate dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:daylightOffset];
|
|
|
|
}
|
|
|
|
}
|
2008-08-19 00:45:59 +02:00
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
2009-12-22 22:07:06 +01:00
|
|
|
[componentCalendar displayName], @"calendar",
|
2009-04-22 23:02:11 +02:00
|
|
|
[event tag], @"component",
|
2008-12-30 17:57:46 +01:00
|
|
|
[dateFormatter formattedDate: eventDate], @"startDate",
|
2008-12-30 15:47:58 +01:00
|
|
|
[dateFormatter formattedTime: eventDate], @"startTime",
|
2010-01-06 23:16:24 +01:00
|
|
|
([event hasRecurrenceRules] ? @"1": @"0"), @"isRecurring",
|
|
|
|
([event isAllDay] ? @"1": @"0"), @"isAllDay",
|
2008-08-19 00:45:59 +02:00
|
|
|
[event summary], @"summary",
|
|
|
|
[event location], @"location",
|
|
|
|
[event comment], @"description",
|
|
|
|
nil];
|
2008-12-23 19:39:36 +01:00
|
|
|
|
2008-08-19 16:48:30 +02:00
|
|
|
[result appendContentString: [data jsonRepresentation]];
|
2008-08-19 00:45:59 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
|
|
|
|
inContext: (WOContext*) context
|
2006-10-18 16:42:44 +02:00
|
|
|
{
|
2007-08-24 00:13:12 +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:12 +02:00
|
|
|
&& [actionName hasPrefix: @"save"]);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
- (void) takeValuesFromRequest: (WORequest *) _rq
|
|
|
|
inContext: (WOContext *) _ctx
|
2006-10-18 16:42:44 +02:00
|
|
|
{
|
2007-06-07 20:12:20 +02:00
|
|
|
int nbrDays;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2007-11-26 18:40:44 +01:00
|
|
|
[self event];
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
[super takeValuesFromRequest: _rq inContext: _ctx];
|
|
|
|
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2007-06-07 20:12:20 +02:00
|
|
|
if (isAllDay)
|
|
|
|
{
|
|
|
|
nbrDays = ((float) abs ([aptEndDate timeIntervalSinceDate: aptStartDate])
|
|
|
|
/ 86400) + 1;
|
|
|
|
[event setAllDayWithStartDate: aptStartDate
|
|
|
|
duration: nbrDays];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[event setStartDate: aptStartDate];
|
|
|
|
[event setEndDate: aptEndDate];
|
|
|
|
}
|
2009-10-15 20:43:28 +02:00
|
|
|
|
|
|
|
if ([[self clientObject] isNew])
|
|
|
|
{
|
|
|
|
iCalTimeZone *tz;
|
2009-11-29 05:19:32 +01:00
|
|
|
|
|
|
|
ud = [[context activeUser] userDefaults];
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
tz = [iCalTimeZone timeZoneForName: [ud timeZoneName]];
|
2009-10-15 20:43:28 +02:00
|
|
|
[[event parent] addTimeZone: tz];
|
2009-10-26 14:39:28 +01:00
|
|
|
[(iCalDateTime *)[event uniqueChildWithTag: @"dtstart"] setTimeZone: tz];
|
|
|
|
[(iCalDateTime *)[event uniqueChildWithTag: @"dtend"] setTimeZone: tz];
|
2009-10-15 20:43:28 +02:00
|
|
|
}
|
2008-11-06 18:19:14 +01:00
|
|
|
|
2008-12-01 23:46:31 +01:00
|
|
|
[event setTransparency: (isTransparent? @"TRANSPARENT" : @"OPAQUE")];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-18 20:19:44 +01:00
|
|
|
// TODO: add tentatively
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (id) acceptAction
|
2007-03-18 20:19:44 +01:00
|
|
|
{
|
2009-08-27 18:20:41 +02:00
|
|
|
[[self clientObject] changeParticipationStatus: @"ACCEPTED"
|
|
|
|
withDelegate: nil];
|
2007-03-18 20:19:44 +01:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-03-21 15:29:31 +01:00
|
|
|
- (id) declineAction
|
|
|
|
{
|
2009-08-27 18:20:41 +02:00
|
|
|
[[self clientObject] changeParticipationStatus: @"DECLINED"
|
|
|
|
withDelegate: nil];
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
return self;
|
2007-03-21 15:29:31 +01:00
|
|
|
}
|
|
|
|
|
2009-09-10 20:31:20 +02:00
|
|
|
- (id) delegateAction
|
|
|
|
{
|
|
|
|
// BOOL receiveUpdates;
|
|
|
|
NSString *delegatedEmail, *delegatedUid;
|
|
|
|
iCalPerson *delegatedAttendee;
|
|
|
|
SOGoUser *user;
|
|
|
|
WORequest *request;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = nil;
|
|
|
|
request = [context request];
|
|
|
|
delegatedEmail = [request formValueForKey: @"to"];
|
|
|
|
if ([delegatedEmail length])
|
|
|
|
{
|
|
|
|
user = [context activeUser];
|
|
|
|
delegatedAttendee = [iCalPerson new];
|
2009-10-13 23:40:18 +02:00
|
|
|
[delegatedAttendee autorelease];
|
2009-09-10 20:31:20 +02:00
|
|
|
[delegatedAttendee setEmail: delegatedEmail];
|
|
|
|
delegatedUid = [delegatedAttendee uid];
|
|
|
|
if (delegatedUid)
|
|
|
|
{
|
|
|
|
SOGoUser *delegatedUser;
|
|
|
|
delegatedUser = [SOGoUser userWithLogin: delegatedUid];
|
|
|
|
[delegatedAttendee setCn: [delegatedUser cn]];
|
|
|
|
}
|
|
|
|
|
|
|
|
[delegatedAttendee setRole: @"REQ-PARTICIPANT"];
|
|
|
|
[delegatedAttendee setRsvp: @"TRUE"];
|
|
|
|
[delegatedAttendee setParticipationStatus: iCalPersonPartStatNeedsAction];
|
|
|
|
[delegatedAttendee setDelegatedFrom:
|
|
|
|
[NSString stringWithFormat: @"mailto:%@", [[user allEmails] objectAtIndex: 0]]];
|
|
|
|
|
|
|
|
// receiveUpdates = [[request formValueForKey: @"receiveUpdates"] boolValue];
|
|
|
|
// if (receiveUpdates)
|
|
|
|
// [delegatedAttendee setRole: @"NON-PARTICIPANT"];
|
|
|
|
|
|
|
|
response = (WOResponse*)[[self clientObject] changeParticipationStatus: @"DELEGATED"
|
|
|
|
withDelegate: delegatedAttendee];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"missing 'to' parameter"];
|
|
|
|
|
|
|
|
if (!response)
|
|
|
|
response = [self responseWithStatus: 200];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-03-18 16:20:38 +01:00
|
|
|
@end
|