From b151b77fa69edc2995e6044b8885726242624c78 Mon Sep 17 00:00:00 2001 From: P-Froggy <60393001+P-Froggy@users.noreply.github.com> Date: Mon, 30 Mar 2020 12:24:07 +0200 Subject: [PATCH 1/9] Fix translation, permission & UI bugs Fix several untranslatable strings Fix permission issue in communication when changing status Fix functions in inbox view broken, like Tags View and Likes Add ability to move emails to another email account Add status = open in standard filters of communication Add ability to sort after communication date in communication list Add indicators for status closed and replied in inbox view Add new role "Inbox User" Reorder and regroup some custom buttons in communication form Show more useful fields in email account list --- .../doctype/communication/communication.js | 89 +++++++++++++++---- .../doctype/communication/communication.json | 10 +++ .../communication/communication_list.js | 2 +- .../doctype/email_account/email_account.json | 9 +- frappe/email/inbox.py | 13 +++ frappe/public/js/frappe/list/list_sidebar.js | 4 +- .../js/frappe/views/inbox/inbox_view.js | 46 +++++++++- frappe/translations/de.csv | 3 +- 8 files changed, 152 insertions(+), 24 deletions(-) diff --git a/frappe/core/doctype/communication/communication.js b/frappe/core/doctype/communication/communication.js index 1c51319790..3924fbd05b 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,44 @@ frappe.ui.form.on("Communication", { d.show(); }, + show_move_dialog: function(frm){ + var lib = "frappe.email"; + 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], + } + } + } + }], + 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(r) { + frappe.msgprint(__("Email has been moved to Account {0}", [values.email_account])); + frm.reload_doc(); + } + }); + } + }); + d.show(); + }, + mark_as_read_unread: function(frm) { var action = frm.doc.seen? "Unread": "Read"; var flag = "(\\SEEN)"; @@ -156,7 +196,26 @@ frappe.ui.form.on("Communication", { 'action': action, 'flag': flag }, - freeze: true + freeze: true, + callback: function(r) { + frm.reload_doc(); + } + }); + }, + + mark_as_closed_open: function(frm) { + var action = frm.doc.status == "Open" ? "Close" : "Open"; + + return frappe.call({ + method: "frappe.email.inbox.mark_as_closed_open", + args: { + communication: frm.doc.name, + action: action + }, + freeze: true, + callback: function(r) { + frm.reload_doc(); + } }); }, diff --git a/frappe/core/doctype/communication/communication.json b/frappe/core/doctype/communication/communication.json index 5e34804b93..7add513b01 100644 --- a/frappe/core/doctype/communication/communication.json +++ b/frappe/core/doctype/communication/communication.json @@ -195,6 +195,7 @@ "label": "More Information" }, { + "bold": 0, "default": "Now", "fieldname": "communication_date", "fieldtype": "Datetime", @@ -421,6 +422,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 e724102fdf..4f25d755f3 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", "reqd": 1 }, @@ -89,14 +90,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" }, { @@ -115,6 +114,8 @@ "fieldname": "domain", "fieldtype": "Link", "label": "Domain", + "in_list_view": 1, + "in_standard_filter": 1, "options": "Email Domain" }, { @@ -423,6 +424,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..dfea6f7ef9 100644 --- a/frappe/email/inbox.py +++ b/frappe/email/inbox.py @@ -96,6 +96,19 @@ def create_email_flag_queue(names, action): update_modified=False) mark_as_seen_unseen(name, action) +@frappe.whitelist() +def mark_as_closed_open(communication, action): + """set status to open or close""" + if action == "Close": + frappe.db.set_value("Communication", communication, "status", "Closed") + else: + frappe.db.set_value("Communication", communication, "status", "Open") + +@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""" diff --git a/frappe/public/js/frappe/list/list_sidebar.js b/frappe/public/js/frappe/list/list_sidebar.js index e3ba08a87c..8ed439bf83 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 = (account.email_id == "All Accounts" || account.email_id == "Sent Mail" || account.email_id == "Spam" || account.email_id == "Trash") ? __(account.email_id) : account.email_id + if (!divider) { this.get_divider().appendTo($dropdown); divider = true; } - $(`
  • ${account.email_id}
  • `).appendTo($dropdown); + $(`
  • ${display_name}
  • `).appendTo($dropdown); if (account.email_id === "Sent Mail") divider = false; }); diff --git a/frappe/public/js/frappe/views/inbox/inbox_view.js b/frappe/public/js/frappe/views/inbox/inbox_view.js index 2b35d38683..0b40faff96 100644 --- a/frappe/public/js/frappe/views/inbox/inbox_view.js +++ b/frappe/public/js/frappe/views/inbox/inbox_view.js @@ -45,13 +45,46 @@ frappe.views.InboxView = class InboxView extends frappe.views.ListView { this.filters = this.get_inbox_filters(); } + setup_columns() { + // setup columns for list view + this.columns = []; + this.columns.push({ + type: 'Subject', + df: { + label: __('Subject'), + fieldname: 'subject' + } + }); + this.columns.push({ + type: 'Field', + df: { + label: this.is_sent_emails ? __("To") : __("From"), + fieldname: this.is_sent_emails ? 'recipients' : 'sender' + } + }); + } + get is_sent_emails() { const f = this.filter_area.get() .find(filter => filter[1] === 'sent_or_received'); return f && f[3] === 'Sent'; } + render_header() { + this.$result.find('.list-row-head').remove() + this.$result.prepend(this.get_header_html()); + } + render() { + this.setup_columns(); + this.render_header(); + this.render_list(); + this.on_row_checked(); + this.render_count(); + this.render_tags(); + } + + /* render() { this.emails = this.data; this.render_inbox_view(); } @@ -90,13 +123,13 @@ frappe.views.InboxView = class InboxView extends frappe.views.ListView { -