From 3de32db5b92b5617c70bdbdb849aad05a5908f51 Mon Sep 17 00:00:00 2001 From: Samuel Pelletier Date: Sat, 4 Dec 2021 13:48:08 -0500 Subject: [PATCH] Add observeDescendentFields support in AjaxUpdateContainer to observe all descendant fields. Very useful to create updatable container that observe field using special elements like thead, tbody or tr that does not supports inner or outer div. --- .../Ajax/Components/AjaxUpdateContainer.api | 12 +++---- .../Sources/er/ajax/AjaxUpdateContainer.java | 35 +++++++++++++------ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Frameworks/Ajax/Ajax/Components/AjaxUpdateContainer.api b/Frameworks/Ajax/Ajax/Components/AjaxUpdateContainer.api index f2408f430d9..7bfb696772f 100644 --- a/Frameworks/Ajax/Ajax/Components/AjaxUpdateContainer.api +++ b/Frameworks/Ajax/Ajax/Components/AjaxUpdateContainer.api @@ -5,6 +5,7 @@ + @@ -23,12 +24,11 @@ - - - - - - + + + + + diff --git a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUpdateContainer.java b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUpdateContainer.java index 0f62f2f71c3..653798eb9ca 100644 --- a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUpdateContainer.java +++ b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUpdateContainer.java @@ -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 { @@ -91,7 +92,7 @@ public WOActionResults invokeAction(WORequest request, WOContext context) { return results; } - public NSDictionary createAjaxOptions(WOComponent component) { + public NSDictionary createAjaxOptions(WOComponent component) { // PROTOTYPE OPTIONS NSMutableArray ajaxOptionsArray = new NSMutableArray<>(); ajaxOptionsArray.addObject(new AjaxOption("frequency", AjaxOption.NUMBER)); @@ -141,9 +142,9 @@ public static String expandInsertion(String originalInsertion, String beforeDura return expandedInsertion; } - public static NSDictionary removeDefaultOptions(NSDictionary options) { + public static NSDictionary removeDefaultOptions(NSDictionary options) { // PROTOTYPE OPTIONS - NSMutableDictionary mutableOptions = options.mutableClone(); + NSMutableDictionary mutableOptions = options.mutableClone(); if ("'get'".equals(mutableOptions.objectForKey("method"))) { mutableOptions.removeObjectForKey("method"); } @@ -156,10 +157,10 @@ public static NSDictionary removeDefaultOptions(NSDictionary options) { return mutableOptions; } - public NSMutableDictionary createObserveFieldOptions(WOComponent component) { - NSMutableArray ajaxOptionsArray = new NSMutableArray(); + public NSMutableDictionary createObserveFieldOptions(WOComponent component) { + NSMutableArray ajaxOptionsArray = new NSMutableArray<>(); ajaxOptionsArray.addObject(new AjaxOption("observeFieldFrequency", AjaxOption.NUMBER)); - NSMutableDictionary options = AjaxOption.createAjaxOptionsDictionary(ajaxOptionsArray, component, associations()); + NSMutableDictionary options = AjaxOption.createAjaxOptionsDictionary(ajaxOptionsArray, component, associations()); return options; } @@ -192,12 +193,13 @@ public void appendToResponse(WOResponse response, WOContext context) { super.appendToResponse(response, context); - NSDictionary options = createAjaxOptions(component); + NSDictionary 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); @@ -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 nonDefaultOptions = AjaxUpdateContainer.removeDefaultOptions(options); if (nonDefaultOptions.count() > 0) { response.appendContentString(", "); AjaxOptions.appendToResponse(nonDefaultOptions, response, context); @@ -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; } @@ -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); } } @@ -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); } }