From 947ba1169367928360b9708db2a6f19163d81a04 Mon Sep 17 00:00:00 2001 From: helge Date: Sun, 20 Mar 2005 23:09:45 +0000 Subject: [PATCH] added support for 'disabled' binding as in WO git-svn-id: http://svn.opengroupware.org/SOPE/trunk@678 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 14 +- .../NGObjWeb/DynamicElements/WOBrowser.m | 35 +-- .../NGObjWeb/DynamicElements/WOCheckBox.m | 58 ++--- .../NGObjWeb/DynamicElements/WOCheckBoxList.m | 226 ++++++++++-------- .../NGObjWeb/DynamicElements/WOImageButton.m | 59 +++-- .../DynamicElements/WOPasswordField.m | 50 ++-- .../NGObjWeb/DynamicElements/WOPopUpButton.m | 10 +- .../NGObjWeb/DynamicElements/WORadioButton.m | 20 +- .../DynamicElements/WORadioButtonList.m | 39 +-- .../NGObjWeb/DynamicElements/WOSubmitButton.m | 61 ++--- .../NGObjWeb/DynamicElements/WOText.m | 78 +++--- .../NGObjWeb/DynamicElements/WOTextField.m | 99 ++++---- .../DynamicElements/_WOComplexHyperlink.m | 3 +- sope-appserver/NGObjWeb/Version | 2 +- 14 files changed, 421 insertions(+), 333 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 4f3d8e1b..86240c9a 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,8 +1,20 @@ 2005-03-20 Helge Hess + * v4.5.139 + + * DynamicElements/WOCheckboxList.m, DynamicElements/WOBrowser.m, + DynamicElements/WOCheckbox.m, DynamicElements/WOPopUpButton.m, + DynamicElements/WORadioButton.m, DynamicElements/WORadioButtonList.m, + DynamicElements/WOSubmitButton.m, DynamicElements/WOText.m, + DynamicElements/WOTextField.m: code cleanups, minor perf + improvements, generate 'disabled' attribute + + * DynamicElements/WOImageButton.m: generate instead of + if 'disabled' binding evaluates to true + * WOContext.m: changed default query parameter separator to & as suggested by Stephane (v4.5.138) - + 2005-03-15 Marcus Mueller * NGObjWeb.xcode: added WOWatchDogApplicationMainOSX.m and removed diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOBrowser.m b/sope-appserver/NGObjWeb/DynamicElements/WOBrowser.m index 4261f6df..fdd07c9c 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOBrowser.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOBrowser.m @@ -239,7 +239,7 @@ sComponent = [_ctx component]; if ([self->disabled boolValueInComponent:sComponent]) - return; + return; formValue = [_request formValuesForKey:OWFormElementName(self, _ctx)]; #if 0 @@ -267,16 +267,19 @@ } } +/* generate response */ + - (void)appendOptionsToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { - WOComponent *sComponent = [_ctx component]; - BOOL isSingle = NO; - NSString *nilStr = nil; - NSArray *array = nil; - id selArray = nil; + WOComponent *sComponent; + BOOL isSingle; + NSString *nilStr; + NSArray *array; + id selArray; int i, toGo; + sComponent = [_ctx component]; nilStr = [self->noSelectionString stringValueInComponent:sComponent]; isSingle = [self->singleSelection boolValueInComponent:sComponent]; @@ -284,30 +287,31 @@ selArray = [self->selection valueInComponent:sComponent]; toGo = [array count]; - if (nilStr) { + if (nilStr != nil) { WOResponse_AddCString(_response, ""); } - + for (i = 0; i < toGo; i++) { - NSString *v = nil; - NSString *displayV = nil; - id object = [array objectAtIndex:i]; + NSString *v, *displayV; + id object; BOOL isSelected; + object = [array objectAtIndex:i]; + if ([self->item isValueSettable]) [self->item setValue:object inComponent:sComponent]; isSelected = NO; - if (selArray) { + if (selArray != nil) { isSelected = isSingle ? [selArray isEqual:object] : [selArray containsObject:object]; } - v = self->value + v = (self->value != nil) ? [self->value stringValueInComponent:sComponent] - : [NSString stringWithFormat:@"%i", i]; + : [NSString stringWithFormat:@"%i", i]; // TODO: slow displayV = self->string ? [self->string stringValueInComponent:sComponent] @@ -349,6 +353,9 @@ WOResponse_AddUInt(_response, s); [_response appendContentCharacter:'"']; } + + if ([self->disabled boolValueInComponent:[_ctx component]]) + WOResponse_AddCString(_response, " disabled=\"disabled\""); if (isMultiple) WOResponse_AddCString(_response, " multiple=\"multiple\""); diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOCheckBox.m b/sope-appserver/NGObjWeb/DynamicElements/WOCheckBox.m index 5510870f..8a6bbfc9 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOCheckBox.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOCheckBox.m @@ -81,38 +81,42 @@ } - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { - if (![[_ctx request] isFromClientComponent]) { - NSString *v; - BOOL isChecked; + NSString *v; + BOOL isChecked; + + if ([[_ctx request] isFromClientComponent]) + return; - v = [self->value stringValueInComponent:[_ctx component]]; - isChecked = [self->checked boolValueInComponent:[_ctx component]]; + v = [self->value stringValueInComponent:[_ctx component]]; + isChecked = [self->checked boolValueInComponent:[_ctx component]]; - WOResponse_AddCString(_response, " 0) ? v : @"1"]; - WOResponse_AddCString(_response, "\""); + WOResponse_AddCString(_response, " 0) ? v : @"1"]; + WOResponse_AddCString(_response, "\""); + + if ([self->disabled boolValueInComponent:[_ctx component]]) + WOResponse_AddCString(_response, " disabled=\"disabled\""); - if (isChecked) - WOResponse_AddCString(_response, " checked=\"checked\""); + if (isChecked) + WOResponse_AddCString(_response, " checked=\"checked\""); - [self appendExtraAttributesToResponse:_response inContext:_ctx]; + [self appendExtraAttributesToResponse:_response inContext:_ctx]; - if (self->otherTagString) { - WOResponse_AddChar(_response, ' '); - WOResponse_AddString(_response, - [self->otherTagString stringValueInComponent: - [_ctx component]]); - } - - if (_ctx->wcFlags.xmlStyleEmptyElements) { - WOResponse_AddCString(_response, " />\n"); - } - else { - WOResponse_AddCString(_response, ">\n"); - } + if (self->otherTagString) { + WOResponse_AddChar(_response, ' '); + WOResponse_AddString(_response, + [self->otherTagString stringValueInComponent: + [_ctx component]]); + } + + if (_ctx->wcFlags.xmlStyleEmptyElements) { + WOResponse_AddCString(_response, " />\n"); + } + else { + WOResponse_AddCString(_response, ">\n"); } } diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOCheckBoxList.m b/sope-appserver/NGObjWeb/DynamicElements/WOCheckBoxList.m index 06c48a06..9e2290fd 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOCheckBoxList.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOCheckBoxList.m @@ -57,19 +57,17 @@ return self; } -#if !LIB_FOUNDATION_BOEHM_GC - (void)dealloc { - RELEASE(self->list); - RELEASE(self->item); - RELEASE(self->index); - RELEASE(self->selections); - RELEASE(self->prefix); - RELEASE(self->suffix); + [self->list release]; + [self->item release]; + [self->index release]; + [self->selections release]; + [self->prefix release]; + [self->suffix release]; [super dealloc]; } -#endif -// OWResponder +/* OWResponder */ - (void)takeValuesFromRequest:(WORequest *)_request inContext:(WOContext *)_ctx @@ -82,134 +80,150 @@ Remember, the 'value' of a checkbox list is _not_ the form value but the string besides the checkbox. */ - if (![self->disabled boolValueInComponent:[_ctx component]]) { // could be optimized to use a single NAME with multiple values .. WOComponent *sComponent = [_ctx component]; NSArray *array = [self->list valueInComponent:sComponent]; NSArray *selArray = nil; unsigned goCount = [array count]; + + if ([self->disabled boolValueInComponent:[_ctx component]]) + return; - if (goCount > 0) { - NSMutableArray *newSelection = nil; - unsigned cnt; + if (goCount > 0) { + NSMutableArray *newSelection = nil; + unsigned cnt; - if (self->selections) - newSelection = [[NSMutableArray alloc] initWithCapacity:goCount]; + if (self->selections) + newSelection = [[NSMutableArray alloc] initWithCapacity:goCount]; - [_ctx appendZeroElementIDComponent]; + [_ctx appendZeroElementIDComponent]; - for (cnt = 0; cnt < goCount; cnt++) { - id formValue = nil; - id object = [array objectAtIndex:cnt]; - - if (self->index) - [self->index setUnsignedIntValue:cnt inComponent:sComponent]; - - if (self->item) - [self->item setValue:object inComponent:sComponent]; - - formValue = [_request formValueForKey:OWFormElementName(self, _ctx)]; - if ([formValue isEqualToString:[self stringForInt:cnt]]) { - if ((object != nil) && (self->selections != nil)) - [newSelection addObject:object]; - } - [_ctx incrementLastElementIDComponent]; + for (cnt = 0; cnt < goCount; cnt++) { + id formValue = nil; + id object = [array objectAtIndex:cnt]; + + if (self->index) + [self->index setUnsignedIntValue:cnt inComponent:sComponent]; + + if (self->item) + [self->item setValue:object inComponent:sComponent]; + + formValue = [_request formValueForKey:OWFormElementName(self, _ctx)]; + if ([formValue isEqualToString:[self stringForInt:cnt]]) { + if ((object != nil) && (self->selections != nil)) + [newSelection addObject:object]; } + [_ctx incrementLastElementIDComponent]; + } - [_ctx deleteLastElementIDComponent]; // list index + [_ctx deleteLastElementIDComponent]; // list index - if (self->selections) { - selArray = [newSelection copy]; - [newSelection release]; - } + if (self->selections) { + selArray = [newSelection copy]; + [newSelection release]; } - else if (self->selections) - selArray = [[NSArray alloc] init]; + } + else if (self->selections) + selArray = [[NSArray alloc] init]; - if ([self->selections isValueSettable]) - [self->selections setValue:selArray inComponent:sComponent]; + if ([self->selections isValueSettable]) + [self->selections setValue:selArray inComponent:sComponent]; - RELEASE(selArray); - } + [selArray release]; } -- (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx { +- (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx { return nil; } +/* generate response */ + - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { - if (![[_ctx request] isFromClientComponent]) { - WOComponent *sComponent = [_ctx component]; - NSArray *array = [self->list valueInComponent:sComponent]; - unsigned goCount = [array count]; - - if (goCount > 0) { - NSArray *selArray = [self->selections valueInComponent:sComponent]; - unsigned cnt; + WOComponent *sComponent; + NSArray *array; + unsigned goCount; + NSArray *selArray; + unsigned cnt; + BOOL canSetIndex, canSetItem; - [_ctx appendZeroElementIDComponent]; - - for (cnt = 0; cnt < goCount; cnt++) { - id object = [array objectAtIndex:cnt]; - - if ([self->index isValueSettable]) - [self->index setUnsignedIntValue:cnt inComponent:sComponent]; + if ([[_ctx request] isFromClientComponent]) + return; + + sComponent = [_ctx component]; + array = [self->list valueInComponent:sComponent]; + goCount = [array count]; - if ([self->item isValueSettable]) - [self->item setValue:object inComponent:sComponent]; + if (goCount == 0) + return; + + selArray = [self->selections valueInComponent:sComponent]; - if (self->prefix) { - NSString *ps; + [_ctx appendZeroElementIDComponent]; - ps = [self->prefix stringValueInComponent:sComponent]; - WOResponse_AddString(_response, ps); - } + canSetIndex = [self->index isValueSettable]; + canSetItem = [self->item isValueSettable]; - /* add checkbox */ - { - NSString *n = nil; + for (cnt = 0; cnt < goCount; cnt++) { + id object = [array objectAtIndex:cnt]; + + if (canSetIndex) + [self->index setUnsignedIntValue:cnt inComponent:sComponent]; + + if (canSetItem) + [self->item setValue:object inComponent:sComponent]; + + if (self->prefix != nil) { + NSString *ps; + + ps = [self->prefix stringValueInComponent:sComponent]; + WOResponse_AddString(_response, ps); + } - n = self->name - ? [self->name stringValueInComponent:sComponent] - : OWFormElementName(self, _ctx); + /* add checkbox */ + { + NSString *n = nil; - WOResponse_AddCString(_response, "name + ? [self->name stringValueInComponent:sComponent] + : OWFormElementName(self, _ctx); - if ([selArray containsObject:object]) - WOResponse_AddCString(_response, " checked=\"checked\""); - - [self appendExtraAttributesToResponse:_response inContext:_ctx]; + WOResponse_AddCString(_response, "disabled boolValueInComponent:sComponent]) + WOResponse_AddCString(_response, " disabled=\"disabled\""); + + [self appendExtraAttributesToResponse:_response inContext:_ctx]; - if (self->otherTagString) { - WOResponse_AddChar(_response, ' '); - WOResponse_AddString(_response, - [self->otherTagString stringValueInComponent: - [_ctx component]]); - } - WOResponse_AddEmptyCloseParens(_response, _ctx); - - // the value in a checkbox list is the string besides the checkbox - if (self->value) { - WOResponse_AddHtmlString(_response, - [self->value stringValueInComponent:sComponent]); - } - } - - if (self->suffix) { - NSString *ss; - - ss = [self->suffix stringValueInComponent:sComponent]; - WOResponse_AddString(_response, ss); - } - [_ctx incrementLastElementIDComponent]; + if (self->otherTagString != nil) { + n = [self->otherTagString stringValueInComponent:sComponent]; + WOResponse_AddChar(_response, ' '); + WOResponse_AddString(_response, n); + } + WOResponse_AddEmptyCloseParens(_response, _ctx); + + // the value in a checkbox list is the string besides the checkbox + if (self->value != nil) { + n = [self->value stringValueInComponent:sComponent]; + WOResponse_AddHtmlString(_response, n); } - [_ctx deleteLastElementIDComponent]; // list index } + + if (self->suffix != nil) { + NSString *ss; + + ss = [self->suffix stringValueInComponent:sComponent]; + WOResponse_AddString(_response, ss); + } + [_ctx incrementLastElementIDComponent]; } + [_ctx deleteLastElementIDComponent]; // list index } /* description */ @@ -217,7 +231,7 @@ - (NSString *)associationDescription { NSMutableString *str; - str = [[NSMutableString alloc] init]; + str = [NSMutableString stringWithCapacity:256]; [str appendString:[super associationDescription]]; if (self->list) [str appendFormat:@" list=%@", self->list]; if (self->item) [str appendFormat:@" item=%@", self->item]; @@ -226,7 +240,7 @@ if (self->suffix) [str appendFormat:@" suffix=%@", self->suffix]; if (self->selections) [str appendFormat:@" selections=%@", self->selections]; - return AUTORELEASE(str); + return str; } @end /* WOCheckBoxList */ diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOImageButton.m b/sope-appserver/NGObjWeb/DynamicElements/WOImageButton.m index e28e3538..839ece94 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOImageButton.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOImageButton.m @@ -90,18 +90,18 @@ } - (void)dealloc { - RELEASE(self->actionClass); - RELEASE(self->directActionName); - RELEASE(self->queryDictionary); - RELEASE(self->queryParameters); - RELEASE(self->action); - RELEASE(self->disabledFilename); - RELEASE(self->framework); - RELEASE(self->filename); - RELEASE(self->src); - RELEASE(self->pageName); - RELEASE(self->x); - RELEASE(self->y); + [self->actionClass release]; + [self->directActionName release]; + [self->queryDictionary release]; + [self->queryParameters release]; + [self->action release]; + [self->disabledFilename release]; + [self->framework release]; + [self->filename release]; + [self->src release]; + [self->pageName release]; + [self->x release]; + [self->y release]; [super dealloc]; } @@ -115,7 +115,7 @@ //NSLog(@"%s: take values ...", __PRETTY_FUNCTION__); - if (self->disabled) { + if (self->disabled != nil) { if ([self->disabled boolValueInComponent:sComponent]) return; } @@ -146,7 +146,7 @@ } - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx { - if (self->disabled) { + if (self->disabled != nil) { if ([self->disabled boolValueInComponent:[_ctx component]]) return nil; } @@ -185,23 +185,29 @@ WOComponent *sComponent = [_ctx component]; NSString *uUri = nil; NSString *uFi = nil; + BOOL isDisabled; uUri = [self->src stringValueInComponent:sComponent]; - - if ([self->disabled boolValueInComponent:sComponent]) { + + if ((isDisabled = [self->disabled boolValueInComponent:sComponent])) { uFi = [self->disabledFilename stringValueInComponent:sComponent]; if (uFi == nil) uFi = [self->filename stringValueInComponent:sComponent]; } else uFi = [self->filename stringValueInComponent:sComponent]; - - WOResponse_AddCString(_response, "otherTagString) { + if (self->otherTagString != nil) { + NSString *s; + + s = [self->otherTagString stringValueInComponent:sComponent]; WOResponse_AddChar(_response, ' '); - WOResponse_AddString(_response, - [self->otherTagString stringValueInComponent: - [_ctx component]]); + WOResponse_AddString(_response, s); } WOResponse_AddEmptyCloseParens(_response, _ctx); } diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOPasswordField.m b/sope-appserver/NGObjWeb/DynamicElements/WOPasswordField.m index 76a23944..ef37ab4e 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOPasswordField.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOPasswordField.m @@ -38,46 +38,52 @@ @implementation WOPasswordField -- (id)initWithName:(NSString *)_name - associations:(NSDictionary *)_config - template:(WOElement *)_root { - - if ((self = [super initWithName:_name associations:_config template:_root])) { - self->size = OWGetProperty(_config, @"size"); +- (id)initWithName:(NSString *)_name associations:(NSDictionary *)_a + template:(WOElement *)_root +{ + if ((self = [super initWithName:_name associations:_a template:_root])) { + self->size = OWGetProperty(_a, @"size"); } return self; } -#if !LIB_FOUNDATION_BOEHM_GC - (void)dealloc { - RELEASE(self->size); self->size = nil; + [self->size release]; [super dealloc]; } -#endif -// ******************** responder ******************** +/* generate response */ - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { - NSString *v = [self->value stringValueInComponent:[_ctx component]]; - unsigned int s = [self->size unsignedIntValueInComponent:[_ctx component]]; - + NSString *v; + unsigned int s; + + v = [self->value stringValueInComponent:[_ctx component]]; + s = [self->size unsignedIntValueInComponent:[_ctx component]]; + WOResponse_AddCString(_response, " 0) { WOResponse_AddCString(_response, " size=\""); WOResponse_AddUInt(_response, s); [_response appendContentCharacter:'"']; } + + if ([self->disabled boolValueInComponent:[_ctx component]]) + WOResponse_AddCString(_response, " disabled=\"disabled\""); + [self appendExtraAttributesToResponse:_response inContext:_ctx]; - if (self->otherTagString) { + + if (self->otherTagString != nil) { + v = [self->otherTagString stringValueInComponent:[_ctx component]]; WOResponse_AddChar(_response, ' '); - WOResponse_AddString(_response, - [self->otherTagString stringValueInComponent: - [_ctx component]]); + WOResponse_AddString(_response, v); } + WOResponse_AddEmptyCloseParens(_response, _ctx); } @@ -85,11 +91,13 @@ - (NSString *)associationDescription { NSMutableString *str = nil; - str = [[NSMutableString alloc] initWithString:[super associationDescription]]; - + + str = [NSMutableString stringWithCapacity:128]; + [str appendString:[super associationDescription]]; + if (self->size) [str appendFormat:@" size=%@", self->size]; - - return AUTORELEASE(str); + + return str; } @end /* WOPasswordField */ diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOPopUpButton.m b/sope-appserver/NGObjWeb/DynamicElements/WOPopUpButton.m index 664d2a0f..2947c8fa 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOPopUpButton.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOPopUpButton.m @@ -231,6 +231,8 @@ static NSNumber *yesNum = nil; [self->item setValue:nil inComponent:sComponent]; // Reset 'item' } +/* generate response */ + - (void)appendOptionsToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { @@ -376,13 +378,19 @@ static NSNumber *yesNum = nil; WOResponse_AddCString(_response, "disabled boolValueInComponent:[_ctx component]]) + WOResponse_AddCString(_response, " disabled=\"disabled\""); + [self appendExtraAttributesToResponse:_response inContext:_ctx]; - if (self->otherTagString) { + if (self->otherTagString != nil) { + v = [self->otherTagString stringValueInComponent:[_ctx component]]; WOResponse_AddChar(_response, ' '); - WOResponse_AddString(_response, - [self->otherTagString stringValueInComponent: - [_ctx component]]); + WOResponse_AddString(_response, v); } WOResponse_AddEmptyCloseParens(_response, _ctx); } @@ -163,11 +167,14 @@ /* description */ - (NSString *)associationDescription { - NSMutableString *str = [NSMutableString stringWithCapacity:128]; + NSMutableString *str; + + str = [NSMutableString stringWithCapacity:128]; [str appendString:[super associationDescription]]; + if (self->action) [str appendFormat:@" action=%@", self->action]; if (self->pageName) [str appendFormat:@" page=%@", self->pageName]; - + if (self->actionClass) [str appendFormat:@" actionClass=%@", self->actionClass]; if (self->directActionName) diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOText.m b/sope-appserver/NGObjWeb/DynamicElements/WOText.m index fb761492..3b7506f3 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOText.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOText.m @@ -48,17 +48,18 @@ - (id)initWithName:(NSString *)_name associations:(NSDictionary *)_config - template:(WOElement *)_root { + template:(WOElement *)_t +{ - if ((self = [super initWithName:_name associations:_config template:_root])) { + if ((self = [super initWithName:_name associations:_config template:_t])) { self->rows = OWGetProperty(_config, @"rows"); self->cols = OWGetProperty(_config, @"cols"); self->formatter = OWGetProperty(_config, @"formatter"); self->numberformat = OWGetProperty(_config, @"numberformat"); self->dateformat = OWGetProperty(_config, @"dateformat"); - + if (self->formatter == nil) { - if ([_config objectForKey:@"formatterClass"]) { + if ([_config objectForKey:@"formatterClass"] != nil) { id className; className = OWGetProperty(_config, @"formatterClass"); @@ -99,14 +100,14 @@ /* formatter */ static inline NSFormatter *_getFormatter(WOText *self, WOContext *_ctx) { - NSFormatter *fmt = nil; + NSFormatter *fmt = nil; - if (self->numberformat) { + if (self->numberformat != nil) { fmt = [[[NSNumberFormatter alloc] init] autorelease]; [(NSNumberFormatter *)fmt setFormat: [self->numberformat valueInComponent:[_ctx component]]]; } - else if (self->dateformat) { + else if (self->dateformat != nil) { fmt = [[NSDateFormatter alloc] initWithDateFormat: [self->dateformat valueInComponent: @@ -121,45 +122,43 @@ static inline NSFormatter *_getFormatter(WOText *self, WOContext *_ctx) { return fmt; } -// ******************** responder ******************** +/* handle requests */ - (id)parseFormValue:(id)_value inContext:(WOContext *)_ctx { - NSFormatter *fmt = nil; + NSFormatter *fmt; + NSException *formatException = nil; + NSString *keyPath = nil; + NSString *errorText = nil; + id object = nil; fmt = _getFormatter(self, _ctx); - - if (fmt) { - NSString *errorText = nil; - id object = nil; + if (fmt == nil) + return [super parseFormValue:_value inContext:_ctx]; - //fmt = [self->formatter valueInComponent:[_ctx component]]; + //fmt = [self->formatter valueInComponent:[_ctx component]]; - if ([fmt getObjectValue:&object forString:[_value stringValue] + if ([fmt getObjectValue:&object forString:[_value stringValue] errorDescription:&errorText]) { return object; - } - else { - NSException *formatException = nil; - NSString *keyPath = nil; + } + - if ([self->value respondsToSelector:@selector(keyPath)]) - keyPath = [(id)self->value keyPath]; + if ([self->value respondsToSelector:@selector(keyPath)]) + keyPath = [(id)self->value keyPath]; - formatException = [NSException exceptionWithName:@"WOValidationException" + formatException = [NSException exceptionWithName:@"WOValidationException" reason:errorText userInfo:nil]; - - [[_ctx component] validationFailedWithException:formatException - value:_value - keyPath:keyPath]; - return nil; - } - } - else - return [super parseFormValue:_value inContext:_ctx]; + + [[_ctx component] validationFailedWithException:formatException + value:_value + keyPath:keyPath]; + return nil; } +/* generate response */ + - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { WOComponent *sComponent; NSFormatter *fmt; @@ -195,12 +194,17 @@ static inline NSFormatter *_getFormatter(WOText *self, WOContext *_ctx) { WOResponse_AddUInt(_response, c); WOResponse_AddChar(_response, '"'); } + + if ([self->disabled boolValueInComponent:sComponent]) + WOResponse_AddCString(_response, " disabled=\"disabled\""); + [self appendExtraAttributesToResponse:_response inContext:_ctx]; if (self->otherTagString) { + NSString *s; + + s = [self->otherTagString stringValueInComponent:[_ctx component]]; WOResponse_AddChar(_response, ' '); - WOResponse_AddString(_response, - [self->otherTagString stringValueInComponent: - [_ctx component]]); + WOResponse_AddString(_response, s); } WOResponse_AddChar(_response, '>'); @@ -230,13 +234,13 @@ static inline NSFormatter *_getFormatter(WOText *self, WOContext *_ctx) { str = [NSMutableString stringWithCapacity:64]; [str appendString:[super associationDescription]]; - if (self->rows) [str appendFormat:@" rows=%@", self->rows]; - if (self->cols) [str appendFormat:@" cols=%@", self->cols]; + if (self->rows) [str appendFormat:@" rows=%@", self->rows]; + if (self->cols) [str appendFormat:@" cols=%@", self->cols]; if (self->formatter) [str appendFormat:@" formatter=%@", self->formatter]; if (self->dateformat) [str appendFormat:@" dateformat=%@", self->dateformat]; if (self->numberformat) [str appendFormat:@" numberformat=%@", self->numberformat]; - + return str; } diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOTextField.m b/sope-appserver/NGObjWeb/DynamicElements/WOTextField.m index a4eb1530..9b56f442 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOTextField.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOTextField.m @@ -62,9 +62,9 @@ - (id)initWithName:(NSString *)_name associations:(NSDictionary *)_config - template:(WOElement *)_root + template:(WOElement *)_t { - if ((self = [super initWithName:_name associations:_config template:_root])) { + if ((self = [super initWithName:_name associations:_config template:_t])) { self->size = OWGetProperty(_config, @"size"); self->formatter = OWGetProperty(_config, @"formatter"); self->numberformat = OWGetProperty(_config, @"numberformat"); @@ -73,17 +73,15 @@ if (self->formatter == nil) { if ([_config objectForKey:@"formatterClass"]) { id className; - - className = OWGetProperty(_config, @"formatterClass"); - className = AUTORELEASE(className); - + + className = [OWGetProperty(_config, @"formatterClass") autorelease]; className = [className valueInComponent:nil]; className = NSClassFromString(className); className = [[className alloc] init]; - self->formatter = [WOAssociation associationWithValue:className]; - self->formatter = RETAIN(self->formatter); - RELEASE(className); + self->formatter = + [[WOAssociation associationWithValue:className] retain]; + [className release]; } } @@ -111,14 +109,15 @@ /* formatter */ static inline NSFormatter *_getFormatter(WOTextField *self, WOContext *_ctx) { - NSFormatter *fmt = nil; + // TODO: a DUP to WOText? + NSFormatter *fmt = nil; - if (self->numberformat) { + if (self->numberformat != nil) { fmt = [[[NSNumberFormatter alloc] init] autorelease]; [(NSNumberFormatter *)fmt setFormat: [self->numberformat valueInComponent:[_ctx component]]]; } - else if (self->dateformat) { + else if (self->dateformat != nil) { fmt = [[NSDateFormatter alloc] initWithDateFormat: [self->dateformat valueInComponent: @@ -126,63 +125,59 @@ static inline NSFormatter *_getFormatter(WOTextField *self, WOContext *_ctx) { allowNaturalLanguage:NO]; fmt = [fmt autorelease]; } - else if (self->formatter) { + else if (self->formatter != nil) { fmt = [self->formatter valueInComponent:[_ctx component]]; } return fmt; } -// ******************** responder ******************** +/* handle requests */ - (id)parseFormValue:(id)_value inContext:(WOContext *)_ctx { - NSFormatter *fmt = nil; - - fmt = _getFormatter(self, _ctx); + // TODO: a DUP to WOText? + NSException *formatException = nil; + NSString *keyPath = nil; + NSFormatter *fmt; + NSString *errorText = nil; + id object = nil; + + if ((fmt = _getFormatter(self, _ctx)) == nil) + return [super parseFormValue:_value inContext:_ctx]; - if (fmt) { - NSString *errorText = nil; - id object = nil; - - //fmt = [self->formatter valueInComponent:[_ctx component]]; + //fmt = [self->formatter valueInComponent:[_ctx component]]; - if ([fmt getObjectValue:&object forString:[_value stringValue] + if ([fmt getObjectValue:&object forString:[_value stringValue] errorDescription:&errorText]) { - return object; - } - else { - NSException *formatException = nil; - NSString *keyPath = nil; - - if ([self->value respondsToSelector:@selector(keyPath)]) - keyPath = [(id)self->value keyPath]; - - formatException = [NSException exceptionWithName:@"WOValidationException" - reason:errorText - userInfo:nil]; - - [[_ctx component] validationFailedWithException:formatException - value:_value - keyPath:keyPath]; - return nil; - } + return object; } - else - return [super parseFormValue:_value inContext:_ctx]; + + if ([self->value respondsToSelector:@selector(keyPath)]) + keyPath = [(id)self->value keyPath]; + + formatException = [NSException exceptionWithName:@"WOValidationException" + reason:errorText + userInfo:nil]; + + [[_ctx component] validationFailedWithException:formatException + value:_value + keyPath:keyPath]; + return nil; } +/* generate response */ + - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { - NSFormatter *fmt = nil; - id obj = nil; - unsigned s = 0; + NSFormatter *fmt; + id obj; + unsigned s; obj = [self->value valueInComponent:[_ctx component]]; s = [self->size unsignedIntValueInComponent:[_ctx component]]; - fmt = _getFormatter(self, _ctx); - if (fmt) { - NSString *formattedObj = nil; + if ((fmt = _getFormatter(self, _ctx)) != nil) { + NSString *formattedObj; formattedObj = [fmt editingStringForObjectValue:obj]; @@ -205,6 +200,12 @@ static inline NSFormatter *_getFormatter(WOTextField *self, WOContext *_ctx) { WOResponse_AddUInt(_response, s); WOResponse_AddChar(_response, '"'); } + + if (self->disabled != nil) { + if ([self->disabled boolValueInComponent:[_ctx component]]) + WOResponse_AddCString(_response, " disabled=\"disabled\""); + } + [self appendExtraAttributesToResponse:_response inContext:_ctx]; if (self->otherTagString) { WOResponse_AddChar(_response, ' '); diff --git a/sope-appserver/NGObjWeb/DynamicElements/_WOComplexHyperlink.m b/sope-appserver/NGObjWeb/DynamicElements/_WOComplexHyperlink.m index 058fee76..b159c363 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/_WOComplexHyperlink.m +++ b/sope-appserver/NGObjWeb/DynamicElements/_WOComplexHyperlink.m @@ -182,7 +182,7 @@ static Class NSURLClass = Nil; - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx { - if (self->disabled) { + if (self->disabled != nil) { if ([self->disabled boolValueInComponent:[_ctx component]]) return nil; } @@ -334,6 +334,7 @@ static Class NSURLClass = Nil; @end /* _WOComplexHyperlink */ + @implementation _WOHrefHyperlink static BOOL debugStaticLinks = NO; diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index d1260870..39200753 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=138 +SUBMINOR_VERSION:=139 # v4.5.122 requires libNGExtensions v4.5.153 # v4.5.91 requires libNGExtensions v4.5.134 -- 2.39.5