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
This commit is contained in:
@ -23,8 +23,8 @@ button {background:#008AFC}
|
|||||||
/* ------- FRAPPE ELEMENTS ------- */
|
/* ------- FRAPPE ELEMENTS ------- */
|
||||||
|
|
||||||
/* Page Card */
|
/* Page Card */
|
||||||
.page-card {background:#1C2037;border:none}
|
.page_content .page-card, .page_content .for-login .page-card {background-color:#1C2037;border:none}
|
||||||
.page-card span {color:white}
|
.page_content .page-card span,.page_content .page-card .page-card-head .indicator {color:white}
|
||||||
|
|
||||||
/* ----- FORMS AND INPUTS ------- */
|
/* ----- FORMS AND INPUTS ------- */
|
||||||
label {color:#A5A5A5;font-size:14px}
|
label {color:#A5A5A5;font-size:14px}
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
frappe.ui.form.on('Lead', {
|
frappe.ui.form.on('Lead', {
|
||||||
refresh(frm) {
|
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) {
|
if (!frm.doc.__islocal && frm.doc.email_id) {
|
||||||
frm.add_custom_button(__('Add to Email Campaign'), () => {
|
frm.add_custom_button(__('Add to Email Campaign'), () => {
|
||||||
open_email_campaign_dialog(frm);
|
open_email_campaign_dialog(frm);
|
||||||
}, __('Action'));
|
}, __('Action'));
|
||||||
} else if (!frm.doc.email_id) {
|
|
||||||
// Optional: give user visual feedback
|
// Email Group Button
|
||||||
frm.dashboard.set_headline(__('This Lead has no email address — cannot add to Email Campaign.'));
|
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')
|
__('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')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Binary file not shown.
@ -1,5 +1,6 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import today
|
from frappe.utils import today
|
||||||
|
from frappe import _
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def add_lead_to_campaign(lead_name, campaign_name, start_date=None):
|
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()
|
frappe.db.commit()
|
||||||
|
|
||||||
return {"status": "success", "message": "Email Campaign created"}
|
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"}
|
||||||
Reference in New Issue
Block a user