From e301150a2f869cdf3fde53948d6110c9ec41b394 Mon Sep 17 00:00:00 2001 From: Jeremy Rangel Date: Thu, 5 Jun 2025 00:54:17 -0700 Subject: [PATCH] Added modal to Action button on Lead DocType form to allow users to add Leads to Email Groups for newsletters and minor changes to CSS --- rangeldigital/public/css/rangeldigital.css | 4 +- rangeldigital/public/js/lead.js | 52 ++++++++++++++++-- .../lead/__pycache__/lead_api.cpython-310.pyc | Bin 981 -> 1558 bytes rangeldigital/utilities/lead/lead_api.py | 30 ++++++++++ 4 files changed, 79 insertions(+), 7 deletions(-) diff --git a/rangeldigital/public/css/rangeldigital.css b/rangeldigital/public/css/rangeldigital.css index e914c34..3d41f73 100644 --- a/rangeldigital/public/css/rangeldigital.css +++ b/rangeldigital/public/css/rangeldigital.css @@ -23,8 +23,8 @@ button {background:#008AFC} /* ------- FRAPPE ELEMENTS ------- */ /* Page Card */ -.page-card {background:#1C2037;border:none} -.page-card span {color:white} +.page_content .page-card, .page_content .for-login .page-card {background-color:#1C2037;border:none} +.page_content .page-card span,.page_content .page-card .page-card-head .indicator {color:white} /* ----- FORMS AND INPUTS ------- */ label {color:#A5A5A5;font-size:14px} diff --git a/rangeldigital/public/js/lead.js b/rangeldigital/public/js/lead.js index ec65adb..883a554 100644 --- a/rangeldigital/public/js/lead.js +++ b/rangeldigital/public/js/lead.js @@ -1,14 +1,16 @@ frappe.ui.form.on('Lead', { refresh(frm) { - // Only show the button if the Lead has been saved and has an email + // Email Campaign Button if (!frm.doc.__islocal && frm.doc.email_id) { frm.add_custom_button(__('Add to Email Campaign'), () => { open_email_campaign_dialog(frm); }, __('Action')); - } else if (!frm.doc.email_id) { - // Optional: give user visual feedback - frm.dashboard.set_headline(__('This Lead has no email address — cannot add to Email Campaign.')); - } + + // Email Group Button + frm.add_custom_button(__('Add to Email Newsletter'), () => { + open_email_group_dialog(frm); + }, __('Action')); + } } }); @@ -63,3 +65,43 @@ function open_email_campaign_dialog(frm) { __('Create') ); } + +function open_email_group_dialog(frm) { + frappe.prompt([ + { + fieldname: 'email_group', + label: 'Email Group', + fieldtype: 'Link', + options: 'Email Group', + reqd: 1 + } + ], + (values) => { + frappe.call({ + method: 'rangeldigital.utilities.lead.lead_api.add_lead_to_email_group', + args: { + lead_name: frm.doc.name, + email_group: values.email_group + }, + freeze: true, + freeze_message: __('Adding to Email Group...'), + callback: (r) => { + if (r.message && r.message.status === 'success') { + frappe.show_alert({ + message: __('Lead added to Email Group successfully'), + indicator: 'green' + }); + } else { + frappe.msgprint(__('Something went wrong. Please try again.')); + } + }, + error: (err) => { + frappe.msgprint(__('Unexpected error. Check the console.')); + console.error(err); + } + }); + }, + __('Add to Email Group'), + __('Add') + ); +} diff --git a/rangeldigital/utilities/lead/__pycache__/lead_api.cpython-310.pyc b/rangeldigital/utilities/lead/__pycache__/lead_api.cpython-310.pyc index 4afff3c2026a14bebebac874089822b1df876df4..c4407b573296eec731b1587ed171511468697509 100644 GIT binary patch delta 905 zcmZ`%&1w`u5T5Gk`Pt28LLwL>Q3v(lAVgH~AR=f`K}yv8Xp+YOUpSQz`mEKbsJJ|=)J0517vn-zu2w@-v~}`9+?FST8q+%>U9At8!YW_APIQqB`<0D(@5G`D(=TEI z&h&wOYZ9`eCm4PY$;6yp=cx}EN{eI(dJduBUhD(fhoWs2a3oNc*0FdaO0i?>mD=z8 z@$bkZ2VLVU0lh=PO1re_dad(Mb(2{jw*(`^1~w1nG3>ZFhpl(OEuY6AF^yc!f$&`Q2 z%y+>UYq)4U%UosGc)La3{i_mlOkZX2#mxX(!W99ywtyzcpHc=OnG29S-5=6%zxy5; zbp)H7=Hm3NefC+MZPj=+ND7tm@1l?ewQ6?%KbiP)FEo|-$d<*x|ImP$QFyC+Ht@qPO%6>m4uD;{5?A(7%($RsNkRWI>ZJlb!>68MI z z=0a(9A@YS#^MWmv&6sVOLgez02PSk!O{bN>NfTGr!FMREY{E(wD9wb|2|e*SHBo&< zb-E?GZ8(yTsHy)PvpTrF6FZu+2ed8VP?7IYqv3rr!n_zF$beEa3Qai%5J2Ut% X>GtAjUgCq6LvT|SIf+OQLb?loaSTzB diff --git a/rangeldigital/utilities/lead/lead_api.py b/rangeldigital/utilities/lead/lead_api.py index 828856c..8a2e565 100644 --- a/rangeldigital/utilities/lead/lead_api.py +++ b/rangeldigital/utilities/lead/lead_api.py @@ -1,5 +1,6 @@ import frappe from frappe.utils import today +from frappe import _ @frappe.whitelist() def add_lead_to_campaign(lead_name, campaign_name, start_date=None): @@ -29,3 +30,32 @@ def add_lead_to_campaign(lead_name, campaign_name, start_date=None): frappe.db.commit() return {"status": "success", "message": "Email Campaign created"} + + +@frappe.whitelist() +def add_lead_to_email_group(lead_name, email_group): + if not lead_name or not email_group: + return {"status": "error", "message": _("Missing required parameters.")} + + lead = frappe.get_doc("Lead", lead_name) + + if not lead.email_id: + return {"status": "error", "message": _("Lead does not have an email address.")} + + # Check if already added + exists = frappe.db.exists( + "Email Group Member", + {"email": lead.email_id, "email_group": email_group} + ) + if exists: + return {"status": "error", "message": _("Lead is already in this Email Group.")} + + # Add to email group + frappe.get_doc({ + "doctype": "Email Group Member", + "email_group": email_group, + "email": lead.email_id, + "status": "Subscribed" + }).insert(ignore_permissions=True) + + return {"status": "success"} \ No newline at end of file