[hotfix] Show Make button only for Email communication (#10876)

This commit is contained in:
Makarand Bauskar 2017-10-05 14:19:45 +05:30 committed by Nabin Hait
parent 671c6610de
commit f23788bb7d

View File

@ -1,39 +1,45 @@
frappe.ui.form.on("Communication", { frappe.ui.form.on("Communication", {
refresh: function(frm) { refresh: (frm) => {
// setup custom Make button only if Communication is Email
if(frm.doc.communication_medium == "Email" && frm.doc.sent_or_received == "Received") {
frm.events.setup_custom_buttons(frm);
}
},
setup_custom_buttons: (frm) => {
let confirm_msg = "Are you sure you want to create {0} from this email";
if(frm.doc.reference_doctype !== "Issue") { if(frm.doc.reference_doctype !== "Issue") {
frm.add_custom_button(__("Issue"), function() { frm.add_custom_button(__("Issue"), () => {
frappe.confirm("Are you sure you want to create Issue from this email", function(){ frappe.confirm(__(confirm_msg, [__("Issue")]), () => {
frm.trigger('make_issue_from_communication'); frm.trigger('make_issue_from_communication');
}) })
}, "Make"); }, "Make");
} }
if(!in_list(["Lead", "Opportunity"], frm.doc.reference_doctype)) { if(!in_list(["Lead", "Opportunity"], frm.doc.reference_doctype)) {
frm.add_custom_button(__("Lead"), function() { frm.add_custom_button(__("Lead"), () => {
frappe.confirm("Are you sure you want to create Lead from this email", function(){ frappe.confirm(__(confirm_msg, [__("Lead")]), () => {
frm.trigger('make_lead_from_communication'); frm.trigger('make_lead_from_communication');
}) })
}, "Make"); }, "Make");
frm.add_custom_button(__("Opportunity"), function() { frm.add_custom_button(__("Opportunity"), () => {
frappe.confirm("Are you sure you want to create Opportunity from this email", function(){ frappe.confirm(__(confirm_msg, [__("Opportunity")]), () => {
frm.trigger('make_opportunity_from_communication'); frm.trigger('make_opportunity_from_communication');
}) })
}, "Make"); }, "Make");
} }
frm.page.set_inner_btn_group_as_primary(__("Make")); frm.page.set_inner_btn_group_as_primary(__("Make"));
}, },
make_lead_from_communication: function(frm) { make_lead_from_communication: (frm) => {
return frappe.call({ return frappe.call({
method: "frappe.email.inbox.make_lead_from_communication", method: "frappe.email.inbox.make_lead_from_communication",
args: { args: {
communication: frm.doc.name communication: frm.doc.name
}, },
freeze: true, freeze: true,
callback: function(r) { callback: (r) => {
if(r.message) { if(r.message) {
frm.reload_doc() frm.reload_doc()
} }
@ -41,14 +47,14 @@ frappe.ui.form.on("Communication", {
}) })
}, },
make_issue_from_communication: function(frm) { make_issue_from_communication: (frm) => {
return frappe.call({ return frappe.call({
method: "frappe.email.inbox.make_issue_from_communication", method: "frappe.email.inbox.make_issue_from_communication",
args: { args: {
communication: frm.doc.name communication: frm.doc.name
}, },
freeze: true, freeze: true,
callback: function(r) { callback: (r) => {
if(r.message) { if(r.message) {
frm.reload_doc() frm.reload_doc()
} }
@ -56,14 +62,14 @@ frappe.ui.form.on("Communication", {
}) })
}, },
make_opportunity_from_communication: function(frm) { make_opportunity_from_communication: (frm) => {
return frappe.call({ return frappe.call({
method: "frappe.email.inbox.make_opportunity_from_communication", method: "frappe.email.inbox.make_opportunity_from_communication",
args: { args: {
communication: frm.doc.name communication: frm.doc.name
}, },
freeze: true, freeze: true,
callback: function(r) { callback: (r) => {
if(r.message) { if(r.message) {
frm.reload_doc() frm.reload_doc()
} }