fix: Form UX
- Fetch contacts - Message to enable Auto Repeat
This commit is contained in:
parent
b11cda2fff
commit
26bb7e4237
2 changed files with 27 additions and 45 deletions
|
|
@ -28,13 +28,21 @@ frappe.ui.form.on('Auto Repeat', {
|
|||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
//if document is not saved do not show schedule and document link
|
||||
// auto repeat message
|
||||
if (frm.is_new()) {
|
||||
let customize_form_link = `<a href="#Form/Customize Form">${__('Customize Form')}</a>`;
|
||||
frm.dashboard.set_headline(__('To configure Auto Repeat, enable "Allow Auto Repeat" from {0}.', [customize_form_link]));
|
||||
}
|
||||
|
||||
// view document button
|
||||
if (!frm.is_dirty()) {
|
||||
let label = __('View {0}', [__(frm.doc.reference_doctype)]);
|
||||
frm.add_custom_button(__(label), () =>
|
||||
frm.add_custom_button(label, () =>
|
||||
frappe.set_route("List", frm.doc.reference_doctype, { auto_repeat: frm.doc.name })
|
||||
);
|
||||
}
|
||||
|
||||
// auto repeat schedule
|
||||
frappe.auto_repeat.render_schedule(frm);
|
||||
},
|
||||
|
||||
|
|
@ -51,22 +59,7 @@ frappe.ui.form.on('Auto Repeat', {
|
|||
},
|
||||
|
||||
get_contacts: function(frm) {
|
||||
frappe.call({
|
||||
method: "frappe.automation.doctype.auto_repeat.auto_repeat.get_contacts",
|
||||
args: {
|
||||
reference_doctype: frm.doc.reference_doctype,
|
||||
reference_name: frm.doc.reference_document
|
||||
},
|
||||
callback: function(r) {
|
||||
if (r.message) {
|
||||
frm.set_value("recipients", r.message.join());
|
||||
frm.refresh_field("recipients");
|
||||
}
|
||||
else {
|
||||
frappe.msgprint("No Contacts linked to Reference Document", "Message");
|
||||
}
|
||||
}
|
||||
});
|
||||
frm.call('fetch_linked_contacts');
|
||||
},
|
||||
|
||||
preview_message: function(frm) {
|
||||
|
|
@ -80,7 +73,7 @@ frappe.ui.form.on('Auto Repeat', {
|
|||
message: frm.doc.message
|
||||
},
|
||||
callback: function(r) {
|
||||
if(r.message) {
|
||||
if (r.message) {
|
||||
frappe.msgprint(r.message.message, r.message.subject)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,6 +223,21 @@ class AutoRepeat(Document):
|
|||
make(doctype=new_doc.doctype, name=new_doc.name, recipients=self.recipients,
|
||||
subject=subject, content=message, attachments=attachments, send_email=1)
|
||||
|
||||
def fetch_linked_contacts(self):
|
||||
if self.reference_doctype and self.reference_document:
|
||||
res = frappe.db.get_all('Contact',
|
||||
fields=['email_id'],
|
||||
filters=[
|
||||
['Dynamic Link', 'link_doctype', '=', self.reference_doctype],
|
||||
['Dynamic Link', 'link_name', '=', self.reference_document]
|
||||
])
|
||||
|
||||
email_ids = list(set([d.email_id for d in res]))
|
||||
if not email_ids:
|
||||
frappe.msgprint(_('No contacts linked to document'), alert=True)
|
||||
else:
|
||||
self.recipients = ', '.join(email_ids)
|
||||
|
||||
def disable_auto_repeat(self):
|
||||
frappe.db.set_value('Auto Repeat', self.name, 'disabled', 1)
|
||||
|
||||
|
|
@ -346,32 +361,6 @@ def get_auto_repeat_doctypes(doctype, txt, searchfield, start, page_len, filters
|
|||
repeatable_docs.append([dt[0]])
|
||||
return repeatable_docs
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_contacts(reference_doctype, reference_name):
|
||||
docfields = frappe.get_meta(reference_doctype).fields
|
||||
|
||||
contact_fields = []
|
||||
for field in docfields:
|
||||
if field.fieldtype == "Link" and field.options == "Contact":
|
||||
contact_fields.append(field.fieldname)
|
||||
|
||||
if contact_fields:
|
||||
contacts = []
|
||||
for contact_field in contact_fields:
|
||||
contacts.append(frappe.db.get_value(reference_doctype, reference_name, contact_field))
|
||||
else:
|
||||
return
|
||||
|
||||
if contacts:
|
||||
emails = []
|
||||
for contact in contacts:
|
||||
emails.append(frappe.db.get_value("Contact", contact, "email_id"))
|
||||
|
||||
return emails
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_reference(docname, reference):
|
||||
result = ""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue