<commit_before>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

frappe.last_edited_communication = {};
frappe.standard_replies = {};

frappe.views.CommunicationComposer = Class.extend({
	init: function(opts) {
		$.extend(this, opts);
		this.make();
	},
	make: function() {
		var me = this;
		this.dialog = new frappe.ui.Dialog({
			title: (this.subject || ""),
			no_submit_on_enter: true,
			fields: this.get_fields(),
			primary_action_label: "Send",
			primary_action: function() {
				me.send_action();
			}
		});

		$(document).on("upload_complete", function(event, attachment) {
			if(me.dialog.display) {
				var wrapper = $(me.dialog.fields_dict.select_attachments.wrapper);

				// find already checked items
				var checked_items = wrapper.find('[data-file-name]:checked').map(function() {
					return $(this).attr("data-file-name");
				});

				// reset attachment list
				me.render_attach();

				// check latest added
				checked_items.push(attachment.name);

				$.each(checked_items, function(i, filename) {
					wrapper.find('[data-file-name="'+ filename +'"]').prop("checked", true);
				});
			}
		})
		this.prepare();
		this.dialog.show();

	},

	get_fields: function() {
		var fields= [
			{label:__("To"), fieldtype:"Data", reqd: 0, fieldname:"recipients",length:524288},
			{fieldtype: "Section Break", collapsible: 1, label: "CC & Standard Reply"},
			{label:__("CC"), fieldtype:"Data", fieldname:"cc",length:524288},
			{label:__("Standard Reply"), fieldtype:"Link", options:"Standard Reply",
				fieldname:"standard_reply"},
			{fieldtype: "Section Break"},
			{label:__("Subject"), fieldtype:"Data", reqd: 1,
				fieldname:"subject",length:524288},
			{fieldtype: "Section Break"},
			{label:__("Message"), fieldtype:"Text Editor", reqd: 1,
				fieldname:"content"},
			{fieldtype: "Section Break"},
			{fieldtype: "Column Break"},
			{label:__("Send As Email"), fieldtype:"Check",
				fieldname:"send_email"},
			{label:__("Send me a copy"), fieldtype:"Check",
				fieldname:"send_me_a_copy"},
			{label:__("Send Read Receipt"), fieldtype:"Check",
				fieldname:"send_read_receipt"},
			{label:__("Communication Medium"), fieldtype:"Select",
				options: ["Phone", "Chat", "Email", "SMS", "Visit", "Other"],
				fieldname:"communication_medium"},
			{label:__("Sent or Received"), fieldtype:"Select",
				options: ["Received", "Sent"],
				fieldname:"sent_or_received"},
			{label:__("Attach Document Print"), fieldtype:"Check",
				fieldname:"attach_document_print"},
			{label:__("Select Print Format"), fieldtype:"Select",
				fieldname:"select_print_format"},
			{label:__("Select Languages"), fieldtype:"Select",
				fieldname:"language_sel"},
			{fieldtype: "Column Break"},
			{label:__("Select Attachments"), fieldtype:"HTML",
				fieldname:"select_attachments"}
		];

		// add from if user has access to multiple email accounts
		if(frappe.boot.email_accounts && frappe.boot.email_accounts.length > 1) {
			fields = [
				{label: __("From"), fieldtype: "Select", reqd: 1, fieldname: "sender",
					options: frappe.boot.email_accounts.map(function(e) { return e.email_id; }) }
			].concat(fields);
		}

		return fields;
	},
	prepare: function() {
		this.setup_subject_and_recipients();
		this.setup_print_language()
		this.setup_print();
		this.setup_attach();
		this.setup_email();
		this.setup_autosuggest();
		this.setup_last_edited_communication();
		this.setup_standard_reply();
		$(this.dialog.fields_dict.recipients.input).val(this.recipients || "").change();
		if(this.dialog.fields_dict.sender) {
		$(this.dialog.fields_dict.sender.input).val(this.sender || "").change();
		}
		$(this.dialog.fields_dict.subject.input).val(this.subject || "").change();
		this.setup_earlier_reply();
	},

	setup_subject_and_recipients: function() {
		this.subject = this.subject || "";

		if(!this.forward && !this.recipients && this.last_email) {
			this.recipients = this.last_email.sender;<commit_msg>email inbox expand mailto params<commit_after>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

frappe.last_edited_communication = {};
frappe.standard_replies = {};

frappe.views.CommunicationComposer = Class.extend({
	init: function(opts) {
		$.extend(this, opts);
		this.make();
	},
	make: function() {
		var me = this;
		this.dialog = new frappe.ui.Dialog({
			title: (this.subject || ""),
			no_submit_on_enter: true,
			fields: this.get_fields(),
			primary_action_label: "Send",
			primary_action: function() {
				me.send_action();
			}
		});

		$(document).on("upload_complete", function(event, attachment) {
			if(me.dialog.display) {
				var wrapper = $(me.dialog.fields_dict.select_attachments.wrapper);

				// find already checked items
				var checked_items = wrapper.find('[data-file-name]:checked').map(function() {
					return $(this).attr("data-file-name");
				});

				// reset attachment list
				me.render_attach();

				// check latest added
				checked_items.push(attachment.name);

				$.each(checked_items, function(i, filename) {
					wrapper.find('[data-file-name="'+ filename +'"]').prop("checked", true);
				});
			}
		})
		this.prepare();
		this.dialog.show();

	},

	get_fields: function() {
		var fields= [
			{label:__("To"), fieldtype:"Data", reqd: 0, fieldname:"recipients",length:524288},
			{fieldtype: "Section Break", collapsible: 1, label: "CC & Standard Reply"},
			{label:__("CC"), fieldtype:"Data", fieldname:"cc",length:524288},
			{label:__("Standard Reply"), fieldtype:"Link", options:"Standard Reply",
				fieldname:"standard_reply"},
			{fieldtype: "Section Break"},
			{label:__("Subject"), fieldtype:"Data", reqd: 1,
				fieldname:"subject",length:524288},
			{fieldtype: "Section Break"},
			{label:__("Message"), fieldtype:"Text Editor", reqd: 1,
				fieldname:"content"},
			{fieldtype: "Section Break"},
			{fieldtype: "Column Break"},
			{label:__("Send As Email"), fieldtype:"Check",
				fieldname:"send_email"},
			{label:__("Send me a copy"), fieldtype:"Check",
				fieldname:"send_me_a_copy"},
			{label:__("Send Read Receipt"), fieldtype:"Check",
				fieldname:"send_read_receipt"},
			{label:__("Communication Medium"), fieldtype:"Select",
				options: ["Phone", "Chat", "Email", "SMS", "Visit", "Other"],
				fieldname:"communication_medium"},
			{label:__("Sent or Received"), fieldtype:"Select",
				options: ["Received", "Sent"],
				fieldname:"sent_or_received"},
			{label:__("Attach Document Print"), fieldtype:"Check",
				fieldname:"attach_document_print"},
			{label:__("Select Print Format"), fieldtype:"Select",
				fieldname:"select_print_format"},
			{label:__("Select Languages"), fieldtype:"Select",
				fieldname:"language_sel"},
			{fieldtype: "Column Break"},
			{label:__("Select Attachments"), fieldtype:"HTML",
				fieldname:"select_attachments"}
		];

		// add from if user has access to multiple email accounts
		if(frappe.boot.email_accounts && frappe.boot.email_accounts.length > 1) {
			fields = [
				{label: __("From"), fieldtype: "Select", reqd: 1, fieldname: "sender",
					options: frappe.boot.email_accounts.map(function(e) { return e.email_id; }) }
			].concat(fields);
		}

		return fields;
	},
	prepare: function() {
		this.setup_subject_and_recipients();
		this.setup_print_language()
		this.setup_print();
		this.setup_attach();
		this.setup_email();
		this.setup_autosuggest();
		this.setup_last_edited_communication();
		this.setup_standard_reply();
		$(this.dialog.fields_dict.recipients.input).val(this.recipients || "").change();
		if(this.dialog.fields_dict.sender) {
		$(this.dialog.fields_dict.sender.input).val(this.sender || "").change();
		}
		$(this.dialog.fields_dict.subject.input).val(this.subject || "").change();

		if (this.content){
			$(this.dialog.fields_dict.content.set_input(this.content || ""))
		}else{
			this.setup_earlier_reply();
		}
	},

	setup_subject_and_recipients: function() {
		this.subject = this.subject || "";

		if(!this.forward && !this.recipients && this.last_email) {
			this.recipients = this.last_email.sender;
{'fraction_non_alphanumeric': 0.17969618377176733, 'fraction_numerical': 0.0069161417809065085, 'mean_word_length': 4.690794096978215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': 0}}
{'dir': 'git-commits-cleaned', 'id': '3862091', 'n_tokens_mistral': 3095, 'n_tokens_neox': 2621, 'n_words': 481}