From 35bf4a2d41d94fdeb6918a5d48afabce1ac4bac6 Mon Sep 17 00:00:00 2001 From: znek Date: Fri, 18 Jun 2004 10:16:51 +0000 Subject: [PATCH] Work in progress - pushed everything from query strings to query parameter dictionaries to allow highly flexible handling. git-svn-id: http://svn.opengroupware.org/SOGo/trunk@48 d1b88da0-ebda-0310-925b-ed51d893ca5b --- ZideStore/UI-X/Common/GNUmakefile | 6 + ZideStore/UI-X/Common/OGoComponent.h | 43 +++++++ ZideStore/UI-X/Common/OGoComponent.m | 111 ++++++++++++++++++ ZideStore/UI-X/Common/bundle-info.plist | 1 + .../UI-X/Scheduler/OGoCalBackForthNavView.m | 9 ++ .../UI-X/Scheduler/OGoCalBackForthNavView.wox | 6 +- ZideStore/UI-X/Scheduler/OGoCalMonthView.m | 19 +-- ZideStore/UI-X/Scheduler/OGoCalSelectTab.m | 54 ++++----- ZideStore/UI-X/Scheduler/OGoCalSelectTab.wox | 8 +- ZideStore/UI-X/Scheduler/OGoCalView.h | 10 +- ZideStore/UI-X/Scheduler/OGoCalView.m | 51 ++++++-- .../UI-X/Scheduler/OGoCalWeekOverview.wox | 10 +- ZideStore/UI-X/Scheduler/OGoCalWeekView.h | 9 +- ZideStore/UI-X/Scheduler/OGoCalWeekView.m | 51 +++----- 14 files changed, 276 insertions(+), 112 deletions(-) create mode 100644 ZideStore/UI-X/Common/OGoComponent.h create mode 100644 ZideStore/UI-X/Common/OGoComponent.m diff --git a/ZideStore/UI-X/Common/GNUmakefile b/ZideStore/UI-X/Common/GNUmakefile index 167a858a..ce11ad9a 100644 --- a/ZideStore/UI-X/Common/GNUmakefile +++ b/ZideStore/UI-X/Common/GNUmakefile @@ -10,6 +10,7 @@ CommonUI_PRINCIPAL_CLASS = CommonUIProduct CommonUI_OBJC_FILES = \ CommonUIProduct.m \ + OGoComponent.m \ OGoPageFrame.m \ OGoAppFrame.m \ OGoAppHeader.m \ @@ -21,6 +22,11 @@ CommonUI_OBJC_FILES = \ UIxTabView.m \ UIxTabItem.m \ + +CommonUI_HEADER_FILES = \ + OGoComponent.h \ + + CommonUI_RESOURCE_FILES += \ Version \ product.plist \ diff --git a/ZideStore/UI-X/Common/OGoComponent.h b/ZideStore/UI-X/Common/OGoComponent.h new file mode 100644 index 00000000..86795fdf --- /dev/null +++ b/ZideStore/UI-X/Common/OGoComponent.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2000-2004 SKYRIX Software AG + + This file is part of OGo + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + + +#ifndef __OGoComponent_H_ +#define __OGoComponent_H_ + +#include + + +@interface OGoComponent : SoComponent +{ + NSMutableDictionary *queryParameters; +} + +- (NSString *)queryParameterForKey:(NSString *)_key; +- (NSDictionary *)queryParameters; + +/* use this to set permanent query parameters */ +- (void)setQueryParameter:(NSString *)_param forKey:(NSString *)_key; + +@end + +#endif /* __OGoComponent_H_ */ diff --git a/ZideStore/UI-X/Common/OGoComponent.m b/ZideStore/UI-X/Common/OGoComponent.m new file mode 100644 index 00000000..e6b4e621 --- /dev/null +++ b/ZideStore/UI-X/Common/OGoComponent.m @@ -0,0 +1,111 @@ +/* + Copyright (C) 2000-2004 SKYRIX Software AG + + This file is part of OGo + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + + +#include "OGoComponent.h" +#include +#include +#include + + +@interface OGoComponent (PrivateAPI) +- (void)_parseQueryString:(NSString *)_s; +@end + + +@implementation OGoComponent + +- (id)init { + if ((self = [super init])) { + self->queryParameters = [[NSMutableDictionary alloc] init]; + } + return self; +} + +- (void)dealloc { + [self->queryParameters release]; + [super dealloc]; +} + + +- (void)awake { + WORequest *req; + NSString *uri; + NSRange r; + + [super awake]; + + req = [[self context] request]; + uri = [req uri]; + r = [uri rangeOfString:@"?"]; + if(r.length > 0) { + NSString *qs; + + qs = [uri substringFromIndex:(r.location + r.length)]; + [self->queryParameters removeAllObjects]; + [self _parseQueryString:qs]; + } +} + +- (void)_parseQueryString:(NSString *)_s { + NSEnumerator *e; + NSString *part; + + e = [[_s componentsSeparatedByString:@"&"] objectEnumerator]; + while ((part = [e nextObject])) { + NSRange r; + NSString *key, *value; + + r = [part rangeOfString:@"="]; + if (r.length == 0) { + /* missing value of query parameter */ + key = [part stringByUnescapingURL]; + value = @"1"; + } + else { + key = [[part substringToIndex:r.location] stringByUnescapingURL]; + value = [[part substringFromIndex:(r.location + r.length)] + stringByUnescapingURL]; + } + [self->queryParameters setObject:value forKey:key]; + } +} + +- (NSString *)queryParameterForKey:(NSString *)_key { + return [self->queryParameters objectForKey:_key]; +} + +- (void)setQueryParameter:(NSString *)_param forKey:(NSString *)_key { + if(_key == nil) + return; + + if(_param != nil) + [self->queryParameters setObject:_param forKey:_key]; + else + [self->queryParameters removeObjectForKey:_key]; +} + +- (NSDictionary *)queryParameters { + return self->queryParameters; +} + +@end diff --git a/ZideStore/UI-X/Common/bundle-info.plist b/ZideStore/UI-X/Common/bundle-info.plist index 13cf8e52..2ccc1b8c 100644 --- a/ZideStore/UI-X/Common/bundle-info.plist +++ b/ZideStore/UI-X/Common/bundle-info.plist @@ -13,6 +13,7 @@ classes = ( { name = CommonUIProduct; }, + { name = OGoComponent; }, { name = OGoPageFrame; }, { name = OGoWinClose; }, { name = OGoAppNavView; }, diff --git a/ZideStore/UI-X/Scheduler/OGoCalBackForthNavView.m b/ZideStore/UI-X/Scheduler/OGoCalBackForthNavView.m index 1b95fe14..56edc051 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalBackForthNavView.m +++ b/ZideStore/UI-X/Scheduler/OGoCalBackForthNavView.m @@ -23,6 +23,15 @@ #include +/* + Associations: + + methodName -> maps to href + prevQueryParameters -> queryDictionary + currentQueryParameters -> queryDictionary + nextQueryParameters -> queryDictionary + label -> user presentable name to display for "this" + */ @interface OGoCalBackForthNavView : WOComponent { diff --git a/ZideStore/UI-X/Scheduler/OGoCalBackForthNavView.wox b/ZideStore/UI-X/Scheduler/OGoCalBackForthNavView.wox index 01d672e8..7c86e8c2 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalBackForthNavView.wox +++ b/ZideStore/UI-X/Scheduler/OGoCalBackForthNavView.wox @@ -8,13 +8,13 @@ > - previous + previous - + - next + next \ No newline at end of file diff --git a/ZideStore/UI-X/Scheduler/OGoCalMonthView.m b/ZideStore/UI-X/Scheduler/OGoCalMonthView.m index eb6ba7e1..3530b839 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalMonthView.m +++ b/ZideStore/UI-X/Scheduler/OGoCalMonthView.m @@ -5,22 +5,15 @@ @implementation OGoCalMonthView -// TODO: look how to properly calculate month range! - - (NSCalendarDate *)startDate { - // TODO: copy of the startdate method - NSCalendarDate *startDate; - NSString *dateString; - - dateString = [[[self context] request] formValueForKey:@"startDate"]; - startDate = dateString - ? [self dateForDateString:dateString] - : [[NSCalendarDate date] mondayOfWeek]; - - return startDate; + return [[super startDate] firstDayOfMonth]; } + - (NSCalendarDate *)endDate { - return [[self startDate] dateByAddingYears:0 months:0 days:31 + NSCalendarDate *startDate; + + startDate = [self startDate]; + return [startDate dateByAddingYears:0 months:0 days:[startDate numberOfDaysInMonth] hours:0 minutes:0 seconds:0]; } diff --git a/ZideStore/UI-X/Scheduler/OGoCalSelectTab.m b/ZideStore/UI-X/Scheduler/OGoCalSelectTab.m index f06d3f3a..a2bcb9fc 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalSelectTab.m +++ b/ZideStore/UI-X/Scheduler/OGoCalSelectTab.m @@ -21,18 +21,18 @@ // $Id$ +#include #include #include -@interface OGoCalSelectTab : WOComponent +@interface OGoCalSelectTab : OGoComponent { NSString *selection; NSCalendarDate *currentDate; } -- (BOOL)isCurrentDateInSameWeek; -- (NSString *)completedLinkForOverview:(NSString *)_overview; +- (NSString *)completeHrefForMethod:(NSString *)_method; @end @@ -65,23 +65,8 @@ /* labels */ -- (BOOL)isCurrentDateInSameWeek { - return [self->currentDate isDateInSameWeek:[NSCalendarDate date]]; -} - - (NSString *)dayLabel { - NSCalendarDate *date; - - date = self->currentDate; - - if(! [[self selection] isEqualToString:@"day"]) { -#if 0 - if(! [self isCurrentDateInSameWeek]) -#endif - date = [date mondayOfWeek]; - } - - return [date descriptionWithCalendarFormat:@"%d"]; + return [self->currentDate descriptionWithCalendarFormat:@"%d"]; } - (NSString *)weekLabel { @@ -100,29 +85,32 @@ /* hrefs */ -- (NSString *)completedLinkForOverview:(NSString *)_overview { - NSString *dateString; +- (NSString *)completeHrefForMethod:(NSString *)_method { + NSDictionary *qp; + NSString *qs; + + qp = [self queryParameters]; + if([qp count] == 0) + return _method; - dateString = [[[self context] request] formValueForKey:@"startDate"]; - if(dateString) - return [_overview stringByAppendingFormat:@"?startDate=%@", dateString]; - return _overview; + qs = [[self context] queryStringFromDictionary:qp]; + return [_method stringByAppendingFormat:@"?%@", qs]; } -- (NSString *)dayoverviewLink { - return [self completedLinkForOverview:@"dayoverview"]; +- (NSString *)daytabLink { + return [self completeHrefForMethod:@"dayoverview"]; } -- (NSString *)weekoverviewLink { - return [self completedLinkForOverview:@"weekoverview"]; +- (NSString *)weektabLink { + return [self completeHrefForMethod:@"weekoverview"]; } -- (NSString *)monthoverviewLink { - return [self completedLinkForOverview:@"monthoverview"]; +- (NSString *)monthtabLink { + return [self completeHrefForMethod:@"monthoverview"]; } -- (NSString *)yearoverviewLink { - return [self completedLinkForOverview:@"yearoverview"]; +- (NSString *)yeartabLink { + return [self completeHrefForMethod:@"yearoverview"]; } diff --git a/ZideStore/UI-X/Scheduler/OGoCalSelectTab.wox b/ZideStore/UI-X/Scheduler/OGoCalSelectTab.wox index 532232e7..98ae502c 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalSelectTab.wox +++ b/ZideStore/UI-X/Scheduler/OGoCalSelectTab.wox @@ -10,16 +10,16 @@ const:selectedTabStyle="tab_selected" const:bodyStyle="tabview_body" > - + - + - + - + diff --git a/ZideStore/UI-X/Scheduler/OGoCalView.h b/ZideStore/UI-X/Scheduler/OGoCalView.h index 6468c7f7..37783a76 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalView.h +++ b/ZideStore/UI-X/Scheduler/OGoCalView.h @@ -3,12 +3,12 @@ #ifndef __ZideStoreUI_OGoCalView_H__ #define __ZideStoreUI_OGoCalView_H__ -#include +#include @class NSArray, NSCalendarDate; @class SxAptManager, SxAptSetIdentifier; -@interface OGoCalView : SoComponent +@interface OGoCalView : OGoComponent { NSArray *appointments; id appointment; @@ -23,8 +23,6 @@ - (NSString *)appointmentViewURL; - (NSString *)ownMethodName; -- (NSString *)dateNavigationURLWithNewStartDate:(NSCalendarDate *)_newDate; -- (NSString *)completedLinkForView:(NSString *)_view; /* backend */ @@ -33,12 +31,16 @@ /* fetching */ +- (NSCalendarDate *)selectedDate; - (NSCalendarDate *)startDate; - (NSCalendarDate *)endDate; - (NSArray *)fetchGIDs; - (NSArray *)fetchCoreInfos; /* date selection */ +- (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date; +- (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate + inDictionary:(NSMutableDictionary *)_qp; - (NSString *)dateStringForDate:(NSCalendarDate *)_date; - (NSCalendarDate *)dateForDateString:(NSString *)_dateString; diff --git a/ZideStore/UI-X/Scheduler/OGoCalView.m b/ZideStore/UI-X/Scheduler/OGoCalView.m index d08551c6..1928ac0e 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalView.m +++ b/ZideStore/UI-X/Scheduler/OGoCalView.m @@ -69,7 +69,8 @@ } - (NSString *)dateNavigationURLWithNewStartDate:(NSCalendarDate *)_newDate { - return [NSString stringWithFormat:@"%@?startDate=%@", +#warning !! REMOVE ME!! + return [NSString stringWithFormat:@"%@?startDate=%@", [self ownMethodName], [self dateStringForDate:_newDate]]; } @@ -112,13 +113,25 @@ queryString:nil]; } +/* date */ + +- (NSCalendarDate *)selectedDate { + NSString *s; + + s = [self queryParameterForKey:@"day"]; + if(s) { + return [self dateForDateString:s]; + } + return [NSCalendarDate date]; +} + /* fetching */ - (NSCalendarDate *)startDate { - return [NSCalendarDate date]; + return [self selectedDate]; } - (NSCalendarDate *)endDate { - return [[NSCalendarDate date] tomorrow]; + return [[self startDate] tomorrow]; } - (NSArray *)fetchGIDs { @@ -145,6 +158,28 @@ return self->appointments; } + +/* date selection & conversion */ + + +- (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date { + NSMutableDictionary *qp; + + qp = [[self queryParameters] mutableCopy]; + [self setSelectedDateQueryParameter:_date inDictionary:qp]; + return [qp autorelease]; +} + +- (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate + inDictionary:(NSMutableDictionary *)_qp; +{ + if(_newDate != nil) + [_qp setObject:[self dateStringForDate:_newDate] + forKey:@"day"]; + else + [_qp removeObjectForKey:@"day"]; +} + - (NSString *)dateStringForDate:(NSCalendarDate *)_date { return [_date descriptionWithCalendarFormat:@"%Y%m%d"]; } @@ -152,15 +187,5 @@ - (NSCalendarDate *)dateForDateString:(NSString *)_dateString { return [NSCalendarDate dateWithString:_dateString calendarFormat:@"%Y%m%d"]; } - -- (NSString *)completedLinkForView:(NSString *)_view { - NSString *dateString; - - dateString = [[[self context] request] formValueForKey:@"startDate"]; - if(dateString) - return [_view stringByAppendingFormat:@"?startDate=%@", dateString]; - return _view; -} - @end /* OGoCalView */ diff --git a/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.wox b/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.wox index 83a26a01..e69e697f 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.wox +++ b/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.wox @@ -29,7 +29,7 @@ TODO: controls - + @@ -41,7 +41,7 @@
- + @@ -62,10 +62,10 @@
- printview + printview - proposal + proposal
@@ -96,6 +96,8 @@
+
+