mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[15.0][MIG] web_dialog_size: migration to 15.0
This commit is contained in:
52
web_dialog_size/static/src/js/web_dialog_draggable.esm.js
Normal file
52
web_dialog_size/static/src/js/web_dialog_draggable.esm.js
Normal file
@@ -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,
|
||||
},
|
||||
});
|
||||
60
web_dialog_size/static/src/js/web_dialog_size.esm.js
Normal file
60
web_dialog_size/static/src/js/web_dialog_size.esm.js
Normal file
@@ -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,
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user