Author: jleroux
Date: Thu Mar 23 14:37:47 2017 New Revision: 1788256 URL: http://svn.apache.org/viewvc?rev=1788256&view=rev Log: Implemented: Make sure the local date time uses the time zone from the local browser. (OFBIZ-9264) If a time zone is already set for a user, this new feature won't override it. The user still can set it's own time zone, but if it isn't set, this avoids the time zone set to the default of the server. jelroux: the momentjs license is MIT Thanks: Francis Douet Added: ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy (with props) ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/moment-timezone-with-data.min.js (with props) ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/moment-with-locales.min.js (with props) ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/setUserLocale.js (with props) Modified: ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services.xml ofbiz/ofbiz-framework/trunk/framework/common/webcommon/WEB-INF/common-controller.xml ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonScreens.xml Added: ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy?rev=1788256&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy (added) +++ ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy Thu Mar 23 14:37:47 2017 @@ -0,0 +1,34 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ + +import org.apache.ofbiz.entity.util.EntityQuery +import org.apache.ofbiz.service.GenericServiceException +import org.apache.ofbiz.service.ServiceUtil + +public Map setLocaleFromBrowser() { + Map results = ServiceUtil.returnSuccess() + userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", parameters.userLogin.userLoginId).queryFirst(); + if (userLogin) { + if (!userLogin.lastTimeZone || userLogin.lastTimeZone.equals("null")) { + userLogin.lastTimeZone = parameters.localeName + userLogin.store() + } + } + return results +} Propchange: ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services.xml?rev=1788256&r1=1788255&r2=1788256&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services.xml Thu Mar 23 14:37:47 2017 @@ -940,4 +940,9 @@ under the License. <description>Delete Uom Record</description> <auto-attributes include="pk" mode="IN"/> </service> + + <service name="setLocaleFromBrowser" engine="groovy" location="component://common/groovyScripts/SetLocaleFromBrowser.groovy" invoke="setLocaleFromBrowser" auth="true"> + <description>Set locale from browser.</description> + <attribute name="localeName" type="String" mode="IN" optional="true"/> + </service> </services> Modified: ofbiz/ofbiz-framework/trunk/framework/common/webcommon/WEB-INF/common-controller.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/webcommon/WEB-INF/common-controller.xml?rev=1788256&r1=1788255&r2=1788256&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/common/webcommon/WEB-INF/common-controller.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/common/webcommon/WEB-INF/common-controller.xml Thu Mar 23 14:37:47 2017 @@ -257,28 +257,28 @@ under the License. <response name="success" type="request" value="json"/> <response name="error" type="request" value="json"/> </request-map> - + <request-map uri="getServerTimestamp"> <security https="true" auth="true"/> <event type="service" invoke="getServerTimestamp"/> <response name="success" type="request" value="json"/> <response name="error" type="request" value="json"/> </request-map> - + <request-map uri="getServerTimeZone"> <security https="true" auth="true"/> <event type="service" invoke="getServerTimeZone"/> <response name="success" type="request" value="json"/> <response name="error" type="request" value="json"/> </request-map> - + <request-map uri="getServerTimestampAsLong"> <security https="true" auth="true"/> <event type="service" invoke="getServerTimestampAsLong"/> <response name="success" type="request" value="json"/> <response name="error" type="request" value="json"/> </request-map> - + <request-map uri="qrcode"> <security auth="true" https="false" /> <event type="java" path="org.apache.ofbiz.common.qrcode.QRCodeEvents" invoke="serveQRCodeImage"/> @@ -286,6 +286,14 @@ under the License. <response name="error" type="none" /> </request-map> + <!-- Set local from user's browser --> + <request-map uri="setLocaleFromBrowser"> + <security https="false" auth="false"/> + <event type="service" invoke="setLocaleFromBrowser"/> + <response name="success" type="request" value="json"/> + <response name="error" type="request" value="json"/> + </request-map> + <!--========================== AJAX events =====================--> <!-- View Mappings --> Modified: ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonScreens.xml?rev=1788256&r1=1788255&r2=1788256&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonScreens.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonScreens.xml Thu Mar 23 14:37:47 2017 @@ -143,7 +143,7 @@ under the License. <field-map field-name="themeResources" from-field="layoutSettings" /> </service> <set field="layoutSettings" from-field="themeResources" default-value="${layoutSettings}" global="true" /> - + <set field="initialLocaleComplete" type="String" value="${groovy:parameters?.userLogin?.lastLocale}" default-value="${groovy:locale.toString()}" /> <set field="layoutSettings.javaScripts[+0]" value="${groovy: org.apache.ofbiz.common.JsLanguageFilesMapping.datejs.getFilePath(initialLocaleComplete)}" global="true" /> <set field="layoutSettings.javaScripts[+0]" value="${groovy: org.apache.ofbiz.common.JsLanguageFilesMapping.jquery.getFilePath(initialLocaleComplete)}" global="true" /> @@ -153,6 +153,10 @@ under the License. <set field="layoutSettings.javaScripts[]" value="/images/jquery/plugins/Readmore.js-master/readmore.js" global="true"/> <set field="layoutSettings.javaScripts[]" value="/images/jquery/plugins/jquery-jgrowl/1.4.1/jquery.jgrowl.min.js" global="true"/> <set field="layoutSettings.styleSheets[+0]" value="/images/jquery/plugins/jquery-jgrowl/1.4.1/jquery.jgrowl.min.css" global="true" /> + <!-- Set default user locale from browser --> + <set field="layoutSettings.javaScripts[+0]" value="/images/setUserLocale.js"/> + <set field="layoutSettings.javaScripts[+0]" value="/images/moment-timezone-with-data.min.js" global="true"/> + <set field="layoutSettings.javaScripts[+0]" value="/images/moment-with-locales.min.js" global="true"/> </actions> <widgets /> </section> Added: ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/moment-timezone-with-data.min.js URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/moment-timezone-with-data.min.js?rev=1788256&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/moment-timezone-with-data.min.js (added) +++ ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/moment-timezone-with-data.min.js Thu Mar 23 14:37:47 2017 @@ -0,0 +1,7 @@ +//! moment-timezone.js +//! version : 0.5.10 +//! Copyright (c) JS Foundation and other contributors +//! license : MIT +//! github.com/moment/moment-timezone [... 4 lines stripped ...] Propchange: ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/moment-timezone-with-data.min.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/moment-timezone-with-data.min.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/images/webapp/images/moment-timezone-with-data.min.js ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |