From 525e13fb61426cbb0654962b20a9caf20d5012b6 Mon Sep 17 00:00:00 2001 From: tarteo Date: Thu, 2 Mar 2023 15:17:23 +0100 Subject: [PATCH] [IMP] web_dialog_size: Migration to 16.0 [IMP] web_dialog_size: Migration to 16.0 [REM] Remove duplicate configuration readme file [FIX] Make it work for normal dialogs also [FIX] SelectCreateDialog precommit --- web_dialog_size/__manifest__.py | 4 +- web_dialog_size/readme/CONFIGURATION.rst | 3 -- web_dialog_size/readme/CONFIGURE.rst | 1 + .../static/src/js/web_dialog_draggable.esm.js | 36 ++++++------- .../static/src/js/web_dialog_size.esm.js | 40 ++++++++++---- .../static/src/scss/web_dialog_size.scss | 20 +++---- .../static/src/xml/DialogDraggable.xml | 4 +- .../static/src/xml/ExpandButton.xml | 4 +- .../static/src/xml/web_dialog_size.xml | 52 ++++++++++++++++--- 9 files changed, 106 insertions(+), 58 deletions(-) delete mode 100644 web_dialog_size/readme/CONFIGURATION.rst diff --git a/web_dialog_size/__manifest__.py b/web_dialog_size/__manifest__.py index b074138b2..20ccc23eb 100644 --- a/web_dialog_size/__manifest__.py +++ b/web_dialog_size/__manifest__.py @@ -15,7 +15,7 @@ "Odoo Community Association (OCA)", "website": "https://github.com/OCA/web", "category": "web", - "version": "15.0.1.0.1", + "version": "16.0.1.0.0", "license": "AGPL-3", "depends": ["web"], "installable": True, @@ -25,8 +25,6 @@ "/web_dialog_size/static/src/js/web_dialog_size.esm.js", "/web_dialog_size/static/src/js/web_dialog_draggable.esm.js", "/web_dialog_size/static/src/scss/web_dialog_size.scss", - ], - "web.assets_qweb": [ "/web_dialog_size/static/src/xml/web_dialog_size.xml", "/web_dialog_size/static/src/xml/ExpandButton.xml", "/web_dialog_size/static/src/xml/DialogDraggable.xml", diff --git a/web_dialog_size/readme/CONFIGURATION.rst b/web_dialog_size/readme/CONFIGURATION.rst deleted file mode 100644 index 18b1ad078..000000000 --- a/web_dialog_size/readme/CONFIGURATION.rst +++ /dev/null @@ -1,3 +0,0 @@ -By default, the module respects the caller's ``dialog_size`` option. -If you want to override this and have all dialogs maximized by default, -set the configuration parameter ``web_dialog_size.default_maximize`` to ``1``. diff --git a/web_dialog_size/readme/CONFIGURE.rst b/web_dialog_size/readme/CONFIGURE.rst index 902f3316e..243ecce5a 100644 --- a/web_dialog_size/readme/CONFIGURE.rst +++ b/web_dialog_size/readme/CONFIGURE.rst @@ -1,3 +1,4 @@ +By default, the module respects the caller's ``dialog_size`` option. If you want to set dialog boxes maximized by default, you need to: #. Go to *Settings -> Technical -> Parameters -> System Parameters* diff --git a/web_dialog_size/static/src/js/web_dialog_draggable.esm.js b/web_dialog_size/static/src/js/web_dialog_draggable.esm.js index f47eae5fc..92ea85a35 100644 --- a/web_dialog_size/static/src/js/web_dialog_draggable.esm.js +++ b/web_dialog_size/static/src/js/web_dialog_draggable.esm.js @@ -1,19 +1,19 @@ /** @odoo-module **/ -import {patch} from "@web/core/utils/patch"; +import {ActionDialog} from "@web/webclient/actions/action_dialog"; +import {onMounted, useExternalListener} from "@odoo/owl"; +import {useListener} from "@web/core/utils/hooks"; +import {LegacyComponent} from "@web/legacy/legacy_component"; import {Dialog} from "@web/core/dialog/dialog"; -const {useExternalListener} = owl.hooks; -import {useListener} from "web.custom_hooks"; -const {Component} = owl; -export class DialogDraggable extends Component { +export class DialogDraggable extends LegacyComponent { setup() { this.element_position = {x: 0, y: 0}; this.mouse_to_element_ratio = {x: 0, y: 0}; const bound_onDrag = this.onDrag.bind(this); useListener("mousedown", "header.modal-header", (event) => { - const y = parseInt(this.el.offsetTop, 10); - const x = parseInt(this.el.offsetLeft, 10); + const y = parseInt(this.el.querySelector(".modal-content").offsetTop, 10); + const x = parseInt(this.el.querySelector(".modal-content").offsetLeft, 10); this.mouse_to_element_ratio = {x: event.x - x, y: event.y - y}; this.element_position = { x: event.x - this.mouse_to_element_ratio.x - x, @@ -24,11 +24,12 @@ export class DialogDraggable extends Component { useExternalListener(document, "mouseup", () => document.removeEventListener("mousemove", bound_onDrag) ); + onMounted(() => { + this.el.querySelector(".modal-content").classList.add("position-absolute"); + this.el.parentNode.classList.add("position-relative"); + }); } - mounted() { - this.el.classList.add("position-absolute"); - this.el.offsetParent.classList.add("position-relative"); - } + getMovePosition({x, y}) { return { x: x - this.mouse_to_element_ratio.x - this.element_position.x, @@ -37,16 +38,13 @@ export class DialogDraggable extends Component { } onDrag(event) { const {x, y} = this.getMovePosition(event); - this.el.style.left = `${x}px`; - this.el.style.top = `${y}px`; + const el = this.el.querySelector(".modal-content"); + el.style.left = `${x}px`; + el.style.top = `${y}px`; } } DialogDraggable.template = "DialogDraggable"; -patch(Dialog, "web_dialog_size.DialogDraggable", { - components: { - ...Dialog.components, - DialogDraggable, - }, -}); +Dialog.components = Object.assign(Dialog.components || {}, {DialogDraggable}); +Object.assign(ActionDialog.components, {DialogDraggable}); diff --git a/web_dialog_size/static/src/js/web_dialog_size.esm.js b/web_dialog_size/static/src/js/web_dialog_size.esm.js index c3f5a083e..ae2a8c771 100644 --- a/web_dialog_size/static/src/js/web_dialog_size.esm.js +++ b/web_dialog_size/static/src/js/web_dialog_size.esm.js @@ -3,8 +3,9 @@ import {ActionDialog} from "@web/webclient/actions/action_dialog"; import {patch} from "@web/core/utils/patch"; import rpc from "web.rpc"; -const {Component} = owl; -const {onMounted} = owl.hooks; +import {Component, onMounted} from "@odoo/owl"; +import {Dialog} from "@web/core/dialog/dialog"; +import {SelectCreateDialog} from "@web/views/view_dialogs/select_create_dialog"; export class ExpandButton extends Component { setup() { @@ -26,16 +27,18 @@ export class ExpandButton extends Component { dialog_button_extend() { this.props.setsize("dialog_full_screen"); + this.render(); } dialog_button_restore() { this.props.setsize(this.last_size); + this.render(); } } ExpandButton.template = "web_dialog_size.ExpandButton"; -patch(ActionDialog.prototype, "web_dialog_size.ActionDialog", { +patch(Dialog.prototype, "web_dialog_size.Dialog", { setup() { this._super(...arguments); this.setSize = this.setSize.bind(this); @@ -43,18 +46,37 @@ patch(ActionDialog.prototype, "web_dialog_size.ActionDialog", { }, setSize(size) { - this.size = size; + this.props.size = size; this.render(); }, getSize() { - return this.size; + return this.props.size; }, }); -patch(ActionDialog, "web_dialog_size.ActionDialog", { - components: { - ...ActionDialog.components, - ExpandButton, +patch(SelectCreateDialog.prototype, "web_dialog_size.SelectCreateDialog", { + setup() { + this._super(...arguments); + this.setSize = this.setSize.bind(this); + this.getSize = this.getSize.bind(this); + }, + + setSize(size) { + this.props.size = size; + this.render(); + }, + + getSize() { + return this.props.size; }, }); + +Object.assign(ActionDialog.components, {ExpandButton}); +SelectCreateDialog.components = Object.assign(SelectCreateDialog.components || {}, { + ExpandButton, +}); +Dialog.components = Object.assign(Dialog.components || {}, {ExpandButton}); +// Patch annoying validation method +Dialog.props.size.validate = (s) => + ["sm", "md", "lg", "xl", "dialog_full_screen"].includes(s); diff --git a/web_dialog_size/static/src/scss/web_dialog_size.scss b/web_dialog_size/static/src/scss/web_dialog_size.scss index abf3aba73..44e2066f1 100644 --- a/web_dialog_size/static/src/scss/web_dialog_size.scss +++ b/web_dialog_size/static/src/scss/web_dialog_size.scss @@ -1,24 +1,16 @@ .modal { - .dialog_full_screen { + .modal-dialog_full_screen { @include media-breakpoint-up(sm) { max-width: 100%; width: calc(100% - 50px); } } - .modal-header button.close { - font-size: 18px; - &:not(.dialog_button_extend):not(.dialog_button_restore) { - @include media-breakpoint-up(sm) { - margin-left: 15px; - } - } - - &.dialog_button_extend, - .dialog_button_restore { - @include media-breakpoint-down(sm) { - display: none !important; - } + .dialog_button_restore, + .dialog_button_extend { + margin-left: auto; + + .btn-close { + margin: -8px -8px -8px 0px; } } } diff --git a/web_dialog_size/static/src/xml/DialogDraggable.xml b/web_dialog_size/static/src/xml/DialogDraggable.xml index 6cafd8641..bc30ace1c 100644 --- a/web_dialog_size/static/src/xml/DialogDraggable.xml +++ b/web_dialog_size/static/src/xml/DialogDraggable.xml @@ -1,6 +1,8 @@ - +
+ +
diff --git a/web_dialog_size/static/src/xml/ExpandButton.xml b/web_dialog_size/static/src/xml/ExpandButton.xml index 22318ef73..9544445b6 100644 --- a/web_dialog_size/static/src/xml/ExpandButton.xml +++ b/web_dialog_size/static/src/xml/ExpandButton.xml @@ -4,7 +4,7 @@ - + + + + + + + + + + + + + + + + + + @@ -23,8 +41,28 @@ - - + + + + + + + + + + + + + + + props.size + + +