You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2020/10/02 12:35:41 UTC

[ofbiz-framework] branch trunk updated: Fixed: Open FTL File from browser (OFBIZ-12018)

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 10fbedb  Fixed: Open FTL File from browser (OFBIZ-12018)
10fbedb is described below

commit 10fbedbce0dff5afab729f07e19fd40756a61b43
Author: James Yong <ja...@apache.org>
AuthorDate: Fri Oct 2 20:33:44 2020 +0800

    Fixed: Open FTL File from browser (OFBIZ-12018)
    
    Not able to open source file when clicking on named border in ecomseo landing page
    
    Thanks Jacques for reporting
---
 .../src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java  | 6 ++++--
 .../apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java    | 9 +++++++--
 themes/common-theme/webapp/common/js/util/OfbizUtil.js           | 5 +++--
 3 files changed, 14 insertions(+), 6 deletions(-)

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 fb70871..708a84b 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
@@ -176,8 +176,10 @@ public class HtmlWidget extends ModelScreenWidget {
                         insertWidgetNamedBorder = true;
                     }
                 }
+                String contextPath = "";
                 if (insertWidgetNamedBorder) {
-                    writer.append(HtmlWidgetRenderer.buildNamedBorder("Begin", "Template", location, namedBorderType));
+                    contextPath = ((HttpServletRequest) context.get("request")).getContextPath();
+                    writer.append(HtmlWidgetRenderer.buildNamedBorder("Begin", "Template", location, namedBorderType, contextPath));
                 }
 
                 Template template = null;
@@ -189,7 +191,7 @@ public class HtmlWidget extends ModelScreenWidget {
                 FreeMarkerWorker.renderTemplate(template, context, writer);
 
                 if (insertWidgetNamedBorder) {
-                    writer.append(HtmlWidgetRenderer.buildNamedBorder("End", "Template", location, namedBorderType));
+                    writer.append(HtmlWidgetRenderer.buildNamedBorder("End", "Template", location, namedBorderType, contextPath));
                 }
                 if (insertWidgetBoundaryComments) {
                     writer.append(HtmlWidgetRenderer.buildBoundaryComment("End", "Template", location));
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java
index 99ee553..950c6f2 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java
@@ -23,6 +23,7 @@ import java.util.List;
 
 import org.apache.ofbiz.base.util.UtilHtml;
 import org.apache.ofbiz.base.util.UtilHttp;
+import org.apache.ofbiz.product.category.SeoConfigUtil;
 import org.apache.ofbiz.widget.model.ModelWidget;
 
 /**
@@ -74,7 +75,8 @@ public class HtmlWidgetRenderer {
         return "<!-- " + boundaryType + " " + widgetType + " " + widgetName + " -->" + WHITE_SPACE;
     }
 
-    public static String buildNamedBorder(String boundaryType, String widgetType, String widgetName, ModelWidget.NamedBorderType namedBorderType) {
+    public static String buildNamedBorder(String boundaryType, String widgetType, String widgetName,
+                                          ModelWidget.NamedBorderType namedBorderType, String contextPath) {
         List<String> themeBasePathsToExempt = UtilHtml.getVisualThemeFolderNamesToExempt();
         if (!themeBasePathsToExempt.stream().anyMatch(widgetName::contains)) {
             // add additional visual label for non-theme ftl
@@ -82,7 +84,10 @@ public class HtmlWidgetRenderer {
                 String fileName = widgetName.substring(widgetName.lastIndexOf("/") + 1);
                 switch (namedBorderType) {
                 case SOURCE:
-                    return "<div class='info-container'><span class='info-overlay-item info-cursor-none' data-source='" + widgetName + "'>"
+                    return "<div class='info-container'><span class='info-overlay-item info-cursor-none' data-source='"
+                            + widgetName + "' data-target='" + contextPath
+                            + (SeoConfigUtil.isCategoryUrlEnabled(contextPath) ? "" : "/control")
+                            + "/openSourceFile'>"
                             + fileName
                             + "</span>";
                 case LABEL:
diff --git a/themes/common-theme/webapp/common/js/util/OfbizUtil.js b/themes/common-theme/webapp/common/js/util/OfbizUtil.js
index 90a1a93..a81f9a2 100644
--- a/themes/common-theme/webapp/common/js/util/OfbizUtil.js
+++ b/themes/common-theme/webapp/common/js/util/OfbizUtil.js
@@ -48,10 +48,11 @@ $(document).ready(function() {
         selectList.each(function(){
             const $this = $(this);
             $this.removeClass("info-cursor-none");
-            var sourceLocaton = $this.data("source");
+            let sourceLocaton = $this.data("source");
+            let target = $this.data("target");
             $this.addClass("info-cursor").click(function(){
                 jQuery.ajax({
-                    url: 'openSourceFile',
+                    url: target,
                     type: "POST",
                     data: {sourceLocation:sourceLocaton},
                     success: function(data) {