summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/views/form_widgets.js49
-rw-r--r--addons/web/static/src/js/web_client.js30
2 files changed, 48 insertions, 31 deletions
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