From 078b31dc7f67f3893bcbe5a3b76936490add0e38 Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Tue, 2 Oct 2018 13:08:18 +0000 Subject: [FIX] web: Make datetimepicker configurable in datetime fields The datetimepicker option was introduced to be able to customize the datetime picker widget in date/datetime fields. However, due to the way the _makeDatePicker function was coded, it did not work in datetime fields. Thank to Yajo for the initial fix closes odoo/odoo#27541 --- addons/web/static/src/js/fields/basic_fields.js | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 71aab9f7992..13c5de86491 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -404,6 +404,10 @@ var FieldDate = InputField.extend({ this._super.apply(this, arguments); // use the session timezone when formatting dates this.formatOptions.timezone = true; + this.datepickerOptions = _.defaults( + this.nodeOptions.datepicker || {}, + {defaultDate: this.value} + ); }, /** * In edit mode, instantiates a DateWidget datepicker and listen to changes. @@ -468,13 +472,7 @@ var FieldDate = InputField.extend({ * @private */ _makeDatePicker: function () { - return new datepicker.DateWidget( - this, - _.defaults( - this.nodeOptions.datepicker || {}, - {defaultDate: this.value} - ) - ); + return new datepicker.DateWidget(this, this.datepickerOptions); }, /** @@ -492,6 +490,17 @@ var FieldDate = InputField.extend({ var FieldDateTime = FieldDate.extend({ supportedFieldTypes: ['datetime'], + /** + * @override + */ + init: function () { + this._super.apply(this, arguments); + if (this.value) { + var offset = this.getSession().getTZOffset(this.value); + var displayedValue = this.value.clone().add(offset, 'minutes'); + this.datepickerOptions.defaultDate = displayedValue; + } + }, //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- @@ -522,10 +531,8 @@ var FieldDateTime = FieldDate.extend({ * @private */ _makeDatePicker: function () { - var value = this.value && this.value.clone().add(this.getSession().getTZOffset(this.value), 'minutes'); - return new datepicker.DateTimeWidget(this, {defaultDate: value}); + return new datepicker.DateTimeWidget(this, this.datepickerOptions); }, - /** * Set the datepicker to the right value rather than the default one. * -- cgit v1.2.3 From 57ae9428b47a7ce6cdb75115a62fc268e4af7770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 12 Oct 2018 12:45:38 +0000 Subject: [FIX] web: prevent URL click from opening a record If we click on a link, we only want to open the URL, and not the record when the button is on a list. PR: #27230 --- addons/web/static/src/js/fields/basic_fields.js | 38 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 13c5de86491..b52567d5c7a 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -925,6 +925,9 @@ var HandleWidget = AbstractField.extend({ var FieldEmail = InputField.extend({ className: 'o_field_email', + events: _.extend({}, InputField.prototype.events, { + 'click': '_onClick', + }), prefix: 'mailto', supportedFieldTypes: ['char'], @@ -965,7 +968,21 @@ var FieldEmail = InputField.extend({ this.$el.text(this.value) .addClass('o_form_uri o_text_overflow') .attr('href', this.prefix + ':' + this.value); - } + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Prevent the URL click from opening the record (when used on a list). + * + * @private + * @param {MouseEvent} ev + */ + _onClick: function (ev) { + ev.stopPropagation(); + }, }); var FieldPhone = FieldEmail.extend({ @@ -1057,6 +1074,9 @@ var FieldPhone = FieldEmail.extend({ var UrlWidget = InputField.extend({ className: 'o_field_url', + events: _.extend({}, InputField.prototype.events, { + 'click': '_onClick', + }), supportedFieldTypes: ['char'], /** @@ -1098,7 +1118,21 @@ var UrlWidget = InputField.extend({ .addClass('o_form_uri o_text_overflow') .attr('target', '_blank') .attr('href', this.value); - } + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Prevent the URL click from opening the record (when used on a list). + * + * @private + * @param {MouseEvent} ev + */ + _onClick: function (ev) { + ev.stopPropagation(); + }, }); var AbstractFieldBinary = AbstractField.extend({ -- cgit v1.2.3 From 972c8e9ff55177a3a4e381b74acf5abdeca60be5 Mon Sep 17 00:00:00 2001 From: TWA Date: Thu, 18 Oct 2018 08:55:07 +0000 Subject: [FIX] web: File upload input on_clear event not propagated The handler function was used directly in the code. The MouseEvent wasn't provided in that case. This FIX split the handler function and the processing function so that it doesn't interfere. closes odoo/odoo#27929 --- addons/web/static/src/js/fields/basic_fields.js | 28 ++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 12b7b8f302c..00b8874a6b1 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1363,7 +1363,7 @@ var AbstractFieldBinary = AbstractField.extend({ 'click .o_select_file_button': function () { this.$('.o_input_file').click(); }, - 'click .o_clear_file_button': 'on_clear', + 'click .o_clear_file_button': '_onClearClick', }), init: function (parent, name, record) { this._super.apply(this, arguments); @@ -1449,11 +1449,33 @@ var AbstractFieldBinary = AbstractField.extend({ }); } }, - on_clear: function () { + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + /** + * Clear the file input + * + * @private + */ + _clearFile: function (){ this.set_filename(''); this._setValue(false); this._render(); }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + /** + * On "clear file" button click + * + * @param {MouseEvent} ev + * @private + */ + _onClearClick: function (ev) { + this._clearFile(); + }, }); var FieldBinaryImage = AbstractFieldBinary.extend({ @@ -1510,7 +1532,7 @@ var FieldBinaryImage = AbstractFieldBinary.extend({ this.$('> img').remove(); this.$el.prepend($img); $img.on('error', function () { - self.on_clear(); + self._clearFile(); $img.attr('src', self.placeholder); self.do_warn(_t("Image"), _t("Could not display the selected image.")); }); -- cgit v1.2.3