blob: caec94512a76db72eb1fa695ec8dd93d9ffb010f [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2// License: GNU General Public License v3. See license.txt
3
Rushabh Mehtad6164132012-12-27 18:40:42 +05304$(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 Mehta46ec2682013-08-29 13:53:36 +053029 if(r.status==="okay") {
30 msgprint(r.message or "Sent")
31 } else {
32 msgprint("There were errors");
33 console.log(r.exc);
34 }
Rushabh Mehtad6164132012-12-27 18:40:42 +053035 $(':input').val('');
36 }
37 });
38 return false;
39 });
40
41});
42
43var msgprint = function(txt) {
44 if(txt) $("#contact-alert").html(txt).toggle(true);
45}