blob: feef6c990700a380cd705b70a9bc02b8ea54d290 [file] [log] [blame]
Rushabh Mehtac4e7b682012-11-26 18:18:10 +05301// ERPNext - web based ERP (http://erpnext.com)
2// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17erpnext.CommunicationView = Class.extend({
18 init: function(opts) {
19 this.comm_list = [];
20 $.extend(this, opts);
21
Anand Doshi319ac972012-11-27 13:30:03 +053022 this.list.sort(function(a, b) { return
23 (new Date(a.modified) > new Date(b.modified))
24 ? -1 : 1; })
Rushabh Mehtac4e7b682012-11-26 18:18:10 +053025
26 this.make();
27 },
28 make: function() {
29 var me = this;
30 this.make_body();
31 $.each(this.list, function(i, d) {
32 me.prepare(d);
33 me.make_line(d);
34 });
35 // show first
36 this.comm_list[0].find('.comm-content').toggle(true);
37 },
38 make_body: function() {
39 $(this.parent)
40 .html("")
41 .css({"margin":"10px 0px"});
42
43 this.wrapper = $("<div><h4>Communication History</h4>\
44 <button class='btn btn-small'>Add Reply</button></p></div>")
Anand Doshi319ac972012-11-27 13:30:03 +053045 .appendTo(this.parent).css({
46 "overflow-x": "auto",
47 });
Rushabh Mehtac4e7b682012-11-26 18:18:10 +053048
49 this.body = $("<table class='table table-bordered table-hover table-striped'>")
50 .appendTo(this.wrapper);
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 doc.email_address = doc.email_address.replace(/</, "&lt;").replace(/>/, "&gt;");
59 doc.content = doc.content.split("=== In response to ===")[0];
60 doc.content = doc.content.split("-----Original Message-----")[0];
61 },
62 make_line: function(doc) {
63 var me = this;
64 var comm = $(repl('<tr><td title="Click to Expand / Collapse">\
65 <p><b>%(email_address)s on %(when)s</b></p>\
66 <div class="comm-content" style="border-top: 1px solid #ddd; padding: 10px; \
67 display: none;"></div>\
68 </td></tr>', doc))
69 .appendTo(this.body)
70 .css({"cursor":"pointer"})
71 .click(function() {
72 $(this).find(".comm-content").toggle();
73 });
74
75 this.comm_list.push(comm);
76 comm.find(".comm-content").html(doc.content);
77 }
78})