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;
254 newStartDate = [self selectedDate];
255 if ([[self queryParameterForKey: @"hm"] length] == 0)
257 now = [NSCalendarDate calendarDate];
258 [now setTimeZone: [[self clientObject] userTimeZone]];
259 if ([now isDateOnSameDay: newStartDate])
261 hour = [now hourOfDay];
263 newStartDate = [now hour: 8 minute: 0];
265 newStartDate = [[now tomorrow] hour: 8 minute: 0];
270 newStartDate = [newStartDate hour: 8 minute: 0];
276 - (id <WOActionResults>) defaultAction
278 NSCalendarDate *startDate, *endDate;
280 unsigned int minutes;
282 event = (iCalEvent *) [[self clientObject] component: NO];
285 startDate = [event startDate];
286 endDate = [event endDate];
290 startDate = [self newStartDate];
291 duration = [self queryParameterForKey:@"dur"];
292 if ([duration length] > 0)
293 minutes = [duration intValue];
297 = [startDate dateByAddingYears: 0 months: 0 days: 0
298 hours: 0 minutes: minutes seconds: 0];
301 ASSIGN (aptStartDate, startDate);
302 ASSIGN (aptEndDate, endDate);
304 /* here comes the code for initializing repeat, reminder and isAllDay... */
309 - (id <WOActionResults>) newAction
311 NSString *objectId, *method, *uri;
312 id <WOActionResults> result;
315 clientKlazz = [[self clientObject] class];
316 objectId = [clientKlazz globallyUniqueObjectId];
317 if ([objectId length] > 0)
319 method = [NSString stringWithFormat:@"%@/Calendar/%@/editAsAppointment",
320 [self userFolderPath], objectId];
321 uri = [self completeHrefForMethod: method];
322 result = [self redirectToLocation: uri];
325 result = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
326 reason: @"could not create a unique ID"];
331 - (id <WOActionResults>) saveAction
333 SOGoAppointmentObject *clientObject;
334 NSString *iCalString;
336 clientObject = [self clientObject];
337 iCalString = [[clientObject calendar: NO] versitString];
338 [clientObject saveContentString: iCalString];
340 return [self jsCloseWithRefreshMethod: @"refreshAppointmentsAndDisplay()"];
343 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
344 inContext: (WOContext*) context
346 return ([[self clientObject] isKindOfClass: [SOGoAppointmentObject class]]
347 && [[request method] isEqualToString: @"POST"]);
350 - (void) takeValuesFromRequest: (WORequest *) _rq
351 inContext: (WOContext *) _ctx
353 SOGoAppointmentObject *clientObject;
355 clientObject = [self clientObject];
356 event = (iCalEvent *) [clientObject component: YES];
358 [super takeValuesFromRequest: _rq inContext: _ctx];
360 [event setStartDate: aptStartDate];
361 [event setEndDate: aptEndDate];
362 if ([clientObject isNew])
363 [event setTransparency: @"OPAQUE"];
366 // TODO: add tentatively
368 - (id) acceptOrDeclineAction: (BOOL) _accept
370 [[self clientObject] changeParticipationStatus:
371 _accept ? @"ACCEPTED" : @"DECLINED"
372 inContext: [self context]];
379 return [self acceptOrDeclineAction:YES];
384 return [self acceptOrDeclineAction:NO];