mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 1 | frappe.ui.form.on("Communication", { |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 2 | 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"; |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 11 | if(frm.doc.reference_doctype !== "Issue") { |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 12 | frm.add_custom_button(__("Issue"), () => { |
| 13 | frappe.confirm(__(confirm_msg, [__("Issue")]), () => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 14 | frm.trigger('make_issue_from_communication'); |
| 15 | }) |
| 16 | }, "Make"); |
| 17 | } |
| 18 | |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 19 | if(!in_list(["Lead", "Opportunity"], frm.doc.reference_doctype)) { |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 20 | frm.add_custom_button(__("Lead"), () => { |
| 21 | frappe.confirm(__(confirm_msg, [__("Lead")]), () => { |
Rushabh Mehta | b5a3df9 | 2018-01-23 16:08:52 +0530 | [diff] [blame] | 22 | frm.trigger('make_lead_from_communication'); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 23 | }) |
Rushabh Mehta | b5a3df9 | 2018-01-23 16:08:52 +0530 | [diff] [blame] | 24 | }, __("Make")); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 25 | |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 26 | frm.add_custom_button(__("Opportunity"), () => { |
| 27 | frappe.confirm(__(confirm_msg, [__("Opportunity")]), () => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 28 | frm.trigger('make_opportunity_from_communication'); |
| 29 | }) |
Rushabh Mehta | b5a3df9 | 2018-01-23 16:08:52 +0530 | [diff] [blame] | 30 | }, __("Make")); |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 31 | } |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 32 | }, |
| 33 | |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 34 | make_lead_from_communication: (frm) => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 35 | return frappe.call({ |
| 36 | method: "frappe.email.inbox.make_lead_from_communication", |
| 37 | args: { |
| 38 | communication: frm.doc.name |
| 39 | }, |
| 40 | freeze: true, |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 41 | callback: (r) => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 42 | if(r.message) { |
| 43 | frm.reload_doc() |
| 44 | } |
| 45 | } |
| 46 | }) |
| 47 | }, |
| 48 | |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 49 | make_issue_from_communication: (frm) => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 50 | return frappe.call({ |
| 51 | method: "frappe.email.inbox.make_issue_from_communication", |
| 52 | args: { |
| 53 | communication: frm.doc.name |
| 54 | }, |
| 55 | freeze: true, |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 56 | callback: (r) => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 57 | if(r.message) { |
| 58 | frm.reload_doc() |
| 59 | } |
| 60 | } |
| 61 | }) |
| 62 | }, |
| 63 | |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 64 | make_opportunity_from_communication: (frm) => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 65 | return frappe.call({ |
| 66 | method: "frappe.email.inbox.make_opportunity_from_communication", |
| 67 | args: { |
| 68 | communication: frm.doc.name |
| 69 | }, |
| 70 | freeze: true, |
Makarand Bauskar | f23788b | 2017-10-05 14:19:45 +0530 | [diff] [blame] | 71 | callback: (r) => { |
mbauskar | f54b104 | 2017-03-13 16:32:46 +0530 | [diff] [blame] | 72 | if(r.message) { |
| 73 | frm.reload_doc() |
| 74 | } |
| 75 | } |
| 76 | }) |
| 77 | } |
| 78 | }); |