From 0ce97b7ad4b30836b88f88f55a13f94683f2f18e Mon Sep 17 00:00:00 2001 From: Du-ma Date: Fri, 26 May 2023 11:26:32 +0000 Subject: [PATCH] [MIG] web_send_message_popup: Migration to 15.0 --- web_send_message_popup/__manifest__.py | 6 +- .../static/src/js/chatter.js | 27 --------- .../static/src/models/chatter/chatter.esm.js | 57 +++++++++++++++++++ web_send_message_popup/templates/assets.xml | 15 ----- 4 files changed, 61 insertions(+), 44 deletions(-) delete mode 100644 web_send_message_popup/static/src/js/chatter.js create mode 100644 web_send_message_popup/static/src/models/chatter/chatter.esm.js delete mode 100644 web_send_message_popup/templates/assets.xml diff --git a/web_send_message_popup/__manifest__.py b/web_send_message_popup/__manifest__.py index 2c93fa35a..485fc1706 100644 --- a/web_send_message_popup/__manifest__.py +++ b/web_send_message_popup/__manifest__.py @@ -2,12 +2,14 @@ # License AGPL-3.0 or later (http://gnu.org/licenses/agpl). { "name": "Web Send Message as Popup", - "version": "14.0.1.0.0", + "version": "15.0.1.0.0", "author": "Camptocamp, Odoo Community Association (OCA)", "maintainer": "Camptocamp", "license": "AGPL-3", "category": "Hidden", "depends": ["web", "mail"], "website": "https://github.com/OCA/web", - "data": ["templates/assets.xml"], + "assets": { + "web.assets_backend": ["web_send_message_popup/static/src/models/**/*.js"] + }, } diff --git a/web_send_message_popup/static/src/js/chatter.js b/web_send_message_popup/static/src/js/chatter.js deleted file mode 100644 index f9cd4f5b0..000000000 --- a/web_send_message_popup/static/src/js/chatter.js +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019-2021 Camptocamp SA - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ -odoo.define("web_send_message_popup/static/src/js/chatter.js", function (require) { - "use strict"; - - const components = { - Composer: require("mail/static/src/components/chatter_topbar/chatter_topbar.js"), - }; - const {patch} = require("web.utils"); - - patch(components.Composer, "web_send_message_popup/static/src/js/chatter.js", { - /** - * Overwrite to always launch full composer instead of quick messages - */ - _onClickSendMessage() { - this._super.apply(this, arguments); - if ( - this.chatter.composer && - this.chatter.isComposerVisible && - !this.chatter.composer.isLog - ) { - this.chatter.update({isComposerVisible: false}); - this.chatter.composer.openFullComposer(); - } - }, - }); -}); diff --git a/web_send_message_popup/static/src/models/chatter/chatter.esm.js b/web_send_message_popup/static/src/models/chatter/chatter.esm.js new file mode 100644 index 000000000..f3b8607bb --- /dev/null +++ b/web_send_message_popup/static/src/models/chatter/chatter.esm.js @@ -0,0 +1,57 @@ +/** @odoo-module **/ + +import {clear} from "@mail/model/model_field_command"; +import {escapeAndCompactTextContent} from "@mail/js/utils"; +import {registerInstancePatchModel} from "@mail/model/model_core"; + +registerInstancePatchModel("mail.chatter", "web_send_message_popup.ChatterPatch", { + onClickSendMessage() { + if (this.composerView) { + // Change `isLog` to false since this should only be possible when you press + // "Log Note" first, otherwise this won't hurt. + this.composerView.composer.update({isLog: false}); + // Open the full composer with `composerView` because it carries through the + // composer options. + this.composerView.openFullComposer(); + // Clear the `composerView` since we don't need it no more. + this.update({composerView: clear()}); + return; + } + this.openFullComposer(); + }, + openFullComposer() { + // Rough copy of composer view function `openFullComposer`. + // Get composer from thread. + // We access data from the composer since history still is saved there. + // e.g. open and close "Log note". + const composer = this.thread.composer; + const context = { + default_attachment_ids: composer.attachments.map((att) => att.id), + default_body: escapeAndCompactTextContent(composer.textInputContent), + default_is_log: false, + default_model: this.threadModel, + default_partner_ids: composer.recipients.map((partner) => partner.id), + default_res_id: this.threadId, + mail_post_autofollow: true, + }; + const action = { + type: "ir.actions.act_window", + res_model: "mail.compose.message", + view_mode: "form", + views: [[false, "form"]], + target: "new", + context, + }; + const options = { + on_close: () => { + if (composer.exists()) { + composer._reset(); + if (composer.activeThread) { + composer.activeThread.loadNewMessages(); + } + } + }, + }; + this.env.bus.trigger("do-action", {action, options}); + }, +}); diff --git a/web_send_message_popup/templates/assets.xml b/web_send_message_popup/templates/assets.xml deleted file mode 100644 index 483450529..000000000 --- a/web_send_message_popup/templates/assets.xml +++ /dev/null @@ -1,15 +0,0 @@ - - -