1 /* UIxAppointmentEditor.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #import <NGObjWeb/SoObject.h>
26 #import <NGObjWeb/WORequest.h>
27 #import <NGObjWeb/WOResponse.h>
28 #import <NGObjWeb/NSException+HTTP.h>
29 #import <NGExtensions/NSCalendarDate+misc.h>
31 #import <NGCards/iCalCalendar.h>
32 #import <NGCards/iCalEvent.h>
33 #import <NGCards/iCalPerson.h>
34 #import <NGCards/iCalRecurrenceRule.h>
36 #import <SoObjects/SOGo/SOGoUser.h>
37 #import <SoObjects/SOGo/SOGoContentObject.h>
38 #import <SoObjects/Appointments/SOGoAppointmentFolder.h>
39 #import <SoObjects/Appointments/SOGoAppointmentObject.h>
41 #import "UIxComponentEditor.h"
42 #import "UIxAppointmentEditor.h"
44 @implementation UIxAppointmentEditor
48 if ((self = [super init]))
63 [aptStartDate release];
73 event = (iCalEvent *) [[self clientObject] component: YES secure: YES];
80 - (NSString *) saveURL
82 return [NSString stringWithFormat: @"%@/saveAsAppointment",
83 [[self clientObject] baseURL]];
86 /* icalendar values */
91 hm = [self queryParameterForKey: @"hm"];
94 || (hm && [hm isEqualToString: @"allday"]));
97 - (void) setIsAllDay: (BOOL) newIsAllDay
99 isAllDay = newIsAllDay;
102 - (void) setAptStartDate: (NSCalendarDate *) newAptStartDate
104 ASSIGN (aptStartDate, newAptStartDate);
107 - (NSCalendarDate *) aptStartDate
112 - (void) setAptEndDate: (NSCalendarDate *) newAptEndDate
114 ASSIGN (aptEndDate, newAptEndDate);
117 - (NSCalendarDate *) aptEndDate
122 - (void) setItem: (NSString *) newItem
124 ASSIGN (item, newItem);
133 - (NSCalendarDate *) newStartDate
135 NSCalendarDate *newStartDate, *now;
136 NSTimeZone *timeZone;
139 newStartDate = [self selectedDate];
140 if ([[self queryParameterForKey: @"hm"] length] == 0)
142 now = [NSCalendarDate calendarDate];
143 timeZone = [[context activeUser] timeZone];
144 [now setTimeZone: timeZone];
145 if ([now isDateOnSameDay: newStartDate])
147 hour = [now hourOfDay];
149 newStartDate = [now hour: 8 minute: 0];
151 newStartDate = [[now tomorrow] hour: 8 minute: 0];
156 newStartDate = [newStartDate hour: 8 minute: 0];
162 - (id <WOActionResults>) defaultAction
164 NSCalendarDate *startDate, *endDate;
166 unsigned int minutes;
169 if ([[self clientObject] isNew])
171 startDate = [self newStartDate];
172 duration = [self queryParameterForKey:@"dur"];
173 if ([duration length] > 0)
174 minutes = [duration intValue];
178 = [startDate dateByAddingYears: 0 months: 0 days: 0
179 hours: 0 minutes: minutes seconds: 0];
183 startDate = [event startDate];
184 isAllDay = [event isAllDay];
186 endDate = [[event endDate] dateByAddingYears: 0 months: 0 days: -1];
188 endDate = [event endDate];
191 ASSIGN (aptStartDate, startDate);
192 ASSIGN (aptEndDate, endDate);
197 - (id <WOActionResults>) newAction
199 NSString *objectId, *method, *uri;
200 id <WOActionResults> result;
201 SOGoAppointmentFolder *co;
203 co = [self clientObject];
204 objectId = [co globallyUniqueObjectId];
205 if ([objectId length] > 0)
207 method = [NSString stringWithFormat:@"%@/%@.ics/editAsAppointment",
208 [co soURL], objectId];
209 uri = [self completeHrefForMethod: method];
210 result = [self redirectToLocation: uri];
213 result = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
214 reason: @"could not create a unique ID"];
219 - (id <WOActionResults>) saveAction
221 [[self clientObject] saveComponent: event];
223 return [self jsCloseWithRefreshMethod: @"refreshEventsAndDisplay()"];
226 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
227 inContext: (WOContext*) context
229 NSString *actionName;
231 actionName = [[request requestHandlerPath] lastPathComponent];
233 return ([[self clientObject] isKindOfClass: [SOGoAppointmentObject class]]
234 && [actionName hasPrefix: @"save"]);
237 - (void) takeValuesFromRequest: (WORequest *) _rq
238 inContext: (WOContext *) _ctx
240 SOGoAppointmentObject *clientObject;
243 clientObject = [self clientObject];
246 [super takeValuesFromRequest: _rq inContext: _ctx];
250 nbrDays = ((float) abs ([aptEndDate timeIntervalSinceDate: aptStartDate])
252 [event setAllDayWithStartDate: aptStartDate
257 [event setStartDate: aptStartDate];
258 [event setEndDate: aptEndDate];
260 if ([clientObject isNew])
261 [event setTransparency: @"OPAQUE"];
264 // TODO: add tentatively
268 [[self clientObject] changeParticipationStatus: @"ACCEPTED"];
275 [[self clientObject] changeParticipationStatus: @"DECLINED"];