選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

141 行
3.8 KiB

  1. // EMAIL
  2. // Autosuggest defaults
  3. _e.email_as_field = 'email_id';
  4. _e.email_as_dt = 'Contact';
  5. _e.email_as_in = 'email_id,contact_name';
  6. sendmail = function(emailto, emailfrom, cc, subject, message, fmt, with_attachments) {
  7. var fn = function(html) {
  8. $c('webnotes.utils.email_lib.send_form', {
  9. 'sendto':emailto,
  10. 'sendfrom': emailfrom?emailfrom:'',
  11. 'cc':cc?cc:'',
  12. 'subject':subject,
  13. 'message':replace_newlines(message),
  14. 'body':html,
  15. 'full_domain': wn.urllib.get_base_url(),
  16. 'with_attachments':with_attachments ? 1 : 0,
  17. 'dt':cur_frm.doctype,
  18. 'dn':cur_frm.docname
  19. },
  20. function(r, rtxt) {
  21. //
  22. }
  23. );
  24. }
  25. // build print format
  26. _p.build(fmt, fn);
  27. }
  28. _e.make = function() {
  29. var d = new Dialog(440, 440, "Send Email");
  30. var email_go = function() {
  31. var emailfrom = d.widgets['From'].value;
  32. var emailto = d.widgets['To'].value;
  33. if(!emailfrom)
  34. emailfrom = user_email;
  35. // validate email ids
  36. var email_list = emailto.split(/[,|;]/);
  37. var valid = 1;
  38. for(var i=0;i<email_list.length;i++){
  39. if(!validate_email(email_list[i])) {
  40. msgprint('error:'+email_list[i] + ' is not a valid email id');
  41. valid = 0;
  42. }
  43. }
  44. // validate from
  45. if(emailfrom && !validate_email(emailfrom)) {
  46. msgprint('error:'+ emailfrom + ' is not a valid email id. To change the default please click on Profile on the top right of the screen and change it.');
  47. return;
  48. }
  49. if(!valid)return;
  50. var cc= emailfrom;
  51. if(!emailfrom) {
  52. emailfrom = locals['Control Panel']['Control Panel'].auto_email_id;
  53. cc = '';
  54. }
  55. sendmail(emailto, emailfrom, emailfrom, d.widgets['Subject'].value, d.widgets['Message'].value, sel_val(cur_frm.print_sel), d.widgets['Send With Attachments'].checked);
  56. _e.dialog.hide();
  57. }
  58. d.onhide = function() {
  59. hide_autosuggest();
  60. }
  61. d.make_body([
  62. ['Data','To','Example: abc@hotmail.com, xyz@yahoo.com']
  63. ,['Select','Format']
  64. ,['Data','Subject']
  65. ,['Data','From','Optional']
  66. ,['Check','Send With Attachments','Will send all attached documents (if any)']
  67. ,['Text','Message']
  68. ,['Button','Send',email_go]]
  69. );
  70. d.widgets['From'].value = (user_email ? user_email:'');
  71. $td(d.rows['Format'].tab,0,1).cur_sel = d.widgets['Format'];
  72. // ---- add auto suggest ----
  73. var opts = { script: '', json: true, maxresults: 10 };
  74. var as = new AutoSuggest(d.widgets['To'], opts);
  75. as.custom_select = function(txt, sel) {
  76. // ---- add to the last comma ----
  77. var r = '';
  78. var tl = txt.split(',');
  79. for(var i=0;i<tl.length-1;i++) r=r+tl[i]+',';
  80. r = r+(r?' ':'')+sel;
  81. if(r[r.length-1]==NEWLINE) r=substr(0,r.length-1);
  82. return r;
  83. }
  84. var emailto = d.widgets['To']
  85. as.set_input_value = function(new_txt) {
  86. if(emailto.value && emailto.value.indexOf(',')!=-1) {
  87. var txt = emailto.value.split(',');
  88. txt.splice(txt.length - 1, 1, new_txt);
  89. for(var i=0;i<txt.length-1;i++) txt[i] = strip(txt[i]);
  90. emailto.value = txt.join(', ');
  91. } else {
  92. emailto.value = new_txt;
  93. }
  94. }
  95. // ---- override server call ----
  96. as.doAjaxRequest = function(txt) {
  97. var pointer = as; var q = '';
  98. // ---- get last few letters typed ----
  99. var last_txt = txt.split(',');
  100. last_txt = last_txt[last_txt.length-1];
  101. // ---- show options ----
  102. var call_back = function(r,rt) {
  103. as.aSug = [];
  104. if(!r.cl) return;
  105. for (var i=0;i<r.cl.length;i++) {
  106. as.aSug.push({'id':r.cl[i], 'value':r.cl[i], 'info':''});
  107. }
  108. as.createList(as.aSug);
  109. }
  110. $c('webnotes.utils.email_lib.get_contact_list',{'select':_e.email_as_field, 'from':_e.email_as_dt, 'where':_e.email_as_in, 'txt':(last_txt ? strip(last_txt) : '%')},call_back);
  111. return;
  112. }
  113. var sel;
  114. _e.dialog = d;
  115. }