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.
23 #import <NGObjWeb/SoObject.h>
24 #import <NGObjWeb/WORequest.h>
25 #import <NGObjWeb/NSException+HTTP.h>
26 #import <NGExtensions/NSCalendarDate+misc.h>
28 #import <NGCards/iCalEvent.h>
29 #import <NGCards/iCalPerson.h>
31 #import <SoObjects/SOGo/AgenorUserManager.h>
32 #import <SoObjects/SOGo/SOGoUser.h>
33 #import <SoObjects/SOGo/SOGoContentObject.h>
34 #import <SoObjects/Appointments/SOGoAppointmentFolder.h>
35 #import <SoObjects/Appointments/SOGoAppointmentObject.h>
37 #import "UIxComponentEditor.h"
38 #import "UIxAppointmentEditor.h"
40 @implementation UIxAppointmentEditor
44 if ((self = [super init]))
61 - (NSString *) saveURL
63 return [NSString stringWithFormat: @"%@/saveAsAppointment",
64 [[self clientObject] baseURL]];
67 - (NSString *) _toolbarForCalObject
69 SOGoUser *currentUser;
70 SOGoAppointmentObject *clientObject;
71 NSString *filename, *email;
73 iCalPersonPartStat participationStatus;
75 clientObject = [self clientObject];
76 currentUser = [[self context] activeUser];
77 email = [currentUser email];
78 if ([clientObject isOrganizer: email
79 orOwner: [currentUser login]])
80 filename = @"SOGoAppointmentObject.toolbar";
83 if ([clientObject isParticipant: email])
85 person = [[clientObject component: NO] findParticipantWithEmail: email];
86 participationStatus = [person participationStatus];
87 if (participationStatus == iCalPersonPartStatAccepted)
88 filename = @"SOGoAppointmentObjectDecline.toolbar";
89 else if (participationStatus == iCalPersonPartStatDeclined)
90 filename = @"SOGoAppointmentObjectAccept.toolbar";
92 filename = @"SOGoAppointmentObjectAcceptOrDecline.toolbar";
95 filename = @"SOGoComponentClose.toolbar";
101 - (NSString *) toolbar
103 return ([self _toolbarForCalObject]);
106 /* icalendar values */
112 - (void) setIsAllDay: (BOOL) newIsAllDay
116 - (void) setAptStartDate: (NSCalendarDate *) newAptStartDate
118 ASSIGN (aptStartDate, newAptStartDate);
121 - (NSCalendarDate *) aptStartDate
126 - (void) setAptEndDate: (NSCalendarDate *) newAptEndDate
128 ASSIGN (aptEndDate, newAptEndDate);
131 - (NSCalendarDate *) aptEndDate
136 - (NSArray *) repeatList
138 static NSArray *repeatItems = nil;
142 repeatItems = [NSArray arrayWithObjects: @"DAILY",
151 [repeatItems retain];
157 - (NSString *) itemRepeatText
161 if ([item isEqualToString: @"-"])
164 text = [self labelForKey: [NSString stringWithFormat: @"repeat_%@", item]];
169 - (void) setItem: (NSString *) newItem
179 - (NSArray *) reminderList
181 static NSArray *reminderItems = nil;
185 reminderItems = [NSArray arrayWithObjects: @"5_MINUTES_BEFORE",
186 @"10_MINUTES_BEFORE",
187 @"15_MINUTES_BEFORE",
188 @"30_MINUTES_BEFORE",
189 @"45_MINUTES_BEFORE",
202 [reminderItems retain];
205 return reminderItems;
208 // - (void) setReminder: (NSString *) reminder
210 // ASSIGN(reminder, _reminder);
213 // - (NSString *) reminder
218 - (NSString *) itemReminderText
222 if ([item isEqualToString: @"-"])
225 text = [self labelForKey: [NSString stringWithFormat: @"reminder_%@", item]];
230 - (NSString *) repeat
235 - (void) setRepeat: (NSString *) newRepeat
239 - (NSString *) reminder
244 - (void) setReminder: (NSString *) newReminder
249 - (NSCalendarDate *) newStartDate
251 NSCalendarDate *newStartDate, *now;
252 NSTimeZone *timeZone;
255 newStartDate = [self selectedDate];
256 if ([[self queryParameterForKey: @"hm"] length] == 0)
258 now = [NSCalendarDate calendarDate];
259 timeZone = [[context activeUser] timeZone];
260 [now setTimeZone: timeZone];
261 if ([now isDateOnSameDay: newStartDate])
263 hour = [now hourOfDay];
265 newStartDate = [now hour: 8 minute: 0];
267 newStartDate = [[now tomorrow] hour: 8 minute: 0];
272 newStartDate = [newStartDate hour: 8 minute: 0];
278 - (id <WOActionResults>) defaultAction
280 NSCalendarDate *startDate, *endDate;
282 unsigned int minutes;
284 event = (iCalEvent *) [[self clientObject] component: NO];
287 startDate = [event startDate];
288 endDate = [event endDate];
292 startDate = [self newStartDate];
293 duration = [self queryParameterForKey:@"dur"];
294 if ([duration length] > 0)
295 minutes = [duration intValue];
299 = [startDate dateByAddingYears: 0 months: 0 days: 0
300 hours: 0 minutes: minutes seconds: 0];
303 ASSIGN (aptStartDate, startDate);
304 ASSIGN (aptEndDate, endDate);
306 /* here comes the code for initializing repeat, reminder and isAllDay... */
311 - (id <WOActionResults>) newAction
313 NSString *objectId, *method, *uri;
314 id <WOActionResults> result;
317 clientKlazz = [[self clientObject] class];
318 objectId = [clientKlazz globallyUniqueObjectId];
319 if ([objectId length] > 0)
321 method = [NSString stringWithFormat:@"%@/Calendar/%@/editAsAppointment",
322 [self userFolderPath], objectId];
323 uri = [self completeHrefForMethod: method];
324 result = [self redirectToLocation: uri];
327 result = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
328 reason: @"could not create a unique ID"];
333 - (id <WOActionResults>) saveAction
335 SOGoAppointmentObject *clientObject;
336 NSString *iCalString;
338 clientObject = [self clientObject];
339 iCalString = [[clientObject calendar: NO] versitString];
340 [clientObject saveContentString: iCalString];
342 return [self jsCloseWithRefreshMethod: @"refreshAppointmentsAndDisplay()"];
345 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
346 inContext: (WOContext*) context
348 return ([[self clientObject] isKindOfClass: [SOGoAppointmentObject class]]
349 && [[request method] isEqualToString: @"POST"]);
352 - (void) takeValuesFromRequest: (WORequest *) _rq
353 inContext: (WOContext *) _ctx
355 SOGoAppointmentObject *clientObject;
357 clientObject = [self clientObject];
358 event = (iCalEvent *) [clientObject component: YES];
360 [super takeValuesFromRequest: _rq inContext: _ctx];
362 [event setStartDate: aptStartDate];
363 [event setEndDate: aptEndDate];
364 if ([clientObject isNew])
365 [event setTransparency: @"OPAQUE"];
368 // TODO: add tentatively
370 - (id) acceptOrDeclineAction: (BOOL) accept
372 [[self clientObject] changeParticipationStatus: (accept
381 return [self acceptOrDeclineAction: YES];
386 return [self acceptOrDeclineAction: NO];