From 1332710982f9b7242025e9b8506ece004c4eb7dc Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Thu, 27 Jul 2017 11:33:31 +0530 Subject: [PATCH] Email footer (#3784) * Add frappe.preview_email for faster feedback on email design * Set Unsubscribe link color to text-muted * error handling for header * codacy fixes --- frappe/email/email_body.py | 14 ++++++++++++-- frappe/email/queue.py | 2 +- frappe/public/build.json | 1 + frappe/public/js/frappe/misc/preview_email.js | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 frappe/public/js/frappe/misc/preview_email.js diff --git a/frappe/email/email_body.py b/frappe/email/email_body.py index 7f97a34b4d..80005eef1d 100755 --- a/frappe/email/email_body.py +++ b/frappe/email/email_body.py @@ -251,6 +251,16 @@ def get_formatted_html(subject, message, footer=None, print_html=None, email_acc transformed_html = inline_style_in_html(sanitized_html) return transformed_html +@frappe.whitelist() +def get_email_html(template, args, subject, header=None): + import json + + args = json.loads(args) + if header and header.startswith('['): + header = json.loads(header) + email = frappe.utils.jinja.get_email_from_template(template, args) + return get_formatted_html(subject, email[0], header=header) + def inline_style_in_html(html): ''' Convert email.css and html to inline-styled html ''' @@ -334,8 +344,6 @@ def get_footer(email_account, footer=None): if email_account and email_account.footer: footer += '
{0}
'.format(email_account.footer) - footer += "" - company_address = frappe.db.get_default("email_footer_address") if company_address: @@ -347,6 +355,8 @@ def get_footer(email_account, footer=None): .format(x) footer += "" + footer += "" + if not cint(frappe.db.get_default("disable_standard_email_footer")): for default_mail_footer in frappe.get_hooks("default_mail_footer"): footer += '
{0}
'.format(default_mail_footer) diff --git a/frappe/email/queue.py b/frappe/email/queue.py index e5630bc88e..ed7337bd93 100755 --- a/frappe/email/queue.py +++ b/frappe/email/queue.py @@ -236,7 +236,7 @@ def get_unsubscribe_message(unsubscribe_message, expose_recipients): html = """

- " style="color: #8d99a6; text-decoration: underline;" target="_blank">{unsubscribe_message}

diff --git a/frappe/public/build.json b/frappe/public/build.json index 3fafb6c5f2..433631c0a9 100755 --- a/frappe/public/build.json +++ b/frappe/public/build.json @@ -132,6 +132,7 @@ "public/js/frappe/misc/help.js", "public/js/frappe/misc/help_links.js", "public/js/frappe/misc/address_and_contact.js", + "public/js/frappe/misc/preview_email.js", "public/js/frappe/ui/upload.html", "public/js/frappe/upload.js", diff --git a/frappe/public/js/frappe/misc/preview_email.js b/frappe/public/js/frappe/misc/preview_email.js new file mode 100644 index 0000000000..b3e3bfddce --- /dev/null +++ b/frappe/public/js/frappe/misc/preview_email.js @@ -0,0 +1,16 @@ +frappe.preview_email = function(template, args, header) { + frappe.call({ + method: 'frappe.email.email_body.get_email_html', + args: { + subject: 'Test', + template, + args, + header + } + }).then((r) => { + var html = r.message; + html = html.replace(/embed=/, 'src='); + var d = frappe.msgprint(html); + d.$wrapper.find('.modal-dialog').css('width', '70%'); + }); +};