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:
@ -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')
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user