diff --git a/frappe/core/doctype/communication/communication.js b/frappe/core/doctype/communication/communication.js index 1c51319790..cdbdf97852 100644 --- a/frappe/core/doctype/communication/communication.js +++ b/frappe/core/doctype/communication/communication.js @@ -37,13 +37,11 @@ frappe.ui.form.on("Communication", { if(frm.doc.status==="Open") { frm.add_custom_button(__("Close"), function() { - frm.set_value("status", "Closed"); - frm.save(); + frm.trigger('mark_as_closed_open'); }); } else if (frm.doc.status !== "Linked") { frm.add_custom_button(__("Reopen"), function() { - frm.set_value("status", "Open"); - frm.save(); + frm.trigger('mark_as_closed_open'); }); } @@ -61,30 +59,34 @@ frappe.ui.form.on("Communication", { frm.add_custom_button(__("Reply All"), function() { frm.trigger('reply_all'); - }, "Actions"); + }, __("Actions")); frm.add_custom_button(__("Forward"), function() { frm.trigger('forward_mail'); - }, "Actions"); + }, __("Actions")); - frm.add_custom_button(__("Mark as {0}", [frm.doc.seen? "Unread": "Read"]), function() { + frm.add_custom_button(frm.doc.seen ? __("Mark as Unread") : __("Mark as Read"), function() { frm.trigger('mark_as_read_unread'); - }, "Actions"); + }, __("Actions")); - frm.add_custom_button(__("Add Contact"), function() { - frm.trigger('add_to_contact'); - }, "Actions"); + frm.add_custom_button(__("Move"), function() { + frm.trigger('show_move_dialog'); + }, __("Actions")); if(frm.doc.email_status != "Spam") frm.add_custom_button(__("Mark as Spam"), function() { frm.trigger('mark_as_spam'); - }, "Actions"); + }, __("Actions")); if(frm.doc.email_status != "Trash") { frm.add_custom_button(__("Move To Trash"), function() { frm.trigger('move_to_trash'); - }, "Actions"); + }, __("Actions")); } + + frm.add_custom_button(__("Contact"), function() { + frm.trigger('add_to_contact'); + }, __('Create')); } if(frm.doc.communication_type=="Communication" @@ -93,7 +95,7 @@ frappe.ui.form.on("Communication", { frm.add_custom_button(__("Add Contact"), function() { frm.trigger('add_to_contact'); - }, "Actions"); + }, __("Actions")); } }, @@ -145,6 +147,43 @@ frappe.ui.form.on("Communication", { d.show(); }, + show_move_dialog: function(frm) { + var d = new frappe.ui.Dialog ({ + title: __("Move"), + fields: [{ + "fieldtype": "Link", + "options": "Email Account", + "label": __("Email Account"), + "fieldname": "email_account", + "reqd": 1, + "get_query": function() { + return { + "filters": { + "name": ["!=", frm.doc.email_account], + "enable_incoming": ["=", 1] + } + }; + } + }], + primary_action_label: __("Move"), + primary_action(values) { + d.hide(); + frappe.call({ + method: "frappe.email.inbox.move_email", + args: { + communication: frm.doc.name, + email_account: values.email_account + }, + freeze: true, + callback: function() { + window.history.back(); + } + }); + } + }); + d.show(); + }, + mark_as_read_unread: function(frm) { var action = frm.doc.seen? "Unread": "Read"; var flag = "(\\SEEN)"; @@ -156,7 +195,26 @@ frappe.ui.form.on("Communication", { 'action': action, 'flag': flag }, - freeze: true + freeze: true, + callback: function() { + frm.reload_doc(); + } + }); + }, + + mark_as_closed_open: function(frm) { + var status = frm.doc.status == "Open" ? "Closed" : "Open"; + + return frappe.call({ + method: "frappe.email.inbox.mark_as_closed_open", + args: { + communication: frm.doc.name, + status: status + }, + freeze: true, + callback: function() { + frm.reload_doc(); + } }); }, diff --git a/frappe/core/doctype/communication/communication.json b/frappe/core/doctype/communication/communication.json index ae6fb164ec..58adc6187c 100644 --- a/frappe/core/doctype/communication/communication.json +++ b/frappe/core/doctype/communication/communication.json @@ -197,6 +197,7 @@ "label": "More Information" }, { + "bold": 0, "default": "Now", "fieldname": "communication_date", "fieldtype": "Datetime", @@ -424,6 +425,15 @@ "share": 1, "write": 1 }, + { + "create": 1, + "delete": 1, + "email": 1, + "export":1, + "print":1, + "read": 1, + "role": "Inbox User" + }, { "delete": 1, "email": 1, diff --git a/frappe/core/doctype/communication/communication_list.js b/frappe/core/doctype/communication/communication_list.js index 67d4855c1f..454897b865 100644 --- a/frappe/core/doctype/communication/communication_list.js +++ b/frappe/core/doctype/communication/communication_list.js @@ -3,7 +3,7 @@ frappe.listview_settings['Communication'] = { "sent_or_received","recipients", "subject", "communication_medium", "communication_type", "sender", "seen", "reference_doctype", "reference_name", - "has_attachment" + "has_attachment", "communication_date" ], filters: [["status", "=", "Open"]], diff --git a/frappe/email/doctype/email_account/email_account.json b/frappe/email/doctype/email_account/email_account.json index 5c57a7f35d..6bde0291a0 100644 --- a/frappe/email/doctype/email_account/email_account.json +++ b/frappe/email/doctype/email_account/email_account.json @@ -65,6 +65,7 @@ "fieldname": "email_id", "fieldtype": "Data", "in_global_search": 1, + "in_list_view": 1, "label": "Email Address", "options": "Email", "reqd": 1 @@ -90,14 +91,12 @@ "default": "0", "fieldname": "awaiting_password", "fieldtype": "Check", - "in_list_view": 1, "label": "Awaiting password" }, { "default": "0", "fieldname": "ascii_encode_password", "fieldtype": "Check", - "in_list_view": 1, "label": "Use ASCII encoding for password" }, { @@ -116,6 +115,8 @@ "fieldname": "domain", "fieldtype": "Link", "label": "Domain", + "in_list_view": 1, + "in_standard_filter": 1, "options": "Email Domain" }, { @@ -424,6 +425,10 @@ "role": "System Manager", "set_user_permissions": 1, "write": 1 + }, + { + "read": 1, + "role": "Inbox User" } ], "sort_field": "modified", diff --git a/frappe/email/inbox.py b/frappe/email/inbox.py index 9d15b387e3..395a2d3e2d 100644 --- a/frappe/email/inbox.py +++ b/frappe/email/inbox.py @@ -96,14 +96,24 @@ def create_email_flag_queue(names, action): update_modified=False) mark_as_seen_unseen(name, action) +@frappe.whitelist() +def mark_as_closed_open(communication, status): + """Set status to open or close""" + frappe.db.set_value("Communication", communication, "status", status) + +@frappe.whitelist() +def move_email(communication, email_account): + """Move email to another email account.""" + frappe.db.set_value("Communication", communication, "email_account", email_account) + @frappe.whitelist() def mark_as_trash(communication): - """set email status to trash""" + """Set email status to trash.""" frappe.db.set_value("Communication", communication, "email_status", "Trash") @frappe.whitelist() def mark_as_spam(communication, sender): - """ set email status to spam """ + """Set email status to spam.""" email_rule = frappe.db.get_value("Email Rule", { "email_id": sender }) if not email_rule: frappe.get_doc({ @@ -118,4 +128,4 @@ def link_communication_to_document(doc, reference_doctype, reference_name, ignor doc.reference_doctype = reference_doctype doc.reference_name = reference_name doc.status = "Linked" - doc.save(ignore_permissions=True) \ No newline at end of file + doc.save(ignore_permissions=True) diff --git a/frappe/public/js/frappe/list/list_sidebar.js b/frappe/public/js/frappe/list/list_sidebar.js index e3ba08a87c..0c7312d537 100644 --- a/frappe/public/js/frappe/list/list_sidebar.js +++ b/frappe/public/js/frappe/list/list_sidebar.js @@ -209,11 +209,13 @@ frappe.views.ListSidebar = class ListSidebar { accounts.forEach((account) => { let email_account = (account.email_id == "All Accounts") ? "All Accounts" : account.email_account; let route = ["List", "Communication", "Inbox", email_account].join('/'); + let display_name = ["All Accounts", "Sent Mail", "Spam", "Trash"].includes(account.email_id) ? __(account.email_id) : account.email_id; + if (!divider) { this.get_divider().appendTo($dropdown); divider = true; } - $(`