[ofbiz-framework] branch trunk updated: Improved: Apply multi-block attr to each application (OFBIZ-11706)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Apply multi-block attr to each application (OFBIZ-11706)

James Yong-2
This is an automated email from the ASF dual-hosted git repository.

jamesyong 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 d94beee  Improved: Apply multi-block attr to each application (OFBIZ-11706)
d94beee is described below

commit d94beee1b6c4dcba2fe2aeca1fa49778d91797e9
Author: James Yong <[hidden email]>
AuthorDate: Fri May 15 15:43:31 2020 +0800

    Improved: Apply multi-block attr to each application (OFBIZ-11706)
   
    For Party application.
    Also fixed bug where external script tag is incorrectly handled
    when extracting internal script tag from freemarker template.
---
 applications/party/widget/partymgr/PartyScreens.xml   |  8 ++++----
 .../org/apache/ofbiz/widget/model/HtmlWidget.java     | 19 +++++++++++++++----
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/applications/party/widget/partymgr/PartyScreens.xml b/applications/party/widget/partymgr/PartyScreens.xml
index 6a8dd6c..0e65511 100644
--- a/applications/party/widget/partymgr/PartyScreens.xml
+++ b/applications/party/widget/partymgr/PartyScreens.xml
@@ -41,7 +41,7 @@ under the License.
             <widgets>
                 <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}">
                     <decorator-section name="body">
-                        <platform-specific><html><html-template location="component://common-theme/template/includes/SetMultipleSelectJs.ftl"/></html></platform-specific>
+                        <platform-specific><html><html-template multi-block="true" location="component://common-theme/template/includes/SetMultipleSelectJs.ftl"/></html></platform-specific>
                         <section>
                             <!-- do check for PARTYMGR, _VIEW permission -->
                             <condition>
@@ -748,7 +748,7 @@ under the License.
                                 <set field="focusFieldName" value="NewUser_USER_PARTY_ID"/>
                             </actions>
                             <widgets>
-                                <platform-specific><html><html-template location="component://common-theme/template/includes/SetDependentDropdownValuesJs.ftl"/></html></platform-specific>
+                                <platform-specific><html><html-template multi-block="true" location="component://common-theme/template/includes/SetDependentDropdownValuesJs.ftl"/></html></platform-specific>
                                 <screenlet title="${uiLabelMap.PartyCreateNewCustomer}">
                                     <include-form name="NewUser" location="component://party/widget/partymgr/PartyForms.xml"/>
                                 </screenlet>
@@ -793,7 +793,7 @@ under the License.
                                 <set field="selectedDependentOption" value="_none_"/>
                             </actions>
                             <widgets>
-                                <platform-specific><html><html-template location="component://common-theme/template/includes/SetDependentDropdownValuesJs.ftl"/></html></platform-specific>
+                                <platform-specific><html><html-template multi-block="true" location="component://common-theme/template/includes/SetDependentDropdownValuesJs.ftl"/></html></platform-specific>
                                 <screenlet title="${uiLabelMap.PartyCreateNewProspect}">
                                     <include-form name="NewUser" location="component://party/widget/partymgr/PartyForms.xml"/>
                                 </screenlet>
@@ -838,7 +838,7 @@ under the License.
                                 <set field="selectedDependentOption" value="_none_"/>
                             </actions>
                             <widgets>
-                                <platform-specific><html><html-template location="component://common-theme/template/includes/SetDependentDropdownValuesJs.ftl"/></html></platform-specific>
+                                <platform-specific><html><html-template multi-block="true" location="component://common-theme/template/includes/SetDependentDropdownValuesJs.ftl"/></html></platform-specific>
                                 <screenlet title="${uiLabelMap.PartyCreateNewEmployee}">
                                     <include-form name="NewUser" location="component://party/widget/partymgr/PartyForms.xml"/>
                                 </screenlet>
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
index acb850c..6f463c4 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
@@ -220,12 +220,19 @@ public class HtmlWidget extends ModelScreenWidget {
                 Document doc = Jsoup.parse(data);
 
                 // extract scripts
-                Elements scriptElements = doc.select("script").remove();
-                if (scriptElements != null) {
+                Elements scriptElements = doc.select("script");
+                if (scriptElements != null && scriptElements.size()>0) {
                     StringBuilder scripts = new StringBuilder();
 
                     for (org.jsoup.nodes.Element script : scriptElements) {
-                        scripts.append(script.data());
+                        String type = script.attr("type");
+                        String src = script.attr("src");
+                        if (UtilValidate.isEmpty(src)) {
+                            if (UtilValidate.isEmpty(type) || type.equals("application/javascript")) {
+                                scripts.append(script.data());
+                                script.remove();
+                            }
+                        }
                     }
 
                     // store script for retrieval by the browser
@@ -242,8 +249,12 @@ public class HtmlWidget extends ModelScreenWidget {
                             + fileName);
                 }
 
+                // check for external script
+                String externalScripts = doc.head().select("script").toString();
+                writer.append(externalScripts);
+
                 // the 'template' block
-                String body = doc.body().html();
+                String body = doc.body().toString();
                 writer.append(body);
             } else {
                 renderHtmlTemplate(writer, this.locationExdr, context);