From 6a50a125f07a7bec1e45c0b71e8e7438d02b4afa Mon Sep 17 00:00:00 2001 From: Julien Mougenot Date: Mon, 9 Sep 2019 11:05:46 +0000 Subject: [FIX] web: readonly many2one in list views Let's assume an editable list with a many2one and a char, the many2one being readonly. Before this rev., if the user clicked on the many2one, the row was switched in edit more, and the many2one link was given the focus. Now, in the same scenario, the focus is given to the char field which can be edited (i.e. its input). Task 2068280 --- addons/web/static/src/js/fields/relational_fields.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index b2d3379aef1..f713342c240 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -821,6 +821,22 @@ var Many2oneBarcode = FieldMany2One.extend({ var ListFieldMany2One = FieldMany2One.extend({ + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * If in readonly, will never be considered as an active widget. + * + * @override + */ + activate: function () { + if (this.mode === 'readonly') { + return false; + } + return this._super.apply(this, arguments); + }, + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- -- cgit v1.2.3 From ff9a0b87e63fd7d2b38514d21a52cbad7702582d Mon Sep 17 00:00:00 2001 From: Julien Mougenot Date: Fri, 6 Sep 2019 12:33:28 +0000 Subject: [FIX] web: list: m2o doesn't trigger fieldChange when empty Gives time to the user to enter an actual value in m2o in list views. Before this commit, emptying a many2one field (selecting all > BACKSPACE or DELETE) triggered instantly a field_change. This was an issue in multi edition as a field changed triggered instantly a save on selected records without giving time to the user to enter a new value. Now, many2ones only trigger a fieldChange when selecting a new valid value. Task 2068280 --- .../web/static/src/js/fields/relational_fields.js | 78 ++++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index f713342c240..1646ef735a2 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -397,8 +397,10 @@ var FieldMany2One = AbstractField.extend({ kanban_view_ref: this.attrs.kanban_view_ref, on_selected: function (records) { self.reinitialize(records[0]); + }, + on_closed: function () { self.activate(); - } + }, }; }, /** @@ -650,7 +652,6 @@ var FieldMany2One = AbstractField.extend({ * in the dialog (each filter has keys 'description' and 'domain') */ _searchCreatePopup: function (view, ids, context, dynamicFilters) { - var self = this; var options = this._getSearchCreatePopupOptions(view, ids, context, dynamicFilters); return new dialogs.SelectCreateDialog(this, _.extend({}, this.nodeOptions, options)).open(); }, @@ -820,6 +821,23 @@ var Many2oneBarcode = FieldMany2One.extend({ }); var ListFieldMany2One = FieldMany2One.extend({ + events: _.extend({}, FieldMany2One.prototype.events, { + 'focusin input': '_onInputFocusin', + }), + + /** + * @override + */ + init: function () { + this._super.apply(this, arguments); + // when we empty the input, we delay the setValue to prevent from + // triggering the 'fieldChanged' event twice when the user wants set + // another m2o value ; the following attribute is used to determine when + // we skipped the setValue, s.t. we can perform it later on if the user + // didn't select another value + this.mustSetValue = false; + this.m2oDialogFocused = false; + }, //-------------------------------------------------------------------------- // Public @@ -836,6 +854,13 @@ var ListFieldMany2One = FieldMany2One.extend({ } return this._super.apply(this, arguments); }, + /** + * @override + */ + reinitialize: function () { + this.mustSetValue = false; + return this._super.apply(this, arguments); + }, //-------------------------------------------------------------------------- // Private @@ -847,6 +872,52 @@ var ListFieldMany2One = FieldMany2One.extend({ _renderReadonly: function () { this.$el.text(this.m2o_value); }, + /** + * @override + * @private + */ + _searchCreatePopup: function () { + this.m2oDialogFocused = true; + return this._super.apply(this, arguments); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + */ + _onInputFocusin: function () { + this.m2oDialogFocused = false; + }, + /** + * In list views, we don't want to try to trigger a fieldChange when the field + * is being emptied. Instead, it will be triggered as the user leaves the field + * while it is empty. + * + * @override + * @private + */ + _onInputFocusout: function () { + this._super.apply(this, arguments); + if (!this.m2oDialogFocused && this.$input.val() === "" && this.mustSetValue) { + this.reinitialize(false); + } + }, + /** + * Prevents the triggering of an immediate _onFieldChanged when emptying the field. + * + * @override + * @private + */ + _onInputKeyup: function () { + if (this.$input.val() !== "") { + this._super.apply(this, arguments); + } else { + this.mustSetValue = true; + } + }, }); var KanbanFieldMany2One = AbstractField.extend({ @@ -2220,8 +2291,7 @@ var FieldMany2ManyTags = AbstractField.extend({ disable_multiple_selection: false, on_selected: function (records) { self.many2one.reinitialize(records); - self.many2one.activate(); - } + }, }); }; return this.many2one.appendTo(this.$el); -- cgit v1.2.3 From 16f23e8246db4da4eb34552f360974c2a15f553b Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Thu, 19 Sep 2019 06:19:05 +0000 Subject: [FIX] web: fix m2mtags widget to be able to use 'SAVE & NEW' PURPOSE Previously when the 'SAVE & NEW' button was pressed in the 'create and edit...' menu of the many2many_tags widget was pressed, the modal window would close and the button would act exactly like the 'SAVE & CLOSE' button. This was due to the fact that whenever a new record was created and added to the field, it would reset the many2one field it uses for display, which would destroy the edit modal. This commit fixes that by not notifying the underlying many2one field of any change until the modal is closed by the user. This has the disadvantage that tags display, if visible behind the modal 'shade', will not be updated until the modal is closed, but restores the functionality of the save&new button. It also adds a test for this behaviour task-2070454 closes odoo/odoo#37114 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/js/fields/relational_fields.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 1646ef735a2..2a56c6c93e8 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -2286,11 +2286,15 @@ var FieldMany2ManyTags = AbstractField.extend({ this.many2one._getSearchCreatePopupOptions = function (view, ids, context, dynamicFilters) { var options = _getSearchCreatePopupOptions.apply(this, arguments); var domain = this.record.getDomain({fieldName: this.name}); + var m2mRecords = []; return _.extend({}, options, { domain: domain.concat(["!", ["id", "in", self.value.res_ids]]), disable_multiple_selection: false, on_selected: function (records) { - self.many2one.reinitialize(records); + m2mRecords.push(...records); + }, + on_closed: function () { + self.many2one.reinitialize(m2mRecords); }, }); }; -- cgit v1.2.3 From b6288e54461426d7aac6cfc549cee3e90309a093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Thu, 19 Sep 2019 10:23:39 +0000 Subject: [IMP] *: remove image_64 and clean views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are too many image sizes. Since they are stored resized this takes time to generate when saving a new image, it's more rows on the attachment table, more files on the disk, ... 64px is close enough to 128px that it can be removed without a big impact on download size. It will even reduce download and number of requests when both images are displayed because now only one has to be downloaded and then benefit from cache. The difference between the two is typically around 1.5kB which is negligible these days, especially when the request overhead is around 0.5kB already, not even taking into account other factors such as latency. If a 64px image must absolutely be returned, it is still possible to pass the size parameters to the image route. But the current guideline is to handle resizing in the views when necessary. Views ===== - remove width and height attributes when existing CSS rules are overriding them (eg. `.oe_kanban_avatar` in the right context) - add CSS rules instead of width and height attributes when possible - use `object-fit: cover;` where width and height are forced to avoid distortion of non-square images - for products, use `object-fit: contain;` instead, keep ratio but without crop - add new CSS rules where the expected size was max 64px*64px before due to the image size itself - remove `img-fluid` where using size classes to avoid conflicting rules task-2060865 closes odoo/odoo#36147 Signed-off-by: Sébastien Theys (seb) --- addons/web/static/src/js/fields/relational_fields.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 2a56c6c93e8..b89900c9b3b 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -2381,7 +2381,7 @@ var FieldMany2ManyTagsAvatar = FieldMany2ManyTags.extend({ _getRenderTagsContext: function () { var result = this._super.apply(this, arguments); result.avatarModel = this.nodeOptions.avatarModel || this.field.relation; - result.avatarField = this.nodeOptions.avatarField || 'image_64'; + result.avatarField = this.nodeOptions.avatarField || 'image_128'; return result; }, }); -- cgit v1.2.3