svn commit: r1835585 - /ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/setUserLocale.js

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

svn commit: r1835585 - /ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/setUserLocale.js

jleroux@apache.org
Author: jleroux
Date: Tue Jul 10 17:27:12 2018
New Revision: 1835585

URL: http://svn.apache.org/viewvc?rev=1835585&view=rev
Log:
Improved: setLocaleFromBrowser should only called once by session
(OFBIZ-10471)

As Deepak mentioned in r1816537, currenlty setLocaleFromBrowser is called each
time a page is refreshed.
We can use sessionStorage to have it called only once by session

Thanks: Deepak for reporting an issue which was boring me for long :)

Modified:
    ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/setUserLocale.js

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/setUserLocale.js
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/setUserLocale.js?rev=1835585&r1=1835584&r2=1835585&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/setUserLocale.js (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/setUserLocale.js Tue Jul 10 17:27:12 2018
@@ -17,15 +17,19 @@ specific language governing permissions
 under the License.
 */
 
-var timezone = moment.tz.guess();
-$.ajax({
-    url: "setLocaleFromBrowser",
-    type: "POST",
-    async: false,
-    data: "localeName=" + timezone,
-    error: function(error) {
-        if (error != "") {
-            console.error("Error while setting user locale: ", error);
+// Only once by session
+if (sessionStorage.getItem("setLocaleFromBrowser") === null || sessionStorage.getItem("setLocaleFromBrowser") !== "done") {
+    sessionStorage.setItem("setLocaleFromBrowser", "done");
+    var timezone = moment.tz.guess();
+    $.ajax({
+        url: "setLocaleFromBrowser",
+        type: "POST",
+        async: false,
+        data: "localeName=" + timezone,
+        error: function(error) {
+            if (error != "") {
+                console.error("Error while setting user locale: ", error);
+            }
         }
-    }
-});
+    });
+}