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/NSException+HTTP.h>
28 #import <NGExtensions/NSCalendarDate+misc.h>
30 #import <NGCards/iCalEvent.h>
31 #import <NGCards/iCalPerson.h>
33 #import <SoObjects/SOGo/SOGoUser.h>
34 #import <SoObjects/SOGo/SOGoContentObject.h>
35 #import <SoObjects/Appointments/SOGoAppointmentFolder.h>
36 #import <SoObjects/Appointments/SOGoAppointmentObject.h>
38 #import "UIxComponentEditor.h"
39 #import "UIxAppointmentEditor.h"
41 @implementation UIxAppointmentEditor
45 if ((self = [super init]))
63 - (NSString *) saveURL
65 return [NSString stringWithFormat: @"%@/saveAsAppointment",
66 [[self clientObject] baseURL]];
69 /* icalendar values */
74 hm = [self queryParameterForKey: @"hm"];
77 || (hm && [hm isEqualToString: @"allday"]));
80 - (void) setIsAllDay: (BOOL) newIsAllDay
82 isAllDay = newIsAllDay;
85 - (void) setAptStartDate: (NSCalendarDate *) newAptStartDate
87 ASSIGN (aptStartDate, newAptStartDate);
90 - (NSCalendarDate *) aptStartDate
95 - (void) setAptEndDate: (NSCalendarDate *) newAptEndDate
97 ASSIGN (aptEndDate, newAptEndDate);
100 - (NSCalendarDate *) aptEndDate
105 - (NSArray *) repeatList
107 static NSArray *repeatItems = nil;
111 repeatItems = [NSArray arrayWithObjects: @"DAILY",
120 [repeatItems retain];
126 - (NSString *) itemRepeatText
130 if ([item isEqualToString: @"-"])
133 text = [self labelForKey: [NSString stringWithFormat: @"repeat_%@", item]];
138 - (void) setItem: (NSString *) newItem
148 - (NSArray *) reminderList
150 static NSArray *reminderItems = nil;
154 reminderItems = [NSArray arrayWithObjects: @"5_MINUTES_BEFORE",
155 @"10_MINUTES_BEFORE",
156 @"15_MINUTES_BEFORE",
157 @"30_MINUTES_BEFORE",
158 @"45_MINUTES_BEFORE",
171 [reminderItems retain];
174 return reminderItems;
177 // - (void) setReminder: (NSString *) reminder
179 // ASSIGN(reminder, _reminder);
182 // - (NSString *) reminder
187 - (NSString *) itemReminderText
191 if ([item isEqualToString: @"-"])
194 text = [self labelForKey: [NSString stringWithFormat: @"reminder_%@", item]];
199 - (NSString *) repeat
204 - (void) setRepeat: (NSString *) newRepeat
208 - (NSString *) reminder
213 - (void) setReminder: (NSString *) newReminder
218 - (NSCalendarDate *) newStartDate
220 NSCalendarDate *newStartDate, *now;
221 NSTimeZone *timeZone;
224 newStartDate = [self selectedDate];
225 if ([[self queryParameterForKey: @"hm"] length] == 0)
227 now = [NSCalendarDate calendarDate];
228 timeZone = [[context activeUser] timeZone];
229 [now setTimeZone: timeZone];
230 if ([now isDateOnSameDay: newStartDate])
232 hour = [now hourOfDay];
234 newStartDate = [now hour: 8 minute: 0];
236 newStartDate = [[now tomorrow] hour: 8 minute: 0];
241 newStartDate = [newStartDate hour: 8 minute: 0];
247 - (id <WOActionResults>) defaultAction
249 NSCalendarDate *startDate, *endDate;
251 unsigned int minutes;
253 event = (iCalEvent *) [[self clientObject] component: NO];
256 startDate = [event startDate];
257 isAllDay = [event isAllDay];
259 endDate = [[event endDate] dateByAddingYears: 0 months: 0 days: -1];
261 endDate = [event endDate];
265 startDate = [self newStartDate];
266 duration = [self queryParameterForKey:@"dur"];
267 if ([duration length] > 0)
268 minutes = [duration intValue];
272 = [startDate dateByAddingYears: 0 months: 0 days: 0
273 hours: 0 minutes: minutes seconds: 0];
276 ASSIGN (aptStartDate, startDate);
277 ASSIGN (aptEndDate, endDate);
280 /* here comes the code for initializing repeat, reminder and isAllDay... */
285 - (id <WOActionResults>) newAction
287 NSString *objectId, *method, *uri;
288 id <WOActionResults> result;
289 SOGoAppointmentFolder *co;
291 co = [self clientObject];
292 objectId = [co globallyUniqueObjectId];
293 if ([objectId length] > 0)
295 method = [NSString stringWithFormat:@"%@/%@/editAsAppointment",
296 [co soURL], objectId];
297 uri = [self completeHrefForMethod: method];
298 result = [self redirectToLocation: uri];
301 result = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
302 reason: @"could not create a unique ID"];
307 - (id <WOActionResults>) saveAction
309 SOGoAppointmentObject *clientObject;
310 NSString *iCalString;
312 clientObject = [self clientObject];
313 iCalString = [[clientObject calendar: NO] versitString];
314 [clientObject saveContentString: iCalString];
316 return [self jsCloseWithRefreshMethod: @"refreshEventsAndDisplay()"];
319 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
320 inContext: (WOContext*) context
322 NSString *actionName;
324 actionName = [[request requestHandlerPath] lastPathComponent];
326 return ([[self clientObject] isKindOfClass: [SOGoAppointmentObject class]]
327 && [actionName hasPrefix: @"save"]);
330 - (void) takeValuesFromRequest: (WORequest *) _rq
331 inContext: (WOContext *) _ctx
333 SOGoAppointmentObject *clientObject;
336 clientObject = [self clientObject];
337 event = (iCalEvent *) [clientObject component: YES];
339 [super takeValuesFromRequest: _rq inContext: _ctx];
343 nbrDays = ((float) abs ([aptEndDate timeIntervalSinceDate: aptStartDate])
345 [event setAllDayWithStartDate: aptStartDate
350 [event setStartDate: aptStartDate];
351 [event setEndDate: aptEndDate];
353 if ([clientObject isNew])
354 [event setTransparency: @"OPAQUE"];
357 // TODO: add tentatively
359 - (id) acceptOrDeclineAction: (BOOL) accept
361 [[self clientObject] changeParticipationStatus: (accept
370 return [self acceptOrDeclineAction: YES];
375 return [self acceptOrDeclineAction: NO];