blob: bb2eaefc44b6a16b602ffb89cf80d5cc248230cb [file] [log] [blame]
mbauskarf54b1042017-03-13 16:32:46 +05301frappe.ui.form.on("Communication", {
Makarand Bauskarf23788b2017-10-05 14:19:45 +05302 refresh: (frm) => {
3 // setup custom Make button only if Communication is Email
4 if(frm.doc.communication_medium == "Email" && frm.doc.sent_or_received == "Received") {
5 frm.events.setup_custom_buttons(frm);
6 }
7 },
8
9 setup_custom_buttons: (frm) => {
10 let confirm_msg = "Are you sure you want to create {0} from this email";
mbauskarf54b1042017-03-13 16:32:46 +053011 if(frm.doc.reference_doctype !== "Issue") {
Makarand Bauskarf23788b2017-10-05 14:19:45 +053012 frm.add_custom_button(__("Issue"), () => {
13 frappe.confirm(__(confirm_msg, [__("Issue")]), () => {
mbauskarf54b1042017-03-13 16:32:46 +053014 frm.trigger('make_issue_from_communication');
15 })
16 }, "Make");
17 }
18
Faris Ansariab74ca72017-05-30 12:54:42 +053019 if(!in_list(["Lead", "Opportunity"], frm.doc.reference_doctype)) {
Makarand Bauskarf23788b2017-10-05 14:19:45 +053020 frm.add_custom_button(__("Lead"), () => {
21 frappe.confirm(__(confirm_msg, [__("Lead")]), () => {
mbauskarf54b1042017-03-13 16:32:46 +053022 frm.trigger('make_lead_from_communication');
23 })
24 }, "Make");
25
Makarand Bauskarf23788b2017-10-05 14:19:45 +053026 frm.add_custom_button(__("Opportunity"), () => {
27 frappe.confirm(__(confirm_msg, [__("Opportunity")]), () => {
mbauskarf54b1042017-03-13 16:32:46 +053028 frm.trigger('make_opportunity_from_communication');
29 })
30 }, "Make");
31 }
mbauskarf54b1042017-03-13 16:32:46 +053032 frm.page.set_inner_btn_group_as_primary(__("Make"));
33 },
34
Makarand Bauskarf23788b2017-10-05 14:19:45 +053035 make_lead_from_communication: (frm) => {
mbauskarf54b1042017-03-13 16:32:46 +053036 return frappe.call({
37 method: "frappe.email.inbox.make_lead_from_communication",
38 args: {
39 communication: frm.doc.name
40 },
41 freeze: true,
Makarand Bauskarf23788b2017-10-05 14:19:45 +053042 callback: (r) => {
mbauskarf54b1042017-03-13 16:32:46 +053043 if(r.message) {
44 frm.reload_doc()
45 }
46 }
47 })
48 },
49
Makarand Bauskarf23788b2017-10-05 14:19:45 +053050 make_issue_from_communication: (frm) => {
mbauskarf54b1042017-03-13 16:32:46 +053051 return frappe.call({
52 method: "frappe.email.inbox.make_issue_from_communication",
53 args: {
54 communication: frm.doc.name
55 },
56 freeze: true,
Makarand Bauskarf23788b2017-10-05 14:19:45 +053057 callback: (r) => {
mbauskarf54b1042017-03-13 16:32:46 +053058 if(r.message) {
59 frm.reload_doc()
60 }
61 }
62 })
63 },
64
Makarand Bauskarf23788b2017-10-05 14:19:45 +053065 make_opportunity_from_communication: (frm) => {
mbauskarf54b1042017-03-13 16:32:46 +053066 return frappe.call({
67 method: "frappe.email.inbox.make_opportunity_from_communication",
68 args: {
69 communication: frm.doc.name
70 },
71 freeze: true,
Makarand Bauskarf23788b2017-10-05 14:19:45 +053072 callback: (r) => {
mbauskarf54b1042017-03-13 16:32:46 +053073 if(r.message) {
74 frm.reload_doc()
75 }
76 }
77 })
78 }
79});