From 21c649527a59a808b0e9c75aa89957f14fb391ff Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 14 Dec 2011 20:35:19 +0530 Subject: [PATCH] Provides better error message to the user --- .../doctype/email_digest/email_digest.js | 55 ++++++++++++------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.js b/erpnext/setup/doctype/email_digest/email_digest.js index 98abbb131e..bc2c4ba68e 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.js +++ b/erpnext/setup/doctype/email_digest/email_digest.js @@ -1,30 +1,43 @@ cur_frm.cscript.refresh = function(doc, dt, dn) { + doc = locals[dt][dn]; + var save_msg = "You must Save the form before proceeding"; + var err_msg = "There was an error. One probable reason could be that you haven't saved the form. Please contact support@erpnext.com if the problem persists." cur_frm.add_custom_button('View Now', function() { - $c_obj(make_doclist(dt, dn), 'get', '', function(r, rt) { - if(r.exc) { - msgprint(r.exc); - } else { - //console.log(arguments); - var d = new wn.widgets.Dialog({ - title: 'Email Digest: ' + dn, - width: 800 - }); + if(doc.__unsaved != 1) { + $c_obj(make_doclist(dt, dn), 'get', '', function(r, rt) { + if(r.exc) { + msgprint(err_msg); + console.log(r.exc); + } else { + //console.log(arguments); + var d = new wn.widgets.Dialog({ + title: 'Email Digest: ' + dn, + width: 800 + }); - $a(d.body, 'div', '', '', r['message'][1]); + $a(d.body, 'div', '', '', r['message'][1]); - d.show(); - } - }); + d.show(); + } + }); + } else { + msgprint(save_msg); + } }, 1); cur_frm.add_custom_button('Send Now', function() { - $c_obj(make_doclist(dt, dn), 'send', '', function(r, rt) { - if(r.exc) { - msgprint(r.exc); - } else { - //console.log(arguments); - msgprint('Message Sent'); - } - }); + if(doc.__unsaved != 1) { + $c_obj(make_doclist(dt, dn), 'send', '', function(r, rt) { + if(r.exc) { + msgprint(err_msg); + console.log(r.exc); + } else { + //console.log(arguments); + msgprint('Message Sent'); + } + }); + } else { + msgprint(save_msg); + } }, 1); }