diff --git a/frappe/boot.py b/frappe/boot.py index dca136c49c..415d38a6de 100644 --- a/frappe/boot.py +++ b/frappe/boot.py @@ -65,6 +65,8 @@ def get_bootinfo(): if bootinfo.lang: bootinfo.lang = unicode(bootinfo.lang) + bootinfo.error_report_email = frappe.get_hooks("error_report_email") + return bootinfo def load_conf_settings(bootinfo): diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index 170418f1f7..24fb621b10 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -13,7 +13,6 @@ STANDARD_USERS = ("Guest", "Administrator") from frappe.model.document import Document class User(Document): - def autoname(self): """set name as email id""" if self.name not in STANDARD_USERS: diff --git a/frappe/hooks.py b/frappe/hooks.py index fd1377c7c0..03c3a8121a 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -7,6 +7,7 @@ app_description = "Full Stack Web Application Framwork in Python" app_icon = "assets/frappe/images/frappe.svg" app_version = __version__ app_color = "#3498db" +app_email = "support@frappe.io" before_install = "frappe.utils.install.before_install" after_install = "frappe.utils.install.after_install" diff --git a/frappe/public/js/frappe/request.js b/frappe/public/js/frappe/request.js index 126a09a6fb..c7d45efd07 100644 --- a/frappe/public/js/frappe/request.js +++ b/frappe/public/js/frappe/request.js @@ -68,10 +68,10 @@ frappe.request.call = function(opts) { if(typeof data === "string") data = JSON.parse(data); opts.error && opts.error(data, xhr.responseText); }, - 500: function() { + 500: function(xhr) { msgprint(__("Server Error: Please check your server logs or contact tech support.")) opts.error && opts.error(); - + frappe.request.report_error(xhr, opts); } }, async: opts.async @@ -174,7 +174,9 @@ frappe.request.cleanup = function(opts, r) { r.exc = JSON.parse(r.exc); if(r.exc instanceof Array) { $.each(r.exc, function(i, v) { - if(v)console.log(v); + if(v) { + console.log(v); + } }) } else { console.log(r.exc); @@ -210,3 +212,44 @@ frappe.request.cleanup = function(opts, r) { frappe.last_response = r; } + +frappe.request.report_error = function(xhr, request_opts) { + var data = JSON.parse(xhr.responseText); + if (data.exc) { + var exc = (JSON.parse(data.exc) || []).join("\n"); + delete data.exc; + } else { + var exc = ""; + } + + if (exc) { + var error_report_email = (frappe.boot.error_report_email || []).join(", "); + var error_message = '
' + + __("Report this issue") + '' + + '
' + exc + '
'; + + var msg_dialog = msgprint(error_message); + + msg_dialog.msg_area.find(".report-btn") + .toggle(error_report_email ? true : false) + .on("click", function() { + var error_report_message = [ + '
Error Report
', + '
' + exc + '
', + '
', + '
Request Data
', + '
' + JSON.stringify(request_opts, null, "\t") + '
', + '
', + '
Response JSON
', + '
' + JSON.stringify(data, null, '\t')+ '
' + ].join("\n"); + + var communication_composer = new frappe.views.CommunicationComposer({ + subject: 'Error Report', + recipients: error_report_email, + message: error_report_message + }); + communication_composer.dialog.$wrapper.css("z-index", cint(msg_dialog.$wrapper.css("z-index")) + 1); + }); + } +}; diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index 990e539aff..53677ce6a3 100644 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -260,13 +260,20 @@ frappe.views.CommunicationComposer = Class.extend({ // select print format $(fields.select_print_format.wrapper).toggle(false); - $(fields.select_print_format.input) - .empty() - .add_options(cur_frm.print_formats) - .val(cur_frm.print_formats[0]); + + if (cur_frm) { + $(fields.select_print_format.input) + .empty() + .add_options(cur_frm.print_formats) + .val(cur_frm.print_formats[0]); + } else { + $(fields.attach_document_print.wrapper).toggle(false); + } }, setup_attach: function() { + if (!cur_frm) return; + var fields = this.dialog.fields_dict; var attach = $(fields.select_attachments.wrapper); @@ -366,10 +373,12 @@ frappe.views.CommunicationComposer = Class.extend({ msgprint(__("Email sent to {0}", [form_values.recipients])); me.dialog.hide(); - if (cur_frm.docname && (frappe.last_edited_communication[cur_frm.doctype] || {})[cur_frm.docname]) { - delete frappe.last_edited_communication[cur_frm.doctype][cur_frm.docname]; + if (cur_frm) { + if (cur_frm.docname && (frappe.last_edited_communication[cur_frm.doctype] || {})[cur_frm.docname]) { + delete frappe.last_edited_communication[cur_frm.doctype][cur_frm.docname]; + } + cur_frm.reload_doc(); } - cur_frm.reload_doc(); } else { msgprint(__("There were errors while sending email. Please try again.")); } @@ -379,7 +388,7 @@ frappe.views.CommunicationComposer = Class.extend({ setup_earlier_reply: function() { var fields = this.dialog.fields_dict; - var comm_list = cur_frm.communication_view + var comm_list = (cur_frm && cur_frm.communication_view) ? cur_frm.communication_view.list : []; var signature = frappe.boot.user.email_signature || "";