<commit_before>// threading structure
// -------- orginal message --------
// xoxoxoxo
// -------- reply 1 --------
// -------- reply 2 --------
// xoxoxoxo
// -------- new reply --------

var cs = cur_frm.cscript;
$.extend(cur_frm.cscript, {
	onload: function(doc, dt, dn) {
		//
		// help area
		//
		if(in_list(user_roles,'System Manager')) {
			cur_frm.page_layout.footer.help_area.innerHTML = '';
			new wn.widgets.Footer({
				parent:cur_frm.page_layout.footer.help_area,
				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']);		
	},
	
	refresh: function(doc) {
		cs.make_listing(doc);
		if(!doc.__islocal) {											
			if(in_list(user_roles,'System Manager')) {
		      if(doc.status!='Closed') cur_frm.add_custom_button('Close Ticket', cs['Close Ticket']);	
			  if(doc.status=='Closed') cur_frm.add_custom_button('Re-Open Ticket', cs['Re-Open Ticket']);		
			}else if(doc.allocated_to) {
			  set_field_permlevel('status',2);
			  if(user==doc.allocated_to && doc.status!='Closed') cur_frm.add_custom_button('Close Ticket', cs['Close Ticket']);
			}
			
			// can't change the main message & subject once set  
			set_field_permlevel('subject',2);
			set_field_permlevel('description',2);
			set_field_permlevel('raised_by',2);
		}
	},
	
	//
	// make thread listing
	//
	make_listing: function(doc) {
		cur_frm.fields_dict['Thread HTML'].wrapper.innerHTML = '';
		
		// render first message
		new EmailMessage(cur_frm.fields_dict['Thread HTML'].wrapper, {
			from_email: doc.raised_by,
			creation: doc.creation,
			mail: doc.description,
			content_type: doc.content_type
		}, null, -1)
		
		// render thread		
		cs.thread_list = new wn.widgets.Listing({<commit_msg>Refresh support ticket status when a new reply is received<commit_after>// threading structure
// -------- orginal message --------
// xoxoxoxo
// -------- reply 1 --------
// -------- reply 2 --------
// xoxoxoxo
// -------- new reply --------

var cs = cur_frm.cscript;
$.extend(cur_frm.cscript, {
	onload: function(doc, dt, dn) {
		//
		// help area
		//
		if(in_list(user_roles,'System Manager')) {
			cur_frm.page_layout.footer.help_area.innerHTML = '';
			new wn.widgets.Footer({
				parent:cur_frm.page_layout.footer.help_area,
				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']);		
	},
	
	refresh: function(doc) {
		cs.make_listing(doc);
		if(!doc.__islocal) {											
			if(in_list(user_roles,'System Manager')) {
		      if(doc.status!='Closed') cur_frm.add_custom_button('Close Ticket', cs['Close Ticket']);	
			  if(doc.status=='Closed') cur_frm.add_custom_button('Re-Open Ticket', cs['Re-Open Ticket']);		
			}else if(doc.allocated_to) {
			  set_field_permlevel('status',2);
			  if(user==doc.allocated_to && doc.status!='Closed') cur_frm.add_custom_button('Close Ticket', cs['Close Ticket']);
			}
			
			// can't change the main message & subject once set  
			set_field_permlevel('subject',2);
			set_field_permlevel('description',2);
			set_field_permlevel('raised_by',2);
		}
		refresh_field('status');
	},
	
	//
	// make thread listing
	//
	make_listing: function(doc) {
		cur_frm.fields_dict['Thread HTML'].wrapper.innerHTML = '';
		
		// render first message
		new EmailMessage(cur_frm.fields_dict['Thread HTML'].wrapper, {
			from_email: doc.raised_by,
			creation: doc.creation,
			mail: doc.description,
			content_type: doc.content_type
		}, null, -1)
		
		// render thread		
		cs.thread_list = new wn.widgets.Listing({
{'fraction_non_alphanumeric': 0.17740361151781356, 'fraction_numerical': 0.004392386530014641, 'mean_word_length': 3.0463968410661404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 8}}
{'dir': 'git-commits-cleaned', 'id': '2492665', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1351, 'n_words': 237}