summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js6
-rw-r--r--addons/web/static/src/js/fields/field_registry.js5
-rw-r--r--addons/web/static/src/js/fields/special_fields.js108
-rw-r--r--addons/web/static/src/js/fields/upgrade_fields.js1
4 files changed, 116 insertions, 4 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index 0d7ed2f4fe2..0c7b6d71908 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -277,7 +277,7 @@ var AbstractField = Widget.extend({
* synchronous.
*
* @private
- * @returns {Deferred}
+ * @returns {Deferred|undefined}
*/
_render: function () {
if (this.mode === 'edit') {
@@ -291,7 +291,7 @@ var AbstractField = Widget.extend({
* concrete widget.
*
* @private
- * @returns {Deferred}
+ * @returns {Deferred|undefined}
*/
_renderEdit: function () {
},
@@ -300,7 +300,7 @@ var AbstractField = Widget.extend({
* the concrete widget.
*
* @private
- * @returns {Deferred}
+ * @returns {Deferred|undefined}
*/
_renderReadonly: function () {
},
diff --git a/addons/web/static/src/js/fields/field_registry.js b/addons/web/static/src/js/fields/field_registry.js
index 00423d670fb..c626aebdaec 100644
--- a/addons/web/static/src/js/fields/field_registry.js
+++ b/addons/web/static/src/js/fields/field_registry.js
@@ -13,6 +13,7 @@ var AbstractField = require('web.AbstractField');
var basic_fields = require('web.basic_fields');
var relational_fields = require('web.relational_fields');
var registry = require('web.field_registry');
+var special_fields = require('web.special_fields');
// Basic fields
@@ -63,4 +64,8 @@ registry
.add('statusbar', relational_fields.FieldStatus)
.add('one2many_list', relational_fields.FieldOne2Many);
+// Special fields
+registry
+ .add('timezone_mismatch', special_fields.FieldTimezoneMismatch);
+
});
diff --git a/addons/web/static/src/js/fields/special_fields.js b/addons/web/static/src/js/fields/special_fields.js
new file mode 100644
index 00000000000..50f5e293eb7
--- /dev/null
+++ b/addons/web/static/src/js/fields/special_fields.js
@@ -0,0 +1,108 @@
+odoo.define('web.special_fields', function (require) {
+"use strict";
+
+var core = require('web.core');
+var field_utils = require('web.field_utils');
+var relational_fields = require('web.relational_fields');
+
+var FieldSelection = relational_fields.FieldSelection;
+var _t = core._t;
+
+
+/**
+ * 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 FieldTimezoneMismatch = FieldSelection.extend({
+ /**
+ * @override
+ */
+ start: function () {
+ this._datetime = setInterval(this._renderDateTimeTimezone.bind(this), 1000);
+ return this._super.apply(this, arguments);
+ },
+ /**
+ * @override
+ */
+ destroy: function () {
+ clearInterval(this._datetime);
+ return this._super();
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ * @private
+ */
+ _render: function () {
+ this._super.apply(this, arguments);
+ this._renderTimezoneMismatch.bind(this);
+ },
+ /**
+ * Display the time in the user timezone (reload each second)
+ *
+ * @private
+ */
+ _renderDateTimeTimezone: function () {
+ if (!this.mismatch) {
+ return;
+ }
+ var offset = this.recordData.tz_offset.match(/([+-])([0-9]{2})([0-9]{2})/);
+ offset = (offset[1] === '-' ? -1 : 1) * (parseInt(offset[2])*60 + parseInt(offset[3]));
+ var datetime = field_utils.format.datetime(moment.utc().add(offset, 'minutes'), {timezone: false});
+ var content = this.$option.html().split(' ')[0];
+ content += ' ('+ datetime + ')';
+ this.$option.html(content);
+ },
+ /**
+ * Display the timezone alert
+ *
+ * Note: timezone alert is a span that is added after $el, and $el is now a
+ * set of two elements
+ *
+ * @private
+ */
+ _renderTimezoneMismatch: function () {
+ // we need to clean the warning to have maximum one alert
+ this.$el.last().filter('.o_tz_warning').remove();
+ this.$el = this.$el.first();
+
+ if (this.$option) {
+ this.$option.html(this.$option.html().split(' ')[0]);
+ }
+
+ var userOffset = this.recordData.tz_offset;
+ this.mismatch = false;
+ if (userOffset) {
+ var offset = -(new Date().getTimezoneOffset());
+ var browserOffset = (offset < 0) ? "-" : "+";
+ browserOffset += _.str.sprintf("%02d", Math.abs(offset / 60));
+ browserOffset += _.str.sprintf("%02d", Math.abs(offset % 60));
+ this.mismatch = (browserOffset !== userOffset);
+ }
+
+ if (this.mismatch){
+ var $span = $('<span class="fa fa-exclamation-triangle o_tz_warning"/>');
+ $span.insertAfter(this.$el);
+ $span.attr('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.$el = this.$el.add($span);
+
+ var value = this.$el.val();
+ this.$option = this.$('option').filter(function () {
+ return $(this).attr('value') === value;
+ });
+ this._renderDateTimeTimezone();
+ }
+ },
+});
+
+return {
+ FieldTimezoneMismatch: FieldTimezoneMismatch,
+};
+
+});
diff --git a/addons/web/static/src/js/fields/upgrade_fields.js b/addons/web/static/src/js/fields/upgrade_fields.js
index e24f26cc8cb..8304165b1c7 100644
--- a/addons/web/static/src/js/fields/upgrade_fields.js
+++ b/addons/web/static/src/js/fields/upgrade_fields.js
@@ -180,7 +180,6 @@ var UpgradeRadio = FieldRadio.extend(AbstractFieldUpgrade, {
},
});
-
field_registry
.add('upgrade_boolean', UpgradeBoolean)
.add('upgrade_radio', UpgradeRadio);