]> err.no Git - sope/blobdiff - sope-appserver/NGObjWeb/WODisplayGroup.m
fixed an issue with lowercase 'webobject name' tags
[sope] / sope-appserver / NGObjWeb / WODisplayGroup.m
index b727b80b3f7d2bb80575718587d8188ef99d433c..8d7ad6c42905194c2f38466968a51375fc377cdb 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <NGObjWeb/WODisplayGroup.h>
 #import <EOControl/EOControl.h>
+#import <EOControl/EOKeyValueArchiver.h>
 #import <Foundation/Foundation.h>
 #import <Foundation/NSNotification.h>
 #include "common.h"
@@ -324,10 +325,10 @@ static NSArray  *uint0Array = nil;
 - (id)selectNext {
   unsigned int idx;
   
-  if ([self->displayObjects count] == 0)
+  if (![self->displayObjects isNotEmpty])
     return nil;
   
-  if ([self->selectionIndexes count] == 0) {
+  if (![self->selectionIndexes isNotEmpty]) {
     [self setSelectionIndexes:uint0Array];
     return nil;
   }
@@ -348,10 +349,10 @@ static NSArray  *uint0Array = nil;
 - (id)selectPrevious {
   unsigned int idx;
   
-  if ([self->displayObjects count] == 0)
+  if (![self->displayObjects isNotEmpty])
     return nil;
   
-  if ([self->selectionIndexes count] == 0) {
+  if (![self->selectionIndexes isNotEmpty]) {
     [self setSelectionIndexes:uint0Array];
     return nil;
   }
@@ -377,10 +378,16 @@ static NSArray  *uint0Array = nil;
   // TODO: maybe we need to retain the selection array and just swap the first
   
   idx = [self->objects indexOfObject:_obj];
-  idxNumber = (idx != NSNotFound) ? [NSNumber numberWithUnsignedInt:idx] : nil;
+  idxNumber = (idx != NSNotFound)
+    ? [NSNumber numberWithUnsignedInt:idx] : (NSNumber *)nil;
 
-  if (idxNumber != nil)
-    [self setSelectionIndexes:[NSArray arrayWithObjects:&idxNumber count:1]];
+  if (idxNumber != nil) {
+    NSArray *a;
+    
+    a = [[NSArray alloc] initWithObjects:&idxNumber count:1];
+    [self setSelectionIndexes:a];
+    [a release]; a = nil;
+  }
   else
     [self setSelectionIndexes:nil];
 }
@@ -429,7 +436,8 @@ static NSArray  *uint0Array = nil;
     return NO;
   
   idx = [self->objects indexOfObject:_obj];
-  idxNumber = (idx != NSNotFound) ? [NSNumber numberWithUnsignedInt:idx] : nil;
+  idxNumber = (idx != NSNotFound) 
+    ? [NSNumber numberWithUnsignedInt:idx] : (NSNumber *)nil;
 
   // TODO: should we just exchange the first item and/or call
   //       -setSelectedObject: ?
@@ -511,9 +519,8 @@ static NSArray  *uint0Array = nil;
   
   /* should try to restore selection */
   [self clearSelection];
-  if ([_objects count] > 0 && [self selectsFirstObjectAfterFetch]) {
+  if ([_objects isNotEmpty] && [self selectsFirstObjectAfterFetch])
     [self setSelectionIndexes:uint0Array];
-  }
 }
  
 - (NSArray *)allObjects {
@@ -543,11 +550,11 @@ static NSArray  *uint0Array = nil;
   }
 
   [self updateDisplayedObjects];
-
+  
   if ([self selectsFirstObjectAfterFetch]) {
     [self clearSelection];
     
-    if ([objs count] > 0)
+    if ([objs isNotEmpty])
       [self setSelectedObject:[objs objectAtIndex:0]];
   }
   
@@ -631,7 +638,7 @@ static NSArray  *uint0Array = nil;
   /* construct qualifier for all query-match entries */
   
   keys = [qm keyEnumerator];
-  while ((key = [keys nextObject])) {
+  while ((key = [keys nextObject]) != nil) {
     NSString *op;
     SEL      ops;
     id       value;
@@ -684,13 +691,13 @@ static NSArray  *uint0Array = nil;
   }
 
   /* construct max qualifiers */
-
+  
   keys = [qmax keyEnumerator];
   while ((key = [keys nextObject]) != nil) {
     EOQualifier *q;
     id value;
     
-    value = [qmin objectForKey:key];
+    value = [qmax objectForKey:key];
 
     q = [[EOKeyValueQualifier alloc]
                               initWithKey:key
@@ -700,7 +707,7 @@ static NSArray  *uint0Array = nil;
     [q release];
   }
 
-  if ([quals count] == 0)
+  if (![quals isNotEmpty])
     return nil;
   if ([quals count] == 1)
     return [quals objectAtIndex:0];
@@ -809,36 +816,64 @@ static NSArray  *uint0Array = nil;
 - (void)qualifyDataSource {
   EODataSource *ds;
   EOQualifier  *q;
+  NSDictionary *bindings;
 
-  ds = [self dataSource];
+  if ((ds = [self dataSource]) == nil)
+    [self warnWithFormat:@"no datasource set: %@", NSStringFromSelector(_cmd)];
+
+  /* build qualifier */
   
   if ((q = [self qualifierFromQueryValues]) != nil)
     [self setQualifier:q];
-
-  if ([ds respondsToSelector:@selector(setAuxiliaryQualifier:)])
+  
+  /* set qualifier in datasource */
+  
+  if ([ds respondsToSelector:@selector(setAuxiliaryQualifier:)]) {
     [ds setAuxiliaryQualifier:[self qualifier]];
+    //[self logWithFormat:@"set aux qualifier in %@: %@", ds,[self qualifier]];
+  }
   else if ([ds respondsToSelector:@selector(setQualifier:)])
     [ds setQualifier:[self qualifier]];
   else {
     /* could not qualify ds */
+    [self warnWithFormat:@"could not qualify datasource: %@", ds];
   }
   
-  if ([ds respondsToSelector:@selector(setQualifierBindings:)])
-    [ds setQualifierBindings:[self queryBindings]];
+  /* set bindings in datasource */
+
+  if ([(bindings = [self queryBindings]) isNotEmpty]) {
+    if ([ds respondsToSelector:@selector(setQualifierBindings:)])
+      [ds setQualifierBindings:bindings];
+    else {
+      [self warnWithFormat:@"could not set bindings in datasource %@: %@", 
+             ds, bindings];
+    }
+  }
   
+  /* perform fetch */
+  
+  /* action method, returns 'nil' to stay on page */
   [self fetch];
   
   if ([self inQueryMode])
     [self setInQueryMode:NO];
 }
 
+- (id)qualifyDataSourceAndReturnDisplayCount {
+  /* 
+     This is a 'hack' created because we can't bind (and therefore 'call')
+     'void' methods in .wod files.
+  */
+  [self qualifyDataSource];
+  return [NSNumber numberWithUnsignedInt:[[self displayedObjects] count]];
+}
 
 /* object creation */
 
 - (id)insert {
   unsigned idx;
 
-  idx = [self->selectionIndexes count] > 0
+  idx = [self->selectionIndexes isNotEmpty]
     ? ([[self->selectionIndexes objectAtIndex:0] unsignedIntValue] + 1)
     : [self->objects count];
   
@@ -1005,7 +1040,7 @@ static NSArray  *uint0Array = nil;
   EODataSource *ds;
   
   return ([(ds = [self dataSource]) respondsToSelector:_cmd])
-    ? [(EODetailDataSource *)ds detailKey] : nil;
+    ? [(EODetailDataSource *)ds detailKey] : (NSString *)nil;
 }
 
 - (void)setMasterObject:(id)_object {
@@ -1157,7 +1192,7 @@ static NSArray  *uint0Array = nil;
 /* description */
 
 - (NSString *)description {
-  return [NSString stringWithFormat:@"<0x%08X %@: ds=%@>",
+  return [NSString stringWithFormat:@"<0x%p %@: ds=%@>",
                      self, NSStringFromClass([self class]),
                      [self dataSource]];
 }