svn commit: r1832307 - in /ofbiz/ofbiz-framework/trunk: framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/ themes/common-theme/template/macro/ themes/common-theme/webapp/common/js/util/ themes/rainbowstone/template/ themes/rainbowst...

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

svn commit: r1832307 - in /ofbiz/ofbiz-framework/trunk: framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/ themes/common-theme/template/macro/ themes/common-theme/webapp/common/js/util/ themes/rainbowstone/template/ themes/rainbowst...

jleroux@apache.org
Author: jleroux
Date: Sat May 26 12:42:20 2018
New Revision: 1832307

URL: http://svn.apache.org/viewvc?rev=1832307&view=rev
Log:
Improved: Replace Inline js with External js in renderFormClose macro
(OFBIZ-9846)

Replaced inline js from renderFormClose macro to external js in OfbizUtils.js
Done following:
Used custom data attributes: data-focus-field to define focus field for the form.
Used attribute selector to find elements and set focus on the particular field.

Added "requireValidation" class to all the forms with required fields.

Used the class selector to find such forms & attached Validator plugin to it.

Steps to verify:

At add ProdCatalog page: https://localhost:8443/catalog/control/EditProdCatalog

Dialogs:
New Example dialog on Find Example page
    Go to Find Example page https://localhost:8443/example/control/FindExample
    Click on New Example button
    Validations should work in dialog on form submit.

Additional Changes:

Link for dialog in HtmlMenuMacroLibrary still had the inline code.
Replaced the code with external js code.

Validations on forms rendered with renderSubmitField macro from
HtmlFormMacroLibrary.ftl seems not working
https://demo-trunk.ofbiz.apache.org/partymgr/control/NewEmployee, will create
a separate ticket for it.

jleroux:
I agree about NewEmployee issue
As mentionned Aditya themes/rainbowstone/template/HtmlMenuMacroLibrary.ftl was
redundant, removed
I also removed commented out code in rainbowstone HtmlMenuMacroLibrary.ftl
(left by Aditya while working on the issue I guess)

Thanks: Aditya

Removed:
    ofbiz/ofbiz-framework/trunk/themes/rainbowstone/template/HtmlMenuMacroLibrary.ftl
Modified:
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java
    ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
    ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlMenuMacroLibrary.ftl
    ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlScreenMacroLibrary.ftl
    ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js
    ofbiz/ofbiz-framework/trunk/themes/rainbowstone/template/macro/HtmlMenuMacroLibrary.ftl

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java?rev=1832307&r1=1832306&r2=1832307&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java Sat May 26 12:42:20 2018
@@ -1398,6 +1398,14 @@ public final class MacroFormRenderer imp
         if (!modelForm.getClientAutocompleteFields()) {
             autocomplete = "off";
         }
+        String hasRequiredField = "";
+        for (ModelFormField formField : modelForm.getFieldList()) {
+            if (formField.getRequiredField()) {
+                hasRequiredField = "Y";
+                break;
+            }
+        }
+        String focusFieldName = modelForm.getFocusFieldName();
         StringWriter sr = new StringWriter();
         sr.append("<@renderFormOpen ");
         sr.append(" linkUrl=\"");
@@ -1414,6 +1422,10 @@ public final class MacroFormRenderer imp
         sr.append(autocomplete);
         sr.append("\" name=\"");
         sr.append(name);
+        sr.append("\" focusFieldName=\"");
+        sr.append(focusFieldName);
+        sr.append("\" hasRequiredField=\"");
+        sr.append(hasRequiredField);
         sr.append("\" viewIndexField=\"");
         sr.append(viewIndexField);
         sr.append("\" viewSizeField=\"");
@@ -1429,27 +1441,8 @@ public final class MacroFormRenderer imp
     }
 
     public void renderFormClose(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
-        String focusFieldName = modelForm.getFocusFieldName();
-        String formName = FormRenderer.getCurrentFormName(modelForm, context);
-        String containerId = FormRenderer.getCurrentContainerId(modelForm, context);
-        String hasRequiredField = "";
-        for (ModelFormField formField : modelForm.getFieldList()) {
-            if (formField.getRequiredField()) {
-                hasRequiredField = "Y";
-                break;
-            }
-        }
         StringWriter sr = new StringWriter();
-        sr.append("<@renderFormClose ");
-        sr.append(" focusFieldName=\"");
-        sr.append(focusFieldName);
-        sr.append("\" formName=\"");
-        sr.append(formName);
-        sr.append("\" containerId=\"");
-        sr.append(containerId);
-        sr.append("\" hasRequiredField=\"");
-        sr.append(hasRequiredField);
-        sr.append("\" />");
+        sr.append("<@renderFormClose />");
         executeMacro(writer, sr.toString());
         if (modelForm instanceof ModelSingleForm) {
             renderEndingBoundaryComment(writer, "Form Widget - Form Element", modelForm);

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java?rev=1832307&r1=1832306&r2=1832307&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java Sat May 26 12:42:20 2018
@@ -302,10 +302,14 @@ public class MacroScreenRenderer impleme
         sr.append(style);
         sr.append("\" name=\"");
         sr.append(name);
-        sr.append("\" width=\"");
-        sr.append(width);
-        sr.append("\" height=\"");
-        sr.append(height);
+        if (UtilValidate.isNotEmpty(width)) {
+            sr.append("\" width=\"");
+            sr.append(width);
+        }
+        if (UtilValidate.isNotEmpty(height)) {
+            sr.append("\" height=\"");
+            sr.append(height);
+        }
         sr.append("\" linkUrl=\"");
         sr.append(linkUrl);
         sr.append("\" text=\"");

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl?rev=1832307&r1=1832306&r2=1832307&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl Sat May 26 12:42:20 2018
@@ -319,8 +319,8 @@ under the License.
 
 <#macro renderSingleFormFieldTitle></#macro>
 
-<#macro renderFormOpen linkUrl formType name viewIndexField viewSizeField viewIndex viewSize targetWindow="" containerId="" containerStyle="" autocomplete="" useRowSubmit="">
-  <form method="post" action="${linkUrl}"<#if formType=="upload"> enctype="multipart/form-data"</#if><#if targetWindow?has_content> target="${targetWindow}"</#if><#if containerId?has_content> id="${containerId}"</#if> class=<#if containerStyle?has_content>"${containerStyle}"<#else>"basic-form"</#if> onsubmit="javascript:submitFormDisableSubmits(this)"<#if autocomplete?has_content> autocomplete="${autocomplete}"</#if> name="${name}"><#lt/>
+<#macro renderFormOpen linkUrl formType name viewIndexField viewSizeField viewIndex viewSize targetWindow="" containerId="" containerStyle="" autocomplete="" useRowSubmit="" focusFieldName="" hasRequiredField="">
+  <form method="post" action="${linkUrl}"<#if formType=="upload"> enctype="multipart/form-data"</#if><#if targetWindow?has_content> target="${targetWindow}"</#if> <#if focusFieldName?has_content> data-focus-field="${focusFieldName}"</#if> class="<#if containerStyle?has_content>${containerStyle}<#else>basic-form</#if><#if hasRequiredField?has_content> requireValidation</#if>" onsubmit="javascript:submitFormDisableSubmits(this)"<#if autocomplete?has_content> autocomplete="${autocomplete}"</#if> name="${name}"<#if autocomplete?has_content> autocomplete="${autocomplete}"</#if>><#lt/>
     <#if useRowSubmit?has_content && useRowSubmit>
       <input type="hidden" name="_useRowSubmit" value="Y"/>
       <#if linkUrl?index_of("VIEW_INDEX") &lt;= 0 && linkUrl?index_of(viewIndexField) &lt;= 0>
@@ -331,29 +331,8 @@ under the License.
       </#if>
     </#if>
 </#macro>
-<#macro renderFormClose formName hasRequiredField focusFieldName="" containerId="">
+<#macro renderFormClose>
   </form><#lt/>
-  <#if focusFieldName?has_content>
-    <script language="JavaScript" type="text/javascript">
-      var form = document.${formName};
-      form.${focusFieldName}.focus();
-      <#-- enable the validation plugin for all generated forms
-      only enable the validation if min one field is marked as 'required' -->
-      if (jQuery(form).find(".required").size() > 0) {
-        jQuery(form).validate();
-      }
-    </script><#lt/>
-  </#if>
-  <#if containerId?has_content && hasRequiredField?has_content>
-    <script type="text/javascript">
-      jQuery("#${containerId}").validate({
-        submitHandler:
-          function(form) {
-            form.submit();
-          }
-      });
-    </script>
-  </#if>
 </#macro>
 <#macro renderMultiFormClose>
   </form><#lt/>

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlMenuMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlMenuMacroLibrary.ftl?rev=1832307&r1=1832306&r2=1832307&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlMenuMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlMenuMacroLibrary.ftl Sat May 26 12:42:20 2018
@@ -46,7 +46,7 @@ under the License.
 <img src="${src}"<#if id?has_content> id="${id}"</#if><#if style?has_content> class="${style}"</#if><#if width?has_content> width="${width}"</#if><#if height?has_content> height="${height}"</#if><#if border?has_content> border="${border}"</#if> />
 </#macro>
 
-<#macro renderLink linkUrl parameterList targetWindow uniqueItemName actionUrl linkType="" id="" style="" name="" height="" width="" text="" imgStr="">
+<#macro renderLink linkUrl parameterList targetWindow uniqueItemName actionUrl linkType="" id="" style="" name="" height="600" width="800" text="" imgStr="">
   <#if linkType?has_content && "hidden-form" == linkType>
 <form method="post" action="${actionUrl}"<#if targetWindow?has_content> target="${targetWindow}"</#if> onsubmit="javascript:submitFormDisableSubmits(this)" name="${uniqueItemName}"><#rt/>
     <#list parameterList as parameter>
@@ -55,40 +55,21 @@ under the License.
 </form><#rt/>
   </#if>
   <#if uniqueItemName?has_content && "layered-modal" == linkType>
-<div id="${uniqueItemName}"></div>
-<a href="javascript:void(0);" id="${uniqueItemName}_link"
-    <#if style?has_content>class="${style}"</#if>>
+    <#local params = "{ 'presentation': 'layer'">
+    <#if parameterList?has_content>
+      <#list parameterList as parameter>
+        <#local params += ",'${parameter.name}': '${parameter.value}'">
+      </#list>
+    </#if>
+    <#local params += " }">
+    <a href="javascript:void(0);" id="${uniqueItemName}_link"
+       data-dialog-params="${params}"
+       data-dialog-width="${width}"
+       data-dialog-height="${height}"
+       data-dialog-url="${linkUrl}"
+       <#if text?has_content>data-dialog-title="${text}"</#if>
+       <#if style?has_content>class="${style}"</#if>>
     <#if text?has_content>${text}</#if></a>
-<script type="text/javascript">
-    function ${uniqueItemName}_data() {
-        var data =  {
-                   <#list parameterList as parameter>
-                    "${parameter.name}": "${parameter.value}",
-                    </#list>
-                    "presentation": "layer"
-                };
-                return data;
-            }
-            jQuery("#${uniqueItemName}_link").click(function () {
-                jQuery("#${uniqueItemName}").dialog("open");
-            });
-            jQuery("#${uniqueItemName}").dialog({
-                 autoOpen: false,
-                 <#if text?has_content>title: "${text}",</#if>
-                 height: <#if height == "">600<#else>${height}</#if>,
-                 width: <#if width == "">800<#else>${width}</#if>,
-                 modal: true,
-                 closeOnEscape: true,
-                 open: function() {
-                         jQuery.ajax({
-                             url: "${linkUrl}",
-                             type: "POST",
-                             data: ${uniqueItemName}_data(),
-                             success: function(data) {jQuery("#${uniqueItemName}").html(data);}
-                         });
-                 }
-            });
-      </script>
   <#else>
 <#if (linkType?has_content && "hidden-form" == linkType) || linkUrl?has_content>
 <a<#if id?has_content> id="${id}"</#if><#if style?has_content> class="${style}"</#if><#if name?has_content> name="${name}"</#if><#if targetWindow?has_content> target="${targetWindow}"</#if> href="<#if "hidden-form"==linkType>javascript:document.${uniqueItemName}.submit()<#else>${linkUrl}</#if>"><#rt/>

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlScreenMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlScreenMacroLibrary.ftl?rev=1832307&r1=1832306&r2=1832307&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlScreenMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlScreenMacroLibrary.ftl Sat May 26 12:42:20 2018
@@ -90,7 +90,7 @@ under the License.
   </#if>
 </#macro>
 
-<#macro renderLink parameterList target uniqueItemName linkType actionUrl height width linkUrl targetWindow="" id="" style="" name="" text="" imgStr="">
+<#macro renderLink parameterList target uniqueItemName linkType actionUrl linkUrl targetWindow="" id="" style="" name="" text="" imgStr="" height="600" width="800">
     <#if "layered-modal" != linkType>
         <#if "hidden-form" == linkType>
             <form method="post" action="${actionUrl}" <#if targetWindow?has_content>target="${targetWindow}"</#if> onsubmit="javascript:submitFormDisableSubmits(this)" name="${uniqueItemName}"><#rt/>
@@ -108,41 +108,21 @@ under the License.
             <#if imgStr?has_content>${imgStr}</#if><#if text?has_content>${text}</#if>
         </a>
     <#else>
-        <div id="${uniqueItemName}"></div>
-        <a href="javascript:void(0);" id="${uniqueItemName}_link"
-        <#if style?has_content>class="${style}"</#if>>
-        <#if text?has_content>${text}</#if></a>
-        <script type="text/javascript">
-            function ${uniqueItemName}_data() {
-                var data =  {
-                    <#list parameterList as parameter>
-                        "${parameter.name}": "${parameter.value}",
-                    </#list>
-                    "presentation": "layer"
-                };
-        
-                return data;
-            }
-            jQuery("#${uniqueItemName}_link").click( function () {
-                jQuery("#${uniqueItemName}").dialog("open");
-            });
-            jQuery("#${uniqueItemName}").dialog({
-                 autoOpen: false,
-                 <#if text?has_content>title: "${text}",</#if>
-                 height: ${height},
-                 width: ${width},
-                 modal: true,
-                 closeOnEscape: true,
-                 open: function() {
-                         jQuery.ajax({
-                             url: "${target}",
-                             type: "POST",
-                             data: ${uniqueItemName}_data(),
-                             success: function(data) {jQuery("#${uniqueItemName}").html(data);}
-                         });
-                 }
-            });
-        </script>
+        <#local params = "{ 'presentation': 'layer'">
+        <#if parameterList?has_content>
+          <#list parameterList as parameter>
+            <#local params += ",'${parameter.name}': '${parameter.value}'">
+          </#list>
+        </#if>
+        <#local params += " }">
+        <a href="javascript:void(0);" id="${uniqueItemName}_link"
+           data-dialog-params="${params}"
+           data-dialog-width="${width}"
+           data-dialog-height="${height}"
+           data-dialog-url="${target}"
+           <#if text?has_content>data-dialog-title="${text}"</#if>
+           <#if style?has_content>class="${style}"</#if>>
+           <#if text?has_content>${text}</#if></a>
     </#if>
 </#macro>
 

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js?rev=1832307&r1=1832306&r2=1832307&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js Sat May 26 12:42:20 2018
@@ -105,6 +105,7 @@ function bindObservers(bind_element) {
                     data: params,
                     success: function(data) {
                         dialogContainer.html(data);
+                        bindObservers(dialogContainer);
                     }
                 });
             }
@@ -213,6 +214,15 @@ function bindObservers(bind_element) {
             ajaxAutoCompleter(ajaxUrl, showDescription, defaultMinLength, defaultDelay);
         }
     });
+    jQuery(bind_element).find("[data-focus-field]").each(function() {
+        var element = jQuery(this);
+        var focusField = element.data("focus-field");
+        element.find("[name=" + focusField + "]").focus();
+    });
+    jQuery(bind_element).find(".requireValidation").each(function(){
+        var element = jQuery(this);
+        element.validate();
+    });
 }
 
 /* SelectAll: This utility can be used when we need to use parent and child box combination over any page. Here is the list of tasks it will do:

Modified: ofbiz/ofbiz-framework/trunk/themes/rainbowstone/template/macro/HtmlMenuMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/rainbowstone/template/macro/HtmlMenuMacroLibrary.ftl?rev=1832307&r1=1832306&r2=1832307&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/rainbowstone/template/macro/HtmlMenuMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/themes/rainbowstone/template/macro/HtmlMenuMacroLibrary.ftl Sat May 26 12:42:20 2018
@@ -19,7 +19,7 @@ under the License.
 
 <#include "component://common-theme/template/macro/HtmlMenuMacroLibrary.ftl"/>
 
-<#macro renderLink linkUrl parameterList targetWindow uniqueItemName actionUrl linkType="" id="" style="" name="" height="" width="" text="" imgStr="">
+<#macro renderLink linkUrl parameterList targetWindow uniqueItemName actionUrl linkType="" id="" style="" name="" height="600" width="800" text="" imgStr="">
     <#if linkType?has_content && "hidden-form" == linkType>
     <form method="post" action="${actionUrl}"<#if targetWindow?has_content> target="${targetWindow}"</#if> onsubmit="javascript:submitFormDisableSubmits(this)" name="${uniqueItemName}"><#rt/>
         <#list parameterList as parameter>
@@ -28,40 +28,16 @@ under the License.
     </form><#rt/>
     </#if>
     <#if uniqueItemName?has_content && "layered-modal" == linkType>
-    <div id="${uniqueItemName}"></div>
+        <#local params = "{ 'presentation': 'layer'">
+        <#local params += " }">
     <a href="javascript:void(0);" id="${uniqueItemName}_link"
-        <#if style?has_content>class="${style}"</#if>>
+       data-dialog-params="${params}"
+       data-dialog-width="${width}"
+       data-dialog-height="${height}"
+       data-dialog-url="${linkUrl}"
+       <#if text?has_content>data-dialog-title="${text}"</#if>
+       <#if style?has_content>class="${style}"</#if>>
         <#if text?has_content>${text}</#if></a>
-    <script type="text/javascript">
-        function ${uniqueItemName}_data() {
-            var data =  {
-            <#--list parameterList as parameter>
-                 "${parameter.name}": "${parameter.value}",
-             </#list-->
-                "presentation": "layer"
-            };
-            return data;
-        }
-        jQuery("#${uniqueItemName}_link").click(function () {
-            jQuery("#${uniqueItemName}").dialog("open");
-        });
-        jQuery("#${uniqueItemName}").dialog({
-            autoOpen: false,
-                <#if text?has_content>title: "${text}",</#if>
-        height: <#if height == "">600<#else>${height}</#if>,
-        width: <#if width == "">800<#else>${width}</#if>,
-            modal: true,
-            closeOnEscape: true,
-            open: function() {
-                jQuery.ajax({
-                    url: "${linkUrl}",
-                    type: "POST",
-                    data: ${uniqueItemName}_data(),
-                    success: function(data) {jQuery("#${uniqueItemName}").html(data);}
-                });
-            }
-        });
-    </script>
     <#else>
         <#if (linkType?has_content && "hidden-form" == linkType) || linkUrl?has_content>
         <a<#if id?has_content> id="${id}"</#if><#if style?has_content> class="${style}"</#if><#if name?has_content> name="${name}"</#if><#if targetWindow?has_content> target="${targetWindow}"</#if> href="<#if "hidden-form"==linkType>javascript:document.${uniqueItemName}.submit()<#else>${linkUrl}</#if>"><#rt/>