Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

280 wiersze
7.9 KiB

  1. // for license information, see license.txt
  2. // opts - parent, list, doc, email
  3. wn.views.CommunicationList = Class.extend({
  4. init: function(opts) {
  5. this.comm_list = [];
  6. $.extend(this, opts);
  7. if(this.doc.__islocal) {
  8. return;
  9. }
  10. this.list.sort(function(a, b) { return
  11. (new Date(a.modified) > new Date(b.modified))
  12. ? -1 : 1; })
  13. this.make();
  14. },
  15. make: function() {
  16. var me = this;
  17. this.make_body();
  18. if(this.list && this.list.length) {
  19. $.each(this.list, function(i, d) {
  20. me.prepare(d);
  21. me.make_line(d);
  22. });
  23. // show first
  24. this.comm_list[0].find('.comm-content').toggle(true);
  25. } else {
  26. this.body.remove()
  27. $("<div class='alert'>No Communication tagged with this "
  28. + this.doc.doctype +" yet.</div>").appendTo(this.wrapper);
  29. }
  30. },
  31. make_body: function() {
  32. $(this.parent)
  33. .html("")
  34. .css({"margin":"10px 0px"});
  35. this.wrapper = $("<div><h4>Communication History</h4>\
  36. <div style='margin-bottom: 8px;'>\
  37. <button class='btn btn-small' \
  38. onclick='cur_frm.communication_view.add_reply()'>\
  39. <i class='icon-plus'></i> Add Message</button></div>\
  40. </div>")
  41. .appendTo(this.parent);
  42. this.body = $("<table class='table table-bordered table-hover table-striped'>")
  43. .appendTo(this.wrapper);
  44. },
  45. add_reply: function() {
  46. new wn.views.CommunicationComposer({
  47. doc: this.doc,
  48. subject: this.doc.subject,
  49. recipients: this.recipients
  50. })
  51. },
  52. prepare: function(doc) {
  53. //doc.when = comment_when(this.doc.modified);
  54. doc.when = doc.modified;
  55. if(doc.content.indexOf("<br>")== -1 && doc.content.indexOf("<p>")== -1) {
  56. doc.content = doc.content.replace(/\n/g, "<br>");
  57. }
  58. if(!doc.sender) doc.sender = "[unknown sender]";
  59. doc._sender = doc.sender.replace(/</, "&lt;").replace(/>/, "&gt;");
  60. doc.content = doc.content.split("-----In response to-----")[0];
  61. doc.content = doc.content.split("-----Original Message-----")[0];
  62. },
  63. make_line: function(doc) {
  64. var me = this;
  65. var comm = $(repl('<tr><td title="Click to Expand / Collapse">\
  66. <a href="#Form/Communication/%(name)s" style="font-size: 90%; float: right;">\
  67. Show Details</a>\
  68. <p class="comm-header"><b>%(_sender)s on %(when)s</b></p>\
  69. <div class="comm-content" style="border-top: 1px solid #ddd; \
  70. padding: 10px; overflow-x: auto; display: none;"></div>\
  71. </td></tr>', doc))
  72. .appendTo(this.body)
  73. comm.find(".comm-header")
  74. .css({"cursor":"pointer"})
  75. .click(function() {
  76. $(this).parent().find(".comm-content").toggle();
  77. });
  78. this.comm_list.push(comm);
  79. comm.find(".comm-content").html(doc.content);
  80. }
  81. });
  82. wn.views.CommunicationComposer = Class.extend({
  83. init: function(opts) {
  84. $.extend(this, opts)
  85. this.make();
  86. this.dialog.show();
  87. },
  88. make: function() {
  89. this.dialog = new wn.ui.Dialog({
  90. width: 640,
  91. title: "Add Reply: " + (this.subject || ""),
  92. no_submit_on_enter: true,
  93. fields: [
  94. {label:"To", fieldtype:"Data", reqd: 1, fieldname:"recipients",
  95. description:"Email addresses, separted by commas"},
  96. {label:"Subject", fieldtype:"Data", reqd: 1},
  97. {label:"Add Reply", fieldtype:"Button"},
  98. {label:"Message", fieldtype:"Text Editor", reqd: 1, fieldname:"content"},
  99. {label:"Send Email", fieldtype:"Check"},
  100. {label:"Send Me A Copy", fieldtype:"Check"},
  101. {label:"Attach Document Print", fieldtype:"Check"},
  102. {label:"Select Print Format", fieldtype:"Select"},
  103. {label:"Select Attachments", fieldtype:"HTML"}
  104. ]
  105. });
  106. this.prepare();
  107. },
  108. prepare: function() {
  109. this.setup_print();
  110. this.setup_attach();
  111. this.setup_email();
  112. this.setup_autosuggest();
  113. $(this.dialog.fields_dict.recipients.input).val(this.recipients || "").change();
  114. $(this.dialog.fields_dict.subject.input).val(this.subject || "").change();
  115. this.setup_earlier_reply();
  116. },
  117. setup_print: function() {
  118. // print formats
  119. var fields = this.dialog.fields_dict;
  120. // toggle print format
  121. $(fields.attach_document_print.input).click(function() {
  122. $(fields.select_print_format.wrapper).toggle($(this).is(":checked"));
  123. });
  124. // select print format
  125. $(fields.select_print_format.wrapper).toggle(false);
  126. $(fields.select_print_format.input)
  127. .empty()
  128. .add_options(cur_frm.print_formats)
  129. .val(cur_frm.print_formats[0]);
  130. },
  131. setup_attach: function() {
  132. var fields = this.dialog.fields_dict;
  133. var attach = $(fields.select_attachments.wrapper);
  134. var files = cur_frm.get_files();
  135. if(files.length) {
  136. $("<p><b>Add Attachments:</b></p>").appendTo(attach);
  137. $.each(files, function(i, f) {
  138. $(repl("<p><input type='checkbox' \
  139. data-file-name='%(file)s'> %(file)s</p>", {file:f})).appendTo(attach)
  140. });
  141. }
  142. },
  143. setup_email: function() {
  144. // email
  145. var me = this;
  146. var fields = this.dialog.fields_dict;
  147. if(this.attach_document_print)
  148. $(fields.attach_document_print.input).attr("checked", "checked")
  149. $(fields.send_email.input).attr("checked", "checked")
  150. $(fields.add_reply.input).click(function() {
  151. var form_values = me.dialog.get_values();
  152. if(!form_values) return;
  153. var selected_attachments = $.map($(me.dialog.wrapper)
  154. .find("[data-file-name]:checked"), function(element) {
  155. return $(element).attr("data-file-name");
  156. })
  157. _p.build(args.select_print_format || "", function(print_html) {
  158. me.dialog.hide();
  159. wn.call({
  160. method:"core.doctype.communication.communication.make",
  161. args: {
  162. sender: wn.user_info(user).fullname + " <" + wn.boot.profile.email + ">",
  163. recipients: form_values.recipients,
  164. subject: form_values.subject,
  165. content: form_values.content,
  166. doctype: me.doc.doctype,
  167. name: me.doc.name,
  168. lead: me.doc.lead,
  169. contact: me.doc.contact,
  170. send_me_a_copy: form_values.send_me_a_copy,
  171. send_email: form_values.send_email,
  172. print_html: form_values.attach_document_print
  173. ? print_html : "",
  174. attachments: selected_attachments
  175. },
  176. callback: function(r) {
  177. cur_frm.reload_doc();
  178. }
  179. });
  180. })
  181. });
  182. },
  183. setup_earlier_reply: function() {
  184. var fields = this.dialog.fields_dict;
  185. var comm_list = cur_frm.communication_view
  186. ? cur_frm.communication_view.list
  187. : [];
  188. var signature = wn.boot.profile.email_signature || "";
  189. if(signature.indexOf("<br>")==-1 && signature.indexOf("<p")==-1
  190. && signature.indexOf("<img")==-1 && signature.indexOf("<div")==-1) {
  191. signature = signature.replace(/\n/g, "<br>");
  192. }
  193. if(comm_list.length > 0) {
  194. fields.content.input.set_input("<p></p>"
  195. + signature
  196. +"<p></p>"
  197. +"-----In response to-----<p></p>"
  198. + comm_list[0].content);
  199. } else {
  200. fields.content.input.set_input((this.message || "")
  201. + "<p></p>" + signature)
  202. }
  203. },
  204. setup_autosuggest: function() {
  205. var me = this;
  206. function split( val ) {
  207. return val.split( /,\s*/ );
  208. }
  209. function extractLast( term ) {
  210. return split(term).pop();
  211. }
  212. $(this.dialog.fields_dict.recipients.input)
  213. .bind( "keydown", function(event) {
  214. if (event.keyCode === $.ui.keyCode.TAB &&
  215. $(this).data( "autocomplete" ).menu.active ) {
  216. event.preventDefault();
  217. }
  218. })
  219. .autocomplete({
  220. source: function(request, response) {
  221. wn.call({
  222. method:'webnotes.utils.email_lib.get_contact_list',
  223. args: {
  224. 'select': "email_id",
  225. 'from': "Contact",
  226. 'where': "email_id",
  227. 'txt': extractLast(request.term).value || '%'
  228. },
  229. callback: function(r) {
  230. response($.ui.autocomplete.filter(
  231. r.cl || [], extractLast(request.term)));
  232. }
  233. });
  234. },
  235. focus: function() {
  236. // prevent value inserted on focus
  237. return false;
  238. },
  239. select: function( event, ui ) {
  240. var terms = split( this.value );
  241. // remove the current input
  242. terms.pop();
  243. // add the selected item
  244. terms.push( ui.item.value );
  245. // add placeholder to get the comma-and-space at the end
  246. terms.push( "" );
  247. this.value = terms.join( ", " );
  248. return false;
  249. }
  250. });
  251. }
  252. });