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)
// render thread comm_list.sort(function(a, b) { return new Date(a.modified) > new Date(b.modified)
cur_frm.cscript.thread_list = new wn.ui.Listing({ ? -1 : 1 })
parent: $a(cur_frm.fields_dict['thread_html'].wrapper, 'div'),
no_result_message: 'No responses yet', $.each(comm_list, function(i, c) {
get_query: function() { var comm = new erpnext.CommunicationView({
return 'select content, email_address, creation '+ doc: c,
'from `tabCommunication` where support_ticket="'+doc.name+'" order by creation asc' support_ticket: doc,
}, parent: wrapper
as_dict: 1, });
render_row: function(parent, data, list, idx) { if(i==0) {
new EmailMessage(parent, data, list, idx); comm.toggle();
} }
}); });
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 = function() {
this.creation = wn.datetime.str_to_user(this.creation);
if(this.email_address)
this.email_address = this.email_address.replace('<', '&lt;').replace('>', '&gt;');
// main wrapper
w = $a(parent, 'div', 'support-ticket-wrapper well');
//$(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.make(); this.make();
this.toggle();
},
prepare: function() {
//this.doc.when = comment_when(this.doc.modified);
this.doc.when = this.doc.modified;
if(this.doc.content.indexOf("<br>")== -1 && this.doc.content.indexOf("<p>")== -1) {
this.doc.content = this.doc.content.replace(/\n/g, "<br>");
} }
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();
}
})
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
{ {
'creation': '2012-04-02 16:02:42', "owner": "Administrator",
'docstatus': 0, "docstatus": 0,
'modified': '2012-05-02 11:33:24', "creation": "2012-11-02 17:17:05",
'modified_by': u'Administrator', "modified_by": "Administrator",
'owner': u'Administrator' "modified": "2012-11-24 16:41:45"
}, },
# These values are common for all DocType
{ {
'_last_update': u'1311584009', "allow_attach": 1,
'allow_attach': 1, "default_print_format": "Standard",
'allow_trash': 1, "search_fields": "status,customer,allocated_to,subject,raised_by",
'colour': u'White:FFF', "module": "Support",
'default_print_format': u'Standard', "doctype": "DocType",
'doctype': 'DocType', "name": "__common__"
'module': u'Support',
'name': '__common__',
'search_fields': u'status,customer,allocated_to,subject,raised_by',
'section_style': u'Tray',
'server_code_error': u' ',
'show_in_menu': 0,
'subject': u'%(subject)s',
'tag_fields': u'status,allocated_to',
'version': 1
}, },
# These values are common for all DocField
{ {
'doctype': u'DocField', "name": "__common__",
'name': '__common__', "parent": "Support Ticket",
'parent': u'Support Ticket', "doctype": "DocField",
'parentfield': u'fields', "parenttype": "DocType",
'parenttype': u'DocType' "parentfield": "fields"
}, },
# These values are common for all DocPerm
{ {
'amend': 0, "name": "__common__",
'cancel': 0, "parent": "Support Ticket",
'doctype': u'DocPerm', "amend": 0,
'name': '__common__', "submit": 0,
'parent': u'Support Ticket', "doctype": "DocPerm",
'parentfield': u'permissions', "read": 1,
'parenttype': u'DocType', "parenttype": "DocType",
'read': 1, "parentfield": "permissions"
'submit': 0
}, },
# DocType, Support Ticket
{ {
'doctype': 'DocType', "name": "Support Ticket",
'name': u'Support Ticket' "doctype": "DocType"
}, },
# DocPerm
{ {
'create': 1, "print_hide": 1,
'doctype': u'DocPerm', "no_copy": 1,
'permlevel': 0, "search_index": 0,
'role': u'Guest', "doctype": "DocField",
'write': 1 "label": "Naming Series",
"options": "SUP",
"fieldname": "naming_series",
"fieldtype": "Select",
"reqd": 0,
"hidden": 0,
"permlevel": 0
}, },
# DocPerm
{ {
'create': 1, "permlevel": 1,
'doctype': u'DocPerm', "no_copy": 1,
'permlevel': 0, "oldfieldtype": "Select",
'role': u'Customer', "colour": "White:FFF",
'write': 1 "doctype": "DocField",
"label": "Status",
"oldfieldname": "status",
"default": "Open",
"fieldname": "status",
"fieldtype": "Select",
"search_index": 1,
"reqd": 0,
"options": "\nOpen\nTo Reply\nWaiting for Customer\nHold\nClosed",
"in_filter": 0
}, },
# DocPerm
{ {
'create': 1, "doctype": "DocField",
'doctype': u'DocPerm', "label": "Subject",
'permlevel': 0, "fieldname": "subject",
'role': u'Support Team', "fieldtype": "Text",
'write': 1 "reqd": 1,
"permlevel": 0,
"in_filter": 1
}, },
# DocPerm
{ {
'create': 0, "oldfieldtype": "Data",
'doctype': u'DocPerm', "doctype": "DocField",
'permlevel': 1, "label": "Raised By (Email)",
'role': u'Support Team', "oldfieldname": "raised_by",
'write': 1 "fieldname": "raised_by",
"fieldtype": "Data",
"depends_on": "eval:doc.__islocal",
"reqd": 1,
"permlevel": 0,
"in_filter": 1
}, },
# DocPerm
{ {
'create': 0, "oldfieldtype": "Text",
'doctype': u'DocPerm', "doctype": "DocField",
'permlevel': 2, "label": "Description",
'role': u'Support Team', "oldfieldname": "problem_description",
'write': 0 "fieldname": "description",
"fieldtype": "Text",
"depends_on": "eval:doc.__islocal",
"reqd": 0,
"permlevel": 0
}, },
# DocField
{ {
'doctype': u'DocField', "depends_on": "eval:!doc.__islocal",
'fieldname': u'naming_series', "doctype": "DocField",
'fieldtype': u'Select', "label": "New Response",
'hidden': 0, "fieldname": "new_response",
'label': u'Naming Series', "fieldtype": "Text",
'no_copy': 1, "permlevel": 0
'options': u'SUP',
'permlevel': 0,
'print_hide': 1,
'reqd': 0,
'search_index': 0
}, },
# DocField
{ {
'colour': u'White:FFF', "depends_on": "eval:!doc.__islocal",
'default': u'Open', "doctype": "DocField",
'doctype': u'DocField', "label": "Send",
'fieldname': u'status', "fieldname": "send",
'fieldtype': u'Select', "fieldtype": "Button",
'in_filter': 0, "permlevel": 0
'label': u'Status',
'no_copy': 1,
'oldfieldname': u'status',
'oldfieldtype': u'Select',
'options': u'\nOpen\nTo Reply\nWaiting for Customer\nHold\nClosed',
'permlevel': 1,
'reqd': 0,
'search_index': 1
}, },
# DocField
{ {
'doctype': u'DocField', "depends_on": "eval:!doc.__islocal",
'fieldname': u'subject', "doctype": "DocField",
'fieldtype': u'Text', "label": "Thread HTML",
'in_filter': 1, "fieldname": "thread_html",
'label': u'Subject', "fieldtype": "HTML",
'permlevel': 0, "permlevel": 1
'reqd': 1
}, },
# DocField
{ {
'depends_on': u'eval:doc.__islocal', "colour": "White:FFF",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'raised_by', "label": "Additional Info",
'fieldtype': u'Data', "fieldname": "additional_info",
'in_filter': 1, "fieldtype": "Section Break",
'label': u'Raised By (Email)', "permlevel": 1
'oldfieldname': u'raised_by',
'oldfieldtype': u'Data',
'permlevel': 0,
'reqd': 1
}, },
# DocField
{ {
'depends_on': u'eval:doc.__islocal', "oldfieldtype": "Column Break",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'description', "width": "50%",
'fieldtype': u'Text', "fieldname": "column_break0",
'label': u'Description', "fieldtype": "Column Break",
'oldfieldname': u'problem_description', "depends_on": "eval:!doc.__islocal",
'oldfieldtype': u'Text', "permlevel": 1
'permlevel': 0,
'reqd': 0
}, },
# DocField
{ {
'depends_on': u'eval:!doc.__islocal', "print_hide": 1,
'doctype': u'DocField', "oldfieldtype": "Link",
'fieldname': u'thread_html', "colour": "White:FFF",
'fieldtype': u'HTML', "doctype": "DocField",
'label': u'Thread HTML', "label": "Customer",
'permlevel': 1 "oldfieldname": "customer",
"permlevel": 1,
"trigger": "Client",
"fieldname": "customer",
"fieldtype": "Link",
"search_index": 1,
"reqd": 0,
"options": "Customer",
"in_filter": 1
}, },
# DocField
{ {
'depends_on': u'eval:!doc.__islocal', "oldfieldtype": "Data",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'new_response', "label": "Customer Name",
'fieldtype': u'Text', "oldfieldname": "customer_name",
'label': u'New Response', "fieldname": "customer_name",
'permlevel': 0 "fieldtype": "Data",
"search_index": 0,
"reqd": 0,
"permlevel": 2,
"in_filter": 1
}, },
# DocField
{ {
'depends_on': u'eval:!doc.__islocal', "doctype": "DocField",
'doctype': u'DocField', "label": "Address",
'fieldname': u'send', "fieldname": "address_display",
'fieldtype': u'Button', "fieldtype": "Small Text",
'label': u'Send', "permlevel": 2
'permlevel': 0
}, },
# DocField
{ {
'colour': u'White:FFF', "doctype": "DocField",
'doctype': u'DocField', "label": "Contact Name",
'fieldname': u'additional_info', "fieldname": "contact_display",
'fieldtype': u'Section Break', "fieldtype": "Data",
'label': u'Additional Info', "permlevel": 2
'permlevel': 1
}, },
# DocField
{ {
'depends_on': u'eval:!doc.__islocal', "doctype": "DocField",
'doctype': u'DocField', "label": "Mobile No",
'fieldname': u'column_break0', "fieldname": "contact_mobile",
'fieldtype': u'Column Break', "fieldtype": "Data",
'oldfieldtype': u'Column Break', "permlevel": 2
'permlevel': 1,
'width': u'50%'
}, },
# DocField
{ {
'colour': u'White:FFF', "oldfieldtype": "Data",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'customer', "label": "Contact Email",
'fieldtype': u'Link', "oldfieldname": "contact_no",
'in_filter': 1, "fieldname": "contact_email",
'label': u'Customer', "fieldtype": "Data",
'oldfieldname': u'customer', "permlevel": 2
'oldfieldtype': u'Link',
'options': u'Customer',
'permlevel': 1,
'print_hide': 1,
'reqd': 0,
'search_index': 1,
'trigger': u'Client'
}, },
# DocField
{ {
'doctype': u'DocField', "default": "Today",
'fieldname': u'customer_name', "oldfieldtype": "Date",
'fieldtype': u'Data', "doctype": "DocField",
'in_filter': 1, "label": "Opening Date",
'label': u'Customer Name', "oldfieldname": "opening_date",
'oldfieldname': u'customer_name', "no_copy": 1,
'oldfieldtype': u'Data', "fieldname": "opening_date",
'permlevel': 2, "fieldtype": "Date",
'reqd': 0, "permlevel": 1
'search_index': 0
}, },
# DocField
{ {
'doctype': u'DocField', "no_copy": 1,
'fieldname': u'address_display', "oldfieldtype": "Time",
'fieldtype': u'Small Text', "doctype": "DocField",
'label': u'Address', "label": "Opening Time",
'permlevel': 2 "oldfieldname": "opening_time",
"fieldname": "opening_time",
"fieldtype": "Time",
"permlevel": 1
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Column Break",
'fieldname': u'contact_display', "doctype": "DocField",
'fieldtype': u'Data', "fieldname": "column_break1",
'label': u'Contact Name', "fieldtype": "Column Break",
'permlevel': 2 "depends_on": "eval:!doc.__islocal",
"permlevel": 1
}, },
# DocField
{ {
'doctype': u'DocField', "depends_on": "eval:!doc.__islocal",
'fieldname': u'contact_mobile', "search_index": 1,
'fieldtype': u'Data', "colour": "White:FFF",
'label': u'Mobile No', "doctype": "DocField",
'permlevel': 2 "label": "Allocated To",
"oldfieldname": "allocated_to",
"permlevel": 1,
"fieldname": "allocated_to",
"fieldtype": "Link",
"oldfieldtype": "Link",
"options": "Profile",
"in_filter": 1
}, },
# DocField
{ {
'doctype': u'DocField', "no_copy": 1,
'fieldname': u'contact_email', "oldfieldtype": "Text",
'fieldtype': u'Data', "doctype": "DocField",
'label': u'Contact Email', "label": "Resolution Details",
'oldfieldname': u'contact_no', "oldfieldname": "resolution_details",
'oldfieldtype': u'Data', "fieldname": "resolution_details",
'permlevel': 2 "fieldtype": "Text",
"depends_on": "eval:!doc.__islocal",
"permlevel": 1
}, },
# DocField
{ {
'default': u'Today', "depends_on": "eval:!doc.__islocal",
'doctype': u'DocField', "no_copy": 1,
'fieldname': u'opening_date', "search_index": 0,
'fieldtype': u'Date', "colour": "White:FFF",
'label': u'Opening Date', "doctype": "DocField",
'no_copy': 1, "label": "Resolution Date",
'oldfieldname': u'opening_date', "oldfieldname": "resolution_date",
'oldfieldtype': u'Date', "fieldname": "resolution_date",
'permlevel': 1 "fieldtype": "Date",
"oldfieldtype": "Date",
"permlevel": 1,
"in_filter": 0
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Time",
'fieldname': u'opening_time', "doctype": "DocField",
'fieldtype': u'Time', "label": "Resolution Time",
'label': u'Opening Time', "oldfieldname": "resolution_time",
'no_copy': 1, "fieldname": "resolution_time",
'oldfieldname': u'opening_time', "fieldtype": "Time",
'oldfieldtype': u'Time', "depends_on": "eval:!doc.__islocal",
'permlevel': 1 "permlevel": 1
}, },
# DocField
{ {
'depends_on': u'eval:!doc.__islocal', "colour": "White:FFF",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'column_break1', "label": "Content Type",
'fieldtype': u'Column Break', "fieldname": "content_type",
'oldfieldtype': u'Column Break', "fieldtype": "Data",
'permlevel': 1 "hidden": 1,
"permlevel": 0
}, },
# DocField
{ {
'colour': u'White:FFF', "print_hide": 1,
'depends_on': u'eval:!doc.__islocal', "no_copy": 1,
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'allocated_to', "label": "File List",
'fieldtype': u'Link', "fieldname": "file_list",
'in_filter': 1, "fieldtype": "Text",
'label': u'Allocated To', "hidden": 1,
'oldfieldname': u'allocated_to', "permlevel": 0
'oldfieldtype': u'Link',
'options': u'Profile',
'permlevel': 1,
'search_index': 1
}, },
# DocField
{ {
'depends_on': u'eval:!doc.__islocal', "create": 1,
'doctype': u'DocField', "doctype": "DocPerm",
'fieldname': u'resolution_details', "write": 1,
'fieldtype': u'Text', "role": "Guest",
'label': u'Resolution Details', "cancel": 0,
'no_copy': 1, "permlevel": 0
'oldfieldname': u'resolution_details',
'oldfieldtype': u'Text',
'permlevel': 1
}, },
# DocField
{ {
'colour': u'White:FFF', "create": 1,
'depends_on': u'eval:!doc.__islocal', "doctype": "DocPerm",
'doctype': u'DocField', "write": 1,
'fieldname': u'resolution_date', "role": "Customer",
'fieldtype': u'Date', "cancel": 0,
'in_filter': 0, "permlevel": 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', "create": 1,
'doctype': u'DocField', "doctype": "DocPerm",
'fieldname': u'resolution_time', "write": 1,
'fieldtype': u'Time', "role": "Support Team",
'label': u'Resolution Time', "cancel": 1,
'oldfieldname': u'resolution_time', "permlevel": 0
'oldfieldtype': u'Time',
'permlevel': 1
}, },
# DocField
{ {
'colour': u'White:FFF', "create": 0,
'doctype': u'DocField', "doctype": "DocPerm",
'fieldname': u'content_type', "write": 1,
'fieldtype': u'Data', "role": "Support Team",
'hidden': 1, "cancel": 0,
'label': u'Content Type', "permlevel": 1
'permlevel': 0
}, },
# DocField
{ {
'doctype': u'DocField', "create": 0,
'fieldname': u'file_list', "doctype": "DocPerm",
'fieldtype': u'Text', "write": 0,
'hidden': 1, "role": "Support Team",
'label': u'File List', "cancel": 0,
'no_copy': 1, "permlevel": 2
'permlevel': 0,
'print_hide': 1
} }
] ]