]> err.no Git - sope/commitdiff
added 'itemGroup' binding for <optgroup> elements
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 30 Mar 2005 22:43:10 +0000 (22:43 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 30 Mar 2005 22:43:10 +0000 (22:43 +0000)
fixed a bug in HTML escaping

git-svn-id: http://svn.opengroupware.org/SOPE/trunk@708 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-appserver/NGObjWeb/ChangeLog
sope-appserver/NGObjWeb/DynamicElements/WOForm.m
sope-appserver/NGObjWeb/DynamicElements/WOPopUpButton.api
sope-appserver/NGObjWeb/DynamicElements/WOPopUpButton.m
sope-appserver/NGObjWeb/Version

index f5fc7694b878b22e67f341132cf0b97e226eb325..8bf2e857f63f6fa33088b2cd0ce2ee397f356e3e 100644 (file)
@@ -1,3 +1,11 @@
+2005-03-31  Stephane Corthesy  <stephane@sente.ch>
+
+       * DynamicElements/WOPopUpButton.m, DynamicElements/WOPopUpButton.api: 
+         added new binding 'itemGroup' which allows generation of the
+         <optgroup> element in a <select> element. Fixed a bug where 
+         displayed value '<nil>' was not HTML-escaped, in some cases
+         (v4.5.146)
+       
 2005-03-28  Stephane Corthesy  <stephane@sente.ch>
 
        * added NSString category NSString+JavaScriptEscaping (v4.5.145)
index b4e18a485e86561ff412373bfd806674cb4e1329..0665ee3bac8ae819717e2ca6982b9160b3abe7e4 100644 (file)
@@ -330,6 +330,7 @@ static int debugTakeValues = -1;
     }
   }
   else if (self->sidInUrl) {
+    /* Note: this is not a problem! Eg this occurs on the OGo Main component */
     [self debugWithFormat:
            @"Note: session-id is requested, but no session is active?"];
   }
index d97ee925a1289688dc3073fed8b911b1b8907c5c..90161cdd6eb54d948878c2ae25fb49fd8fc32005 100644 (file)
@@ -14,6 +14,7 @@
   <binding name="value" passthrough="NO"/>
   <binding name="disabled" passthrough="NO" defaults="YES/NO"/>
 
+  <binding name="itemGroup"/>
   <binding name="otherTagString" passthrough="NO"/>
 
   <validation message="&apos;list&apos; must not be a constant">
index 2947c8fac3cfe582b42d7aef0d292303fdcf4aa3..072874684794e1e2a5eafaac1f2886175f16dead 100644 (file)
@@ -38,6 +38,7 @@
   WOAssociation *noSelectionString; // WO4
   WOAssociation *selectedValue;     // WO4.5
   WOAssociation *escapeHTML;        // WO4.5
+  WOAssociation *itemGroup;         // SOPE
 }
 
 @end
@@ -124,12 +125,13 @@ static NSNumber *yesNum = nil;
     self->noSelectionString = OWGetProperty(_config, @"noSelectionString");
     self->selectedValue     = OWGetProperty(_config, @"selectedValue");
     self->escapeHTML        = OWGetProperty(_config, @"escapeHTML");
+    self->itemGroup         = OWGetProperty(_config, @"itemGroup");
     
     if (self->selection != nil && self->selectedValue != nil)
       [self logWithFormat:
         @"cannot have both 'selection' and 'selectedValue' bindings!"];
     
-    /* compatiblity */
+    /* compatibility */
     
     if (self->noSelectionString == nil)
       self->noSelectionString = OWGetProperty(_config, @"nilString");
@@ -150,6 +152,7 @@ static NSNumber *yesNum = nil;
   [self->selection         release];
   [self->string            release];
   [self->selectedValue     release];
+  [self->itemGroup         release];
   [super dealloc];
 }
 
@@ -188,7 +191,7 @@ static NSNumber *yesNum = nil;
       object = [objects objectAtIndex:i];
       
       if ([self->item isValueSettable])
-       [self->item setValue:object inComponent:sComponent];
+        [self->item setValue:object inComponent:sComponent];
       
       cv = [self->value stringValueInComponent:sComponent];
           
@@ -243,6 +246,7 @@ static NSNumber *yesNum = nil;
   int      i, toGo;
   BOOL     escapesHTML;
   BOOL     byVal;
+  id       previousGroup = nil;
 #if DEBUG
   NSTimeInterval st = 0.0;
     
@@ -292,12 +296,32 @@ static NSNumber *yesNum = nil;
   }
 #endif
   
-  if (nilStr) {
+  if (nilStr != nil) {
+    if (self->itemGroup != nil) {
+      id  group;
+      
+      if ([self->item isValueSettable])
+        [self->item setValue:nil inComponent:sComponent];
+      group = [self->itemGroup stringValueInComponent:sComponent];
+      
+      if (group != nil) {
+        WOResponse_AddCString(_response, "<optgroup label=\"");
+        if (escapesHTML) {
+          WOResponse_AddHtmlString(_response, group);
+       }
+        else {
+          WOResponse_AddString(_response, group);
+       }
+        WOResponse_AddCString(_response, "\">");
+        previousGroup = [group retain];
+      }
+    }
     WOResponse_AddCString(_response, "<option value=\"");
     WOResponse_AddString(_response, WONoSelectionString);
     WOResponse_AddCString(_response, "\">");
     WOResponse_AddHtmlString(_response, nilStr);
     WOResponse_AddCString(_response, "</option>");
+    // FIXME (stephane) Shouldn't we set the 'selected' if selArray/selValueArray is empty?
   }
   
   for (i = 0; i < toGo; i++) {
@@ -305,6 +329,7 @@ static NSNumber *yesNum = nil;
     NSString *displayV  = nil;
     id       object;
     BOOL     isSelected;
+    id       group;
 #if DEBUG
     NSTimeInterval st = 0.0;
     
@@ -332,10 +357,43 @@ static NSNumber *yesNum = nil;
       ? [self->string stringValueInComponent:sComponent]
       : [object stringValue];
 
-    if (displayV == nil) displayV = @"<nil>";
+    if (displayV == nil) displayV = (escapesHTML ? @"<nil>" : @"&lt;nil&gt;");
+    
+    group = self->itemGroup != nil
+      ? [self->itemGroup stringValueInComponent:sComponent]
+      : nil;
     
+    if (group != nil) {
+      BOOL  groupChanged = NO;
+      
+      if (previousGroup == nil)
+        groupChanged = YES;
+      else {
+        if (![group isEqualToString:previousGroup]) {
+          WOResponse_AddCString(_response, "</optgroup>");
+          groupChanged = YES;
+        }
+      }
+      if (groupChanged) {
+        WOResponse_AddCString(_response, "<optgroup label=\"");
+        if (escapesHTML) {
+          WOResponse_AddHtmlString(_response, group);
+       }
+        else {
+          WOResponse_AddString(_response, group);
+       }
+        WOResponse_AddCString(_response, "\">");
+        ASSIGN(previousGroup, group);
+      }
+    }
+    else {
+      if (previousGroup != nil) {
+        WOResponse_AddCString(_response, "</optgroup>");
+        ASSIGN(previousGroup, nil);
+      }
+    }
     WOResponse_AddCString(_response, "<option value=\"");
-    WOResponse_AddHtmlString(_response, v); // WO escapes it
+    WOResponse_AddHtmlString(_response, v); // WO escapes it, always
     WOResponse_AddCString(_response, 
                          isSelected ? 
                          "\" selected=\"selected\">" : "\">");
@@ -363,6 +421,10 @@ static NSNumber *yesNum = nil;
     }
 #endif
   }
+  if (previousGroup != nil) {
+    WOResponse_AddCString(_response, "</optgroup>");
+    [previousGroup release];
+  }
   if ([self->item isValueSettable])
     [self->item setValue:nil inComponent:sComponent]; // Reset 'item'
 }
@@ -432,6 +494,8 @@ static NSNumber *yesNum = nil;
     [str appendFormat:@" escapeHTML=%@", self->escapeHTML];
   if (self->selectedValue)
     [str appendFormat:@" selectedValue=%@", self->selectedValue];
+  if (self->itemGroup)
+    [str appendFormat:@" itemGroup=%@", self->itemGroup];
   
   return str;
 }
index 6deb9f8e246868ff2af9ddf06e201f5c255203ef..361f213bf92cd542b010c35808cc36d6843a24b3 100644 (file)
@@ -1,6 +1,6 @@
 # version file
 
-SUBMINOR_VERSION:=145
+SUBMINOR_VERSION:=146
 
 # v4.5.122 requires libNGExtensions v4.5.153
 # v4.5.91  requires libNGExtensions v4.5.134