]> err.no Git - sope/commitdiff
code cleanups
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Fri, 8 Apr 2005 19:39:56 +0000 (19:39 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Fri, 8 Apr 2005 19:39:56 +0000 (19:39 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@715 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-appserver/WEExtensions/ChangeLog
sope-appserver/WEExtensions/Version
sope-appserver/WEExtensions/WETableView/README
sope-appserver/WEExtensions/WETableView/WETableCell.m
sope-appserver/WEExtensions/WETableView/WETableData.m

index 7586f3b059e140885cc2060e9b2a8ce58d5e2938..b9ee3d0b877632e3388aa7eddd1bb4af975697e9 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-08  Helge Hess  <helge.hess@opengroupware.org>
+
+       * WETableView/WETableData.m, WETableCell.m: some code cleanups
+         (v4.5.70)
+
 2005-03-07  Helge Hess  <helge.hess@opengroupware.org>
 
        * added some support for -generateXMLStyleEmptyElements (v4.5.69)
index ce9f1f8e3576ba64ca8870b8b056e6e79301abb5..dbd207ec6489085490a188b0e1ddc4573a13fade 100644 (file)
@@ -1,5 +1,5 @@
 # version file
 
-SUBMINOR_VERSION:=69
+SUBMINOR_VERSION:=70
 
 # v4.5.65 requires libNGObjWeb v4.5.106
index 03b314a55c04e8a4aaaa00f0661a62c8f65fb2f0..2f9129c7f9a2a69ac86c8677abda2b14cb8dc1e2 100644 (file)
@@ -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
 ============
 
index 52489e10d584d0520555411815c3cf385d9fd542..7d1a2d54f1c214e8239421e224a4fe123662f36b 100644 (file)
@@ -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 ||
index 373f62f4a943fedbdfb9fb5802cb13646bf1d12a..a6eaad05146467883bc547f4ff574a3bb31c3db1 100644 (file)
   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:@"<td "];          // <td...>
-    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:@"<td "];          // <td...>
+  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);                      //   <font...>
-    [self->template appendToResponse:_response inContext:_ctx];
+  if (hasFont)
+    WEAppendFont(_response, tC, tF, tS);                      //   <font...>
+  [self->template appendToResponse:_response inContext:_ctx];
 
-    [self _appendStringContentToResponse:_response inContext:_ctx];
-    if (hasFont)
-      [_response appendContentString:@"</font>"];                 // </font>
+  [self _appendStringContentToResponse:_response inContext:_ctx];
+  if (hasFont)
+    [_response appendContentString:@"</font>"];                 // </font>
 
-    [_response appendContentString:@"</td>"];                  // </td>
-  }
+  [_response appendContentString:@"</td>"];                  // </td>
 }
 
 /* responder */
   }
 }
 
-- (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];
   }
 }
 
     /* 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);
     }
 }
 
 - (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
 {
   
   /* 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:@"</font>"];                 // </font>
   
-  if (self->action) {
+  if (self->action != nil) {
     [_ctx deleteLastElementIDComponent]; // delete 'act'
     [_response appendContentString:@"</a>"];
   }