[ofbiz-framework] branch trunk updated: Improved: Move page-specific script links to html template (OFBIZ-11799)

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: Move page-specific script links to html template (OFBIZ-11799)

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 ede5aa1  Improved: Move page-specific script links to html template (OFBIZ-11799)
ede5aa1 is described below

commit ede5aa15501b13035417f4ad343522d19d430fe9
Author: James Yong <[hidden email]>
AuthorDate: Mon Aug 17 21:52:19 2020 +0800

    Improved: Move page-specific script links to html template (OFBIZ-11799)
   
    ensure select2 lang js is loaded after the main js.
---
 .../template/includes/SetMultipleSelectJs.ftl      | 49 +++++++++++----------
 .../template/includes/SetMultipleSelectJsList.ftl  | 50 ++++++++++++----------
 2 files changed, 53 insertions(+), 46 deletions(-)

diff --git a/themes/common-theme/template/includes/SetMultipleSelectJs.ftl b/themes/common-theme/template/includes/SetMultipleSelectJs.ftl
index acf835d..4d72567 100644
--- a/themes/common-theme/template/includes/SetMultipleSelectJs.ftl
+++ b/themes/common-theme/template/includes/SetMultipleSelectJs.ftl
@@ -20,36 +20,39 @@ under the License.
 <script type="application/javascript">
 jQuery(document).ready(function () {
     var libraryFiles = ["/common/js/jquery/plugins/select2/js/select2-4.0.6.js",
-        "/common/js/jquery/plugins/select2/css/select2-4.0.6.css",
-        "<@jsLangFilesMap>select2</@jsLangFilesMap>"];
+        "/common/js/jquery/plugins/select2/css/select2-4.0.6.css"];
     importLibrary(libraryFiles, function(){
 
-        multiple = jQuery("#${asm_multipleSelect!}");
+        var langFile = ["<@jsLangFilesMap>select2</@jsLangFilesMap>"];
+        importLibrary(langFile, function(){
 
-        <#if asm_title??>
-        // set the dropdown "title" if??
-        multiple.attr('title', '${asm_title}');
-        </#if>
+            multiple = jQuery("#${asm_multipleSelect!}");
 
-        multiple.select2({
-            tags: true,
-            multiple: true,
-            lang: <#if userLogin??>'${userLogin.lastLocale!"en"}'<#else>"en"</#if>,
-            width: "50%"
-        });
+            <#if asm_title??>
+            // set the dropdown "title" if??
+            multiple.attr('title', '${asm_title}');
+            </#if>
 
-        <#if asm_relatedField??> <#-- can be used without related field -->
-        // track possible relatedField changes
-        // on initial focus (focus-field-name must be asm_relatedField) or if the field value changes, select related multi values.
-        typeValue = jQuery('#${asm_typeField}').val();
-        jQuery("#${asm_relatedField}").one('focus', function () {
-            selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
-        });
-        jQuery("#${asm_relatedField}").change(function () {
+            multiple.select2({
+                tags: true,
+                multiple: true,
+                lang: <#if userLogin??>'${userLogin.lastLocale!"en"}'<#else>"en"</#if>,
+                width: "50%"
+            });
+
+            <#if asm_relatedField??> <#-- can be used without related field -->
+            // track possible relatedField changes
+            // on initial focus (focus-field-name must be asm_relatedField) or if the field value changes, select related multi values.
+            typeValue = jQuery('#${asm_typeField}').val();
+            jQuery("#${asm_relatedField}").one('focus', function () {
+                selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
+            });
+            jQuery("#${asm_relatedField}").change(function () {
+                selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
+            });
             selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
+            </#if>
         });
-        selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
-        </#if>
     });
 });
 </script>
diff --git a/themes/common-theme/template/includes/SetMultipleSelectJsList.ftl b/themes/common-theme/template/includes/SetMultipleSelectJsList.ftl
index e59cec4..a201476 100644
--- a/themes/common-theme/template/includes/SetMultipleSelectJsList.ftl
+++ b/themes/common-theme/template/includes/SetMultipleSelectJsList.ftl
@@ -22,35 +22,39 @@ under the License.
       <script type="application/javascript">
           jQuery(document).ready(function () {
               var libraryFiles = ["/common/js/jquery/plugins/select2/js/select2-4.0.6.js",
-                  "/common/js/jquery/plugins/select2/css/select2-4.0.6.css",
-                  "<@jsLangFilesMap>select2</@jsLangFilesMap>"];
+                  "/common/js/jquery/plugins/select2/css/select2-4.0.6.css"];
               importLibrary(libraryFiles, function() {
-                  multiple = jQuery("#${row.asm_multipleSelect!}");
 
-                  <#if row.asm_title??>
-                  // set the dropdown "title" if??
-                  multiple.attr('title', '${row.asm_title}');
-                  </#if>
+                  var langFile = ["<@jsLangFilesMap>select2</@jsLangFilesMap>"];
+                  importLibrary(langFile, function() {
 
-                  multiple.select2({
-                      tags: true,
-                      multiple: true,
-                      lang: <#if userLogin??>'${userLogin.lastLocale!"en"}'<#else>"en"</#if>,
-                      width: "50%"
-                  });
+                      multiple = jQuery("#${row.asm_multipleSelect!}");
 
-                  <#if row.asm_relatedField??> <#-- can be used without related field -->
-                  // track possible relatedField changes
-                  // on initial focus (focus-field-name must be asm_relatedField) or if the field value changes, select related multi values.
-                  typeValue = jQuery('#${row.asm_typeField}').val();
-                  jQuery("#${row.asm_relatedField}").one('focus', function () {
-                      selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
-                  });
-                  jQuery("#${row.asm_relatedField}").change(function () {
+                      <#if row.asm_title??>
+                      // set the dropdown "title" if??
+                      multiple.attr('title', '${row.asm_title}');
+                      </#if>
+
+                      multiple.select2({
+                          tags: true,
+                          multiple: true,
+                          lang: <#if userLogin??>'${userLogin.lastLocale!"en"}'<#else>"en"</#if>,
+                          width: "50%"
+                      });
+
+                      <#if row.asm_relatedField??> <#-- can be used without related field -->
+                      // track possible relatedField changes
+                      // on initial focus (focus-field-name must be asm_relatedField) or if the field value changes, select related multi values.
+                      typeValue = jQuery('#${row.asm_typeField}').val();
+                      jQuery("#${row.asm_relatedField}").one('focus', function () {
+                          selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
+                      });
+                      jQuery("#${row.asm_relatedField}").change(function () {
+                          selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
+                      });
                       selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
+                      </#if>
                   });
-                  selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
-                  </#if>
               });
           });
       </script>