Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | // License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | d616413 | 2012-12-27 18:40:42 +0530 | [diff] [blame] | 4 | $(document).ready(function() { |
| 5 | |
| 6 | $('.btn-send').click(function() { |
| 7 | var email = $('[name="email"]').val(); |
| 8 | var message = $('[name="message"]').val(); |
| 9 | |
| 10 | if(!(email && message)) { |
| 11 | msgprint("Please enter both your email and message so that we \ |
| 12 | can get back to you. Thanks!"); |
| 13 | return false; |
| 14 | } |
| 15 | |
| 16 | if(!valid_email(email)) { |
| 17 | msgprint("You seem to have written your name instead of your email. \ |
| 18 | Please enter a valid email address so that we can get back."); |
| 19 | $('[name="email"]').focus(); |
| 20 | return false; |
| 21 | } |
| 22 | |
| 23 | $("#contact-alert").toggle(false); |
| 24 | erpnext.send_message({ |
| 25 | subject: $('[name="subject"]').val(), |
| 26 | sender: email, |
| 27 | message: message, |
| 28 | callback: function(r) { |
Rushabh Mehta | 46ec268 | 2013-08-29 13:53:36 +0530 | [diff] [blame] | 29 | if(r.status==="okay") { |
| 30 | msgprint(r.message or "Sent") |
| 31 | } else { |
| 32 | msgprint("There were errors"); |
| 33 | console.log(r.exc); |
| 34 | } |
Rushabh Mehta | d616413 | 2012-12-27 18:40:42 +0530 | [diff] [blame] | 35 | $(':input').val(''); |
| 36 | } |
| 37 | }); |
| 38 | return false; |
| 39 | }); |
| 40 | |
| 41 | }); |
| 42 | |
| 43 | var msgprint = function(txt) { |
| 44 | if(txt) $("#contact-alert").html(txt).toggle(true); |
| 45 | } |