[IMP] web : replace timezone warning icon with a form widget
This commit is contained in:
committed by
Jérome Maes
parent
53e1fc5d87
commit
e09ea0de92
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -440,24 +440,8 @@
|
||||
</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="WebClient.timezone_systray">
|
||||
<li class="oe_topbar_item oe_timezone_systray" title="Timezone mismatch">
|
||||
<a href="#"><i class="fa fa-exclamation-triangle" style="color:red;"></i></a>
|
||||
</li>
|
||||
<t t-name="WebClient.timezone_warning">
|
||||
<i class="fa fa-exclamation-triangle oe_tz_warning"></i>
|
||||
</t>
|
||||
|
||||
<t t-name="EmbedClient">
|
||||
|
||||
@@ -197,7 +197,8 @@
|
||||
<group>
|
||||
<group string="Localization" name="preferences">
|
||||
<field name="lang"/>
|
||||
<field name="tz"/>
|
||||
<field name="tz" widget="timezone_mismatch" options="{'tz_offset_field': 'tz_offset'}" />
|
||||
<field name="tz_offset" invisible="1"/>
|
||||
</group>
|
||||
<group string="Menus Customization" groups="base.group_no_one">
|
||||
<field name="action_id"/>
|
||||
@@ -280,7 +281,8 @@
|
||||
<button name="preference_change_password" type="object" string="Change password" class="oe_link"/>
|
||||
<group name="preferences" col="4">
|
||||
<field name="lang" readonly="0"/>
|
||||
<field name="tz" readonly="0"/>
|
||||
<field name="tz" widget="timezone_mismatch" options="{'tz_offset_field': 'tz_offset'}" readonly="0"/>
|
||||
<field name="tz_offset" invisible="1"/>
|
||||
<field name="company_id" options="{'no_create': True}" readonly="0"
|
||||
groups="base.group_multi_company"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user