summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields/basic_fields.js
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2017-04-12 11:53:42 +0200
committerChristophe Matthieu <chm@odoo.com>2017-04-13 16:55:00 +0200
commitc32724eae06c987e74a0600f1669696e499edc33 (patch)
treee80d8ccc3c08ec4a95889a06f6624e2c63b5bb29 /addons/web/static/src/js/fields/basic_fields.js
parent9c43ad85d463ef8f1fb4b8d16924bc71c0885a55 (diff)
[FIX] web: calendar timezone with user configuration
The client must receive the tzOffset to apply this on all hours. To use the date picker we must change the date to apply the change in the user's tzOffset, without this change the result is wrong. For datetime widget we must change like it to avoid max stack error. The server send the tzOffset, if it's undefined, by default the client use the browser time offset. Every test are change to use tzOffset. A test is added in calendar to use the click by position for the fullcalendar lib. This test create and drag and drop an event to check timezone error and error when we use default value in the context. Use formating date like 2026-04-04T08:00:00Z instead of 2026-04-04 08:00:00 is important for phantomjs, because it's crash without information if the formating is not the standard format. For the parsing, when the client receive a server date the date is utc formating but when it's parsed from the client is in the user's timezone
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js49
1 files changed, 46 insertions, 3 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index af5d9bcf233..69fd7c5b791 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -267,8 +267,9 @@ var FieldDate = InputField.extend({
if (this.mode === 'edit') {
this.datewidget = this._makeDatePicker();
this.datewidget.on('datetime_changed', this, function () {
- if (!this.datewidget.get_value().isSame(this.value)) {
- this._setValue(this.datewidget.get_value());
+ var value = this._getDateWidgetValue();
+ if (!value.isSame(this.value)) {
+ this._setValue(value);
}
});
def = this.datewidget.appendTo('<div>').done(function () {
@@ -286,6 +287,15 @@ var FieldDate = InputField.extend({
//--------------------------------------------------------------------------
/**
+ * return the datepicker value
+ *
+ * @private
+ */
+ _getDateWidgetValue: function () {
+ return this.datewidget.get_value();
+ },
+
+ /**
* Instantiates a new DateWidget datepicker.
*
* @private
@@ -315,13 +325,46 @@ var FieldDateTime = FieldDate.extend({
//--------------------------------------------------------------------------
/**
+ * return the datepicker value
+ *
+ * @private
+ */
+ _getDateWidgetValue: function () {
+ return this.datewidget.get_value().add(-this.getSession().tzOffset, 'minutes');
+ },
+
+ /**
* Instantiates a new DateTimeWidget datepicker rather than DateWidget.
*
* @override
* @private
*/
_makeDatePicker: function () {
- return new datepicker.DateTimeWidget(this, {defaultDate: this.value});
+ var value = this.value && this.value.clone().add(this.getSession().tzOffset, 'minutes');
+ return new datepicker.DateTimeWidget(this, {defaultDate: value});
+ },
+
+ /**
+ * Set the datepicker to the right value rather than the default one.
+ *
+ * @override
+ * @private
+ */
+ _renderEdit: function () {
+ var value = this.value && this.value.clone().add(this.getSession().tzOffset, 'minutes');
+ this.datewidget.set_value(value);
+ this.$input = this.datewidget.$input;
+ },
+
+ /**
+ * FieldDateTime overrides _formatValue to use the session timezone
+ *
+ * @override
+ * @private
+ * @param {Moment} value
+ */
+ _formatValue: function (value) {
+ return field_utils.format.datetime(value, {timezone: true});
},
});