From 7c2fb9bb16aa5e30cd4e3f49d228e2610c09a5d1 Mon Sep 17 00:00:00 2001 From: Sunil Shrimali Date: Tue, 16 Mar 2021 12:38:18 +0000 Subject: [PATCH 1/2] [IMP] web: set visible overflow on modal for inline domain editor When we have (inline) domain widget within a modal, user can not see all the fields because overflow is hidden on the modals by default. This is not ideal behavior. With this commit, when the inline domain editor is opened with field widget within a modal, we allow field selector to overflow by manually setting visible overflow on the parent modal. The changes are inspired by 'DomainSelectorDialog'. Task ID-2480625 COM odoo/odoo#68586 --- .../web/static/src/js/fields/basic_fields.js | 10 +++++++ .../static/src/js/widgets/domain_selector.js | 10 +++++++ .../tests/widgets/domain_selector_tests.js | 29 +++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index af800d4f708..77d52fd61b5 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -3321,6 +3321,16 @@ var FieldDomain = AbstractField.extend({ this._setState(); }, + /** + * We use the on_attach_callback hook here when widget is attached to the DOM, so that + * the inline 'DomainSelector' widget allows field selector to overflow if widget is + * attached within a modal. + */ + on_attach_callback() { + if (this.domainSelector && !this.inDialog) { + this.domainSelector.on_attach_callback(); + } + }, //-------------------------------------------------------------------------- // Public diff --git a/addons/web/static/src/js/widgets/domain_selector.js b/addons/web/static/src/js/widgets/domain_selector.js index 9fe71ce163f..79c22126593 100644 --- a/addons/web/static/src/js/widgets/domain_selector.js +++ b/addons/web/static/src/js/widgets/domain_selector.js @@ -477,6 +477,16 @@ var DomainSelector = DomainTree.extend({ } }); }, + /** + * If 'DomainSelector' is attached within modal, the modal should have + * visible overflow to allow user to see fields drop-down. + */ + on_attach_callback() { + let $modalBodyEl = this.$el.closest('.modal-body'); + if ($modalBodyEl.length !== 0) { + $modalBodyEl.css('overflow', 'visible'); + } + }, //-------------------------------------------------------------------------- // Public diff --git a/addons/web/static/tests/widgets/domain_selector_tests.js b/addons/web/static/tests/widgets/domain_selector_tests.js index a587117f95a..784a7c632f5 100644 --- a/addons/web/static/tests/widgets/domain_selector_tests.js +++ b/addons/web/static/tests/widgets/domain_selector_tests.js @@ -244,6 +244,35 @@ QUnit.module('DomainSelector', { domainSelector.destroy(); }); + + QUnit.test("inline domain editor in modal", async function (assert) { + assert.expect(1); + const actions = [ + { + id: 5, + name: "Partner Form", + res_model: "partner", + target: "new", + type: "ir.actions.act_window", + views: [["view_ref", "form"]], + }, + ]; + const actionManager = await testUtils.createActionManager({ + actions, + archs: { + "partner,view_ref,form": ` +
+ + + `, + }, + data: this.data, + }); + await actionManager.doAction(5); + assert.strictEqual(document.querySelector('div[name="foo"]').closest('.modal-body').style.overflow, + 'visible', "modal should have visible overflow if there is inline domain field widget"); + actionManager.destroy(); + }); }); }); }); From 424f7e96cb7c880841e0b4688a02ddcda4ba0322 Mon Sep 17 00:00:00 2001 From: Sunil Shrimali Date: Tue, 30 Mar 2021 10:40:36 +0000 Subject: [PATCH 2/2] [IMP] coupon: adapt the changes from domain widget The domain field widget is now adapted to set visible overflow on modal if it iss inline. With that changes, the custom controller for coupon generator is not needed anymore. With this commit, we remove the code related to custom controller of coupon generator that used to set visible overflow on the modal. Task ID-2480625 COM odoo/odoo#68586 --- addons/coupon/__manifest__.py | 5 ---- addons/coupon/static/src/js/coupon.js | 30 ------------------- .../coupon/wizard/coupon_generate_views.xml | 2 +- 3 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 addons/coupon/static/src/js/coupon.js diff --git a/addons/coupon/__manifest__.py b/addons/coupon/__manifest__.py index 84798bd6969..bc60daf3e21 100644 --- a/addons/coupon/__manifest__.py +++ b/addons/coupon/__manifest__.py @@ -21,9 +21,4 @@ 'demo/coupon_demo.xml', ], 'installable': True, - 'assets': { - 'web.assets_backend': [ - 'coupon/static/**/*', - ], - } } diff --git a/addons/coupon/static/src/js/coupon.js b/addons/coupon/static/src/js/coupon.js deleted file mode 100644 index 8e2b01b8a3c..00000000000 --- a/addons/coupon/static/src/js/coupon.js +++ /dev/null @@ -1,30 +0,0 @@ -odoo.define("coupon.CouponGenerateWizard", function (require) { - "use strict"; - - const FormController = require('web.FormController'); - const FormView = require('web.FormView'); - const viewRegistry = require('web.view_registry'); - - const CouponGenerateFormController = FormController.extend({ - - /** - * Display the domain selector popover outside the modal without scroll on modal. - * @override - */ - on_attach_callback() { - this._super(...arguments); - this.el.closest('.modal-body').style.overflow = 'visible'; - }, - }); - - const couponGenerateWizard = FormView.extend({ - config: _.extend({}, FormView.prototype.config, { - Controller: CouponGenerateFormController, - }), - }); - - viewRegistry.add('coupons_generate_form', couponGenerateWizard); - - return couponGenerateWizard; - -}); diff --git a/addons/coupon/wizard/coupon_generate_views.xml b/addons/coupon/wizard/coupon_generate_views.xml index 55bff911d4c..3233b5350ef 100644 --- a/addons/coupon/wizard/coupon_generate_views.xml +++ b/addons/coupon/wizard/coupon_generate_views.xml @@ -4,7 +4,7 @@ coupon.generate.wizard.form coupon.generate.wizard -
+