From 5519fbc9506c40dda6fe441a77482347c3fb6702 Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 8 Apr 2005 19:39:56 +0000 Subject: [PATCH] code cleanups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@715 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/WEExtensions/ChangeLog | 5 + sope-appserver/WEExtensions/Version | 2 +- .../WEExtensions/WETableView/README | 8 +- .../WEExtensions/WETableView/WETableCell.m | 18 +- .../WEExtensions/WETableView/WETableData.m | 229 +++++++++--------- 5 files changed, 142 insertions(+), 120 deletions(-) diff --git a/sope-appserver/WEExtensions/ChangeLog b/sope-appserver/WEExtensions/ChangeLog index 7586f3b0..b9ee3d0b 100644 --- a/sope-appserver/WEExtensions/ChangeLog +++ b/sope-appserver/WEExtensions/ChangeLog @@ -1,3 +1,8 @@ +2005-04-08 Helge Hess + + * WETableView/WETableData.m, WETableCell.m: some code cleanups + (v4.5.70) + 2005-03-07 Helge Hess * added some support for -generateXMLStyleEmptyElements (v4.5.69) diff --git a/sope-appserver/WEExtensions/Version b/sope-appserver/WEExtensions/Version index ce9f1f8e..dbd207ec 100644 --- a/sope-appserver/WEExtensions/Version +++ b/sope-appserver/WEExtensions/Version @@ -1,5 +1,5 @@ # version file -SUBMINOR_VERSION:=69 +SUBMINOR_VERSION:=70 # v4.5.65 requires libNGObjWeb v4.5.106 diff --git a/sope-appserver/WEExtensions/WETableView/README b/sope-appserver/WEExtensions/WETableView/README index 03b314a5..2f9129c7 100644 --- a/sope-appserver/WEExtensions/WETableView/README +++ b/sope-appserver/WEExtensions/WETableView/README @@ -1,10 +1,14 @@ -# $Id$ - WETableView =========== TODO: write some documentation how it works, what it supports, etc ... +TODO: +- add support for CSS +- allow sort icon on the right +- allow click on the whole title for sorting + - disable when in form mode? (could enable in JS mode?) + Capabilities ============ diff --git a/sope-appserver/WEExtensions/WETableView/WETableCell.m b/sope-appserver/WEExtensions/WETableView/WETableCell.m index 52489e10..7d1a2d54 100644 --- a/sope-appserver/WEExtensions/WETableView/WETableCell.m +++ b/sope-appserver/WEExtensions/WETableView/WETableCell.m @@ -54,14 +54,14 @@ static NSNumber *NoNumber = nil; } - (void)dealloc { - RELEASE(self->sortKey); - RELEASE(self->negateSortDir); - RELEASE(self->bgColor); - RELEASE(self->upwardSortIcon); - RELEASE(self->downwardSortIcon); - RELEASE(self->nonSortIcon); - RELEASE(self->sortLabel); - RELEASE(self->template); + [self->sortKey release]; + [self->negateSortDir release]; + [self->bgColor release]; + [self->upwardSortIcon release]; + [self->downwardSortIcon release]; + [self->nonSortIcon release]; + [self->sortLabel release]; + [self->template release]; [super dealloc]; } @@ -87,7 +87,7 @@ static NSNumber *NoNumber = nil; if (sk == nil) return; - + if (![sk isEqualToString:sortedKey]) sortDir = 0; else if ( [_ctx objectForKey:WETableView_ISDESCENDING] == nil || diff --git a/sope-appserver/WEExtensions/WETableView/WETableData.m b/sope-appserver/WEExtensions/WETableView/WETableData.m index 373f62f4..a6eaad05 100644 --- a/sope-appserver/WEExtensions/WETableView/WETableData.m +++ b/sope-appserver/WEExtensions/WETableView/WETableData.m @@ -181,75 +181,79 @@ inContext:(WOContext *)_ctx info:(WETableViewInfo *)_info { - if (!_info->isGroup) { - WOComponent *cmp = [_ctx component]; - NSString *bg = [self->bgColor stringValueInComponent:cmp]; - NSString *a = [self->align stringValueInComponent:cmp]; - NSString *va = [self->valign stringValueInComponent:cmp]; - NSString *tC, *tF, *tS; // text font attrtibutes - BOOL hasFont; + WOComponent *cmp; + NSString *bg, *a, *va; + NSString *tC, *tF, *tS; // text font attrtibutes + BOOL hasFont; + + if (_info->isGroup) + return; + + cmp = [_ctx component]; + bg = [self->bgColor stringValueInComponent:cmp]; + a = [self->align stringValueInComponent:cmp]; + va = [self->valign stringValueInComponent:cmp]; - tC = [_ctx objectForKey:WETableView_fontColor]; - tF = [_ctx objectForKey:WETableView_fontFace]; - tS = [_ctx objectForKey:WETableView_fontSize]; - hasFont = (tC || tF || tS) ? YES : NO; + tC = [_ctx objectForKey:WETableView_fontColor]; + tF = [_ctx objectForKey:WETableView_fontFace]; + tS = [_ctx objectForKey:WETableView_fontSize]; + hasFont = (tC || tF || tS) ? YES : NO; - if (bg == nil) { - bg = (_info->isEven) - ? [_ctx objectForKey:WETableView_evenColor] - : [_ctx objectForKey:WETableView_oddColor]; - } + if (bg == nil) { + bg = (_info->isEven) + ? [_ctx objectForKey:WETableView_evenColor] + : [_ctx objectForKey:WETableView_oddColor]; + } - [_response appendContentString:@" - if (bg) { - [_response appendContentString:@" bgcolor=\""]; - [_response appendContentString:bg]; - [_response appendContentCharacter:'"']; - } - if (_info->rowSpan > 1) { - switch (_info->rowSpan) { - case 0: - [_response appendContentString:@" rowspan=\"0\""]; - break; - case 1: - [_response appendContentString:@" rowspan=\"1\""]; - break; - case 2: - [_response appendContentString:@" rowspan=\"2\""]; - break; - default: { - NSString *s; - s = [[NSString alloc] initWithFormat:@"%i", _info->rowSpan]; - [_response appendContentString:@" rowspan=\""]; - [_response appendContentString:s]; - [_response appendContentCharacter:'"']; - [s release]; - break; } - } - } - if (a) { - [_response appendContentString:@" align=\""]; - [_response appendContentString:a]; - [_response appendContentCharacter:'"']; - } - if (va) { - [_response appendContentString:@" valign=\""]; - [_response appendContentString:va]; + [_response appendContentString:@" + if (bg) { + [_response appendContentString:@" bgcolor=\""]; + [_response appendContentString:bg]; + [_response appendContentCharacter:'"']; + } + if (_info->rowSpan > 1) { + switch (_info->rowSpan) { + case 0: + [_response appendContentString:@" rowspan=\"0\""]; + break; + case 1: + [_response appendContentString:@" rowspan=\"1\""]; + break; + case 2: + [_response appendContentString:@" rowspan=\"2\""]; + break; + default: { + NSString *s; + s = [[NSString alloc] initWithFormat:@"%i", _info->rowSpan]; + [_response appendContentString:@" rowspan=\""]; + [_response appendContentString:s]; [_response appendContentCharacter:'"']; + [s release]; + break; } } - [self appendExtraAttributesToResponse:_response inContext:_ctx]; - [_response appendContentCharacter:'>']; + } + if (a) { + [_response appendContentString:@" align=\""]; + [_response appendContentString:a]; + [_response appendContentCharacter:'"']; + } + if (va) { + [_response appendContentString:@" valign=\""]; + [_response appendContentString:va]; + [_response appendContentCharacter:'"']; + } + [self appendExtraAttributesToResponse:_response inContext:_ctx]; + [_response appendContentCharacter:'>']; - if (hasFont) - WEAppendFont(_response, tC, tF, tS); // - [self->template appendToResponse:_response inContext:_ctx]; + if (hasFont) + WEAppendFont(_response, tC, tF, tS); // + [self->template appendToResponse:_response inContext:_ctx]; - [self _appendStringContentToResponse:_response inContext:_ctx]; - if (hasFont) - [_response appendContentString:@""]; // + [self _appendStringContentToResponse:_response inContext:_ctx]; + if (hasFont) + [_response appendContentString:@""]; // - [_response appendContentString:@""]; // - } + [_response appendContentString:@""]; // } /* responder */ @@ -275,12 +279,10 @@ } } -- (void)takeValuesFromRequest:(WORequest *)_request - inContext:(WOContext *)_ctx -{ - if ([[_ctx objectForKey:WETableView_DataMode] boolValue] || +- (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx { + if ([[_ctx objectForKey:WETableView_DataMode] boolValue] || [[_ctx objectForKey:WETableView_HeaderMode] boolValue]) { - [super takeValuesFromRequest:_request inContext:_ctx]; + [super takeValuesFromRequest:_rq inContext:_ctx]; } } @@ -303,9 +305,9 @@ /* check formats */ { int num = 0; - if (self->formatter) num++; - if (self->numberformat) num++; - if (self->dateformat) num++; + if (self->formatter != nil) num++; + if (self->numberformat != nil) num++; + if (self->dateformat != nil) num++; if (num > 1) NSLog(@"WARNING: more than one formats specified in element %@", self); } @@ -314,15 +316,49 @@ } - (void)dealloc { - RELEASE(self->formatter); - RELEASE(self->numberformat); - RELEASE(self->dateformat); - RELEASE(self->string); - RELEASE(self->value); - RELEASE(self->action); + [self->formatter release]; + [self->numberformat release]; + [self->dateformat release]; + [self->string release]; + [self->value release]; + [self->action release]; [super dealloc]; } +/* generate response */ + +- (NSFormatter *)retainedFormatterInContext:(id)_ctx { + NSFormatter *fmt; + id s; + + if (self->numberformat != nil) { + fmt = [[NSNumberFormatter alloc] init]; + s = [self->numberformat valueInComponent:[_ctx component]]; + [(NSNumberFormatter *)fmt setFormat:s]; + return fmt; + } + + if (self->dateformat != nil) { + s = [self->dateformat valueInComponent:[_ctx component]]; + fmt = [[NSDateFormatter alloc] initWithDateFormat:s + allowNaturalLanguage:NO]; + return fmt; + } + + if (self->formatter != nil) { + fmt = [self->formatter valueInComponent:[_ctx component]]; +#ifdef DEBUG + if (fmt && ![fmt respondsToSelector:@selector(stringForObjectValue:)]) { + [self logWithFormat:@"invalid formatter determined by keypath %@: %@", + self->formatter, fmt]; + } +#endif + return [fmt retain]; + } + + return nil; +} + - (void)_appendStringContentToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { @@ -349,55 +385,32 @@ /* add value */ - if (self->value) { + if (self->value != nil) { NSFormatter *fmt = nil; id obj; obj = [self->value valueInComponent:cmp]; - - if (self->numberformat) { - fmt = AUTORELEASE([[NSNumberFormatter alloc] init]); - [(NSNumberFormatter *)fmt setFormat: - [self->numberformat valueInComponent:cmp]]; - } - else if (self->dateformat) { - fmt = [[NSDateFormatter alloc] - initWithDateFormat: - [self->dateformat valueInComponent: - cmp] - allowNaturalLanguage:NO]; - fmt = AUTORELEASE(fmt); - } - else if (self->formatter) { - fmt = [self->formatter valueInComponent:cmp]; -#ifdef DEBUG - if (fmt && ![fmt respondsToSelector:@selector(stringForObjectValue:)]) { - [cmp logWithFormat: - @"invalid formatter determined by keypath %@: %@", - self->formatter, - fmt]; - } -#endif - } - if (fmt) - obj = [fmt stringForObjectValue:obj]; - - s = [obj stringValue]; + if ((fmt = [self retainedFormatterInContext:_ctx]) != nil) { + s = [fmt stringForObjectValue:obj]; + [fmt release]; + } + else + s = [obj stringValue]; - if (s) [_response appendContentHTMLString:s]; + if (s != nil) [_response appendContentHTMLString:s]; } /* add string */ - if (self->string) { + if (self->string != nil) { s = [self->string stringValueInComponent:cmp]; [_response appendContentHTMLString:s]; } if (hasFont) [_response appendContentString:@""]; // - if (self->action) { + if (self->action != nil) { [_ctx deleteLastElementIDComponent]; // delete 'act' [_response appendContentString:@""]; } -- 2.39.5