From e09ea0de92e0d6a6f302a85cc4ee62f1cb77ae69 Mon Sep 17 00:00:00 2001 From: Vidhin Mehta Date: Thu, 30 Apr 2015 11:15:26 +0200 Subject: [PATCH] [IMP] web : replace timezone warning icon with a form widget --- addons/web/static/src/css/base.css | 16 ++---- addons/web/static/src/css/base.sass | 13 ++--- .../web/static/src/js/views/form_widgets.js | 49 ++++++++++++++++++- addons/web/static/src/js/web_client.js | 30 ------------ addons/web/static/src/xml/base.xml | 20 +------- openerp/addons/base/res/res_users_view.xml | 6 ++- 6 files changed, 64 insertions(+), 70 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 8ef5ec07fbb..31cb1d35b5f 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -52,17 +52,6 @@ z-index: 1600; } -.oe_webclient_timezone_notification a { - color: white; - text-decoration: underline; -} -.oe_webclient_timezone_notification p { - margin-top: 1em; -} -.oe_webclient_timezone_notification dt { - font-weight: bold; -} - .oe_timezone_systray span { margin-top: 1px; background-color: #f6cf3b; @@ -664,6 +653,11 @@ color: #4c4c4c; text-decoration: none; } +.oe_tz_warning { + color: red; + float: right; + margin: 4px; +} .openerp .oe_dropdown_menu > li > a:hover { text-decoration: none; } diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 7ab0e150637..b27eddb890e 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -145,6 +145,11 @@ $sheet-padding: 16px // Notifications {{{ +.oe_tz_warning + color: red + float: right + margin: 4px + .oe_indicator z-index: 99999 position: absolute @@ -160,14 +165,6 @@ $sheet-padding: 16px .oe_notification z-index: 1600 -.oe_webclient_timezone_notification - a - color: white - text-decoration: underline - p - margin-top: 1em - dt - font-weight: bold .oe_timezone_systray span margin-top: 1px diff --git a/addons/web/static/src/js/views/form_widgets.js b/addons/web/static/src/js/views/form_widgets.js index 2539b0d7566..685151d8de4 100644 --- a/addons/web/static/src/js/views/form_widgets.js +++ b/addons/web/static/src/js/views/form_widgets.js @@ -888,6 +888,52 @@ var FieldSelection = common.AbstractField.extend(common.ReinitializeFieldMixin, } }); +/** + This widget is intended to display a warning near a label of a 'timezone' field + indicating if the browser timezone is identical (or not) to the selected timezone. + This widget depends on a field given with the param 'tz_offset_field', which contains + the time difference between UTC time and local time, in minutes. +*/ +var TimezoneMismatch = FieldSelection.extend({ + initialize_content: function(){ + this._super.apply(this, arguments); + this.tz_offset_field = (this.options && this.options.tz_offset_field) || this.tz_offset_field || 'tz_offset'; + this.set({"tz_offset": this.field_manager.get_field_value(this.tz_offset_field)}); + this.on("change:tz_offset", this, this.render_value); + }, + start: function(){ + this._super.apply(this, arguments); + // trigger a render_value when tz_offset field change + this.field_manager.on("field_changed:" + this.tz_offset_field, this, function() { + this.set({"tz_offset": this.field_manager.get_field_value(this.tz_offset_field)}); + }); + }, + check_timezone: function(){ + var user_offset = this.get('tz_offset'); + if (user_offset) { + var offset = -(new Date().getTimezoneOffset()); + var browser_offset = (offset < 0) ? "-" : "+"; + browser_offset += _.str.sprintf("%02d", Math.abs(offset / 60)); + browser_offset += _.str.sprintf("%02d", Math.abs(offset % 60)); + return (browser_offset !== user_offset); + } + return false; + }, + render_value: function(){ + this._super.apply(this, arguments); + if(this.check_timezone()){ + this.$label.find('.oe_tz_warning').remove(); + var options = _.extend({ + delay: { show: 501, hide: 0 }, + title: _t("Timezone Mismatch : The timezone of your browser doesn't match the selected one. The time in Odoo is displayed according to your field timezone."), + }); + this.$label.css('white-space', 'normal'); + $(QWeb.render('WebClient.timezone_warning')).appendTo(this.$label); + this.$label.find('.oe_tz_warning').tooltip(options); + } + } +}); + var FieldRadio = common.AbstractField.extend(common.ReinitializeFieldMixin, { template: 'FieldRadio', events: { @@ -1579,7 +1625,8 @@ core.form_widget_registry .add('monetary', FieldMonetary) .add('priority', Priority) .add('kanban_state_selection', KanbanSelection) - .add('statinfo', StatInfo); + .add('statinfo', StatInfo) + .add('timezone_mismatch', TimezoneMismatch); /** diff --git a/addons/web/static/src/js/web_client.js b/addons/web/static/src/js/web_client.js index 1b99fddaef2..ae95001add8 100644 --- a/addons/web/static/src/js/web_client.js +++ b/addons/web/static/src/js/web_client.js @@ -191,7 +191,6 @@ var WebClient = Widget.extend({ self.bind_hashchange(); self.set_title(); - self.check_timezone(); if (self.client_options.action_post_login) { self.action_manager.do_action(self.client_options.action_post_login); delete(self.client_options.action_post_login); @@ -226,35 +225,6 @@ var WebClient = Widget.extend({ }); return false; }, - check_timezone: function() { - var self = this; - return self.alive(new Model('res.users').call('read', [[session.uid], ['tz_offset']])).then(function(result) { - var user_offset = result[0]['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 $icon = $(QWeb.render('WebClient.timezone_systray')); - $icon.on('click', function() { - var notification = self.do_warn(_t("Timezone Mismatch"), QWeb.render('WebClient.timezone_notification', { - user_timezone: 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; - }); - }); - $icon.prependTo(window.$('.oe_systray')); - } - }); - }, /** * When do_action is performed on the WebClient, forward it to the main ActionManager * This allows to widgets that are not inside the ActionManager to perform do_action diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 65d81dcb3e8..18a34bcb87e 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -440,24 +440,8 @@ - -
-

Your user's preference timezone does not match your browser timezone:

- -
-
User's timezone
-
()
-
Browser's timezone
-
-
- -

Click here to change your user's timezone.

-
-
- -
  • - -
  • + + diff --git a/openerp/addons/base/res/res_users_view.xml b/openerp/addons/base/res/res_users_view.xml index d7abde31018..3a1fbecc219 100644 --- a/openerp/addons/base/res/res_users_view.xml +++ b/openerp/addons/base/res/res_users_view.xml @@ -197,7 +197,8 @@ - + + @@ -280,7 +281,8 @@