blob: de4be6939ffc31d24764011cdc8d4025b9f14434 [file] [log] [blame]
Rushabh Mehta173a0fd2012-12-14 16:39:27 +05301
2var erpnext = {};
3
4// subject, sender, description
5erpnext.send_message = function(opts) {
6 if(opts.btn) {
7 $(opts.btn).attr("disabled", "disabled");
8 }
9
10 $.ajax({
Rushabh Mehtafdc629b2013-01-31 22:05:39 +053011 type: "POST",
Rushabh Mehta173a0fd2012-12-14 16:39:27 +053012 url: "server.py",
13 data: {
Rushabh Mehta2e5db352013-01-16 11:34:26 +053014 cmd: "website.helpers.contact.send_message",
Rushabh Mehta173a0fd2012-12-14 16:39:27 +053015 subject: opts.subject,
16 sender: opts.sender,
Anand Doshie47ceae2012-12-24 19:50:15 +053017 status: opts.status,
Rushabh Mehta173a0fd2012-12-14 16:39:27 +053018 message: typeof opts.message == "string"
19 ? opts.message
20 : JSON.stringify(opts.message)
21 },
22 dataType: "json",
23 success: function(data) {
24 if(opts.btn) {
25 $(opts.btn).attr("disabled", false);
26 }
27 if(opts.callback)
28 opts.callback(data);
29 }
30 });
31}
32
33function valid_email(id) {
34 if(id.toLowerCase().search("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")==-1)
35 return 0; else return 1; }
36
Rushabh Mehta2e5db352013-01-16 11:34:26 +053037var validate_email = valid_email;
38
Rushabh Mehta173a0fd2012-12-14 16:39:27 +053039function get_url_arg(name) {
40 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
41 var regexS = "[\\?&]"+name+"=([^&#]*)";
42 var regex = new RegExp( regexS );
43 var results = regex.exec( window.location.href );
44 if(results == null)
45 return "";
46 else
47 return decodeURIComponent(results[1]);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053048}
49
50function repl(s, dict) {
51 if(s==null)return '';
52 for(key in dict) {
53 s = s.split("%("+key+")s").join(dict[key]);
54 }
55 return s;
56}