Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add observeDescendentFields support in AjaxUpdateContainer #966

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Frameworks/Ajax/Ajax/Components/AjaxUpdateContainer.api
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<binding name="elementName"/>
<binding name="observeFieldID"/>
<binding name="observeFieldFrequency"/>
<binding defaults="Boolean" name="observeDescendentFields"/>
<binding name="action"/>
<binding name="fullSubmit"/>
<binding name="skipFunction"/>
Expand All @@ -23,12 +24,11 @@
<binding name="insertionDuration"/>
<binding name="beforeInsertionDuration"/>
<binding name="afterInsertionDuration"/>


<binding name="id"/>
<binding name="asynchronous"/>
<binding defaults="Boolean" name="stopped"/>
<binding name="class"/>
<binding name="style"/>
<binding name="id"/>
<binding name="asynchronous"/>
<binding defaults="Boolean" name="stopped"/>
<binding name="class"/>
<binding name="style"/>
</wo>
</wodefinitions>
35 changes: 24 additions & 11 deletions Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUpdateContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*
* @binding frequency the frequency (in seconds) of a periodic update
* @binding decay a multiplier (default is one) applied to the frequency if the response of the update is unchanged
* @binding observeDescendentFields observe descendent fields
* @binding stopped determines whether a periodic update container loads as stopped.
*/
public class AjaxUpdateContainer extends AjaxDynamicElement {
Expand Down Expand Up @@ -91,7 +92,7 @@ public WOActionResults invokeAction(WORequest request, WOContext context) {
return results;
}

public NSDictionary createAjaxOptions(WOComponent component) {
public NSDictionary<String, String> createAjaxOptions(WOComponent component) {
// PROTOTYPE OPTIONS
NSMutableArray<AjaxOption> ajaxOptionsArray = new NSMutableArray<>();
ajaxOptionsArray.addObject(new AjaxOption("frequency", AjaxOption.NUMBER));
Expand Down Expand Up @@ -141,9 +142,9 @@ public static String expandInsertion(String originalInsertion, String beforeDura
return expandedInsertion;
}

public static NSDictionary removeDefaultOptions(NSDictionary options) {
public static NSDictionary<String, String> removeDefaultOptions(NSDictionary<String, String> options) {
// PROTOTYPE OPTIONS
NSMutableDictionary mutableOptions = options.mutableClone();
NSMutableDictionary<String, String> mutableOptions = options.mutableClone();
if ("'get'".equals(mutableOptions.objectForKey("method"))) {
mutableOptions.removeObjectForKey("method");
}
Expand All @@ -156,10 +157,10 @@ public static NSDictionary removeDefaultOptions(NSDictionary options) {
return mutableOptions;
}

public NSMutableDictionary createObserveFieldOptions(WOComponent component) {
NSMutableArray ajaxOptionsArray = new NSMutableArray();
public NSMutableDictionary<String, String> createObserveFieldOptions(WOComponent component) {
NSMutableArray<AjaxOption> ajaxOptionsArray = new NSMutableArray<>();
ajaxOptionsArray.addObject(new AjaxOption("observeFieldFrequency", AjaxOption.NUMBER));
NSMutableDictionary options = AjaxOption.createAjaxOptionsDictionary(ajaxOptionsArray, component, associations());
NSMutableDictionary<String, String> options = AjaxOption.createAjaxOptionsDictionary(ajaxOptionsArray, component, associations());
return options;
}

Expand Down Expand Up @@ -192,12 +193,13 @@ public void appendToResponse(WOResponse response, WOContext context) {

super.appendToResponse(response, context);

NSDictionary options = createAjaxOptions(component);
NSDictionary<String, String> options = createAjaxOptions(component);

Object frequency = valueForBinding("frequency", component);
String observeFieldID = (String) valueForBinding("observeFieldID", component);
boolean observeDescendentFields = booleanValueForBinding("observeDescendentFields", false, component);

boolean skipFunction = frequency == null && observeFieldID == null && booleanValueForBinding("skipFunction", false, component);
boolean skipFunction = frequency == null && observeFieldID == null && observeDescendentFields == false && booleanValueForBinding("skipFunction", false, component);
if (!skipFunction) {
AjaxUtils.appendScriptHeader(response);

Expand Down Expand Up @@ -232,9 +234,13 @@ public void appendToResponse(WOResponse response, WOContext context) {
boolean fullSubmit = booleanValueForBinding("fullSubmit", false, component);
AjaxObserveField.appendToResponse(response, context, this, observeFieldID, false, id, fullSubmit, createObserveFieldOptions(component));
}
else if (observeDescendentFields) {
boolean fullSubmit = booleanValueForBinding("fullSubmit", false, component);
AjaxObserveField.appendToResponse(response, context, this, id, true, id, fullSubmit, createObserveFieldOptions(component));
}

response.appendContentString("AUC.register('" + id + "'");
NSDictionary nonDefaultOptions = AjaxUpdateContainer.removeDefaultOptions(options);
NSDictionary<String, String> nonDefaultOptions = AjaxUpdateContainer.removeDefaultOptions(options);
if (nonDefaultOptions.count() > 0) {
response.appendContentString(", ");
AjaxOptions.appendToResponse(nonDefaultOptions, response, context);
Expand Down Expand Up @@ -277,6 +283,13 @@ public WOActionResults handleRequest(WORequest request, WOContext context) {
response.appendContentString("AMD.contentUpdated();");
AjaxUtils.appendScriptFooter(response);
}
boolean observeDescendentFields = booleanValueForBinding("observeDescendentFields", false, component);
if (observeDescendentFields) {
AjaxUtils.appendScriptHeader(response);
boolean fullSubmit = booleanValueForBinding("fullSubmit", false, component);
AjaxObserveField.appendToResponse(response, context, this, id, true, id, fullSubmit, createObserveFieldOptions(component));
AjaxUtils.appendScriptFooter(response);
}
return null;
}

Expand All @@ -295,7 +308,7 @@ public static String updateContainerID(WORequest request) {

public static void setUpdateContainerID(WORequest request, String updateContainerID) {
if (updateContainerID != null) {
ERXWOContext.contextDictionary().setObjectForKey(updateContainerID, ERXAjaxApplication.KEY_UPDATE_CONTAINER_ID);
ERXWOContext.contextDictionary().takeValueForKey(updateContainerID, ERXAjaxApplication.KEY_UPDATE_CONTAINER_ID);
}
}

Expand All @@ -312,7 +325,7 @@ public static void setCurrentUpdateContainerID(String updateContainerID) {
ERXWOContext.contextDictionary().removeObjectForKey(AjaxUpdateContainer.CURRENT_UPDATE_CONTAINER_ID_KEY);
}
else {
ERXWOContext.contextDictionary().setObjectForKey(updateContainerID, AjaxUpdateContainer.CURRENT_UPDATE_CONTAINER_ID_KEY);
ERXWOContext.contextDictionary().takeValueForKey(updateContainerID, AjaxUpdateContainer.CURRENT_UPDATE_CONTAINER_ID_KEY);
}
}

Expand Down