#include <NGObjWeb/SoComponent.h>
+@class NSCalendarDate;
+
@interface UIxComponent : SoComponent
{
- (NSString *)ownMethodName;
+/* date selection */
+- (NSCalendarDate *)selectedDate;
+- (NSString *)dateStringForDate:(NSCalendarDate *)_date;
+- (NSCalendarDate *)dateForDateString:(NSString *)_dateString;
+
@end
#endif /* __UIxComponent_H_ */
return [uri substringFromIndex:(r.location + 1)];
}
+/* date */
+
+- (NSCalendarDate *)selectedDate {
+ NSString *s;
+
+ s = [self queryParameterForKey:@"day"];
+ if(s) {
+ return [self dateForDateString:s];
+ }
+ return [NSCalendarDate date];
+}
+
+- (NSString *)dateStringForDate:(NSCalendarDate *)_date {
+ return [_date descriptionWithCalendarFormat:@"%Y%m%d"];
+}
+
+- (NSCalendarDate *)dateForDateString:(NSString *)_dateString {
+ return [NSCalendarDate dateWithString:_dateString calendarFormat:@"%Y%m%d"];
+}
+
@end
</tr>
<tr>
<td valign="middle">
- <a href="/OpenGroupware/wo/5A715A710740C43D13/12440c4518c09603e3c.0.15.1.17.3.1.1.3.3.1.8.14" class="skydockfont">Logout</a>
+ <a href="/OpenGroupware/x/dock" class="skydockfont">Logout</a>
</td>
</tr>
</table>
#include "common.h"
#include <Common/UIxComponent.h>
#include <SOGoLogic/SOGoAppointment.h>
+#include <NGiCal/NGiCal.h>
+/* TODO: CLEAN THIS MESS UP */
+
+
+@interface NSObject (AppointmentHack)
+- (BOOL)isAppointment;
+@end
+
+@implementation NSObject (AppointmentHack)
+- (BOOL)isAppointment {
+ return NO;
+}
+@end
+
+@interface SxAppointment : NSObject
+@end
+
+@implementation SxAppointment (AppointmentHack)
+- (BOOL)isAppointment {
+ return YES;
+}
+@end
+
+@interface iCalPerson (Convenience)
+- (NSString *)rfc822Email;
+@end
+
+@implementation iCalPerson (Convenience)
+- (NSString *)rfc822Email {
+ NSString *_email = [self email];
+ NSRange colon = [_email rangeOfString:@":"];
+ if(colon.location != NSNotFound) {
+ return [_email substringFromIndex:colon.location + 1];
+ }
+ return _email;
+}
+@end
+
@interface UIxAppointmentEditor : UIxComponent
{
id appointment;
+ id participants;
}
- (SOGoAppointment *)appointment;
+- (NSString *)iCalStringTemplate;
+- (BOOL)isNewAppointment;
@end
- (void)dealloc {
[self->appointment release];
+ [self->participants release];
[super dealloc];
}
return [date descriptionWithCalendarFormat:@"%A, %Y-%m-%d %H:%M %Z"];
}
+- (BOOL)isNewAppointment {
+ return ! [[self clientObject] isAppointment];
+}
/* backend */
- (SOGoAppointment *)appointment {
if(self->appointment == nil) {
NSString *iCalString;
-
- iCalString = [[self clientObject] valueForKey:@"iCalString"];
- self->appointment = [[SOGoAppointment alloc] initWithICalString:iCalString];
+
+ if([[self clientObject] isAppointment]) {
+ iCalString = [[self clientObject] valueForKey:@"iCalString"];
+ }
+ else {
+ iCalString = [self iCalStringTemplate];
+ }
+ self->appointment = [[SOGoAppointment alloc]
+ initWithICalString:iCalString];
}
return self->appointment;
}
+- (id)participants {
+ if(self->participants == nil) {
+ NSArray *attendees;
+ NSMutableArray *emailAddresses;
+ unsigned i, count;
+
+ attendees = [self->appointment attendees];
+ count = [attendees count];
+ emailAddresses = [[NSMutableArray alloc] initWithCapacity:count];
+ for(i = 0; i < count; i++) {
+ NSString *email;
+
+ email = [[attendees objectAtIndex:i] rfc822Email];
+ if(email)
+ [emailAddresses addObject:email];
+ }
+ self->participants = [[emailAddresses componentsJoinedByString:@"\n"]
+ retain];
+ [emailAddresses release];
+ }
+ return self->participants;
+}
+
+- (NSString *)iCalStringTemplate {
+ static NSString *iCalStringTemplate = \
+ @"BEGIN:VCALENDAR\nMETHOD:REQUEST\nPRODID:OpenGroupware.org ZideStore 1.2\n" \
+ @"VERSION:2.0\nBEGIN:VEVENT\nCLASS:PRIVATE\nSTATUS:CONFIRMED\n" \
+ @"DTSTART:%@\nDTEND:%@\n" \
+ @"TRANSP:OPAQUE\n" \
+ @"END:VEVENT\nEND:VCALENDAR";
+ NSCalendarDate *startDate, *endDate;
+ NSString *template;
+
+ startDate = [self selectedDate];
+ endDate = [startDate dateByAddingYears:0 months:0 days:0
+ hours:1 minutes:0 seconds:0];
+
+
+ template = [NSString stringWithFormat:iCalStringTemplate,
+ [startDate icalString],
+ [endDate icalString]];
+
+ return template;
+}
+
+
+/* helper */
+
+- (NSString *)uriAsFormat {
+ NSString *uri, *qp;
+ NSRange r;
+
+ uri = [[[self context] request] uri];
+
+ /* first: identify query parameters */
+ r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
+ if (r.length > 0) {
+ uri = [uri substringToIndex:r.location];
+ qp = [uri substringFromIndex:r.location];
+ }
+ else {
+ qp = nil;
+ }
+
+ /* next: strip trailing slash */
+ if([uri hasSuffix:@"/"])
+ uri = [uri substringToIndex:([uri length] - 1)];
+ r = [uri rangeOfString:@"/" options:NSBackwardsSearch];
+
+ /* then: cut of last path component */
+ if(r.location == NSNotFound) { // no slash? are we at root?
+ uri = @"/";
+ }
+ else {
+ uri = [uri substringToIndex:(r.location + 1)];
+ }
+ /* next: append format token */
+ uri = [uri stringByAppendingString:@"%@"];
+ if(qp != nil)
+ uri = [uri stringByAppendingString:qp];
+ return uri;
+}
+
+
+/* save */
+
+
+- (id)saveAction {
+ NSString *foo, *nextMethod, *uri, *uriFormat;
+ NSMutableArray *attendees;
+ WOResponse *r;
+ WORequest *req;
+
+ req = [[self context] request];
+ foo = [req formValueForKey:@"ical"];
+
+ if([self isNewAppointment])
+ nextMethod = @"duhduh";
+ else
+ nextMethod = @"view";
+
+ uriFormat = [self uriAsFormat];
+ uri = [NSString stringWithFormat:uriFormat, nextMethod];
+ NSLog(@"%s got foo:%@, redirecting to '%@'",
+ __PRETTY_FUNCTION__,
+ foo,
+ uri);
+
+ r = [WOResponse responseWithRequest:req];
+ [r setStatus:302 /* moved */];
+ [r setHeader:uri forKey:@"location"];
+ return r;
+}
+
@end
title="name"
>
+ <form href="save">
<table cellspacing="0" cellpadding="5" width="100%">
<tr>
<td>
</td>
<td align="left" bgcolor="#FFFFF0">
<span class="aptview_text">
- start time
+ <input type="text" name="startDate" var:value="appointment.startDate" const:dateformat="%Y-%m-%d %H:%M" const:size="40" />
+ </span>
+ </td>
+ </tr>
+ <tr valign="top">
+ <td align="right" width="15%">
+ <span class="aptview_text">End time:</span>
+ </td>
+ <td align="left" bgcolor="#FFFFF0">
+ <span class="aptview_text">
+ <input type="text" name="endDate" var:value="appointment.endDate" const:dateformat="%Y-%m-%d %H:%M" const:size="40" />
+ </span>
+ </td>
+ </tr>
+ <tr valign="top">
+ <td align="right" width="15%">
+ <span class="aptview_text">Title:</span>
+ </td>
+ <td align="left" bgcolor="#FFFFF0">
+ <span class="aptview_text">
+ <input type="text" name="summary" var:value="appointment.summary" const:size="40" />
+ </span>
+ </td>
+ </tr>
+ <tr valign="top">
+ <td align="right" width="15%">
+ <span class="aptview_text">Location:</span>
+ </td>
+ <td align="left" bgcolor="#FFFFF0">
+ <span class="aptview_text">
+ <input type="text" name="location" var:value="appointment.location" const:size="40"/>
</span>
</td>
</tr>
</tr>
<tr valign="top">
<td align="right" width="15%">
- <span class="aptview_text">Start time:</span>
+ <span class="aptview_text">Participants:</span>
</td>
<td align="left" bgcolor="#FFFFF0">
<span class="aptview_text">
- textarea
+ <textarea name="participants" var:value="participants" cols="40" rows="5" />
</span>
</td>
</tr>
</tr>
<tr>
- <td valign="top" width="100%">
- <table width="100%" border="0" cellpadding="4" cellspacing="0">
- <tr valign="top">
- <td align="right" width="15%" bgcolor="#E8E8E0">
- <span class="aptview_text">Title:</span>
- </td>
- <td align="left" bgcolor="#FFFFF0">
- <span class="aptview_text">
- <var:string value="appointment.summary" />
- </span>
- </td>
- </tr>
- <tr valign="top">
- <td align="right" width="15%" bgcolor="#E8E8E0">
- <span class="aptview_text">Location:</span>
- </td>
- <td align="left" bgcolor="#FFFFF0">
- <span class="aptview_text">
- <var:string value="appointment.location" />
- </span>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td valign="top" width="100%">
+ <td>
+ <input type="submit" value="Save" />
+ <input type="hidden" name="ical" var:value="appointment.iCalString" />
</td>
</tr>
</table>
+ </form>
<!-- -->
<hr />
clientObject: <var:string value="clientObject" />
forKey:@"tab"];
}
+- (NSString *)debugTabLink {
+ return [self completeHrefForMethod:[self ownMethodName]
+ withParameter:@"debug"
+ forKey:@"tab"];
+}
+
- (NSString *)completeHrefForMethod:(NSString *)_method
withParameter:(NSString *)_param
forKey:(NSString *)_key
</var:foreach>
</table>
</uix:tab>
+ <uix:tab const:key="debug"
+ const:label="DEBUG"
+ var:href="debugTabLink">
+ OGo ZideStore Server - <var:string value="name"/>
+ <br />
+ Client: <var:string value="clientObject"/>
+ <br />
+ Group: <var:string value="clientObject.group"/><br />
+ Deletable: <var:string value="clientObject.isDeletionAllowed"/><br />
+ Generation: <var:string value="clientObject.zlGenerationCount"/><br />
+ MsgClass: <var:string value="clientObject.outlookMessageClass"/><br />
+
+ <hr />
+ As iCal:<br />
+ <pre><var:string value="clientObject.iCalString"/></pre>
+
+ <hr />
+ As Mail:<br />
+ <pre><var:string value="clientObject.iCalMailString"/></pre>
+
+ </uix:tab>
</uix:tabview>
</td>
</tr>
</table>
-
-<!-- DEBUGGING
- <a href="../weekoverview" >week</a>
- <a href="../monthoverview">month</a>
- <br />
- <h4>Appointment Viewer</h4>
- OGo ZideStore Server - <var:string value="name"/>
- <br />
- Client: <var:string value="clientObject"/>
- <br />
- Group: <var:string value="clientObject.group"/><br />
- Deletable: <var:string value="clientObject.isDeletionAllowed"/><br />
- Generation: <var:string value="clientObject.zlGenerationCount"/><br />
- MsgClass: <var:string value="clientObject.outlookMessageClass"/><br />
-
- <hr />
-
- As iCal:<br />
- <pre><var:string value="clientObject.iCalString"/></pre>
-
- <hr />
-
- As Mail:<br />
- <pre><var:string value="clientObject.iCalMailString"/></pre>
-
- <hr />
-
- As SOGoApt:<br />
- <pre><var:string value="sogoApt"/></pre>
- <pre><var:string value="sogoApt.event"/></pre>
--->
</var:component>
/* fetching */
-- (NSCalendarDate *)selectedDate;
- (NSCalendarDate *)startDate;
- (NSCalendarDate *)endDate;
- (NSArray *)fetchGIDs;
- (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
inDictionary:(NSMutableDictionary *)_qp;
-- (NSString *)dateStringForDate:(NSCalendarDate *)_date;
-- (NSCalendarDate *)dateForDateString:(NSString *)_dateString;
-
@end
#endif /* __ZideStoreUI_UIxCalView_H__ */
queryString:nil];
}
-/* date */
-
-- (NSCalendarDate *)selectedDate {
- NSString *s;
-
- s = [self queryParameterForKey:@"day"];
- if(s) {
- return [self dateForDateString:s];
- }
- return [NSCalendarDate date];
-}
-
/* fetching */
- (NSCalendarDate *)startDate {
[_qp removeObjectForKey:@"day"];
}
-- (NSString *)dateStringForDate:(NSCalendarDate *)_date {
- return [_date descriptionWithCalendarFormat:@"%Y%m%d"];
-}
-
-- (NSCalendarDate *)dateForDateString:(NSString *)_dateString {
- return [NSCalendarDate dateWithString:_dateString calendarFormat:@"%Y%m%d"];
-}
-
@end /* UIxCalView */
protectedBy = "View";
pageName = "UIxAppointmentEditor";
};
+ "save" = {
+ protectedBy = "View";
+ pageName = "UIxAppointmentEditor";
+ actionName = "save";
+ };
};
};
};