support_ticket: load communication onload

This commit is contained in:
Rushabh Mehta 2012-11-24 17:00:10 +05:30
parent 24447791b8
commit a3207977d9
4 changed files with 419 additions and 491 deletions

View File

@ -1,3 +1,18 @@
.communication {
border: 1px solid #aaa;
border-top: 0px;
padding: 7px;
background-color: #f2f2f2
}
.communication:hover {
background-color: #fffff0;
}
.communication:first-child {
border-top: 1px solid #aaa;
}
.support-ticket-wrapper { .support-ticket-wrapper {
margin-top: 10px; margin-top: 10px;
} }

View File

@ -22,26 +22,15 @@
// xoxoxoxo // xoxoxoxo
// -------- new reply -------- // -------- new reply --------
var cs = cur_frm.cscript;
$.extend(cur_frm.cscript, { $.extend(cur_frm.cscript, {
onload: function(doc, dt, dn) { onload: function(doc, dt, dn) {
// //
// help area // help area
// //
if(in_list(user_roles,'System Manager')) { if(in_list(user_roles,'System Manager')) {
cur_frm.page_layout.footer.help_area.innerHTML = ''; cur_frm.page_layout.footer.help_area.innerHTML = '<hr>\
new wn.widgets.Footer({ <p><a href="#Form/Email Settings/Email Settings">Email Settings</a><br>\
parent:cur_frm.page_layout.footer.help_area, <span class="help">Integrate incoming support emails to Support Ticket</span></p>';
columns:2,
items: [
{
column: 0,
label:'Email Settings',
description:'Integrate your incoming support emails to support ticket',
onclick: function() { loaddoc('Email Settings','Email Settings'); }
},
]
})
} }
if(!doc.customer) hide_field(['customer_name','address_display','contact_display','contact_mobile','contact_email']); if(!doc.customer) hide_field(['customer_name','address_display','contact_display','contact_mobile','contact_email']);
@ -71,30 +60,30 @@ $.extend(cur_frm.cscript, {
// make thread listing // make thread listing
// //
make_listing: function(doc) { make_listing: function(doc) {
cur_frm.fields_dict['thread_html'].wrapper.innerHTML = ''; var wrapper = cur_frm.fields_dict['thread_html'].wrapper;
$(wrapper)
.html("")
.css({"margin":"10px 0px"});
// render first message var comm_list = wn.model.get("Communication", {"support_ticket": doc.name})
new EmailMessage($a(cur_frm.fields_dict['thread_html'].wrapper, 'div'), { comm_list.push({
email_address: doc.raised_by, "email_address": doc.raised_by,
creation: doc.creation, "modified": doc.creation,
content: doc.description, "content": doc.description});
}, null, -1)
comm_list.sort(function(a, b) { return new Date(a.modified) > new Date(b.modified)
// render thread ? -1 : 1 })
cur_frm.cscript.thread_list = new wn.ui.Listing({
parent: $a(cur_frm.fields_dict['thread_html'].wrapper, 'div'), $.each(comm_list, function(i, c) {
no_result_message: 'No responses yet', var comm = new erpnext.CommunicationView({
get_query: function() { doc: c,
return 'select content, email_address, creation '+ support_ticket: doc,
'from `tabCommunication` where support_ticket="'+doc.name+'" order by creation asc' parent: wrapper
}, });
as_dict: 1, if(i==0) {
render_row: function(parent, data, list, idx) { comm.toggle();
new EmailMessage(parent, data, list, idx);
} }
}); });
cur_frm.cscript.thread_list.run();
}, },
send: function(doc, dt, dn) { send: function(doc, dt, dn) {
@ -140,55 +129,39 @@ $.extend(cur_frm.cscript, {
}) })
erpnext.CommunicationView = Class.extend({
init: function(opts) {
EmailMessage = function(parent, args, list, idx) { $.extend(this, opts);
var me = this; this.prepare();
$.extend(this, args); this.make();
this.make = function() { this.toggle();
this.creation = wn.datetime.str_to_user(this.creation); },
if(this.email_address) prepare: function() {
this.email_address = this.email_address.replace('<', '&lt;').replace('>', '&gt;'); //this.doc.when = comment_when(this.doc.modified);
this.doc.when = this.doc.modified;
// main wrapper if(this.doc.content.indexOf("<br>")== -1 && this.doc.content.indexOf("<p>")== -1) {
w = $a(parent, 'div', 'support-ticket-wrapper well'); this.doc.content = this.doc.content.replace(/\n/g, "<br>");
//$(w).addClass('support-ticket-wrapper');
// sender and timestamp
$a($a(w, 'div', 'support-ticket-title'),
'span', 'link_type', {}, repl('By %(email_address)s on %(creation)s:', this),
function() {
// toggle message display on timestamp
if(me.message.style.display.toLowerCase()=='none') {
$ds(me.message);
} else {
$dh(me.message);
}
}
);
// email text
this.message = $a(w, 'div', '',
// style
{lineHeight:'1.7em', display:'none', padding: '7px', width: '575px',
wordWrap: 'break-word', textWrap: 'normal', overflowX: 'auto'},
// newlines for text email
(this.content.indexOf("<br>")== -1 && this.content.indexOf("<p>")== -1)
? this.content.replace(/\n[ ]*\n[\n\t ]*/g, '\n') // excess whitespace
.replace(/\n/g, '<br>')
: this.content
);
// show only first and last message
if(idx==-1 || list && list.data.length-1==idx) {
$ds(this.message)
} }
this.doc.content = this.doc.content.split("=== In response to ===")[0];
this.doc.content = this.doc.content.split("-----Original Message-----")[0];
},
make: function() {
var me = this;
this.body = $(repl('<div class="communication" title="Click to Expand / Collapse">\
<p><b>%(email_address)s on %(when)s</b></p>\
<p class="comm-content" style="border-top: 1px solid #ddd">%(content)s</p>\
</div>', this.doc))
.appendTo(this.parent)
.css({"cursor":"pointer"})
.click(function() {
$(this).find(".comm-content").toggle();
});
},
toggle: function() {
this.body.find(".comm-content").toggle();
} }
this.make(); })
}
cur_frm.fields_dict.allocated_to.get_query = erpnext.utils.profile_query; cur_frm.fields_dict.allocated_to.get_query = erpnext.utils.profile_query;
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;

View File

@ -29,6 +29,21 @@ class DocType(TransactionBase):
def autoname(self): def autoname(self):
self.doc.name = make_autoname(self.doc.naming_series+'.#####') self.doc.name = make_autoname(self.doc.naming_series+'.#####')
def onload(self):
self.add_communication_list()
def add_communication_list(self):
# remove communications if present
self.doclist = self.doclist.get({"doctype": ["!=", "Communcation"]})
comm_list = webnotes.conn.sql("""select * from tabCommunication
where support_ticket=%s order by modified desc limit 20""", self.doc.name, as_dict=1)
[d.update({"doctype":"Communication"}) for d in comm_list]
self.doclist.extend(webnotes.doclist([webnotes.doc(fielddata=d) \
for d in comm_list]))
def send_response(self): def send_response(self):
""" """
Adds a new response to the ticket and sends an email to the sender Adds a new response to the ticket and sends an email to the sender
@ -61,6 +76,7 @@ class DocType(TransactionBase):
self.doc.new_response = None self.doc.new_response = None
webnotes.conn.set(self.doc, 'status', 'Waiting for Customer') webnotes.conn.set(self.doc, 'status', 'Waiting for Customer')
self.make_response_record(response) self.make_response_record(response)
self.add_communication_list()
def last_response(self): def last_response(self):
"""return last response""" """return last response"""

View File

@ -1,411 +1,335 @@
# DocType, Support Ticket
[ [
{
# These values are common in all dictionaries "owner": "Administrator",
{ "docstatus": 0,
'creation': '2012-04-02 16:02:42', "creation": "2012-11-02 17:17:05",
'docstatus': 0, "modified_by": "Administrator",
'modified': '2012-05-02 11:33:24', "modified": "2012-11-24 16:41:45"
'modified_by': u'Administrator', },
'owner': u'Administrator' {
}, "allow_attach": 1,
"default_print_format": "Standard",
# These values are common for all DocType "search_fields": "status,customer,allocated_to,subject,raised_by",
{ "module": "Support",
'_last_update': u'1311584009', "doctype": "DocType",
'allow_attach': 1, "name": "__common__"
'allow_trash': 1, },
'colour': u'White:FFF', {
'default_print_format': u'Standard', "name": "__common__",
'doctype': 'DocType', "parent": "Support Ticket",
'module': u'Support', "doctype": "DocField",
'name': '__common__', "parenttype": "DocType",
'search_fields': u'status,customer,allocated_to,subject,raised_by', "parentfield": "fields"
'section_style': u'Tray', },
'server_code_error': u' ', {
'show_in_menu': 0, "name": "__common__",
'subject': u'%(subject)s', "parent": "Support Ticket",
'tag_fields': u'status,allocated_to', "amend": 0,
'version': 1 "submit": 0,
}, "doctype": "DocPerm",
"read": 1,
# These values are common for all DocField "parenttype": "DocType",
{ "parentfield": "permissions"
'doctype': u'DocField', },
'name': '__common__', {
'parent': u'Support Ticket', "name": "Support Ticket",
'parentfield': u'fields', "doctype": "DocType"
'parenttype': u'DocType' },
}, {
"print_hide": 1,
# These values are common for all DocPerm "no_copy": 1,
{ "search_index": 0,
'amend': 0, "doctype": "DocField",
'cancel': 0, "label": "Naming Series",
'doctype': u'DocPerm', "options": "SUP",
'name': '__common__', "fieldname": "naming_series",
'parent': u'Support Ticket', "fieldtype": "Select",
'parentfield': u'permissions', "reqd": 0,
'parenttype': u'DocType', "hidden": 0,
'read': 1, "permlevel": 0
'submit': 0 },
}, {
"permlevel": 1,
# DocType, Support Ticket "no_copy": 1,
{ "oldfieldtype": "Select",
'doctype': 'DocType', "colour": "White:FFF",
'name': u'Support Ticket' "doctype": "DocField",
}, "label": "Status",
"oldfieldname": "status",
# DocPerm "default": "Open",
{ "fieldname": "status",
'create': 1, "fieldtype": "Select",
'doctype': u'DocPerm', "search_index": 1,
'permlevel': 0, "reqd": 0,
'role': u'Guest', "options": "\nOpen\nTo Reply\nWaiting for Customer\nHold\nClosed",
'write': 1 "in_filter": 0
}, },
{
# DocPerm "doctype": "DocField",
{ "label": "Subject",
'create': 1, "fieldname": "subject",
'doctype': u'DocPerm', "fieldtype": "Text",
'permlevel': 0, "reqd": 1,
'role': u'Customer', "permlevel": 0,
'write': 1 "in_filter": 1
}, },
{
# DocPerm "oldfieldtype": "Data",
{ "doctype": "DocField",
'create': 1, "label": "Raised By (Email)",
'doctype': u'DocPerm', "oldfieldname": "raised_by",
'permlevel': 0, "fieldname": "raised_by",
'role': u'Support Team', "fieldtype": "Data",
'write': 1 "depends_on": "eval:doc.__islocal",
}, "reqd": 1,
"permlevel": 0,
# DocPerm "in_filter": 1
{ },
'create': 0, {
'doctype': u'DocPerm', "oldfieldtype": "Text",
'permlevel': 1, "doctype": "DocField",
'role': u'Support Team', "label": "Description",
'write': 1 "oldfieldname": "problem_description",
}, "fieldname": "description",
"fieldtype": "Text",
# DocPerm "depends_on": "eval:doc.__islocal",
{ "reqd": 0,
'create': 0, "permlevel": 0
'doctype': u'DocPerm', },
'permlevel': 2, {
'role': u'Support Team', "depends_on": "eval:!doc.__islocal",
'write': 0 "doctype": "DocField",
}, "label": "New Response",
"fieldname": "new_response",
# DocField "fieldtype": "Text",
{ "permlevel": 0
'doctype': u'DocField', },
'fieldname': u'naming_series', {
'fieldtype': u'Select', "depends_on": "eval:!doc.__islocal",
'hidden': 0, "doctype": "DocField",
'label': u'Naming Series', "label": "Send",
'no_copy': 1, "fieldname": "send",
'options': u'SUP', "fieldtype": "Button",
'permlevel': 0, "permlevel": 0
'print_hide': 1, },
'reqd': 0, {
'search_index': 0 "depends_on": "eval:!doc.__islocal",
}, "doctype": "DocField",
"label": "Thread HTML",
# DocField "fieldname": "thread_html",
{ "fieldtype": "HTML",
'colour': u'White:FFF', "permlevel": 1
'default': u'Open', },
'doctype': u'DocField', {
'fieldname': u'status', "colour": "White:FFF",
'fieldtype': u'Select', "doctype": "DocField",
'in_filter': 0, "label": "Additional Info",
'label': u'Status', "fieldname": "additional_info",
'no_copy': 1, "fieldtype": "Section Break",
'oldfieldname': u'status', "permlevel": 1
'oldfieldtype': u'Select', },
'options': u'\nOpen\nTo Reply\nWaiting for Customer\nHold\nClosed', {
'permlevel': 1, "oldfieldtype": "Column Break",
'reqd': 0, "doctype": "DocField",
'search_index': 1 "width": "50%",
}, "fieldname": "column_break0",
"fieldtype": "Column Break",
# DocField "depends_on": "eval:!doc.__islocal",
{ "permlevel": 1
'doctype': u'DocField', },
'fieldname': u'subject', {
'fieldtype': u'Text', "print_hide": 1,
'in_filter': 1, "oldfieldtype": "Link",
'label': u'Subject', "colour": "White:FFF",
'permlevel': 0, "doctype": "DocField",
'reqd': 1 "label": "Customer",
}, "oldfieldname": "customer",
"permlevel": 1,
# DocField "trigger": "Client",
{ "fieldname": "customer",
'depends_on': u'eval:doc.__islocal', "fieldtype": "Link",
'doctype': u'DocField', "search_index": 1,
'fieldname': u'raised_by', "reqd": 0,
'fieldtype': u'Data', "options": "Customer",
'in_filter': 1, "in_filter": 1
'label': u'Raised By (Email)', },
'oldfieldname': u'raised_by', {
'oldfieldtype': u'Data', "oldfieldtype": "Data",
'permlevel': 0, "doctype": "DocField",
'reqd': 1 "label": "Customer Name",
}, "oldfieldname": "customer_name",
"fieldname": "customer_name",
# DocField "fieldtype": "Data",
{ "search_index": 0,
'depends_on': u'eval:doc.__islocal', "reqd": 0,
'doctype': u'DocField', "permlevel": 2,
'fieldname': u'description', "in_filter": 1
'fieldtype': u'Text', },
'label': u'Description', {
'oldfieldname': u'problem_description', "doctype": "DocField",
'oldfieldtype': u'Text', "label": "Address",
'permlevel': 0, "fieldname": "address_display",
'reqd': 0 "fieldtype": "Small Text",
}, "permlevel": 2
},
# DocField {
{ "doctype": "DocField",
'depends_on': u'eval:!doc.__islocal', "label": "Contact Name",
'doctype': u'DocField', "fieldname": "contact_display",
'fieldname': u'thread_html', "fieldtype": "Data",
'fieldtype': u'HTML', "permlevel": 2
'label': u'Thread HTML', },
'permlevel': 1 {
}, "doctype": "DocField",
"label": "Mobile No",
# DocField "fieldname": "contact_mobile",
{ "fieldtype": "Data",
'depends_on': u'eval:!doc.__islocal', "permlevel": 2
'doctype': u'DocField', },
'fieldname': u'new_response', {
'fieldtype': u'Text', "oldfieldtype": "Data",
'label': u'New Response', "doctype": "DocField",
'permlevel': 0 "label": "Contact Email",
}, "oldfieldname": "contact_no",
"fieldname": "contact_email",
# DocField "fieldtype": "Data",
{ "permlevel": 2
'depends_on': u'eval:!doc.__islocal', },
'doctype': u'DocField', {
'fieldname': u'send', "default": "Today",
'fieldtype': u'Button', "oldfieldtype": "Date",
'label': u'Send', "doctype": "DocField",
'permlevel': 0 "label": "Opening Date",
}, "oldfieldname": "opening_date",
"no_copy": 1,
# DocField "fieldname": "opening_date",
{ "fieldtype": "Date",
'colour': u'White:FFF', "permlevel": 1
'doctype': u'DocField', },
'fieldname': u'additional_info', {
'fieldtype': u'Section Break', "no_copy": 1,
'label': u'Additional Info', "oldfieldtype": "Time",
'permlevel': 1 "doctype": "DocField",
}, "label": "Opening Time",
"oldfieldname": "opening_time",
# DocField "fieldname": "opening_time",
{ "fieldtype": "Time",
'depends_on': u'eval:!doc.__islocal', "permlevel": 1
'doctype': u'DocField', },
'fieldname': u'column_break0', {
'fieldtype': u'Column Break', "oldfieldtype": "Column Break",
'oldfieldtype': u'Column Break', "doctype": "DocField",
'permlevel': 1, "fieldname": "column_break1",
'width': u'50%' "fieldtype": "Column Break",
}, "depends_on": "eval:!doc.__islocal",
"permlevel": 1
# DocField },
{ {
'colour': u'White:FFF', "depends_on": "eval:!doc.__islocal",
'doctype': u'DocField', "search_index": 1,
'fieldname': u'customer', "colour": "White:FFF",
'fieldtype': u'Link', "doctype": "DocField",
'in_filter': 1, "label": "Allocated To",
'label': u'Customer', "oldfieldname": "allocated_to",
'oldfieldname': u'customer', "permlevel": 1,
'oldfieldtype': u'Link', "fieldname": "allocated_to",
'options': u'Customer', "fieldtype": "Link",
'permlevel': 1, "oldfieldtype": "Link",
'print_hide': 1, "options": "Profile",
'reqd': 0, "in_filter": 1
'search_index': 1, },
'trigger': u'Client' {
}, "no_copy": 1,
"oldfieldtype": "Text",
# DocField "doctype": "DocField",
{ "label": "Resolution Details",
'doctype': u'DocField', "oldfieldname": "resolution_details",
'fieldname': u'customer_name', "fieldname": "resolution_details",
'fieldtype': u'Data', "fieldtype": "Text",
'in_filter': 1, "depends_on": "eval:!doc.__islocal",
'label': u'Customer Name', "permlevel": 1
'oldfieldname': u'customer_name', },
'oldfieldtype': u'Data', {
'permlevel': 2, "depends_on": "eval:!doc.__islocal",
'reqd': 0, "no_copy": 1,
'search_index': 0 "search_index": 0,
}, "colour": "White:FFF",
"doctype": "DocField",
# DocField "label": "Resolution Date",
{ "oldfieldname": "resolution_date",
'doctype': u'DocField', "fieldname": "resolution_date",
'fieldname': u'address_display', "fieldtype": "Date",
'fieldtype': u'Small Text', "oldfieldtype": "Date",
'label': u'Address', "permlevel": 1,
'permlevel': 2 "in_filter": 0
}, },
{
# DocField "oldfieldtype": "Time",
{ "doctype": "DocField",
'doctype': u'DocField', "label": "Resolution Time",
'fieldname': u'contact_display', "oldfieldname": "resolution_time",
'fieldtype': u'Data', "fieldname": "resolution_time",
'label': u'Contact Name', "fieldtype": "Time",
'permlevel': 2 "depends_on": "eval:!doc.__islocal",
}, "permlevel": 1
},
# DocField {
{ "colour": "White:FFF",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'contact_mobile', "label": "Content Type",
'fieldtype': u'Data', "fieldname": "content_type",
'label': u'Mobile No', "fieldtype": "Data",
'permlevel': 2 "hidden": 1,
}, "permlevel": 0
},
# DocField {
{ "print_hide": 1,
'doctype': u'DocField', "no_copy": 1,
'fieldname': u'contact_email', "doctype": "DocField",
'fieldtype': u'Data', "label": "File List",
'label': u'Contact Email', "fieldname": "file_list",
'oldfieldname': u'contact_no', "fieldtype": "Text",
'oldfieldtype': u'Data', "hidden": 1,
'permlevel': 2 "permlevel": 0
}, },
{
# DocField "create": 1,
{ "doctype": "DocPerm",
'default': u'Today', "write": 1,
'doctype': u'DocField', "role": "Guest",
'fieldname': u'opening_date', "cancel": 0,
'fieldtype': u'Date', "permlevel": 0
'label': u'Opening Date', },
'no_copy': 1, {
'oldfieldname': u'opening_date', "create": 1,
'oldfieldtype': u'Date', "doctype": "DocPerm",
'permlevel': 1 "write": 1,
}, "role": "Customer",
"cancel": 0,
# DocField "permlevel": 0
{ },
'doctype': u'DocField', {
'fieldname': u'opening_time', "create": 1,
'fieldtype': u'Time', "doctype": "DocPerm",
'label': u'Opening Time', "write": 1,
'no_copy': 1, "role": "Support Team",
'oldfieldname': u'opening_time', "cancel": 1,
'oldfieldtype': u'Time', "permlevel": 0
'permlevel': 1 },
}, {
"create": 0,
# DocField "doctype": "DocPerm",
{ "write": 1,
'depends_on': u'eval:!doc.__islocal', "role": "Support Team",
'doctype': u'DocField', "cancel": 0,
'fieldname': u'column_break1', "permlevel": 1
'fieldtype': u'Column Break', },
'oldfieldtype': u'Column Break', {
'permlevel': 1 "create": 0,
}, "doctype": "DocPerm",
"write": 0,
# DocField "role": "Support Team",
{ "cancel": 0,
'colour': u'White:FFF', "permlevel": 2
'depends_on': u'eval:!doc.__islocal', }
'doctype': u'DocField',
'fieldname': u'allocated_to',
'fieldtype': u'Link',
'in_filter': 1,
'label': u'Allocated To',
'oldfieldname': u'allocated_to',
'oldfieldtype': u'Link',
'options': u'Profile',
'permlevel': 1,
'search_index': 1
},
# DocField
{
'depends_on': u'eval:!doc.__islocal',
'doctype': u'DocField',
'fieldname': u'resolution_details',
'fieldtype': u'Text',
'label': u'Resolution Details',
'no_copy': 1,
'oldfieldname': u'resolution_details',
'oldfieldtype': u'Text',
'permlevel': 1
},
# DocField
{
'colour': u'White:FFF',
'depends_on': u'eval:!doc.__islocal',
'doctype': u'DocField',
'fieldname': u'resolution_date',
'fieldtype': u'Date',
'in_filter': 0,
'label': u'Resolution Date',
'no_copy': 1,
'oldfieldname': u'resolution_date',
'oldfieldtype': u'Date',
'permlevel': 1,
'search_index': 0
},
# DocField
{
'depends_on': u'eval:!doc.__islocal',
'doctype': u'DocField',
'fieldname': u'resolution_time',
'fieldtype': u'Time',
'label': u'Resolution Time',
'oldfieldname': u'resolution_time',
'oldfieldtype': u'Time',
'permlevel': 1
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'content_type',
'fieldtype': u'Data',
'hidden': 1,
'label': u'Content Type',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'file_list',
'fieldtype': u'Text',
'hidden': 1,
'label': u'File List',
'no_copy': 1,
'permlevel': 0,
'print_hide': 1
}
] ]