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 += '
- " 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%'); + }); +};