diff --git a/web_send_message_popup/README.rst b/web_send_message_popup/README.rst new file mode 100644 index 000000000..9441a233e --- /dev/null +++ b/web_send_message_popup/README.rst @@ -0,0 +1,88 @@ +========================= +Web Send Message as Popup +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:0083ff4f27d544631c17fd7354b1243d92d296ca3a3a9f61b183e739ec6e8346 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/18.0/web_send_message_popup + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_send_message_popup + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +In the email/notes threads below the form views, the link 'Send a +message' unfold a text field. From there, a button allows to open the +text field in a full featured email popup with the subject, templates, +attachments and followers. + +This module changes the link 'Send a message' so it opens directly the +full featured popup instead of the text field, avoiding an extra click +if the popup is always wanted. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Guewen Baconnier +- Yannick Vaucher +- Nicolas JEUDY +- Artem Kostyuk +- Stéphane Mangin +- Helly kapatel + +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_send_message_popup/__init__.py b/web_send_message_popup/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_send_message_popup/__manifest__.py b/web_send_message_popup/__manifest__.py new file mode 100644 index 000000000..3283b74cd --- /dev/null +++ b/web_send_message_popup/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2014-2021 Camptocamp SA +# License AGPL-3.0 or later (http://gnu.org/licenses/agpl). +{ + "name": "Web Send Message as Popup", + "version": "18.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", + "assets": {"web.assets_backend": ["web_send_message_popup/static/src/**/*.js"]}, +} diff --git a/web_send_message_popup/i18n/fa.po b/web_send_message_popup/i18n/fa.po new file mode 100644 index 000000000..e022053e5 --- /dev/null +++ b/web_send_message_popup/i18n/fa.po @@ -0,0 +1,6 @@ +#. module: web_send_message_popup +#. odoo-javascript +#: code:addons/web_send_message_popup/static/src/models/chatter/chatter.esm.js:0 +#, python-format +msgid "Compose Email" +msgstr "" diff --git a/web_send_message_popup/i18n/it.po b/web_send_message_popup/i18n/it.po new file mode 100644 index 000000000..b099051d5 --- /dev/null +++ b/web_send_message_popup/i18n/it.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_send_message_popup +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-03-05 14:40+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: web_send_message_popup +#. odoo-javascript +#: code:addons/web_send_message_popup/static/src/models/chatter/chatter.esm.js:0 +#, python-format +msgid "Compose Email" +msgstr "Componi e-mail" diff --git a/web_send_message_popup/i18n/web_send_message_popup.pot b/web_send_message_popup/i18n/web_send_message_popup.pot new file mode 100644 index 000000000..2b13ff2c2 --- /dev/null +++ b/web_send_message_popup/i18n/web_send_message_popup.pot @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_send_message_popup +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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_send_message_popup +#. odoo-javascript +#: code:addons/web_send_message_popup/static/src/models/chatter/chatter.esm.js:0 +#, python-format +msgid "Compose Email" +msgstr "" diff --git a/web_send_message_popup/pyproject.toml b/web_send_message_popup/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/web_send_message_popup/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_send_message_popup/readme/CONTRIBUTORS.md b/web_send_message_popup/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..434ee0c51 --- /dev/null +++ b/web_send_message_popup/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- Guewen Baconnier \<\> +- Yannick Vaucher \<\> +- Nicolas JEUDY \<\> +- Artem Kostyuk \<\> +- Stéphane Mangin \<\> +- Helly kapatel \<\> diff --git a/web_send_message_popup/readme/DESCRIPTION.md b/web_send_message_popup/readme/DESCRIPTION.md new file mode 100644 index 000000000..c661e1b33 --- /dev/null +++ b/web_send_message_popup/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +In the email/notes threads below the form views, the link 'Send a +message' unfold a text field. From there, a button allows to open the +text field in a full featured email popup with the subject, templates, +attachments and followers. + +This module changes the link 'Send a message' so it opens directly the +full featured popup instead of the text field, avoiding an extra click +if the popup is always wanted. diff --git a/web_send_message_popup/static/description/icon.png b/web_send_message_popup/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/web_send_message_popup/static/description/icon.png differ diff --git a/web_send_message_popup/static/description/index.html b/web_send_message_popup/static/description/index.html new file mode 100644 index 000000000..32001fe82 --- /dev/null +++ b/web_send_message_popup/static/description/index.html @@ -0,0 +1,434 @@ + + + + + +Web Send Message as Popup + + + +
+

Web Send Message as Popup

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

In the email/notes threads below the form views, the link ‘Send a +message’ unfold a text field. From there, a button allows to open the +text field in a full featured email popup with the subject, templates, +attachments and followers.

+

This module changes the link ‘Send a message’ so it opens directly the +full featured popup instead of the text field, avoiding an extra click +if the popup is always wanted.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • 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_send_message_popup/static/src/chatter/web/chatter_patch.esm.js b/web_send_message_popup/static/src/chatter/web/chatter_patch.esm.js new file mode 100644 index 000000000..69fdefe36 --- /dev/null +++ b/web_send_message_popup/static/src/chatter/web/chatter_patch.esm.js @@ -0,0 +1,183 @@ +import {EventBus, markup, toRaw} from "@odoo/owl"; +import {Chatter} from "@mail/chatter/web_portal/chatter"; +import {SIGNATURE_CLASS} from "@html_editor/main/signature_plugin"; +import {_t} from "@web/core/l10n/translation"; +import {browser} from "@web/core/browser/browser"; +import {childNodes} from "@html_editor/utils/dom_traversal"; +import {parseHTML} from "@html_editor/utils/html"; +import {patch} from "@web/core/utils/patch"; +import {prettifyMessageContent} from "@mail/utils/common/format"; +import {renderToElement} from "@web/core/utils/render"; +import {rpc} from "@web/core/network/rpc"; +import {wrapInlinesInBlocks} from "@html_editor/utils/dom"; + +patch(Chatter.prototype, { + setup() { + super.setup(...arguments); + this.fullComposerBus = new EventBus(); + this.isFullComposerOpen = false; + }, + toggleComposer(mode = false) { + if (mode === "message") { + this.closeSearch(); + this.state.composerType = false; + if (!this.state.thread.id) { + this.props.saveRecord?.(); + } + this.openFullComposer(); + return; + } + return super.toggleComposer(...arguments); + }, + // A rough composer function copy of `onClickFullComposer` + async openFullComposer() { + const newPartners = this.state.thread.suggestedRecipients.filter( + (recipient) => recipient.checked && !recipient.persona + ); + if (newPartners.length) { + const recipientEmails = []; + const recipientAdditionalValues = {}; + newPartners.forEach((recipient) => { + recipientEmails.push(recipient.email); + recipientAdditionalValues[recipient.email] = + recipient.create_values || {}; + }); + const partners = await rpc("/mail/partner/from_email", { + emails: recipientEmails, + additional_values: recipientAdditionalValues, + }); + for (const index in partners) { + const partnerData = partners[index]; + const persona = this.store.Persona.insert({ + ...partnerData, + type: "partner", + }); + const email = recipientEmails[index]; + const recipient = this.state.thread.suggestedRecipients.find( + (rec) => rec.email === email + ); + Object.assign(recipient, {persona}); + } + } + const body = this.state.thread.composer.text; + const validMentions = this.store.getMentionsFromText(body, { + mentionedChannels: this.state.thread.composer.mentionedChannels, + mentionedPartners: this.state.thread.composer.mentionedPartners, + }); + let default_body = await prettifyMessageContent(body, validMentions); + if (!default_body) { + const composer = toRaw(this.state.thread.composer); + composer.emailAddSignature = true; + } + default_body = this.formatDefaultBodyForFullComposer( + default_body, + this.state.thread.composer.emailAddSignature + ? markup(this.store.self.signature) + : "" + ); + const action = { + name: _t("Compose Email"), + type: "ir.actions.act_window", + res_model: "mail.compose.message", + view_mode: "form", + views: [[false, "form"]], + target: "new", + context: { + default_attachment_ids: this.state.thread.composer.attachments.map( + (attachment) => attachment.id + ), + default_body, + default_email_add_signature: false, + default_model: this.state.thread.model, + default_partner_ids: this.state.thread.suggestedRecipients + .filter((recipient) => recipient.checked) + .map((recipient) => recipient.persona.id), + default_res_ids: [this.state.thread.id], + default_subtype_xmlid: "mail.mt_comment", + mail_post_autofollow: this.state.thread.hasWriteAccess, + }, + }; + const options = { + onClose: (...args) => { + const accidentalDiscard = !args.length; + const isDiscard = accidentalDiscard || args[0]?.special; + if (!isDiscard && this.state.thread.model === "mail.box") { + this.notifySendFromMailbox(); + } + if (accidentalDiscard) { + this.fullComposerBus.trigger("ACCIDENTAL_DISCARD", { + onAccidentalDiscard: (isEmpty) => { + if (!isEmpty) { + this.saveContent(); + this.restoreContent(); + } + }, + }); + } else { + this.clear(); + } + this.onCloseFullComposerCallback(); + this.isFullComposerOpen = false; + this.fullComposerBus = new EventBus(); + }, + props: {fullComposerBus: this.fullComposerBus}, + }; + await this.env.services.action.doAction(action, options); + this.isFullComposerOpen = true; + }, + // Method copied not from the composer file but the composer_patch one + formatDefaultBodyForFullComposer(defaultBody, signature = "") { + const fragment = parseHTML(document, defaultBody); + if (!fragment.firstChild) { + fragment.append(document.createElement("BR")); + } + if (signature) { + const signatureEl = renderToElement("html_editor.Signature", { + signature, + signatureClass: SIGNATURE_CLASS, + }); + fragment.append(signatureEl); + } + const container = document.createElement("DIV"); + container.append(...childNodes(fragment)); + wrapInlinesInBlocks(container, {baseContainerNodeName: "DIV"}); + return container.innerHTML; + }, + // Copied and modified methods from composer + notifySendFromMailbox() { + this.env.services.notification.add( + _t('Message posted on "%s"', this.state.thread.displayName), + {type: "info"} + ); + }, + saveContent() { + const composer = toRaw(this.state.thread.composer); + const onSaveContent = (text, emailAddSignature) => { + browser.localStorage.setItem( + composer.localId, + JSON.stringify({emailAddSignature, text}) + ); + }; + if (this.isFullComposerOpen) { + this.fullComposerBus.trigger("SAVE_CONTENT", {onSaveContent}); + } else { + onSaveContent(composer.text, true); + } + }, + restoreContent() { + const composer = toRaw(this.state.thread.composer); + try { + const config = JSON.parse(browser.localStorage.getItem(composer.localId)); + if (config.text) { + composer.emailAddSignature = config.emailAddSignature; + composer.text = config.text; + } + } catch { + browser.localStorage.removeItem(composer.localId); + } + }, + clear() { + this.state.thread.composer.clear(); + browser.localStorage.removeItem(this.state.thread.composer.localId); + }, +});