Skip to content

Commit

Permalink
Modify ERMDInspectPageRepetition to support ERMDAjaxNotificationCenter.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarthez committed Dec 12, 2015
1 parent 6f47ce1 commit 9f67d86
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ <h2><webobject name = "Section" /></h2>
</div>
</webobject>
<webobject name = "AttributeRepetition">
<webobject name = "IsNotOmitted">
<webobject name = "LineDiv">
<webobject name = "LineDiv">
<webobject name = "IsNotOmitted">
<div class = "LineInner">
<webobject name = "LabelWrapper">
<webobject name = "HasPropertyName"><webobject name = "PropertyName" /></webobject>
<webobject name = "HasNoPropertyName">
<webobject name = "EmptyLabelSpan">&#160;</webobject>
<webobject name = "EmptyLabelSpan">&nbsp;</webobject>
</webobject>
</webobject>
<webobject name = "AttributeWrapper">
<span>
<webobject name = "SafeWrapper"><webobject name = "AttributeValue" /></webobject>
<webobject name = "shouldObserve">
<webobject name = "SafeWrapper"><webobject name = "AjaxObserveField"><webobject name = "AttributeValue" /></webobject></webobject>
</webobject>
<webobject name = "shouldNotObserve">
<webobject name = "SafeWrapper"><webobject name = "AttributeValue" /></webobject>
</webobject>
</span>
</webobject><div class="AttributeClear"></div>
</webobject>
<div class = "AttributeClear"></div>
</div>
</webobject>
</webobject>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ IsNotOmitted : WOConditional {
negate = true;
}


AttributeValue: WOSwitchComponent {
WOComponentName = d2wContext.componentName;
localContext = d2wContext;
object = object;
}

LineDiv : WOGenericContainer {
elementName = "div";
LineDiv : WOSwitchComponent {
WOComponentName = lineDivComponentName;
id = lineDivId;
class = lineDivClass;
elementName = "div";
}

EmptyLabelSpan : WOGenericContainer {
Expand Down Expand Up @@ -63,6 +66,20 @@ SafeWrapper : D2WEmptyWrapper {

}

shouldObserve : WOConditional {
condition = shouldObserve;
}

shouldNotObserve : WOConditional {
condition = shouldObserve;
negate = true;
}

AjaxObserveField: AjaxObserveField {
action = postChangeNotification;
updateContainerID = d2wContext.ajaxNotificationCenterID;
}

Section: WOSwitchComponent {
WOComponentName = d2wContext.sectionComponentName;
d2wContext = d2wContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package er.modern.directtoweb.components.repetitions;

import com.webobjects.appserver.WOContext;
import com.webobjects.appserver._private.WOGenericContainer;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSNotificationCenter;

import er.ajax.AjaxUpdateContainer;
import er.directtoweb.components.repetitions.ERDInspectPageRepetition;
import er.extensions.foundation.ERXStringUtilities;
import er.extensions.foundation.ERXValueUtilities;
import er.modern.directtoweb.components.ERMDAjaxNotificationCenter;

/**
* Modern tableless inspect/edit page repetition
Expand All @@ -25,7 +30,9 @@
*/
public class ERMDInspectPageRepetition extends ERDInspectPageRepetition {

public int index;
private static final long serialVersionUID = 1L;

public int index;

public ERMDInspectPageRepetition(WOContext context) {
super(context);
Expand Down Expand Up @@ -67,10 +74,10 @@ public String lineDivClass() {
// ERRORS //

public boolean hasNoErrors() {
if(false) {
String keyPath = "errorMessages." + displayNameForProperty();
return d2wContext().valueForKeyPath(keyPath) == null;
}
// if(false) {
// String keyPath = "errorMessages." + displayNameForProperty();
// return d2wContext().valueForKeyPath(keyPath) == null;
// }
return !validationExceptionOccurredForPropertyKey();
}

Expand All @@ -88,10 +95,56 @@ public boolean validationExceptionOccurredForPropertyKey() {
}
}

@SuppressWarnings("unchecked")
public NSArray<String> keyPathsWithValidationExceptions() {
@SuppressWarnings({ "unchecked", "rawtypes" })
public NSArray<String> keyPathsWithValidationExceptions() {
NSArray exceptions = (NSArray)d2wContext().valueForKey("keyPathsWithValidationExceptions");
return exceptions != null ? exceptions : NSArray.EmptyArray;
}

// AJAX notification center support

public boolean isDependent() {
return ERXValueUtilities.booleanValueWithDefault(
d2wContext().valueForKey("isDependent"), false);
}

public boolean shouldObserve() {
return ERXValueUtilities.booleanValueWithDefault(
d2wContext().valueForKey("shouldObserve"), false);
}

public String lineDivId() {
String lineDivId = null;
// only needed if this is a dependent property
if (isDependent()) {
String pageConfiguration = (String) d2wContext().valueForKey(
"pageConfiguration");
lineDivId = pageConfiguration
+ ERXStringUtilities.capitalize(propertyKey()).replaceAll("\\.", "_")
+ "LineUC";
}
return lineDivId;
}

/**
* If the current property key is depending on an observed property key, we
* surround it with an update container.
*
* @return the component name to use as the line div
*/
public String lineDivComponentName() {
String lineDivComponentName = WOGenericContainer.class.getSimpleName();
if (isDependent()) {
lineDivComponentName = AjaxUpdateContainer.class.getSimpleName();
}
return lineDivComponentName;
}

/**
* Posts a change notification when an observed property key has changed.
*/
public void postChangeNotification() {
NSNotificationCenter.defaultCenter().postNotification(
ERMDAjaxNotificationCenter.PropertyChangedNotification, d2wContext());
}
}

0 comments on commit 9f67d86

Please sign in to comment.