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

commit 149e90e60827115754c6bb2465634f1fac461d0e
Author: James Yong <jamesy...@apache.org>
AuthorDate: Wed Aug 19 10:17:51 2020 +0800

    Improved: Move page-specific script links to html template (OFBIZ-11799)
    
    use importLibrary js function to load moment js.
---
 .../webapp/common/js/util/setUserTimeZone.js       | 27 +++++++++++++---------
 themes/common-theme/widget/CommonScreens.xml       |  2 --
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/themes/common-theme/webapp/common/js/util/setUserTimeZone.js 
b/themes/common-theme/webapp/common/js/util/setUserTimeZone.js
index b74504b..0c29340 100644
--- a/themes/common-theme/webapp/common/js/util/setUserTimeZone.js
+++ b/themes/common-theme/webapp/common/js/util/setUserTimeZone.js
@@ -19,16 +19,21 @@ under the License.
 
 // Only once by session (ref 
https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)
 if (sessionStorage.getItem("SetTimeZoneFromBrowser") === null || 
sessionStorage.getItem("SetTimeZoneFromBrowser") !== "done") {
-    var timezone = moment.tz.guess();
-    $.ajax({
-        url: "SetTimeZoneFromBrowser",
-        type: "POST",
-        async: false,
-        data: "localeName=" + timezone,
-        success: function(success) {
-            if (success._ERROR_MESSAGE_ === undefined && 
success._ERROR_MESSAGE_LIST_ === undefined) {
-                sessionStorage.setItem("SetTimeZoneFromBrowser", "done");
-            }
-        }
+    var libraryFiles = 
["/common/js/plugins/moment-timezone/moment-with-locales.min.js"];
+    importLibrary(libraryFiles, function(){
+        
importLibrary(["/common/js/plugins/moment-timezone/moment-timezone-with-data.min.js"],
 function(){
+            var timezone = moment.tz.guess();
+            $.ajax({
+                url: "SetTimeZoneFromBrowser",
+                type: "POST",
+                async: false,
+                data: "localeName=" + timezone,
+                success: function(success) {
+                    if (success._ERROR_MESSAGE_ === undefined && 
success._ERROR_MESSAGE_LIST_ === undefined) {
+                        sessionStorage.setItem("SetTimeZoneFromBrowser", 
"done");
+                    }
+                }
+            });
+        });
     });
 }
diff --git a/themes/common-theme/widget/CommonScreens.xml 
b/themes/common-theme/widget/CommonScreens.xml
index a49716a..292a50b 100644
--- a/themes/common-theme/widget/CommonScreens.xml
+++ b/themes/common-theme/widget/CommonScreens.xml
@@ -130,8 +130,6 @@ under the License.
                 <set field="layoutSettings.styleSheets[+0]" 
value="/common/js/jquery/plugins/jquery-jgrowl/jquery.jgrowl-1.4.6.min.css" 
global="true" />
                 <!-- Set default user locale from browser -->
                 <set field="layoutSettings.javaScripts[+0]" 
value="/common/js/util/setUserTimeZone.js"/>
-                <set field="layoutSettings.javaScripts[+0]" 
value="/common/js/plugins/moment-timezone/moment-timezone-with-data.min.js" 
global="true"/>
-                <set field="layoutSettings.javaScripts[+0]" 
value="/common/js/plugins/moment-timezone/moment-with-locales.min.js" 
global="true"/>
             </actions>
             <widgets />
         </section>

Reply via email to