forked from Techsystech/web
[15.0][MIG] web_dialog_size: migration to 15.0
parent
ce486d9597
commit
6c7bfa9f56
|
@ -15,10 +15,21 @@
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/web",
|
"website": "https://github.com/OCA/web",
|
||||||
"category": "web",
|
"category": "web",
|
||||||
"version": "14.0.1.0.0",
|
"version": "15.0.1.0.0",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"depends": ["web"],
|
"depends": ["web"],
|
||||||
"qweb": ["static/src/xml/web_dialog_size.xml"],
|
|
||||||
"data": ["templates/assets.xml"],
|
|
||||||
"installable": True,
|
"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",
|
||||||
|
],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,3 +13,4 @@
|
||||||
|
|
||||||
* Sudhir Arya <sudhir@erpharbor.com>
|
* Sudhir Arya <sudhir@erpharbor.com>
|
||||||
* Pierre Pizzetta <pierre@devreaction.com>
|
* Pierre Pizzetta <pierre@devreaction.com>
|
||||||
|
* Mantas Šniukas <mantas@vialaurea.lt>
|
||||||
|
|
|
@ -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,
|
||||||
|
},
|
||||||
|
});
|
|
@ -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,
|
||||||
|
},
|
||||||
|
});
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="DialogDraggable" owl="1">
|
||||||
|
<t t-slot="default" />
|
||||||
|
</t>
|
||||||
|
</templates>
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="web_dialog_size.ExpandButton" owl="1">
|
||||||
|
<button
|
||||||
|
t-if="props.getsize() == 'dialog_full_screen'"
|
||||||
|
type="button"
|
||||||
|
class="close dialog_button_extend"
|
||||||
|
t-on-click="dialog_button_restore"
|
||||||
|
>
|
||||||
|
<i class="fa fa-compress" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
t-if="props.getsize() != 'dialog_full_screen'"
|
||||||
|
type="button"
|
||||||
|
class="close dialog_button_restore"
|
||||||
|
t-on-click="dialog_button_extend"
|
||||||
|
>
|
||||||
|
<i class="fa fa-expand" />
|
||||||
|
</button>
|
||||||
|
</t>
|
||||||
|
</templates>
|
|
@ -1,5 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<templates id="template" xml:space="preserve">
|
<templates xml:space="preserve">
|
||||||
|
<!-- This is for old Dialog template.
|
||||||
|
Because Odoo haven't done every template to OWL. -->
|
||||||
<t t-extend="Dialog">
|
<t t-extend="Dialog">
|
||||||
<t t-jquery="button.close" t-operation="inner">
|
<t t-jquery="button.close" t-operation="inner">
|
||||||
<i class="fa fa-close" />
|
<i class="fa fa-close" />
|
||||||
|
@ -13,4 +15,16 @@
|
||||||
</button>
|
</button>
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
|
<t t-inherit="web.ActionDialog" t-inherit-mode="extension" owl="1">
|
||||||
|
<xpath expr="//div[hasclass('modal-content')]" position="before">
|
||||||
|
<DialogDraggable />
|
||||||
|
</xpath>
|
||||||
|
<DialogDraggable position="inside">
|
||||||
|
<xpath expr="//div[hasclass('modal-content')]" position="move" />
|
||||||
|
</DialogDraggable>
|
||||||
|
<xpath expr="//button[hasclass('close')]" position="before">
|
||||||
|
<ExpandButton getsize="getSize" setsize="setSize" />
|
||||||
|
</xpath>
|
||||||
|
</t>
|
||||||
</templates>
|
</templates>
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<odoo>
|
|
||||||
<template
|
|
||||||
id="assets_backend"
|
|
||||||
name="web_dialog_size assets"
|
|
||||||
inherit_id="web.assets_backend"
|
|
||||||
>
|
|
||||||
<xpath expr="." position="inside">
|
|
||||||
<link
|
|
||||||
rel="stylesheet"
|
|
||||||
href="/web_dialog_size/static/src/scss/web_dialog_size.scss"
|
|
||||||
/>
|
|
||||||
<script
|
|
||||||
type="text/javascript"
|
|
||||||
src="/web_dialog_size/static/src/js/web_dialog_size.js"
|
|
||||||
/>
|
|
||||||
</xpath>
|
|
||||||
</template>
|
|
||||||
</odoo>
|
|
Loading…
Reference in New Issue