From 68829ab2e6d2ca8238bd9d5bd44844e032cee089 Mon Sep 17 00:00:00 2001
From: barredterra <14891507+barredterra@users.noreply.github.com>
Date: Thu, 21 Jan 2021 19:06:33 +0100
Subject: [PATCH 01/14] feat: default_email_template
---
frappe/core/doctype/doctype/doctype.json | 13 ++++++++++++-
frappe/public/js/frappe/views/communication.js | 1 +
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/frappe/core/doctype/doctype/doctype.json b/frappe/core/doctype/doctype/doctype.json
index 215ef8cd62..55c74a4e63 100644
--- a/frappe/core/doctype/doctype/doctype.json
+++ b/frappe/core/doctype/doctype/doctype.json
@@ -55,6 +55,8 @@
"show_preview_popup",
"show_name_in_global_search",
"email_settings_sb",
+ "default_email_template",
+ "column_break_51",
"email_append_to",
"sender_field",
"subject_field",
@@ -528,6 +530,15 @@
"fieldname": "index_web_pages_for_search",
"fieldtype": "Check",
"label": "Index Web Pages for Search"
+ },
+ {
+ "fieldname": "default_email_template",
+ "fieldtype": "Data",
+ "label": "Default Email Template"
+ },
+ {
+ "fieldname": "column_break_51",
+ "fieldtype": "Column Break"
}
],
"icon": "fa fa-bolt",
@@ -609,7 +620,7 @@
"link_fieldname": "reference_doctype"
}
],
- "modified": "2020-09-24 13:13:58.227153",
+ "modified": "2021-01-21 18:09:47.135696",
"modified_by": "Administrator",
"module": "Core",
"name": "DocType",
diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js
index c69be04347..7b9668a96e 100755
--- a/frappe/public/js/frappe/views/communication.js
+++ b/frappe/public/js/frappe/views/communication.js
@@ -159,6 +159,7 @@ frappe.views.CommunicationComposer = Class.extend({
this.setup_last_edited_communication();
this.setup_email_template();
+ this.dialog.set_value("email_template", this.frm.meta.default_email_template || '');
this.dialog.set_value("recipients", this.recipients || '');
this.dialog.set_value("cc", this.cc || '');
this.dialog.set_value("bcc", this.bcc || '');
From 2618ee74d898f48a0899691c045e2ce1e0a4b4da Mon Sep 17 00:00:00 2001
From: barredterra <14891507+barredterra@users.noreply.github.com>
Date: Wed, 27 Jan 2021 18:55:54 +0100
Subject: [PATCH 02/14] feat: add default_email_template to Customize Form
---
.../doctype/customize_form/customize_form.json | 13 ++++++++++++-
.../custom/doctype/customize_form/customize_form.py | 1 +
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/frappe/custom/doctype/customize_form/customize_form.json b/frappe/custom/doctype/customize_form/customize_form.json
index ff102b3c08..dee2dfce0d 100644
--- a/frappe/custom/doctype/customize_form/customize_form.json
+++ b/frappe/custom/doctype/customize_form/customize_form.json
@@ -31,6 +31,8 @@
"show_preview_popup",
"image_view",
"email_settings_section",
+ "default_email_template",
+ "column_break_26",
"email_append_to",
"sender_field",
"subject_field",
@@ -261,6 +263,15 @@
"fieldtype": "Table",
"label": "Actions",
"options": "DocType Action"
+ },
+ {
+ "fieldname": "default_email_template",
+ "fieldtype": "Data",
+ "label": "Default Email Template"
+ },
+ {
+ "fieldname": "column_break_26",
+ "fieldtype": "Column Break"
}
],
"hide_toolbar": 1,
@@ -269,7 +280,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
- "modified": "2020-09-24 14:16:49.594012",
+ "modified": "2021-01-27 18:26:59.705786",
"modified_by": "Administrator",
"module": "Custom",
"name": "Customize Form",
diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py
index 82513783c7..0718f5d84c 100644
--- a/frappe/custom/doctype/customize_form/customize_form.py
+++ b/frappe/custom/doctype/customize_form/customize_form.py
@@ -479,6 +479,7 @@ doctype_properties = {
'allow_auto_repeat': 'Check',
'allow_import': 'Check',
'show_preview_popup': 'Check',
+ 'default_email_template': 'Data',
'email_append_to': 'Check',
'subject_field': 'Data',
'sender_field': 'Data'
From b14b28d7650001af5d7812bda07c15cb74e883ff Mon Sep 17 00:00:00 2001
From: barredterra <14891507+barredterra@users.noreply.github.com>
Date: Wed, 27 Jan 2021 18:59:00 +0100
Subject: [PATCH 03/14] fix: check if frm is available
Prevents error when creating new Communication from list view.
---
frappe/public/js/frappe/views/communication.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js
index 7b9668a96e..073ce44206 100755
--- a/frappe/public/js/frappe/views/communication.js
+++ b/frappe/public/js/frappe/views/communication.js
@@ -159,7 +159,10 @@ frappe.views.CommunicationComposer = Class.extend({
this.setup_last_edited_communication();
this.setup_email_template();
- this.dialog.set_value("email_template", this.frm.meta.default_email_template || '');
+ if ('frm' in this) {
+ this.dialog.set_value("email_template", this.frm.meta.default_email_template || '');
+ }
+
this.dialog.set_value("recipients", this.recipients || '');
this.dialog.set_value("cc", this.cc || '');
this.dialog.set_value("bcc", this.bcc || '');
From fa39484571d993ed5562149b6c85615e39cdc27b Mon Sep 17 00:00:00 2001
From: barredterra <14891507+barredterra@users.noreply.github.com>
Date: Wed, 27 Jan 2021 18:59:47 +0100
Subject: [PATCH 04/14] fix: check if email_template is set
Prevents error on empty email_template.
---
frappe/public/js/frappe/views/communication.js | 3 +++
1 file changed, 3 insertions(+)
diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js
index 073ce44206..c5c6cdced9 100755
--- a/frappe/public/js/frappe/views/communication.js
+++ b/frappe/public/js/frappe/views/communication.js
@@ -232,6 +232,9 @@ frappe.views.CommunicationComposer = Class.extend({
this.dialog.fields_dict["email_template"].df.onchange = () => {
var email_template = me.dialog.fields_dict.email_template.get_value();
+ if (email_template === '') {
+ return;
+ }
var prepend_reply = function(reply) {
if(me.reply_added===email_template) {
From 885d198622703ef50b0f6443f3a00ee76b0c2d58 Mon Sep 17 00:00:00 2001
From: barredterra <14891507+barredterra@users.noreply.github.com>
Date: Thu, 4 Feb 2021 12:20:12 +0100
Subject: [PATCH 05/14] fix: don't apply default email template for reply
---
frappe/public/js/frappe/views/communication.js | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js
index f1feb4f6a3..66e050f3d1 100755
--- a/frappe/public/js/frappe/views/communication.js
+++ b/frappe/public/js/frappe/views/communication.js
@@ -196,10 +196,6 @@ frappe.views.CommunicationComposer = Class.extend({
this.setup_last_edited_communication();
this.setup_email_template();
- if ('frm' in this) {
- this.dialog.set_value("email_template", this.frm.meta.default_email_template || '');
- }
-
this.dialog.set_value("recipients", this.recipients || '');
this.dialog.set_value("cc", this.cc || '');
this.dialog.set_value("bcc", this.bcc || '');
@@ -210,6 +206,11 @@ frappe.views.CommunicationComposer = Class.extend({
this.dialog.fields_dict.subject.set_value(this.subject || '');
this.setup_earlier_reply();
+
+ if ('frm' in this && !this.is_a_reply) {
+ // set default email template for the first email in a document
+ this.dialog.set_value("email_template", this.frm.meta.default_email_template || '');
+ }
},
setup_subject_and_recipients: function() {
From cb211c6272669662d1012aa7331538ba856c1579 Mon Sep 17 00:00:00 2001
From: barredterra <14891507+barredterra@users.noreply.github.com>
Date: Mon, 8 Feb 2021 12:51:47 +0100
Subject: [PATCH 06/14] fix: signature should be an empty string by default
(would become undefined if the server message was empty)
---
frappe/public/js/frappe/views/communication.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js
index 66e050f3d1..5329967e12 100755
--- a/frappe/public/js/frappe/views/communication.js
+++ b/frappe/public/js/frappe/views/communication.js
@@ -726,7 +726,7 @@ frappe.views.CommunicationComposer = Class.extend({
if (!signature) {
const res = await this.get_default_outgoing_email_account_signature();
- signature = res.message.signature;
+ signature = res.message.signature || "";
}
if(!frappe.utils.is_html(signature)) {
From 87326625fed3f0ce0b72977f2e988783e59741c8 Mon Sep 17 00:00:00 2001
From: barredterra <14891507+barredterra@users.noreply.github.com>
Date: Mon, 22 Mar 2021 12:31:58 +0100
Subject: [PATCH 07/14] fix: make Default Email Template a link field
---
frappe/core/doctype/doctype/doctype.json | 7 ++++---
frappe/custom/doctype/customize_form/customize_form.json | 7 ++++---
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/frappe/core/doctype/doctype/doctype.json b/frappe/core/doctype/doctype/doctype.json
index 7bf91892ee..fb24c095f3 100644
--- a/frappe/core/doctype/doctype/doctype.json
+++ b/frappe/core/doctype/doctype/doctype.json
@@ -533,8 +533,9 @@
},
{
"fieldname": "default_email_template",
- "fieldtype": "Data",
- "label": "Default Email Template"
+ "fieldtype": "Link",
+ "label": "Default Email Template",
+ "options": "Email Template"
},
{
"fieldname": "column_break_51",
@@ -620,7 +621,7 @@
"link_fieldname": "reference_doctype"
}
],
- "modified": "2021-02-23 15:10:09.227205",
+ "modified": "2021-03-22 12:26:41.031135",
"modified_by": "Administrator",
"module": "Core",
"name": "DocType",
diff --git a/frappe/custom/doctype/customize_form/customize_form.json b/frappe/custom/doctype/customize_form/customize_form.json
index dee2dfce0d..f8db73137e 100644
--- a/frappe/custom/doctype/customize_form/customize_form.json
+++ b/frappe/custom/doctype/customize_form/customize_form.json
@@ -266,8 +266,9 @@
},
{
"fieldname": "default_email_template",
- "fieldtype": "Data",
- "label": "Default Email Template"
+ "fieldtype": "Link",
+ "label": "Default Email Template",
+ "options": "Email Template"
},
{
"fieldname": "column_break_26",
@@ -280,7 +281,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
- "modified": "2021-01-27 18:26:59.705786",
+ "modified": "2021-03-22 12:27:15.462727",
"modified_by": "Administrator",
"module": "Custom",
"name": "Customize Form",
From 5290b4c65f15642c5bc7c84d70fcfc4c14c3d883 Mon Sep 17 00:00:00 2001
From: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
Date: Sat, 27 Mar 2021 15:01:37 +0100
Subject: [PATCH 08/14] fix: add back column break that was lost in merge
---
frappe/custom/doctype/customize_form/customize_form.json | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/frappe/custom/doctype/customize_form/customize_form.json b/frappe/custom/doctype/customize_form/customize_form.json
index fc74f0881b..442b8dbb31 100644
--- a/frappe/custom/doctype/customize_form/customize_form.json
+++ b/frappe/custom/doctype/customize_form/customize_form.json
@@ -272,6 +272,10 @@
"label": "Default Email Template",
"options": "Email Template"
},
+ {
+ "fieldname": "column_break_26",
+ "fieldtype": "Column Break"
+ },
{
"collapsible": 1,
"fieldname": "naming_section",
@@ -312,4 +316,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
-}
\ No newline at end of file
+}
From d12c47681e05e7ce6db7097d82a1963ece82563e Mon Sep 17 00:00:00 2001
From: Sagar Vora
", parts[1]];
- } else {
- content = [reply.message, "
", content];
- }
-
- content_field.set_value(content.join(''));
+ let content = content_field.get_value() || "";
+ content = content.split('')[1] || content;
+ content_field.set_value(`${reply.message}
${content}`);
subject_field.set_value(reply.subject);
me.reply_added = email_template;
@@ -307,83 +272,105 @@ frappe.views.CommunicationComposer = Class.extend({
doc: me.frm.doc,
_lang: me.dialog.get_value("language_sel")
},
- callback: function(r) {
+ callback(r) {
prepend_reply(r.message);
},
});
}
},
- setup_last_edited_communication: function() {
- var me = this;
- if (!this.doc){
- if (cur_frm){
- this.doc = cur_frm.doctype;
- }else{
- this.doc = "Inbox";
- }
- }
- if (cur_frm && cur_frm.docname) {
- this.key = cur_frm.docname;
+ setup_last_edited_communication() {
+ if (this.frm) {
+ this.doctype = this.frm.doctype;
+ this.key = this.frm.docname;
} else {
- this.key = "Inbox";
+ this.doctype = this.key = "Inbox";
}
- if(this.last_email) {
+
+ if (this.last_email) {
this.key = this.key + ":" + this.last_email.name;
}
- if(this.subject){
+
+ if (this.subject) {
this.key = this.key + ":" + this.subject;
}
- this.dialog.onhide = function() {
- var last_edited_communication = me.get_last_edited_communication();
- $.extend(last_edited_communication, {
- sender: me.dialog.get_value("sender"),
- recipients: me.dialog.get_value("recipients"),
- cc: me.dialog.get_value("cc"),
- bcc: me.dialog.get_value("bcc"),
- subject: me.dialog.get_value("subject"),
- content: me.dialog.get_value("content"),
- });
- if (me.frm) {
- $(document).trigger("form-stopped-typing", [me.frm]);
+ this.dialog.on_hide = () => {
+ $.extend(
+ this.get_last_edited_communication(true),
+ this.dialog.get_values(true)
+ );
+
+ if (this.frm) {
+ $(document).trigger("form-stopped-typing", [this.frm]);
}
}
+ },
- this.dialog.on_page_show = function() {
- if (!me.txt) {
- var last_edited_communication = me.get_last_edited_communication();
- if(last_edited_communication.content) {
- me.dialog.set_value("sender", last_edited_communication.sender || "");
- me.dialog.set_value("subject", last_edited_communication.subject || "");
- me.dialog.set_value("recipients", last_edited_communication.recipients || "");
- me.dialog.set_value("cc", last_edited_communication.cc || "");
- me.dialog.set_value("bcc", last_edited_communication.bcc || "");
- me.dialog.set_value("content", last_edited_communication.content || "");
- }
+ get_last_edited_communication(clear) {
+ if (!frappe.last_edited_communication[this.doctype]) {
+ frappe.last_edited_communication[this.doctype] = {};
+ }
+
+ if (clear || !frappe.last_edited_communication[this.doctype][this.key]) {
+ frappe.last_edited_communication[this.doctype][this.key] = {};
+ console.log('cleared!');
+ }
+
+ return frappe.last_edited_communication[this.doctype][this.key];
+ },
+
+ set_values: async function () {
+ for (const fieldname of ["recipients", "cc", "bcc", "sender"]) {
+ await this.dialog.set_value(fieldname, this[fieldname] || "");
+ }
+
+ const subject = frappe.utils.html2text(this.subject) || '';
+ await this.dialog.set_value("subject", subject);
+
+ await this.set_values_from_last_edited_communication();
+ await this.set_content();
+
+ // set default email template for the first email in a document
+ if (this.frm && !this.is_a_reply && !this.content_set) {
+ const email_template = this.frm.meta.default_email_template || '';
+ await this.dialog.set_value("email_template", email_template);
+ }
+
+ for (const fieldname of ['email_template', 'cc', 'bcc']) {
+ if (this.dialog.get_value(fieldname)) {
+ this.toggle_more_options(true);
+ break;
}
-
}
-
},
- get_last_edited_communication: function() {
- if (!frappe.last_edited_communication[this.doc]) {
- frappe.last_edited_communication[this.doc] = {};
+ set_values_from_last_edited_communication: async function () {
+ if (this.txt) return;
+
+ const last_edited = this.get_last_edited_communication();
+ if (!last_edited.content) return;
+
+ // prevent re-triggering of email template
+ if (last_edited.email_template) {
+ const template_field = this.dialog.fields_dict.email_template;
+ await template_field.set_model_value(last_edited.email_template);
+ delete last_edited.email_template;
}
- if(!frappe.last_edited_communication[this.doc][this.key]) {
- frappe.last_edited_communication[this.doc][this.key] = {};
- }
-
- return frappe.last_edited_communication[this.doc][this.key];
+ await this.dialog.set_values(last_edited);
+ this.content_set = true;
},
- selected_format: function() {
- return this.dialog.fields_dict.select_print_format.input.value || (this.frm && this.frm.meta.default_print_format) || "Standard";
+ selected_format() {
+ return (
+ this.dialog.fields_dict.select_print_format.input.value
+ || this.frm && this.frm.meta.default_print_format
+ || "Standard"
+ );
},
- get_print_format: function(format) {
+ get_print_format(format) {
if (!format) {
format = this.selected_format();
}
@@ -395,9 +382,9 @@ frappe.views.CommunicationComposer = Class.extend({
}
},
- setup_print_language: function() {
- var doc = this.doc || cur_frm.doc;
- var fields = this.dialog.fields_dict;
+ setup_print_language() {
+ const doc = this.frm && this.frm.doc;
+ const fields = this.dialog.fields_dict;
//Load default print language from doctype
this.lang_code = doc.language
@@ -407,7 +394,7 @@ frappe.views.CommunicationComposer = Class.extend({
}
//On selection of language retrieve language code
- var me = this;
+ const me = this;
$(fields.language_sel.input).change(function(){
me.lang_code = this.value
})
@@ -422,9 +409,9 @@ frappe.views.CommunicationComposer = Class.extend({
}
},
- setup_print: function() {
+ setup_print() {
// print formats
- var fields = this.dialog.fields_dict;
+ const fields = this.dialog.fields_dict;
// toggle print format
$(fields.attach_document_print.input).click(function() {
@@ -434,8 +421,8 @@ frappe.views.CommunicationComposer = Class.extend({
// select print format
$(fields.select_print_format.wrapper).toggle(false);
- if (cur_frm) {
- const print_formats = frappe.meta.get_print_formats(cur_frm.meta.name);
+ if (this.frm) {
+ const print_formats = frappe.meta.get_print_formats(this.frm.meta.name);
$(fields.select_print_format.input)
.empty()
.add_options(print_formats)
@@ -446,9 +433,9 @@ frappe.views.CommunicationComposer = Class.extend({
},
- setup_attach: function() {
- var fields = this.dialog.fields_dict;
- var attach = $(fields.select_attachments.wrapper);
+ setup_attach() {
+ const fields = this.dialog.fields_dict;
+ const attach = $(fields.select_attachments.wrapper);
if (!this.attachments) {
this.attachments = [];
@@ -493,7 +480,7 @@ frappe.views.CommunicationComposer = Class.extend({
this.render_attachment_rows();
},
- render_attachment_rows: function(attachment) {
+ render_attachment_rows(attachment) {
const select_attachments = this.dialog.fields_dict.select_attachments;
const attachment_rows = $(select_attachments.wrapper).find(".attach-list");
if (attachment) {
@@ -536,9 +523,9 @@ frappe.views.CommunicationComposer = Class.extend({
'+__('Dear') +' ' - + this.real_name + ",
${__('Dear')} ${this.real_name},
+- last_email_content = this.html2text(last_email_content).replace(/\n/g, '
'); - - // clip last email for a maximum of 20k characters - // to prevent the email content from getting too large - if (last_email_content.length > 20 * 1024) { - last_email_content += '' + __('Message clipped') + '' + last_email_content; - last_email_content = last_email_content.slice(0, 20 * 1024); - } - - let communication_date = last_email.communication_date || last_email.creation; - content = ` - ${reply} -- ${frappe.separator_element || ''} -${__("On {0}, {1} wrote:", [frappe.datetime.global_date_format(communication_date) , last_email.sender])}
-- ${last_email_content} -- `; - } else { - content = reply; + message += this.get_earlier_reply(); } - fields.content.set_value(content); + + await this.dialog.set_value("content", message); }, - html2text: function(html) { + get_signature: async function () { + let signature = frappe.boot.user.email_signature; + + if (!signature) { + const response = await frappe.db.get_value( + 'Email Account', + {'default_outgoing': 1, 'add_signature': 1}, + 'signature' + ); + + signature = response.message.signature; + } + + if (!signature) return ""; + + if (!frappe.utils.is_html(signature)) { + signature = signature.replace(/\n/g, "
"); + } + + return "
" + signature; + }, + + get_earlier_reply() { + const last_email = ( + this.last_email + || this.frm && this.frm.timeline.get_last_email(true) + ); + + if (!last_email) return ""; + let last_email_content = last_email.original_comment || last_email.content; + + // convert the email context to text as we are enclosing + // this inside+ last_email_content = this.html2text(last_email_content).replace(/\n/g, '`; - }, + } html2text(html) { // convert HTML to text and try and preserve whitespace @@ -798,4 +799,4 @@ frappe.views.CommunicationComposer = Class.extend({ // replace multiple empty lines with just one return d.textContent.replace(/\n{3,}/g, '\n\n'); } -}); +}; From c02fbb27b641153be54dd5025e7b183e19ac181a Mon Sep 17 00:00:00 2001 From: Sagar Vora
'); + + // clip last email for a maximum of 20k characters + // to prevent the email content from getting too large + if (last_email_content.length > 20 * 1024) { + last_email_content += '' + __('Message clipped') + '' + last_email_content; + last_email_content = last_email_content.slice(0, 20 * 1024); + } + + const communication_date = last_email.communication_date || last_email.creation; + return ` ++ ${separator_element || ''} +${__("On {0}, {1} wrote:", [ + frappe.datetime.global_date_format(communication_date), + last_email.sender + ])}
++ ${last_email_content} ++ `; + }, + + html2text(html) { // convert HTML to text and try and preserve whitespace - var d = document.createElement( 'div' ); + const d = document.createElement( 'div' ); d.innerHTML = html.replace(/<\/div>/g, '
') // replace end of blocks .replace(/<\/p>/g, '
') // replace end of paragraphs .replace(/
/g, '\n'); - let text = d.textContent; // replace multiple empty lines with just one - return text.replace(/\n{3,}/g, '\n\n'); + return d.textContent.replace(/\n{3,}/g, '\n\n'); } }); From e4527284d735e7b472bbbf0fad1ed7d299d5335a Mon Sep 17 00:00:00 2001 From: Sagar VoraDate: Sat, 17 Apr 2021 02:12:12 +0530 Subject: [PATCH 10/14] fix: sider issues --- .../public/js/frappe/views/communication.js | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index 7cf7b32797..c3e6dfe00a 100755 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -187,7 +187,7 @@ frappe.views.CommunicationComposer = Class.extend({ this.dialog.fields_dict[field].set_data(r.message); } }); - } + }; }); }, @@ -210,12 +210,12 @@ frappe.views.CommunicationComposer = Class.extend({ if (last) { this.subject = last.subject; - if(!this.recipients) { + if (!this.recipients) { this.recipients = last.sender; } // prepend "Re:" - if(strip(this.subject.toLowerCase().split(":")[0])!="re") { + if (strip(this.subject.toLowerCase().split(":")[0])!="re") { this.subject = __("Re: {0}", [this.subject]); } } @@ -304,7 +304,7 @@ frappe.views.CommunicationComposer = Class.extend({ if (this.frm) { $(document).trigger("form-stopped-typing", [this.frm]); } - } + }; }, get_last_edited_communication(clear) { @@ -314,7 +314,6 @@ frappe.views.CommunicationComposer = Class.extend({ if (clear || !frappe.last_edited_communication[this.doctype][this.key]) { frappe.last_edited_communication[this.doctype][this.key] = {}; - console.log('cleared!'); } return frappe.last_edited_communication[this.doctype][this.key]; @@ -527,7 +526,7 @@ frappe.views.CommunicationComposer = Class.extend({ // email const fields = this.dialog.fields_dict; - if(this.attach_document_print) { + if (this.attach_document_print) { $(fields.attach_document_print.input).click(); $(fields.select_print_format.wrapper).toggle(true); } @@ -545,7 +544,7 @@ frappe.views.CommunicationComposer = Class.extend({ const me = this; const btn = me.dialog.get_primary_btn(); const form_values = this.get_values(); - if(!form_values) return; + if (!form_values) return; const selected_attachments = $.map($(me.dialog.wrapper).find("[data-file-name]:checked"), function (element) { @@ -553,7 +552,7 @@ frappe.views.CommunicationComposer = Class.extend({ }); - if(form_values.attach_document_print) { + if (form_values.attach_document_print) { me.send_email(btn, form_values, selected_attachments, null, form_values.select_print_format || ""); } else { me.send_email(btn, form_values, selected_attachments); @@ -617,18 +616,18 @@ frappe.views.CommunicationComposer = Class.extend({ const me = this; me.dialog.hide(); - if(!form_values.recipients) { + if (!form_values.recipients) { frappe.msgprint(__("Enter Email Recipient(s)")); return; } - if(!form_values.attach_document_print) { + if (!form_values.attach_document_print) { print_html = null; print_format = null; } - if(this.frm && !frappe.model.can_email(me.doc.doctype, this.frm)) { + if (this.frm && !frappe.model.can_email(me.doc.doctype, this.frm)) { frappe.msgprint(__("You are not allowed to send emails related to this document")); return; } @@ -660,10 +659,10 @@ frappe.views.CommunicationComposer = Class.extend({ }, btn, callback(r) { - if(!r.exc) { + if (!r.exc) { frappe.utils.play_sound("email"); - if(r.message["emails_not_sent_to"]) { + if (r.message["emails_not_sent_to"]) { frappe.msgprint(__("Email not sent to {0} (unsubscribed / disabled)", [ frappe.utils.escape_html(r.message["emails_not_sent_to"]) ]) ); } @@ -680,7 +679,7 @@ frappe.views.CommunicationComposer = Class.extend({ try { me.success(r); } catch (e) { - console.log(e); + console.log(e); // eslint-disable-line } } @@ -692,7 +691,7 @@ frappe.views.CommunicationComposer = Class.extend({ try { me.error(r); } catch (e) { - console.log(e); + console.log(e); // eslint-disable-line } } } @@ -777,14 +776,16 @@ frappe.views.CommunicationComposer = Class.extend({ last_email_content = last_email_content.slice(0, 20 * 1024); } - const communication_date = last_email.communication_date || last_email.creation; + const communication_date = frappe.datetime.global_date_format( + last_email.communication_date || last_email.creation + ); + return ` ${separator_element || ''} -${__("On {0}, {1} wrote:", [ - frappe.datetime.global_date_format(communication_date), - last_email.sender - ])}
++ ${__("On {0}, {1} wrote:", [communication_date, last_email.sender])} +
${last_email_content}From 4a28b2f20285fe4d481a28f50b0473c20147e095 Mon Sep 17 00:00:00 2001 From: Sagar VoraDate: Sat, 17 Apr 2021 02:36:52 +0530 Subject: [PATCH 11/14] fix: set lang to frappe.boot.lang by default --- frappe/public/js/frappe/views/communication.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index c3e6dfe00a..34201a7900 100755 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -387,10 +387,8 @@ frappe.views.CommunicationComposer = Class.extend({ //Load default print language from doctype this.lang_code = doc.language - - if (!this.lang_code && this.get_print_format().default_print_language) { - this.lang_code = this.get_print_format().default_print_language; - } + || this.get_print_format().default_print_language + || frappe.boot.lang; //On selection of language retrieve language code const me = this; From 354e89f4c60e241bbc16b64d0fd6c8dd995f1130 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Sat, 17 Apr 2021 03:24:01 +0530 Subject: [PATCH 12/14] fix: clear_cache only on success; use me instead of this --- frappe/public/js/frappe/views/communication.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index 34201a7900..ef05ef5857 100755 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -17,16 +17,15 @@ frappe.views.CommunicationComposer = Class.extend({ no_submit_on_enter: true, fields: this.get_fields(), primary_action_label: __("Send"), - size: 'large', primary_action() { me.send_action(); - me.clear_cache(); }, secondary_action_label: __("Discard"), secondary_action() { me.dialog.hide(); me.clear_cache(); }, + size: 'large', minimizable: true }); @@ -665,11 +664,10 @@ frappe.views.CommunicationComposer = Class.extend({ [ frappe.utils.escape_html(r.message["emails_not_sent_to"]) ]) ); } - if ((frappe.last_edited_communication[me.doc] || {})[me.key]) { - delete frappe.last_edited_communication[me.doc][me.key]; - } - if (this.frm) { - this.frm.reload_doc(); + me.clear_cache(); + + if (me.frm) { + me.frm.reload_doc(); } // try the success callback if it exists From 47d13a40c754949fc2110ab667dfaad6716c3f3d Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Sat, 17 Apr 2021 12:21:19 +0530 Subject: [PATCH 13/14] style: use ES6 class --- .../public/js/frappe/views/communication.js | 75 ++++++++++--------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index ef05ef5857..77cc91b4ba 100755 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -4,11 +4,12 @@ frappe.last_edited_communication = {}; const separator_element = ' ---'; -frappe.views.CommunicationComposer = Class.extend({ - init(opts) { +frappe.views.CommunicationComposer = class { + constructor(opts) { $.extend(this, opts); this.make(); - }, + } + make() { const me = this; @@ -37,7 +38,7 @@ frappe.views.CommunicationComposer = Class.extend({ if (this.frm) { $(document).trigger('form-typing', [this.frm]); } - }, + } get_fields() { const fields = [ @@ -151,7 +152,7 @@ frappe.views.CommunicationComposer = Class.extend({ } return fields; - }, + } toggle_more_options(show_options) { show_options = show_options || this.dialog.fields_dict.more_options.df.hidden; @@ -159,7 +160,7 @@ frappe.views.CommunicationComposer = Class.extend({ const label = frappe.utils.icon(show_options ? 'up-line': 'down'); this.dialog.get_field('option_toggle_button').set_label(label); - }, + } prepare() { this.setup_multiselect_queries(); @@ -171,7 +172,7 @@ frappe.views.CommunicationComposer = Class.extend({ this.setup_email_template(); this.setup_last_edited_communication(); this.set_values(); - }, + } setup_multiselect_queries() { ['recipients', 'cc', 'bcc'].forEach(field => { @@ -188,7 +189,7 @@ frappe.views.CommunicationComposer = Class.extend({ }); }; }); - }, + } setup_subject_and_recipients() { this.subject = this.subject || ""; @@ -240,7 +241,7 @@ frappe.views.CommunicationComposer = Class.extend({ if (this.frm && !this.recipients) { this.recipients = this.frm.doc[this.frm.email_field]; } - }, + } setup_email_template() { const me = this; @@ -276,7 +277,7 @@ frappe.views.CommunicationComposer = Class.extend({ }, }); } - }, + } setup_last_edited_communication() { if (this.frm) { @@ -304,7 +305,7 @@ frappe.views.CommunicationComposer = Class.extend({ $(document).trigger("form-stopped-typing", [this.frm]); } }; - }, + } get_last_edited_communication(clear) { if (!frappe.last_edited_communication[this.doctype]) { @@ -316,9 +317,9 @@ frappe.views.CommunicationComposer = Class.extend({ } return frappe.last_edited_communication[this.doctype][this.key]; - }, + } - set_values: async function () { + async set_values() { for (const fieldname of ["recipients", "cc", "bcc", "sender"]) { await this.dialog.set_value(fieldname, this[fieldname] || ""); } @@ -341,9 +342,9 @@ frappe.views.CommunicationComposer = Class.extend({ break; } } - }, + } - set_values_from_last_edited_communication: async function () { + async set_values_from_last_edited_communication() { if (this.txt) return; const last_edited = this.get_last_edited_communication(); @@ -358,7 +359,7 @@ frappe.views.CommunicationComposer = Class.extend({ await this.dialog.set_values(last_edited); this.content_set = true; - }, + } selected_format() { return ( @@ -366,7 +367,7 @@ frappe.views.CommunicationComposer = Class.extend({ || this.frm && this.frm.meta.default_print_format || "Standard" ); - }, + } get_print_format(format) { if (!format) { @@ -378,7 +379,7 @@ frappe.views.CommunicationComposer = Class.extend({ } else { return {}; } - }, + } setup_print_language() { const doc = this.frm && this.frm.doc; @@ -403,7 +404,7 @@ frappe.views.CommunicationComposer = Class.extend({ if (this.lang_code) { $(fields.language_sel.input).val(this.lang_code); } - }, + } setup_print() { // print formats @@ -427,7 +428,7 @@ frappe.views.CommunicationComposer = Class.extend({ $(fields.attach_document_print.wrapper).toggle(false); } - }, + } setup_attach() { const fields = this.dialog.fields_dict; @@ -474,7 +475,7 @@ frappe.views.CommunicationComposer = Class.extend({ .find(".add-more-attachments button") .on('click', () => new frappe.ui.FileUploader(args)); this.render_attachment_rows(); - }, + } render_attachment_rows(attachment) { const select_attachments = this.dialog.fields_dict.select_attachments; @@ -500,7 +501,7 @@ frappe.views.CommunicationComposer = Class.extend({ }); } } - }, + } get_attachment_row(attachment, checked) { return $(`@@ -517,7 +518,7 @@ frappe.views.CommunicationComposer = Class.extend({ ${frappe.utils.icon('link-url')}
`); - }, + } setup_email() { // email @@ -535,7 +536,7 @@ frappe.views.CommunicationComposer = Class.extend({ frappe.boot.user.send_me_a_copy = val; }); - }, + } send_action() { const me = this; @@ -554,7 +555,7 @@ frappe.views.CommunicationComposer = Class.extend({ } else { me.send_email(btn, form_values, selected_attachments); } - }, + } get_values() { const form_values = this.dialog.get_values(); @@ -575,7 +576,7 @@ frappe.views.CommunicationComposer = Class.extend({ } return form_values; - }, + } save_as_draft() { if (this.dialog && this.frm) { @@ -590,12 +591,12 @@ frappe.views.CommunicationComposer = Class.extend({ }); } - }, + } clear_cache() { this.delete_saved_draft(); this.get_last_edited_communication(true); - }, + } delete_saved_draft() { if (this.dialog && this.frm) { @@ -607,7 +608,7 @@ frappe.views.CommunicationComposer = Class.extend({ } }); } - }, + } send_email(btn, form_values, selected_attachments, print_html, print_format) { const me = this; @@ -693,7 +694,7 @@ frappe.views.CommunicationComposer = Class.extend({ } } }); - }, + } is_print_letterhead_checked() { if (this.frm && $(this.frm.wrapper).find('.form-print-wrapper').is(':visible')){ @@ -702,9 +703,9 @@ frappe.views.CommunicationComposer = Class.extend({ return (frappe.model.get_doc(":Print Settings", "Print Settings") || { with_letterhead: 1 }).with_letterhead ? 1 : 0; } - }, + } - set_content: async function() { + async set_content() { if (this.content_set) return; let message = this.txt || ""; @@ -728,9 +729,9 @@ frappe.views.CommunicationComposer = Class.extend({ } await this.dialog.set_value("content", message); - }, + } - get_signature: async function () { + async get_signature() { let signature = frappe.boot.user.email_signature; if (!signature) { @@ -750,7 +751,7 @@ frappe.views.CommunicationComposer = Class.extend({ } return "
" + signature; - }, + } get_earlier_reply() { const last_email = ( @@ -786,7 +787,7 @@ frappe.views.CommunicationComposer = Class.extend({ ${last_email_content}Date: Sat, 17 Apr 2021 12:24:00 +0530 Subject: [PATCH 14/14] fix: sider issue --- frappe/public/js/frappe/views/communication.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index 77cc91b4ba..0479ec6d31 100755 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -276,7 +276,7 @@ frappe.views.CommunicationComposer = class { prepend_reply(r.message); }, }); - } + }; } setup_last_edited_communication() {