blob: 5e7a010144ce723fa06d805676d0b5a48fed0269 [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
22 this.list.sort(function(a, b) { return new Date(a.modified) > new Date(b.modified)
23 ? -1 : 1 })
24
25 this.make();
26 },
27 make: function() {
28 var me = this;
29 this.make_body();
30 $.each(this.list, function(i, d) {
31 me.prepare(d);
32 me.make_line(d);
33 });
34 // show first
35 this.comm_list[0].find('.comm-content').toggle(true);
36 },
37 make_body: function() {
38 $(this.parent)
39 .html("")
40 .css({"margin":"10px 0px"});
41
42 this.wrapper = $("<div><h4>Communication History</h4>\
43 <button class='btn btn-small'>Add Reply</button></p></div>")
44 .appendTo(this.parent);
45
46 this.body = $("<table class='table table-bordered table-hover table-striped'>")
47 .appendTo(this.wrapper);
48 },
49 prepare: function(doc) {
50 //doc.when = comment_when(this.doc.modified);
51 doc.when = doc.modified;
52 if(doc.content.indexOf("<br>")== -1 && doc.content.indexOf("<p>")== -1) {
53 doc.content = doc.content.replace(/\n/g, "<br>");
54 }
55 doc.email_address = doc.email_address.replace(/</, "&lt;").replace(/>/, "&gt;");
56 doc.content = doc.content.split("=== In response to ===")[0];
57 doc.content = doc.content.split("-----Original Message-----")[0];
58 },
59 make_line: function(doc) {
60 var me = this;
61 var comm = $(repl('<tr><td title="Click to Expand / Collapse">\
62 <p><b>%(email_address)s on %(when)s</b></p>\
63 <div class="comm-content" style="border-top: 1px solid #ddd; padding: 10px; \
64 display: none;"></div>\
65 </td></tr>', doc))
66 .appendTo(this.body)
67 .css({"cursor":"pointer"})
68 .click(function() {
69 $(this).find(".comm-content").toggle();
70 });
71
72 this.comm_list.push(comm);
73 comm.find(".comm-content").html(doc.content);
74 }
75})