@@ -60,7 +60,19 @@ frappe.ui.form.on("Communication", { | |||||
frm.add_custom_button(__("Mark as {0}", [frm.doc.seen? "Unread": "Read"]), function() { | frm.add_custom_button(__("Mark as {0}", [frm.doc.seen? "Unread": "Read"]), function() { | ||||
frm.trigger('mark_as_read_unread'); | 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){ | show_relink_dialog: function(frm){ | ||||
@@ -110,6 +122,7 @@ frappe.ui.form.on("Communication", { | |||||
}); | }); | ||||
d.show(); | d.show(); | ||||
}, | }, | ||||
mark_as_read_unread: function(frm) { | mark_as_read_unread: function(frm) { | ||||
action = frm.doc.seen? "Unread": "Read"; | action = frm.doc.seen? "Unread": "Read"; | ||||
flag = "(\\SEEN)"; | flag = "(\\SEEN)"; | ||||
@@ -117,15 +130,58 @@ frappe.ui.form.on("Communication", { | |||||
return frappe.call({ | return frappe.call({ | ||||
method: "frappe.email.inbox.create_email_flag_queue", | method: "frappe.email.inbox.create_email_flag_queue", | ||||
args: { | args: { | ||||
'communications': [{ | |||||
'name': frm.doc.name, | |||||
'uid': frm.doc.uid || 1 | |||||
}], | |||||
'names': [frm.doc.name], | |||||
'action': action, | 'action': action, | ||||
'flag': flag | '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 | |||||
} | |||||
} | } | ||||
}); | }); |
@@ -4,5 +4,17 @@ frappe.listview_settings['Communication'] = { | |||||
"communication_medium", "communication_type", | "communication_medium", "communication_type", | ||||
"sender", "seen" | "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" }) | |||||
}); | |||||
} | |||||
}; | }; |
@@ -12,7 +12,10 @@ def get_email_accounts(user=None): | |||||
distinct=True, order_by="idx") | distinct=True, order_by="idx") | ||||
if not accounts: | if not accounts: | ||||
return None | |||||
return { | |||||
"email_accounts": [], | |||||
"all_accounts": "" | |||||
} | |||||
email_accounts.append({ | email_accounts.append({ | ||||
"email_account": "Sent", | "email_account": "Sent", | ||||
@@ -34,25 +37,27 @@ def get_email_accounts(user=None): | |||||
} | } | ||||
@frappe.whitelist() | @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 """ | """ create email flag queue to mark email either as read or unread """ | ||||
class Found(Exception): | class Found(Exception): | ||||
pass | pass | ||||
if not all([communications, action, flag]): | |||||
if not all([names, action, flag]): | |||||
return | 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 | continue | ||||
seen = 1 if action == "Read" else "Unread" | seen = 1 if action == "Read" else "Unread" | ||||
# check if states are correct | # 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: | try: | ||||
queue = frappe.db.sql("""select name, action, flag from `tabEmail Flag Queue` | 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: | for q in queue: | ||||
# is same email with same flag | # is same email with same flag | ||||
if q.flag == flag: | if q.flag == flag: | ||||
@@ -63,12 +68,12 @@ def create_email_flag_queue(communications, action, flag): | |||||
flag_queue = frappe.get_doc({ | flag_queue = frappe.get_doc({ | ||||
"doctype": "Email Flag Queue", | "doctype": "Email Flag Queue", | ||||
"communication": communication.get("name"), | |||||
"communication": name, | |||||
"action": action, | "action": action, | ||||
"flag": flag | "flag": flag | ||||
}) | }) | ||||
flag_queue.save(ignore_permissions=True); | 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) | update_modified=False) | ||||
except Found: | except Found: | ||||
pass | pass |
@@ -89,6 +89,7 @@ frappe.views.CommunicationComposer = Class.extend({ | |||||
return !inList(["All Accounts", "Sent"], account.email_account) | return !inList(["All Accounts", "Sent"], account.email_account) | ||||
}) | }) | ||||
if(frappe.boot.email_accounts && email_accounts.length > 1) { | if(frappe.boot.email_accounts && email_accounts.length > 1) { | ||||
fields = [ | fields = [ | ||||
{label: __("From"), fieldtype: "Select", reqd: 1, fieldname: "sender", | {label: __("From"), fieldtype: "Select", reqd: 1, fieldname: "sender", | ||||
options: accounts.map(function(e) { return e.email_id; }) } | 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_last_edited_communication(); | ||||
this.setup_standard_reply(); | this.setup_standard_reply(); | ||||
$(this.dialog.fields_dict.recipients.input).val(this.recipients || "").change(); | $(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) { | if(this.dialog.fields_dict.sender) { | ||||
$(this.dialog.fields_dict.sender.input).val(this.sender || "").change(); | $(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) { | if(!this.forward && !this.recipients && this.last_email) { | ||||
this.recipients = this.last_email.sender; | this.recipients = this.last_email.sender; | ||||
this.cc = this.last_email.cc; | |||||
} | } | ||||
if(!this.forward && !this.recipients) { | if(!this.forward && !this.recipients) { | ||||