This is an automated email from the ASF dual-hosted git repository. pgil pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new ab9ca12 Execute a callback with parameters from the request (OFBIZ-12262) ab9ca12 is described below commit ab9ca1222136368f21b32175c2a5daf8a4a57dc4 Author: Gil Portenseigne <p...@apache.org> AuthorDate: Fri Sep 3 14:51:34 2021 +0200 Execute a callback with parameters from the request (OFBIZ-12262) Transform workEffort creation using modal and callback system to illustrate this improvement. A new Attribute `from-event-result` is created for `set-callback` parameters, to indicate that the callback should be called with a parameter which value comes from the event result initiated by the link. In this example, is retrieved from the workeffort creation event the id needed to display the WorkEffortSummary screen of the new data. A new pattern is created to encode in CALLBACK JWT token the data that should be parsed from the event. The parsing occurs in javascript. --- .../webapp/workeffort/WEB-INF/controller.xml | 15 ++++++++++++++ applications/workeffort/widget/CommonScreens.xml | 7 +++++-- applications/workeffort/widget/WorkEffortForms.xml | 4 +++- .../workeffort/widget/WorkEffortScreens.xml | 23 ++++++++++++++++++++++ framework/widget/dtd/widget-common.xsd | 7 +++++++ .../ofbiz/widget/model/CommonWidgetModels.java | 6 ++++++ .../webapp/common/js/util/OfbizUtil.js | 7 +++++++ 7 files changed, 66 insertions(+), 3 deletions(-) diff --git a/applications/workeffort/webapp/workeffort/WEB-INF/controller.xml b/applications/workeffort/webapp/workeffort/WEB-INF/controller.xml index 7c26fa4..2c52a0a 100644 --- a/applications/workeffort/webapp/workeffort/WEB-INF/controller.xml +++ b/applications/workeffort/webapp/workeffort/WEB-INF/controller.xml @@ -72,6 +72,20 @@ under the License. <request-map uri="EditWorkEffortAndAssoc"><security https="true" auth="true"/><response name="success" type="view" value="EditWorkEffortAndAssoc"/></request-map> <request-map uri="AddWorkEffortAndAssoc"><security https="true" auth="true"/><response name="success" type="view" value="AddWorkEffortAndAssoc"/></request-map> + <request-map uri="WorkEffort/Edit"><security https="true" auth="true"/><response name="success" type="view" value="WorkEffort/Edit"/></request-map> + + <request-map uri="WorkEffort/create"> + <security https="true" auth="true"/> + <event type="service" invoke="createWorkEffort"/> + <response name="success" type="request" value="json"/> + <response name="error" type="request" value="json"/> + </request-map> + <request-map uri="WorkEffort/update"> + <security https="true" auth="true"/> + <event type="service" invoke="updateWorkEffort"/> + <response name="success" type="request" value="json"/> + <response name="error" type="request" value="json"/> + </request-map> <request-map uri="EditWorkEffort"><security https="true" auth="true"/><response name="success" type="view" value="EditWorkEffort"/></request-map> <request-map uri="createWorkEffort"> <security https="true" auth="true"/> @@ -334,6 +348,7 @@ under the License. <view-map name="SearchWorkEffort" type="screen" page="component://workeffort/widget/WorkEffortScreens.xml#SearchWorkEffort"/> <view-map name="FoundWorkEfforts" type="screen" page="component://workeffort/widget/WorkEffortScreens.xml#FoundWorkEfforts"/> <view-map name="EditWorkEffort" type="screen" page="component://workeffort/widget/WorkEffortScreens.xml#EditWorkEffort"/> + <view-map name="WorkEffort/Edit" type="screen" page="component://workeffort/widget/WorkEffortScreens.xml#AddWorkEffort"/> <view-map name="ListWorkEfforts" type="screen" page="component://workeffort/widget/WorkEffortScreens.xml#ListWorkEfforts"/> <view-map name="ChildWorkEfforts" type="screen" page="component://workeffort/widget/WorkEffortScreens.xml#ChildWorkEfforts"/> <view-map name="AddWorkEffortAndAssoc" type="screen" page="component://workeffort/widget/WorkEffortScreens.xml#AddWorkEffortAndAssoc"/> diff --git a/applications/workeffort/widget/CommonScreens.xml b/applications/workeffort/widget/CommonScreens.xml index a56be31..10bcf2d 100644 --- a/applications/workeffort/widget/CommonScreens.xml +++ b/applications/workeffort/widget/CommonScreens.xml @@ -89,8 +89,11 @@ under the License. </condition> <widgets> <container style="button-bar"> - <link text="${uiLabelMap.WorkEffortCreate}" target="EditWorkEffort" style="buttontext"> - <parameter param-name="DONE_PAGE" from-field="donePage"/> + <link text="${uiLabelMap.WorkEffortCreate}" target="WorkEffort/Edit" + style="buttontext" link-type="layered-modal"> + <set-callback area-target="WorkEffortSummary" area-id="window"> + <parameter param-name="workEffortId" from-event-result="workEffortId"/> + </set-callback> </link> </container> <section> diff --git a/applications/workeffort/widget/WorkEffortForms.xml b/applications/workeffort/widget/WorkEffortForms.xml index 4bddb6e..54a68f1 100644 --- a/applications/workeffort/widget/WorkEffortForms.xml +++ b/applications/workeffort/widget/WorkEffortForms.xml @@ -185,7 +185,9 @@ under the License. <sort-field name="actualCompletionDate"/> </sort-order> </form> - + <form name="AddWorkEffort" target="WorkEffort/update" type="single" extends="EditWorkEffort"> + <alt-target target="WorkEffort/create" use-when="workEffort==null"/> + </form> <form name="FindWorkEffort" default-map-name="parameters" target="SearchWorkEffort" extends="CommonDynamicSingle" extends-resource="component://common/widget/CommonForms.xml"> <field name="workEffortId" title="${uiLabelMap.WorkEffortWorkEffortId}"><text-find/></field> diff --git a/applications/workeffort/widget/WorkEffortScreens.xml b/applications/workeffort/widget/WorkEffortScreens.xml index 86f3e45..5216cc4 100644 --- a/applications/workeffort/widget/WorkEffortScreens.xml +++ b/applications/workeffort/widget/WorkEffortScreens.xml @@ -120,6 +120,29 @@ under the License. </widgets> </section> </screen> + <screen name="AddWorkEffort"> + <section> + <actions> + <set field="titleProperty" value="PageTitleEditWorkEffort"/> + <set field="workEffortId" from-field="parameters.workEffortId"/> + <set field="thisWorkEffortId" from-field="parameters.workEffortId"/> + <entity-one entity-name="WorkEffort" value-field="workEffort"/> + </actions> + <widgets> + <decorator-screen name="CommonEmbeddedDecorator" location="component://workeffort/widget/CommonScreens.xml"> + <decorator-section name="single"> + <section> + <widgets> + <screenlet> + <include-form name="AddWorkEffort" location="component://workeffort/widget/WorkEffortForms.xml"/> + </screenlet> + </widgets> + </section> + </decorator-section> + </decorator-screen> + </widgets> + </section> + </screen> <screen name="FindWorkEffort"> <section> diff --git a/framework/widget/dtd/widget-common.xsd b/framework/widget/dtd/widget-common.xsd index 4445fe6..d6ddd11 100644 --- a/framework/widget/dtd/widget-common.xsd +++ b/framework/widget/dtd/widget-common.xsd @@ -478,6 +478,13 @@ under the License. <xs:attribute type="xs:string" name="param-name" use="required" /> <xs:attribute type="xs:string" name="from-field" /> <xs:attribute type="xs:string" name="value" /> + <xs:attribute type="xs:string" name="from-event-result"> + <xs:annotation> + <xs:documentation>For set-callback only, indicates the event return variable from where the + parameter value is retrieved. + </xs:documentation> + </xs:annotation> + </xs:attribute> </xs:complexType> </xs:element> <xs:element name="auto-parameters-service"> diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java index 87661e5..f92c2d2 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java @@ -638,6 +638,7 @@ public final class CommonWidgetModels { private FlexibleMapAccessor<Object> fromField; private String name; private FlexibleStringExpander value; + private String fromEventResult; public Parameter(Element element) { this.name = element.getAttribute("param-name"); @@ -645,6 +646,8 @@ public final class CommonWidgetModels { .getAttribute("value")) : null; this.fromField = UtilValidate.isNotEmpty(element.getAttribute("from-field")) ? FlexibleMapAccessor .getInstance(element.getAttribute("from-field")) : null; + this.fromEventResult = UtilValidate.isEmpty(element.getAttribute("from-event-result")) ? null + : element.getAttribute("from-event-result"); } public Parameter(String paramName, String paramValue, boolean isField) { @@ -689,6 +692,9 @@ public final class CommonWidgetModels { if (this.value != null) { return this.value.expandString(context); } + if (this.fromEventResult != null) { + return "_JS_EVENT_RESULT_" + this.fromEventResult + "_"; + } Object retVal = null; if (this.fromField != null && this.fromField.get(context) != null) { retVal = this.fromField.get(context); diff --git a/themes/common-theme/webapp/common/js/util/OfbizUtil.js b/themes/common-theme/webapp/common/js/util/OfbizUtil.js index dc5c13a..2b5899b 100644 --- a/themes/common-theme/webapp/common/js/util/OfbizUtil.js +++ b/themes/common-theme/webapp/common/js/util/OfbizUtil.js @@ -807,6 +807,13 @@ function ajaxSubmitFormUpdateAreas(formName, areaCsvString) { if (containsEventMessage(data)) { displayEventMessage(data) } + while (areaCsvString.indexOf("_JS_EVENT_RESULT_") !== -1) { + temp = areaCsvString; + areaCsvString = temp.substring(0, areaCsvString.indexOf("_JS_EVENT_RESULT_")) + endString = temp.substring(temp.indexOf("_JS_EVENT_RESULT_") + 17) + variableName = endString.substring(0, endString.indexOf("_")) + areaCsvString += data[variableName] + endString.substring(endString.indexOf("_") + 1) + } ajaxUpdateAreas(areaCsvString); $form.trigger("closeCurrentModalAfterAjaxSubmitFormUpdateAreasInSuccess"); }