Browse Source

[minor] mark mail as read, unread added actions like reply, reply-all and forword

version-14
mbauskar 8 years ago
parent
commit
e541249b8a
4 changed files with 93 additions and 17 deletions
  1. +62
    -6
      frappe/core/doctype/communication/communication.js
  2. +13
    -1
      frappe/core/doctype/communication/communication_list.js
  3. +15
    -10
      frappe/email/inbox.py
  4. +3
    -0
      frappe/public/js/frappe/views/communication.js

+ 62
- 6
frappe/core/doctype/communication/communication.js View File

@@ -60,7 +60,19 @@ frappe.ui.form.on("Communication", {

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");

frm.add_custom_button(__("Reply-All"), function() {
frm.trigger('reply_all');
}, "Actions");

frm.add_custom_button(__("Forward"), function() {
frm.trigger('forward_mail');
}, "Actions");
}
},
show_relink_dialog: function(frm){
@@ -110,6 +122,7 @@ frappe.ui.form.on("Communication", {
});
d.show();
},

mark_as_read_unread: function(frm) {
action = frm.doc.seen? "Unread": "Read";
flag = "(\\SEEN)";
@@ -117,15 +130,58 @@ frappe.ui.form.on("Communication", {
return frappe.call({
method: "frappe.email.inbox.create_email_flag_queue",
args: {
'communications': [{
'name': frm.doc.name,
'uid': frm.doc.uid || 1
}],
'names': [frm.doc.name],
'action': action,
'flag': flag
},
callback: function(r) {
freeze: true
});
},

reply: function(frm) {
args = frm.events.get_mail_args(frm);
$.extend(args, {
subject: __("Re: {0}", [frm.doc.subject]),
recipients: frm.doc.sender
})

new frappe.views.CommunicationComposer(args);
},

reply_all: function(frm) {
args = frm.events.get_mail_args(frm)
$.extend(args, {
subject: __("Re: {0}", [frm.doc.subject]),
recipients: frm.doc.sender,
cc: frm.doc.cc
})
new frappe.views.CommunicationComposer(args);
},

forward_mail: function(frm) {
args = frm.events.get_mail_args(frm)
$.extend(args, {
forward: true,
subject: __("Fw: {0}", [frm.doc.subject]),
})

new frappe.views.CommunicationComposer(args);
},

get_mail_args: function(frm) {
sender_email_id = ""
$.each(frappe.boot.email_accounts, function(idx, account) {
if(account.email_account == frm.doc.email_account) {
sender_email_id = account.email_id
return
}
});

return {
doc: frm.doc,
last_email: frm.doc,
sender: sender_email_id,
attachments: frm.doc.attachments
}
}
});

+ 13
- 1
frappe/core/doctype/communication/communication_list.js View File

@@ -4,5 +4,17 @@ frappe.listview_settings['Communication'] = {
"communication_medium", "communication_type",
"sender", "seen"
],
filters: [["status", "=", "Open"]]

filters: [["status", "=", "Open"]],

onload: function(listview) {
method = "frappe.email.inbox.create_email_flag_queue"

listview.page.add_menu_item(__("Mark as Read"), function() {
listview.call_for_selected_items(method, { action: "Read" })
});
listview.page.add_menu_item(__("Mark as Unread"), function() {
listview.call_for_selected_items(method, { action: "Unread" })
});
}
};

+ 15
- 10
frappe/email/inbox.py View File

@@ -12,7 +12,10 @@ def get_email_accounts(user=None):
distinct=True, order_by="idx")

if not accounts:
return None
return {
"email_accounts": [],
"all_accounts": ""
}

email_accounts.append({
"email_account": "Sent",
@@ -34,25 +37,27 @@ def get_email_accounts(user=None):
}

@frappe.whitelist()
def create_email_flag_queue(communications, action, flag):
def create_email_flag_queue(names, action, flag="(\\Seen)"):
""" create email flag queue to mark email either as read or unread """
class Found(Exception):
pass

if not all([communications, action, flag]):
if not all([names, action, flag]):
return

for communication in json.loads(communications or []):
if not communication.get("uid", None):
for name in json.loads(names or []):
uid, seen_status = frappe.db.get_value("Communication", name,
["ifnull(uid, -1)", "ifnull(seen, 0)"])

if not uid or uid == -1:
continue

seen = 1 if action == "Read" else "Unread"
# check if states are correct
state = frappe.db.get_value("Communication", communication.get("name"), "seen")
if (action =='Read' and state == 0) or (action =='Unread' and state == 1):
if (action =='Read' and seen_status == 0) or (action =='Unread' and seen_status == 1):
try:
queue = frappe.db.sql("""select name, action, flag from `tabEmail Flag Queue`
where communication = %(name)s""", {"name":communication.get("name")}, as_dict=True)
where communication = %(name)s""", {"name":name}, as_dict=True)
for q in queue:
# is same email with same flag
if q.flag == flag:
@@ -63,12 +68,12 @@ def create_email_flag_queue(communications, action, flag):

flag_queue = frappe.get_doc({
"doctype": "Email Flag Queue",
"communication": communication.get("name"),
"communication": name,
"action": action,
"flag": flag
})
flag_queue.save(ignore_permissions=True);
frappe.db.set_value("Communication", communication.get("name"), "seen", seen,
frappe.db.set_value("Communication", name, "seen", seen,
update_modified=False)
except Found:
pass

+ 3
- 0
frappe/public/js/frappe/views/communication.js View File

@@ -89,6 +89,7 @@ frappe.views.CommunicationComposer = Class.extend({
return !inList(["All Accounts", "Sent"], account.email_account)
})
if(frappe.boot.email_accounts && email_accounts.length > 1) {

fields = [
{label: __("From"), fieldtype: "Select", reqd: 1, fieldname: "sender",
options: accounts.map(function(e) { return e.email_id; }) }
@@ -107,6 +108,7 @@ frappe.views.CommunicationComposer = Class.extend({
this.setup_last_edited_communication();
this.setup_standard_reply();
$(this.dialog.fields_dict.recipients.input).val(this.recipients || "").change();
$(this.dialog.fields_dict.cc.input).val(this.cc || "").change();
if(this.dialog.fields_dict.sender) {
$(this.dialog.fields_dict.sender.input).val(this.sender || "").change();
}
@@ -119,6 +121,7 @@ frappe.views.CommunicationComposer = Class.extend({

if(!this.forward && !this.recipients && this.last_email) {
this.recipients = this.last_email.sender;
this.cc = this.last_email.cc;
}

if(!this.forward && !this.recipients) {


Loading…
Cancel
Save