diff --git a/setup/web_chatter_position/odoo/addons/web_chatter_position b/setup/web_chatter_position/odoo/addons/web_chatter_position new file mode 120000 index 000000000..e34df916d --- /dev/null +++ b/setup/web_chatter_position/odoo/addons/web_chatter_position @@ -0,0 +1 @@ +../../../../web_chatter_position \ No newline at end of file diff --git a/setup/web_chatter_position/setup.py b/setup/web_chatter_position/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_chatter_position/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_chatter_position/README.rst b/web_chatter_position/README.rst new file mode 100644 index 000000000..6edab7831 --- /dev/null +++ b/web_chatter_position/README.rst @@ -0,0 +1,89 @@ +================ +Chatter Position +================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/15.0/web_chatter_position + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_chatter_position + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Configurable Chatter Position. +Change Chatter Position in User Preferences. +Change Chatter Position on the fly. +Supports Both Community & Enterprise Edition. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. There's a **Chatter Position** option in **User Preferences**, where you can choose between "bottom" and "sided". +#. The position can also be changed on the fly using a new button on the top left side of Form Views. + +Known issues / Roadmap +====================== + +* This module implements the same feature as **web_responsive**. Once the enterprise interface is moved to community in version 16, only this module will be needed. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Hynsys Technologies +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Hynsys Technologies +* Juan Miguel Sánchez Arce + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_chatter_position/__init__.py b/web_chatter_position/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/web_chatter_position/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_chatter_position/__manifest__.py b/web_chatter_position/__manifest__.py new file mode 100644 index 000000000..2fbc833b0 --- /dev/null +++ b/web_chatter_position/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2022 Hynsys Technologies +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Chatter Position", + "summary": "Add an option to change the chatter position", + "version": "16.0.1.0.0", + "author": "Hynsys Technologies, Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "license": "LGPL-3", + "category": "Extra Tools", + "depends": ["web", "mail"], + "data": ["views/res_users.xml", "views/web.xml"], + "assets": { + "web.assets_backend": [ + "/web_chatter_position/static/src/**/*.js", + ], + }, +} diff --git a/web_chatter_position/i18n/web_chatter_position.pot b/web_chatter_position/i18n/web_chatter_position.pot new file mode 100644 index 000000000..1645b038c --- /dev/null +++ b/web_chatter_position/i18n/web_chatter_position.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_chatter_position +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_chatter_position +#: model:ir.model.fields.selection,name:web_chatter_position.selection__res_users__chatter_position__bottom +msgid "Bottom" +msgstr "" + +#. module: web_chatter_position +#: model:ir.model.fields,field_description:web_chatter_position.field_res_users__chatter_position +msgid "Chatter Position" +msgstr "" + +#. module: web_chatter_position +#: model:ir.model.fields.selection,name:web_chatter_position.selection__res_users__chatter_position__sided +msgid "Sided" +msgstr "" + +#. module: web_chatter_position +#: model:ir.model,name:web_chatter_position.model_res_users +msgid "Users" +msgstr "" diff --git a/web_chatter_position/models/__init__.py b/web_chatter_position/models/__init__.py new file mode 100644 index 000000000..883516533 --- /dev/null +++ b/web_chatter_position/models/__init__.py @@ -0,0 +1 @@ +from . import res_users diff --git a/web_chatter_position/models/res_users.py b/web_chatter_position/models/res_users.py new file mode 100644 index 000000000..3cfb7b7ac --- /dev/null +++ b/web_chatter_position/models/res_users.py @@ -0,0 +1,25 @@ +# Copyright 2022 Hynsys Technologies +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +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/web_chatter_position/readme/CONTRIBUTORS.rst b/web_chatter_position/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..e0a264ebb --- /dev/null +++ b/web_chatter_position/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Hynsys Technologies +* Juan Miguel Sánchez Arce +* `Camptocamp `_ + + * Iván Todorovich diff --git a/web_chatter_position/readme/DESCRIPTION.rst b/web_chatter_position/readme/DESCRIPTION.rst new file mode 100644 index 000000000..9c874e16e --- /dev/null +++ b/web_chatter_position/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +Configurable chatter position from the user preferences. + +Supports Both Community & Enterprise Edition. diff --git a/web_chatter_position/readme/USAGE.rst b/web_chatter_position/readme/USAGE.rst new file mode 100644 index 000000000..dd8265496 --- /dev/null +++ b/web_chatter_position/readme/USAGE.rst @@ -0,0 +1,2 @@ +#. There's a **Chatter Position** option in **User Preferences**, where you can +choose between ``auto``, ``bottom`` and ``sided``. diff --git a/web_chatter_position/static/description/icon.png b/web_chatter_position/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/web_chatter_position/static/description/icon.png differ diff --git a/web_chatter_position/static/description/index.html b/web_chatter_position/static/description/index.html new file mode 100644 index 000000000..2aad9e350 --- /dev/null +++ b/web_chatter_position/static/description/index.html @@ -0,0 +1,439 @@ + + + + + + +Chatter Position + + + +
+

Chatter Position

+ + +

Beta License: LGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

Configurable Chatter Position. +Change Chatter Position in User Preferences. +Change Chatter Position on the fly. +Supports Both Community & Enterprise Edition.

+

Table of contents

+ +
+

Usage

+
    +
  1. There’s a Chatter Position option in User Preferences, where you can choose between “bottom” and “sided”.
  2. +
  3. The position can also be changed on the fly using a new button on the top left side of Form Views.
  4. +
+
+
+

Known issues / Roadmap

+
    +
  • This module implements the same feature as web_responsive. Once the enterprise interface is moved to community in version 16, only this module will be needed.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Hynsys Technologies
  • +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_chatter_position/static/src/js/web_chatter_position.esm.js b/web_chatter_position/static/src/js/web_chatter_position.esm.js new file mode 100644 index 000000000..3c648ce0f --- /dev/null +++ b/web_chatter_position/static/src/js/web_chatter_position.esm.js @@ -0,0 +1,158 @@ +/** @odoo-module **/ +/* + Copyright 2023 Camptocamp SA (https://www.camptocamp.com). + License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). +*/ + +import {FormCompiler} from "@web/views/form/form_compiler"; +import {FormController} from "@web/views/form/form_controller"; +import {MailFormCompiler} from "@mail/views/form/form_compiler"; +import {append} from "@web/core/utils/xml"; +import {patch} from "@web/core/utils/patch"; + +/** + * So, you've landed here and you have no idea what this is about. Don't worry, you're + * not the only one. Here's a quick summary of what's going on: + * + * In core, the chatter position depends on the size of the screen and wether there is + * an attachment viewer or not. There are 3 possible positions, and for each position a + * different chatter instance is displayed. + * + * So, in fact, we have 3 chatter instances running, and we switch their visibility + * depending on the desired position. + * + * A) Bottom position + * https://github.com/odoo/odoo/blob/2ef010907/addons/mail/static/src/views/form/form_compiler.js#L160 + * Condition: `!this.props.hasAttachmentViewer and uiService.size < ${SIZES.XXL}` + * + * This is the bottom position you would except. However it can only be there until + * XXL screen sizes, because the container is a flexbox and changes from row to + * column display. It's hidden in the presence of an attachment viewer. + * + * B) Bottom In-sheet position + * https://github.com/odoo/odoo/blob/2ef010907/addons/mail/static/src/views/form/form_compiler.js#L181 + * Condition: `this.props.hasAttachmentViewer` + * + * This is the bottom position that's used when there's an attachment viewer in place. + * It's rendered within the form sheet, possibly to by-pass the flexbox issue + * beforementioned. It's only instanciated when there's an attachment viewer. + * + * C) Sided position + * https://github.com/odoo/odoo/blob/2ef010907/addons/mail/static/src/views/form/form_compiler.js#L83 + * Condition: `!hasAttachmentViewer() and uiService.size >= ${SIZES.XXL}` + * + * This is the sided position, hidden in the presence of an attachment viewer. + * It's the better half of `A`. + * + * The patches and overrides you see below are here to alter these conditions to force + * a specific position regardless of the screen size, depending on an user setting. + */ + +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") { + 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"); + 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; + }, +}); diff --git a/web_chatter_position/views/res_users.xml b/web_chatter_position/views/res_users.xml new file mode 100644 index 000000000..0cf19ea22 --- /dev/null +++ b/web_chatter_position/views/res_users.xml @@ -0,0 +1,12 @@ + + + + res.users + + + + + + + + diff --git a/web_chatter_position/views/web.xml b/web_chatter_position/views/web.xml new file mode 100644 index 000000000..b65b4e1e8 --- /dev/null +++ b/web_chatter_position/views/web.xml @@ -0,0 +1,12 @@ + + + +