diff --git a/web_dialog_size/__manifest__.py b/web_dialog_size/__manifest__.py index a5be6d098..9e6bb8360 100644 --- a/web_dialog_size/__manifest__.py +++ b/web_dialog_size/__manifest__.py @@ -15,10 +15,21 @@ "Odoo Community Association (OCA)", "website": "https://github.com/OCA/web", "category": "web", - "version": "14.0.1.0.0", + "version": "15.0.1.0.0", "license": "AGPL-3", "depends": ["web"], - "qweb": ["static/src/xml/web_dialog_size.xml"], - "data": ["templates/assets.xml"], "installable": True, + "assets": { + "web.assets_backend": [ + "/web_dialog_size/static/src/js/web_dialog_size.js", + "/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/CONTRIBUTORS.rst b/web_dialog_size/readme/CONTRIBUTORS.rst index 9da11ab82..5f67550d1 100644 --- a/web_dialog_size/readme/CONTRIBUTORS.rst +++ b/web_dialog_size/readme/CONTRIBUTORS.rst @@ -13,3 +13,4 @@ * Sudhir Arya * Pierre Pizzetta +* Mantas Šniukas 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 new file mode 100644 index 000000000..f47eae5fc --- /dev/null +++ b/web_dialog_size/static/src/js/web_dialog_draggable.esm.js @@ -0,0 +1,52 @@ +/** @odoo-module **/ + +import {patch} from "@web/core/utils/patch"; +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 { + 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); + 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, + y: event.y - this.mouse_to_element_ratio.y - y, + }; + document.addEventListener("mousemove", bound_onDrag); + }); + useExternalListener(document, "mouseup", () => + document.removeEventListener("mousemove", bound_onDrag) + ); + } + 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, + y: y - this.mouse_to_element_ratio.y - this.element_position.y, + }; + } + onDrag(event) { + const {x, y} = this.getMovePosition(event); + this.el.style.left = `${x}px`; + this.el.style.top = `${y}px`; + } +} + +DialogDraggable.template = "DialogDraggable"; + +patch(Dialog, "web_dialog_size.DialogDraggable", { + components: { + ...Dialog.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 new file mode 100644 index 000000000..c3f5a083e --- /dev/null +++ b/web_dialog_size/static/src/js/web_dialog_size.esm.js @@ -0,0 +1,60 @@ +/** @odoo-module **/ + +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; + +export class ExpandButton extends Component { + setup() { + this.last_size = this.props.getsize(); + this.config = rpc.query({ + model: "ir.config_parameter", + method: "get_web_dialog_size_config", + }); + + onMounted(() => { + var self = this; + this.config.then(function (r) { + if (r.default_maximize && stop) { + self.dialog_button_extend(); + } + }); + }); + } + + dialog_button_extend() { + this.props.setsize("dialog_full_screen"); + } + + dialog_button_restore() { + this.props.setsize(this.last_size); + } +} + +ExpandButton.template = "web_dialog_size.ExpandButton"; + +patch(ActionDialog.prototype, "web_dialog_size.ActionDialog", { + setup() { + this._super(...arguments); + this.setSize = this.setSize.bind(this); + this.getSize = this.getSize.bind(this); + }, + + setSize(size) { + this.size = size; + this.render(); + }, + + getSize() { + return this.size; + }, +}); + +patch(ActionDialog, "web_dialog_size.ActionDialog", { + components: { + ...ActionDialog.components, + ExpandButton, + }, +}); diff --git a/web_dialog_size/static/src/xml/DialogDraggable.xml b/web_dialog_size/static/src/xml/DialogDraggable.xml new file mode 100644 index 000000000..6cafd8641 --- /dev/null +++ b/web_dialog_size/static/src/xml/DialogDraggable.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/web_dialog_size/static/src/xml/ExpandButton.xml b/web_dialog_size/static/src/xml/ExpandButton.xml new file mode 100644 index 000000000..22318ef73 --- /dev/null +++ b/web_dialog_size/static/src/xml/ExpandButton.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/web_dialog_size/static/src/xml/web_dialog_size.xml b/web_dialog_size/static/src/xml/web_dialog_size.xml index d43a79b73..e7cc3a7b6 100644 --- a/web_dialog_size/static/src/xml/web_dialog_size.xml +++ b/web_dialog_size/static/src/xml/web_dialog_size.xml @@ -1,5 +1,7 @@ - + + @@ -13,4 +15,16 @@ + + + + + + + + + + + + diff --git a/web_dialog_size/templates/assets.xml b/web_dialog_size/templates/assets.xml deleted file mode 100644 index cb68c4697..000000000 --- a/web_dialog_size/templates/assets.xml +++ /dev/null @@ -1,19 +0,0 @@ - - -