]> err.no Git - scalable-opengroupware.org/blobdiff - ZideStore/UI-X/Scheduler/UIxAppointmentEditor.m
see changelog
[scalable-opengroupware.org] / ZideStore / UI-X / Scheduler / UIxAppointmentEditor.m
index 6239cb0cf9bebc560d33e1a37f6b46395735f083..5d1ef100362e9ae94f6ceac133f4ac17f100318d 100644 (file)
@@ -63,6 +63,7 @@
 
 - (SOGoAppointment *)appointment;
 - (NSString *)iCalStringTemplate;
+- (NSString *)iCalString;
 - (BOOL)isNewAppointment;
 
 @end
     return ! [[self clientObject] isAppointment];
 }
 
+- (NSString *)iCalString {
+    if([self isNewAppointment]) {
+        return [self iCalStringTemplate];
+    }
+    else {
+        return [[self clientObject] valueForKey:@"iCalString"];
+    }
+}
+
+- (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;
+}
+
+
 /* backend */
 
 
 - (SOGoAppointment *)appointment {
     if(self->appointment == nil) {
-        NSString *iCalString;
-
-        if([[self clientObject] isAppointment]) {
-            iCalString = [[self clientObject] valueForKey:@"iCalString"];
-        }
-        else {
-            iCalString = [self iCalStringTemplate];
-        }
         self->appointment = [[SOGoAppointment alloc]
-                                              initWithICalString:iCalString];
+          initWithICalString:[self iCalString]];
     }
     return self->appointment;
 }
     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 */
 
 
 
 - (id)saveAction {
-    NSString *foo, *nextMethod, *uri, *uriFormat;
-    NSMutableArray *attendees;
+    SOGoAppointment *apt;
+    NSString *iCalString, *summary, *location, *nextMethod, *uri, *uriFormat;
+    NSCalendarDate *sd, *ed;
+    NSArray *ps;
+    unsigned i, count;
     WOResponse *r;
     WORequest *req;
 
     req = [[self context] request];
-    foo = [req formValueForKey:@"ical"];
 
-    if([self isNewAppointment])
+    /* get iCalString from hidden input */
+    iCalString = [req formValueForKey:@"ical"];
+    apt = [[SOGoAppointment alloc] initWithICalString:iCalString];
+
+    /* merge in form values */
+    sd = [NSCalendarDate dateWithString:[req formValueForKey:@"startDate"]
+                         calendarFormat:@"%Y-%m-%d %H:%M"];
+    [apt setStartDate:sd];
+    ed = [NSCalendarDate dateWithString:[req formValueForKey:@"endDate"]
+                         calendarFormat:@"%Y-%m-%d %H:%M"];
+    [apt setEndDate:ed];
+    summary = [req formValueForKey:@"summary"];
+    [apt setSummary:title];
+    location = [req formValueForKey:@"location"];
+    [apt setLocation:location];
+
+    [apt removeAllAttendees]; /* clean up */
+    ps = [[req formValueForKey:@"participants"]
+        componentsSeparatedByString:@"\n"];
+    count = [ps count];
+    for(i = 0; i < count; i++) {
+        NSString *email;
+        
+        email = [ps objectAtIndex:i];
+        if([email length] > 0) {
+            iCalPerson *p;
+            NSRange cnr;
+
+            p = [[iCalPerson alloc] init];
+            [p setEmail:[NSString stringWithFormat:@"mailto:%@", email]];
+            /* construct a fake CN */
+            cnr = [email rangeOfString:@"@"];
+            if(cnr.location != NSNotFound) {
+                [p setCn:[email substringToIndex:cnr.location]];
+            }
+            [apt addToAttendees:p];
+            [p release];
+        }
+    }
+
+    /* receive current representation for save operation */
+    iCalString = [apt iCalString];
+    [apt release];
+    
+
+    /* determine what's to do and where to go next */
+    if([self isNewAppointment]) {
         nextMethod = @"duhduh";
-    else
+    }
+    else {
         nextMethod = @"view";
+    }
+
+    NSLog(@"%s new iCalString:\n%@", __PRETTY_FUNCTION__, iCalString);
 
     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 */];