Fabien Meghazi (OpenERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-timezone-notification-fme into lp:openerp-web.

Requested reviews:
  OpenERP R&D Team (openerp-dev)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-timezone-notification-fme/+merge/135745

When application starts, warn the user if it's timezone does not match it's 
browser's timezone.
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-timezone-notification-fme/+merge/135745
Your team OpenERP R&D Team is requested to review the proposed merge of 
lp:~openerp-dev/openerp-web/trunk-timezone-notification-fme into lp:openerp-web.
=== modified file 'addons/web/static/src/js/chrome.js'
--- addons/web/static/src/js/chrome.js	2012-11-22 13:02:20 +0000
+++ addons/web/static/src/js/chrome.js	2012-11-22 17:43:02 +0000
@@ -24,7 +24,7 @@
         if (sticky) {
             opts.expires = false;
         }
-        this.$el.notify('create', {
+        return this.$el.notify('create', {
             title: title,
             text: text
         }, opts);
@@ -35,7 +35,7 @@
         if (sticky) {
             opts.expires = false;
         }
-        this.$el.notify('create', 'oe_notification_alert', {
+        return this.$el.notify('create', 'oe_notification_alert', {
             title: title,
             text: text
         }, opts);
@@ -1151,6 +1151,30 @@
         self.user_menu.do_update();
         self.bind_hashchange();
         self.set_title();
+        self.check_timezone();
+    },
+    check_timezone: function() {
+        var self = this;
+        var user_offset = instance.session.user_context.tz_offset;
+        var offset = -(new Date().getTimezoneOffset());
+        // _.str.sprintf()'s zero front padding is buggy with signed decimals, so doing it manually
+        var browser_offset = (offset < 0) ? "-" : "+";
+        browser_offset += _.str.sprintf("%02d", Math.abs(offset / 60));
+        browser_offset += _.str.sprintf("%02d", Math.abs(offset % 60));
+        if (browser_offset !== user_offset) {
+            var notification = this.do_warn(_t("Timezone"), QWeb.render('WebClient.timezone_notification', {
+                user_timezone: instance.session.user_context.tz || 'UTC',
+                user_offset: user_offset,
+                browser_offset: browser_offset,
+            }), true);
+            notification.element.find('.oe_webclient_timezone_notification').on('click', function() {
+                notification.close();
+            }).find('a').on('click', function() {
+                notification.close();
+                self.user_menu.on_menu_settings();
+                return false;
+            });
+        }
     },
     destroy_content: function() {
         _.each(_.clone(this.getChildren()), function(el) {
@@ -1167,11 +1191,11 @@
     },
     do_notify: function() {
         var n = this.notification;
-        n.notify.apply(n, arguments);
+        return n.notify.apply(n, arguments);
     },
     do_warn: function() {
         var n = this.notification;
-        n.warn.apply(n, arguments);
+        return n.warn.apply(n, arguments);
     },
     on_logout: function() {
         var self = this;

=== modified file 'addons/web/static/src/xml/base.xml'
--- addons/web/static/src/xml/base.xml	2012-11-22 13:35:55 +0000
+++ addons/web/static/src/xml/base.xml	2012-11-22 17:43:02 +0000
@@ -443,6 +443,20 @@
     </table>
     </div>
 </t>
+<t t-name="WebClient.timezone_notification">
+    <div class="oe_webclient_timezone_notification">
+        <p>Your user's preference timezone does not match your browser timezone:</p>
+
+        <dl>
+            <dt>User's timezone</dt>
+            <dd><t t-esc="user_timezone"/> (<t t-esc="user_offset"/>)</dd>
+            <dt>Browser's timezone</dt>
+            <dd><t t-esc="browser_offset"/></dd>
+        </dl>
+
+        <p><a href="#">Click here to change your user's timezone.</a></p>
+    </div>
+</t>
 
 <t t-name="EmbedClient">
     <div class="openerp">

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : openerp-dev-gtk@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to