Skip to content

Commit

Permalink
feat: add option to set default email recipients (#25555)
Browse files Browse the repository at this point in the history
* feat: add option to set default email recipients

* fix: don't crash if no events

communication.js:206 Uncaught TypeError: Cannot read properties of undefined (reading 'events')
    at frappe.views.CommunicationComposer.get_default_recipients (communication.js:206:16)
    at frappe.views.CommunicationComposer.get_fields (communication.js:57:19)
    at frappe.views.CommunicationComposer.make (communication.js:25:17)
    at new frappe.views.CommunicationComposer (communication.js:16:8)
    at Object.primary_action (communication__list_js:34:3)
    at HTMLButtonElement.<anonymous> (list_view.js:1432:19)
    at HTMLButtonElement.dispatch (jquery.js:5135:27)
    at elemData.handle (jquery.js:4939:28)

Signed-off-by: Akhil Narang <me@akhilnarang.dev>

---------

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Co-authored-by: Akhil Narang <me@akhilnarang.dev>
  • Loading branch information
barredterra and akhilnarang committed Mar 22, 2024
1 parent bad3b9e commit 4c85626
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions frappe/public/js/frappe/views/communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ frappe.views.CommunicationComposer = class {
fieldtype: "MultiSelect",
reqd: 0,
fieldname: "recipients",
default: this.get_default_recipients("recipients"),
},
{
fieldtype: "Button",
Expand All @@ -72,11 +73,13 @@ frappe.views.CommunicationComposer = class {
label: __("CC"),
fieldtype: "MultiSelect",
fieldname: "cc",
default: this.get_default_recipients("cc"),
},
{
label: __("BCC"),
fieldtype: "MultiSelect",
fieldname: "bcc",
default: this.get_default_recipients("bcc"),
},
{
label: __("Schedule Send At"),
Expand Down Expand Up @@ -199,6 +202,14 @@ frappe.views.CommunicationComposer = class {
return fields;
}

get_default_recipients(fieldname) {
if (this.frm?.events.get_email_recipients) {
return (this.frm.events.get_email_recipients(this.frm, fieldname) || []).join(", ");
} else {
return "";
}
}

guess_language() {
// when attach print for print format changes try to guess language
// if print format has language then set that else boot lang.
Expand Down

0 comments on commit 4c85626

Please sign in to comment.