Files
upstream-frappe-crm/crm/public/js/domain_enrichment.js
upstream-mirror db69de1c11
Some checks failed
Frontend / Unit Tests & Coverage (push) Has been skipped
Regenerate POT file (translatable strings) / Regenerate POT file (develop) (push) Failing after 1m13s
Regenerate POT file (translatable strings) / Regenerate POT file (main-hotfix) (push) Failing after 6s
Server / Tests (frappe ${{ matrix.frappe-branch }}) (push) Has been skipped
Server / Resolve frappe matrix (push) Failing after 1s
Frontend / Lint (push) Failing after 1s
Frontend / Production Build (push) Failing after 1s
Server / Coverage Wrap Up (push) Has been skipped
Frontend / Coverage Wrap Up (push) Has been skipped
snapshot of https://github.com/frappe/crm.git (develop, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:36:01 +05:00

87 lines
2.2 KiB
JavaScript

// Domain Enrichment — desk form button + live progress.
//
// Adds an "Enrich from Website" button to CRM Lead / CRM Organization / CRM Deal.
// Clicking it queues a background job; the progress steps stream back over realtime
// and are shown to the user. When done, the form reloads to show the enriched fields.
frappe.provide("crm.domain_enrichment");
crm.domain_enrichment.setup = function (frm) {
if (frm.is_new()) return;
frm.add_custom_button(__("Enrich from Website"), () => {
const website = (frm.doc.website || "").trim();
if (!website) {
frappe.msgprint({
title: __("No Website"),
message: __("Set a Website on this record before enriching."),
indicator: "orange",
});
return;
}
crm.domain_enrichment.run(frm, website);
});
};
crm.domain_enrichment.run = function (frm, website) {
// A determinate progress dialog driven by realtime events.
const total = 7; // pipeline.PROGRESS_STEPS; each event also carries data.total
frappe.show_progress(__("Domain Enrichment"), 0, total, __("Queued…"));
const event = "domain_enrichment_progress";
const handler = (data) => {
if (
!data ||
data.reference_doctype !== frm.doctype ||
data.reference_name !== frm.docname
) {
return; // not for this document
}
frappe.show_progress(
__("Domain Enrichment"),
data.step,
data.total,
data.message
);
if (data.status === "completed") {
frappe.realtime.off(event, handler);
frappe.hide_progress();
frappe.show_alert(
{ message: __("Enrichment complete"), indicator: "green" },
5
);
frm.reload_doc();
} else if (data.status === "error") {
frappe.realtime.off(event, handler);
frappe.hide_progress();
frappe.msgprint({
title: __("Enrichment Failed"),
message: data.message || __("See Error Log."),
indicator: "red",
});
}
};
frappe.realtime.on(event, handler);
frappe.call({
method: "crm.domain_enrichment.api.enrich",
args: {
reference_doctype: frm.doctype,
reference_name: frm.docname,
},
error: () => {
frappe.realtime.off(event, handler);
frappe.hide_progress();
},
});
};
["CRM Lead", "CRM Organization", "CRM Deal"].forEach((doctype) => {
frappe.ui.form.on(doctype, {
refresh: crm.domain_enrichment.setup,
});
});