diff --git a/frappe/core/doctype/communication/communication.js b/frappe/core/doctype/communication/communication.js index 518a0416b5..305d8fe586 100644 --- a/frappe/core/doctype/communication/communication.js +++ b/frappe/core/doctype/communication/communication.js @@ -58,10 +58,6 @@ frappe.ui.form.on("Communication", { && frm.doc.communication_medium == "Email" && frm.doc.sent_or_received == "Received") { - frm.add_custom_button(__("Mark as {0}", [frm.doc.seen? "Unread": "Read"]), function() { - frm.trigger('mark_as_read_unread'); - }, "Actions"); - frm.add_custom_button(__("Reply"), function() { frm.trigger('reply'); }, "Actions"); @@ -73,6 +69,14 @@ frappe.ui.form.on("Communication", { frm.add_custom_button(__("Forward"), function() { frm.trigger('forward_mail'); }, "Actions"); + + frm.add_custom_button(__("Add to Contact"), function() { + frm.trigger('add_to_contact'); + }, "Actions"); + + frm.add_custom_button(__("Mark as {0}", [frm.doc.seen? "Unread": "Read"]), function() { + frm.trigger('mark_as_read_unread'); + }, "Actions"); } }, show_relink_dialog: function(frm){ @@ -183,5 +187,21 @@ frappe.ui.form.on("Communication", { sender: sender_email_id, attachments: frm.doc.attachments } + }, + + add_to_contact: function(frm) { + var me = this; + fullname = frm.doc.sender_full_name || "" + + names = fullname.split(" ") + first_name = names[0] + last_name = names.length >= 2? last_name[names.length - 1]: "" + + frappe.route_options = { + "email_id": frm.doc.sender, + "first_name": first_name, + "last_name": last_name, + } + frappe.new_doc("Contact") } }); diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index 12fb2340d5..aeaa75c5e0 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -569,7 +569,6 @@ class EmailAccount(Document): if self.email_sync_option == "ALL": max_uid = get_max_email_uid(self.name) last_uid = max_uid + int(self.initial_sync_count or 100) if max_uid == 1 else "*" - print "UID {}:{}".format(max_uid, last_uid) return "UID {}:{}".format(max_uid, last_uid) else: return self.email_sync_option or "UNSEEN" diff --git a/frappe/email/page/email_inbox/__init__.py b/frappe/email/page/email_inbox/__init__.py deleted file mode 100644 index cc3df29034..0000000000 --- a/frappe/email/page/email_inbox/__init__.py +++ /dev/null @@ -1,84 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - -from __future__ import unicode_literals -import frappe -import json -from frappe.model.document import Document -from frappe.desk.form.load import get_attachments - -@frappe.whitelist() -def get_email_content(name): - docinfo = frappe.desk.form.load.get_attachments("Communication", name) - content = frappe.db.get_value("Communication", name, "content") - return docinfo, content - -@frappe.whitelist() -def create_flag_queue(names, action, flag): - names = json.loads(names) - class Found(Exception): - pass - - for item in names: - if item.get("uid"): - state = frappe.db.get_value("Communication", item.get("name"), "seen") - frappe.errprint(state) - - # check states are correct - if (action =='Read' and state == 0) or (action =='Unread' and state == 1): - try: - queue = frappe.db.sql("""select name, action, flag from `tabEmail Flag Queue` - where communication = %(name)s""", {"name":item.get("name")}, as_dict=True) - for q in queue: - # is same email with same flag - if q.flag == flag: - # to prevent flag local and server states being out of sync - if q.action != action: - frappe.delete_doc("Email Flag Queue", q.name) - raise Found - - flag_queue = frappe.get_doc({ - "doctype": "Email Flag Queue", - "communication": item.get("name"), - "action": action, - "flag": flag - }) - flag_queue.save(ignore_permissions=True); - except Found: - pass - -@frappe.whitelist() -def setnomatch(name): - frappe.db.set_value("Communication", name, "nomatch", 1, update_modified=False) - -@frappe.whitelist() -def update_local_flags(names, field, val): - names = json.loads(names) - for d in names: - frappe.db.set_value("Communication", d.get("name"), field, val, update_modified=False) - -@frappe.whitelist() -def get_accounts(user): - email_accounts = [] - - accounts = frappe.get_all("User Email", filters={ "parent": user }, - fields=["email_account as account", "email_id as title"], - distinct=True, order_by="idx") - - if not accounts: - return None - - all_accounts = ",".join([ account.get("account") for account in accounts ]) - if len(accounts) > 1: - email_accounts.append({ - "account": all_accounts, - "title": "All Accounts" - }) - - email_accounts.extend(accounts) - - return { - "email_accounts": email_accounts, - "all_accounts": all_accounts - } diff --git a/frappe/email/page/email_inbox/email_inbox.js b/frappe/email/page/email_inbox/email_inbox.js deleted file mode 100644 index 9338c74b42..0000000000 --- a/frappe/email/page/email_inbox/email_inbox.js +++ /dev/null @@ -1,665 +0,0 @@ -frappe.provide("frappe.email") - -frappe.pages['email_inbox'].on_page_load = function(wrapper) { - frappe.ui.make_app_page({ - parent: wrapper, - title: 'Email Inbox', - icon: 'fa fa-inbox', - single_column: false - }); - - frappe.model.with_doctype('Communication', function() { - wrapper.inbox = new frappe.email.EmailInbox({ - method: 'frappe.desk.reportview.get', - wrapper: wrapper, - page: wrapper.page, - no_loading: true - }); - }); -}; - -frappe.pages['email_inbox'].refresh = function(wrapper) { - if (wrapper.inbox) { - wrapper.inbox.refresh() - } -}; - -frappe.email.EmailInbox = frappe.ui.Listing.extend({ - init: function(opts) { - $.extend(this, opts); - wrap = this; - this.wrapper = opts.wrapper; - this.page_length = 20; - this.start = 0; - this.no_result_message = 'No Emails to Display'; - - this.get_accounts(); - }, - - setup_inbox: function() { - var me = this; - // setup listing - me.make({ - doctype: 'Communication', - page: me.page, - method: 'frappe.desk.reportview.get', - get_args: me.get_args, - parent: me.page.main, - start: 0, - show_filters: true - }); - - this.render_sidebar(); - this.render_headers(); - this.render_buttons(); - this.init_select_all(); - this.setup_notifications(); - - this.refresh(); - }, - - get_accounts: function() { - // get all the configured email account for the user - - var me = this; - frappe.call({ - method: 'frappe.email.page.email_inbox.get_accounts', - args: { - 'user': user - }, - callback:function(r){ - me.page.sidebar.empty() - if(!r.message) { - frappe.msgprint(__("No Email Account assigned to you. Please contact your System Administrator")); - - setTimeout(function() { - if (frappe.session.user==="Administrator") - frappe.set_route("List", "User"); - else - frappe.set_route(''); - }, 3000); - } - - me.accounts = r.message; - me.setup_inbox(); - } - }); - }, - - refresh:function(){ - delete frappe.route_flags.create_contact; - delete frappe.route_flags.update_contact; - this.run(); - }, - - render_sidebar: function (data) { - var me = this; - frappe.call({ - method: 'frappe.email.page.email_inbox.get_accounts', - args:{user:frappe.user["name"]}, - async:false, - callback:function(list){ - var buttons = '
'; - if (list["message"]){ - me.accounts = []; - var rows = ""; - - for (var i = 0;i'+list["message"][i]["email_id"]+'
'; - me.accounts.push({name:list["message"][i]["email_account"],email:list["message"][i]["email_id"]}) - } - me.allaccounts = $.map(me.accounts,function(v){return v.name}).join(","); - buttons += '
All Accounts
'; - buttons += rows; - buttons += '
Sent
'; - me.account = me.allaccounts; - me.default_filters=[ - ["Communication", "communication_type", "=", "Communication"], - ["Communication", "email_account", "in", me.account], - ["Communication", "sent_or_received", "=", "Received"]] - - me.page.sidebar.empty().append(buttons); - $(".inbox-select").on("click",function(btn){ - me.account = $(btn.currentTarget).find(".inbox-item").data("account"); - $(me.page.sidebar).find(".list-row").removeClass("list-row-head").css("font-weight","normal"); - $(btn.currentTarget).closest(".list-row").addClass("list-row-head").css("font-weight","bold"); - me.cur_page = 1; - $(me.page.main).find(".list-select-all,.list-row-checkbox").prop("checked",false); - me.toggle_actions(); - - if(me.account=="Sent"){ - me.filter_list.default_filters=[ - ["Communication", "communication_type", "=", "Communication"], - ["Communication", "sent_or_received", "=", "Sent"]] - }else { - me.filter_list.default_filters = [ - ["Communication", "communication_type", "=", "Communication"], - ["Communication", "email_account", "in", me.account], - ["Communication", "sent_or_received", "=", "Received"]]; - } - me.filter_list.clear_filters(); - - if (me.filter_list.reload_stats){me.filter_list.reload_stats()} - me.refresh(); - }); - } - } - }) - }, - - toggle_accounts: function() { - $(this.page.main).find(".list-select-all,.list-delete").prop("checked", false); - this.toggle_actions(); - - this.filter_list.clear_filters(); - this.refresh(); - }, - - render_headers: function(){ - $(".layout-main-section-wrapper").css("padding-left","0px").css("padding-right","0px"); - var data = { - "start":this.start, - "page_length":this.page_length.toString() - }; - - headers_html = frappe.render_template("inbox_headers", data) - this.list_header = $(headers_html).appendTo(this.page.main.find(".list-headers")); - }, - - get_args: function(){ - var args = { - doctype: this.doctype, - fields: [ - "name", "sender", "sender_full_name", "communication_date", "recipients", - "cc","communication_medium", "subject", "status" ,"reference_doctype", - "reference_name", "timeline_doctype", "timeline_name", "timeline_label", - "sent_or_received", "uid", "message_id", "seen" - ], - filters: this.get_email_filters(), - order_by: 'communication_date desc', - save_list_settings: false - }; - - return args; - }, - - get_email_filters: function() { - filters = this.filter_list.get_filters() - - if(this.account == "Sent") { - this.filter_list.default_filters = [ - ["Communication", "communication_type", "=", "Communication"], - ["Communication", "communication_medium", "=", "Email"], - ["Communication", "user", "=", user], - ["Communication", "sent_or_received", "=", "Sent"] - ] - } else { - this.filter_list.default_filters = [ - ["Communication", "communication_type", "=", "Communication"], - ["Communication", "communication_medium", "=", "Email"], - ["Communication", "sent_or_received", "=", "Received"], - ["Communication", "email_account", "in", this.account], - ] - } - - $.extend(filters, this.filter_list.default_filters) - return filters; - }, - - setup_notifications: function() { - // setup real time email notification using frappe.realtime - - var me = this; - frappe.realtime.on("new_email", function(data) { - for(var i =0; i")[0]; - c.comment = frappe.utils.strip_original_content(c.comment); - c.comment = frappe.dom.remove_script_and_style(c.comment); - - c.original_comment = c.comment; - c.comment = frappe.utils.toggle_blockquote(c.comment); - } - - - if (!frappe.utils.is_html(c.comment)) { - c.comment_html = frappe.markdown(__(c.comment)); - } else { - c.comment_html = c.comment; - c.comment_html = frappe.utils.strip_whitespace(c.comment_html); - c.comment_html = c.comment_html.replace(/</g,"<").replace(/>/g,">") - } - - // bold @mentions - if (c.comment_type === "Comment") { - c.comment_html = c.comment_html.replace(/(^|\W)(@\w+)/g, "$1$2"); - } - - return c - }, - - init_select_all: function () { - var me = this; - - $(".list-select-all").on("click", function () { - $(me.wrapper).find('.list-row-checkbox').prop("checked", $(this).prop("checked")); - me.toggle_actions(); - }); - - $(me.wrapper).on("click", ".list-row-checkbox", function (event) { - me.toggle_actions(); - - // multi-select using shift key - var $this = $(this); - if (event.shiftKey && $this.prop("checked")) { - var $end_row = $this.parents(".list-row"); - var $start_row = $end_row.prevAll(".list-row") - .find(".list-row-checkbox:checked").last().parents(".list-row"); - if ($start_row) { - $start_row.nextUntil($end_row).find(".list-row-checkbox").prop("checked", true); - } - } - }); - - // after delete, hide delete button - me.toggle_actions(); - }, - - render_buttons: function(){ - var me = this; - - me.page.add_action_item("Delete", function(){ me.delete_email() }); - me.page.add_action_item("Mark as Unread", function(){ me.mark_unread() }); - me.page.add_action_item("Mark as Read", function(){ me.mark_read() }); - - me.page.set_primary_action("New Email", function(){ - var sender = ""; - for (var i=0;i -
  • - - - \ No newline at end of file diff --git a/frappe/email/page/email_inbox/inbox_list.html b/frappe/email/page/email_inbox/inbox_list.html deleted file mode 100644 index f39dbc6dbc..0000000000 --- a/frappe/email/page/email_inbox/inbox_list.html +++ /dev/null @@ -1,45 +0,0 @@ -
    -
    -
    -
    -
    - - - {% if (data.sender_full_name){var sender = data.sender_full_name} else {var sender = data.sender} %} - {%= sender %} - -
    - - - - - -
    -
    -
    -
    \ No newline at end of file diff --git a/frappe/public/css/form.css b/frappe/public/css/form.css index 5ef60dc9b3..bbe8396be2 100644 --- a/frappe/public/css/form.css +++ b/frappe/public/css/form.css @@ -595,3 +595,6 @@ select.form-control { box-shadow: none; } } +body[data-route^="Form/Communication"] textarea[data-fieldname="subject"] { + height: 80px !important; +} diff --git a/frappe/public/less/form.less b/frappe/public/less/form.less index e8f0eeca89..46e5c03e75 100644 --- a/frappe/public/less/form.less +++ b/frappe/public/less/form.less @@ -767,3 +767,7 @@ select.form-control { // } } } + +body[data-route^="Form/Communication"] textarea[data-fieldname="subject"] { + height: 80px !important; +}