From d1d4e04440be9e6ed10aaa6e002c7b4e4441c479 Mon Sep 17 00:00:00 2001 From: Chill Date: Fri, 8 Dec 2023 16:09:24 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#I8H48V=20app=5Fweb=5Ffullwidth=E5=B0=86w?= =?UTF-8?q?eb=5Fchatter=5Fposition=E7=9A=84=E5=8A=9F=E8=83=BD=E5=8A=A0?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_web_fullwidth/__init__.py | 1 + app_web_fullwidth/__manifest__.py | 8 +- app_web_fullwidth/models/__init__.py | 2 + app_web_fullwidth/models/res_users.py | 21 +++ .../static/src/js/form_compiler.js | 123 ++++++++++++++++++ app_web_fullwidth/views/res_users_views.xml | 13 ++ .../views/webclient_templates.xml | 12 ++ 7 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 app_web_fullwidth/models/res_users.py create mode 100644 app_web_fullwidth/static/src/js/form_compiler.js create mode 100644 app_web_fullwidth/views/res_users_views.xml create mode 100644 app_web_fullwidth/views/webclient_templates.xml diff --git a/app_web_fullwidth/__init__.py b/app_web_fullwidth/__init__.py index 633f8661..cde864ba 100644 --- a/app_web_fullwidth/__init__.py +++ b/app_web_fullwidth/__init__.py @@ -1,2 +1,3 @@ # -*- coding: utf-8 -*- +from . import models diff --git a/app_web_fullwidth/__manifest__.py b/app_web_fullwidth/__manifest__.py index 484db379..516e4c88 100644 --- a/app_web_fullwidth/__manifest__.py +++ b/app_web_fullwidth/__manifest__.py @@ -22,7 +22,7 @@ { 'name': 'Web Form Fullwidth, Full screen full width. Chatter Position ', - 'version': '16.23.02.19', + 'version': '16.23.12.08', 'category': 'web', 'author': 'odooai.cn', 'website': 'https://www.odooai.cn', @@ -44,10 +44,14 @@ 'depends': [ 'web' ], - 'data': [], + 'data': [ + 'views/res_users_views.xml', + 'views/webclient_templates.xml', + ], 'assets': { 'web.assets_backend': [ ('after', 'web/static/src/views/**/*', 'app_web_fullwidth/static/src/scss/app_style_after.scss'), + '/app_web_fullwidth/static/src/js/*.js' ], }, diff --git a/app_web_fullwidth/models/__init__.py b/app_web_fullwidth/models/__init__.py index 40a96afc..12efd2f2 100644 --- a/app_web_fullwidth/models/__init__.py +++ b/app_web_fullwidth/models/__init__.py @@ -1 +1,3 @@ # -*- coding: utf-8 -*- + +from . import res_users diff --git a/app_web_fullwidth/models/res_users.py b/app_web_fullwidth/models/res_users.py new file mode 100644 index 00000000..461dd328 --- /dev/null +++ b/app_web_fullwidth/models/res_users.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + chatter_position = fields.Selection([ + ("auto", "Responsive"), + ("bottom", "Bottom"), + ("sided", "Sided"), + ], default="auto",) + + @property + def SELF_READABLE_FIELDS(self): + return super().SELF_READABLE_FIELDS + ["chatter_position"] + + @property + def SELF_WRITEABLE_FIELDS(self): + return super().SELF_WRITEABLE_FIELDS + ["chatter_position"] diff --git a/app_web_fullwidth/static/src/js/form_compiler.js b/app_web_fullwidth/static/src/js/form_compiler.js new file mode 100644 index 00000000..e9f98369 --- /dev/null +++ b/app_web_fullwidth/static/src/js/form_compiler.js @@ -0,0 +1,123 @@ +/** @odoo-module **/ + +import {patch} from "@web/core/utils/patch"; +import {append} from "@web/core/utils/xml"; +import {MailFormCompiler} from "@mail/views/form/form_compiler"; +import {FormCompiler} from "@web/views/form/form_compiler"; +import {FormController} from "@web/views/form/form_controller"; + +patch(MailFormCompiler.prototype, "web_chatter_position", { + /** + * Patch the visibility of the Sided chatter (`C` above). + * + * @override + */ + compile() { + const res = this._super.apply(this, arguments); + const chatterContainerHookXml = res.querySelector( + ".o_FormRenderer_chatterContainer" + ); + if (!chatterContainerHookXml) { + return res; + } + // Don't patch anything if the setting is "auto": this is the core behaviour + if (odoo.web_chatter_position === "auto") { + return res; + } else if (odoo.web_chatter_position === "sided") { + chatterContainerHookXml.setAttribute("t-if", "!hasAttachmentViewer()"); + } else if (odoo.web_chatter_position === "bottom") { + chatterContainerHookXml.setAttribute("t-if", false); + } + return res; + }, +}); + +patch(FormCompiler.prototype, "web_chatter_position", { + /** + * Patch the css classes of the `Form`, to include an extra `h-100` class. + * Without it, the form sheet will not be full height in some situations, + * looking a bit weird. + * + * @override + */ + compileForm() { + const res = this._super.apply(this, arguments); + if (odoo.web_chatter_position === "sided") { + const classes = res.getAttribute("t-attf-class"); + res.setAttribute("t-attf-class", `${classes} h-100`); + } + return res; + }, + /** + * Patch the visibility of bottom chatters (`A` and `B` above). + * `B` may not exist in some situations, so we ensure it does by creating it. + * + * @override + */ + compile(node, params) { + const res = this._super.apply(this, arguments); + const chatterContainerHookXml = res.querySelector( + ".o_FormRenderer_chatterContainer:not(.o-isInFormSheetBg)" + ); + if (!chatterContainerHookXml) { + return res; + } + if (chatterContainerHookXml.parentNode.classList.contains("o_form_sheet")) { + return res; + } + // Don't patch anything if the setting is "auto": this is the core behaviour + if (odoo.web_chatter_position === "auto") { + return res; + // For "sided", we have to remote the bottom chatter + // (except if there is an attachment viewer, as we have to force bottom) + } else if (odoo.web_chatter_position === "sided") { + const formSheetBgXml = res.querySelector(".o_form_sheet_bg"); + if (!formSheetBgXml) { + return res; + } + chatterContainerHookXml.setAttribute("t-if", false); + // For "bottom", we keep the chatter in the form sheet + // (the one used for the attachment viewer case) + // If it's not there, we create it. + } else if (odoo.web_chatter_position === "bottom") { + if (params.hasAttachmentViewerInArch) { + const sheetBgChatterContainerHookXml = res.querySelector( + ".o_FormRenderer_chatterContainer.o-isInFormSheetBg" + ); + sheetBgChatterContainerHookXml.setAttribute("t-if", true); + chatterContainerHookXml.setAttribute("t-if", false); + } else { + const formSheetBgXml = res.querySelector(".o_form_sheet_bg"); + if (!formSheetBgXml) { + return res; + } + const sheetBgChatterContainerHookXml = + chatterContainerHookXml.cloneNode(true); + sheetBgChatterContainerHookXml.classList.add("o-isInFormSheetBg"); + sheetBgChatterContainerHookXml.setAttribute("t-if", true); + append(formSheetBgXml, sheetBgChatterContainerHookXml); + const sheetBgChatterContainerXml = + sheetBgChatterContainerHookXml.querySelector("ChatterContainer"); + sheetBgChatterContainerXml.setAttribute("isInFormSheetBg", "true"); + chatterContainerHookXml.setAttribute("t-if", false); + } + } + return res; + }, +}); + +patch(FormController.prototype, "web_chatter_position", { + /** + * Patch the css classes of the form container, to include an extra `flex-row` class. + * Without it, it'd go for flex columns direction and it won't look good. + * + * @override + */ + get className() { + const result = this._super(); + if (odoo.web_chatter_position === "sided") { + result["flex-row"] = true; + } + return result; + }, +}); \ No newline at end of file diff --git a/app_web_fullwidth/views/res_users_views.xml b/app_web_fullwidth/views/res_users_views.xml new file mode 100644 index 00000000..a4cdf467 --- /dev/null +++ b/app_web_fullwidth/views/res_users_views.xml @@ -0,0 +1,13 @@ + + + + app.res.users.form + res.users + + + + + + + + \ No newline at end of file diff --git a/app_web_fullwidth/views/webclient_templates.xml b/app_web_fullwidth/views/webclient_templates.xml new file mode 100644 index 00000000..a3808c53 --- /dev/null +++ b/app_web_fullwidth/views/webclient_templates.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file