25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

167 lines
4.7 KiB

  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. // EMAIL
  23. // Autosuggest defaults
  24. _e.email_as_field = 'email_id';
  25. _e.email_as_dt = 'Contact';
  26. _e.email_as_in = 'email_id,contact_name';
  27. sendmail = function(emailto, emailfrom, cc, subject, message, fmt, with_attachments) {
  28. var fn = function(html) {
  29. $c('webnotes.utils.email_lib.send_form', {
  30. 'sendto':emailto,
  31. 'sendfrom': emailfrom?emailfrom:'',
  32. 'cc':cc?cc:'',
  33. 'subject':subject,
  34. 'message':replace_newlines(message),
  35. 'body':html,
  36. 'full_domain': wn.urllib.get_base_url(),
  37. 'with_attachments':with_attachments ? 1 : 0,
  38. 'dt':cur_frm.doctype,
  39. 'dn':cur_frm.docname,
  40. 'customer': cur_frm.doc.customer || '',
  41. 'supplier': cur_frm.doc.supplier || ''
  42. },
  43. function(r, rtxt) {
  44. //
  45. }
  46. );
  47. }
  48. // build print format
  49. _p.build(fmt, fn);
  50. }
  51. _e.make = function() {
  52. var d = new Dialog(440, 440, "Send Email");
  53. var email_go = function() {
  54. var emailfrom = d.widgets['From'].value;
  55. var emailto = d.widgets['To'].value;
  56. if(!emailfrom)
  57. emailfrom = user_email;
  58. emailto = emailto.replace(/ /g, "");
  59. // validate email ids
  60. var email_list = emailto.split(/[,|;]/);
  61. var valid = 1;
  62. for(var i=0;i<email_list.length;i++){
  63. if(!email_list[i]) {
  64. email_list.splice(i, 1);
  65. } else if(!validate_email(email_list[i])) {
  66. msgprint('error:'+email_list[i] + ' is not a valid email id');
  67. valid = 0;
  68. }
  69. }
  70. emailto = email_list.join(",");
  71. // validate from
  72. if(emailfrom && !validate_email(emailfrom)) {
  73. 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.');
  74. return;
  75. }
  76. if(!valid)return;
  77. var cc= emailfrom;
  78. if(!emailfrom) {
  79. emailfrom = wn.control_panel.auto_email_id;
  80. cc = '';
  81. }
  82. sendmail(emailto, emailfrom, emailfrom, d.widgets['Subject'].value, d.widgets['Message'].value, sel_val(cur_frm.print_sel), d.widgets['Send With Attachments'].checked);
  83. _e.dialog.hide();
  84. }
  85. d.onhide = function() {
  86. }
  87. d.make_body([
  88. ['Data','To','Example: abc@hotmail.com, xyz@yahoo.com']
  89. ,['Select','Format']
  90. ,['Data','Subject']
  91. ,['Data','From','Optional']
  92. ,['Check','Send With Attachments','Will send all attached documents (if any)']
  93. ,['Text','Message']
  94. ,['Button','Send',email_go]]
  95. );
  96. d.widgets['From'].value = (user_email ? user_email:'');
  97. $td(d.rows['Format'].tab,0,1).cur_sel = d.widgets['Format'];
  98. function split( val ) {
  99. return val.split( /,\s*/ );
  100. }
  101. function extractLast( term ) {
  102. return split(term).pop();
  103. }
  104. $(d.widgets['To'])
  105. .bind( "keydown", function(event) {
  106. if (event.keyCode === $.ui.keyCode.TAB &&
  107. $(this).data( "autocomplete" ).menu.active ) {
  108. event.preventDefault();
  109. }
  110. })
  111. .autocomplete({
  112. source: function(request, response) {
  113. wn.call({
  114. method:'webnotes.utils.email_lib.get_contact_list',
  115. args: {
  116. 'select': _e.email_as_field,
  117. 'from': _e.email_as_dt,
  118. 'where': _e.email_as_in,
  119. 'txt': extractLast(request.term).value || '%'
  120. },
  121. callback: function(r) {
  122. response($.ui.autocomplete.filter(
  123. r.cl || [], extractLast(request.term)));
  124. }
  125. });
  126. },
  127. focus: function() {
  128. // prevent value inserted on focus
  129. return false;
  130. },
  131. select: function( event, ui ) {
  132. var terms = split( this.value );
  133. // remove the current input
  134. terms.pop();
  135. // add the selected item
  136. terms.push( ui.item.value );
  137. // add placeholder to get the comma-and-space at the end
  138. terms.push( "" );
  139. this.value = terms.join( ", " );
  140. return false;
  141. }
  142. });
  143. _e.dialog = d;
  144. }