refactor: load email list for to, cc, bcc in a better
This commit is contained in:
parent
19072dd3d6
commit
41324dda27
@ -132,3 +132,36 @@ def set_as_primary(contact, field, value):
|
|||||||
|
|
||||||
contact.save()
|
contact.save()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def search_emails(txt: str):
|
||||||
|
doctype = "Contact"
|
||||||
|
meta = frappe.get_meta(doctype)
|
||||||
|
filters = [["Contact", "email_id", "is", "set"]]
|
||||||
|
|
||||||
|
if meta.get("fields", {"fieldname": "enabled", "fieldtype": "Check"}):
|
||||||
|
filters.append([doctype, "enabled", "=", 1])
|
||||||
|
if meta.get("fields", {"fieldname": "disabled", "fieldtype": "Check"}):
|
||||||
|
filters.append([doctype, "disabled", "!=", 1])
|
||||||
|
|
||||||
|
or_filters = []
|
||||||
|
search_fields = ["full_name", "email_id", "name"]
|
||||||
|
if txt:
|
||||||
|
for f in search_fields:
|
||||||
|
or_filters.append([doctype, f.strip(), "like", f"%{txt}%"])
|
||||||
|
|
||||||
|
results = frappe.get_list(
|
||||||
|
doctype,
|
||||||
|
filters=filters,
|
||||||
|
fields=search_fields,
|
||||||
|
or_filters=or_filters,
|
||||||
|
limit_start=0,
|
||||||
|
limit_page_length=20,
|
||||||
|
order_by='email_id, full_name, name',
|
||||||
|
ignore_permissions=False,
|
||||||
|
as_list=True,
|
||||||
|
strict=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
return results
|
||||||
@ -133,7 +133,7 @@ const signature = createResource({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function setSignature(editor) {
|
function setSignature(editor) {
|
||||||
signature.data = signature.data.replace(/\n/g, '<br>')
|
signature.data = signature.data?.replace(/\n/g, '<br>')
|
||||||
let emailContent = editor.getHTML()
|
let emailContent = editor.getHTML()
|
||||||
emailContent = emailContent.startsWith('<p></p>')
|
emailContent = emailContent.startsWith('<p></p>')
|
||||||
? emailContent.slice(7)
|
? emailContent.slice(7)
|
||||||
|
|||||||
@ -133,30 +133,26 @@ watchDebounced(
|
|||||||
query,
|
query,
|
||||||
(val) => {
|
(val) => {
|
||||||
val = val || ''
|
val = val || ''
|
||||||
if (text.value === val) return
|
if (text.value === val && options.value?.length) return
|
||||||
text.value = val
|
text.value = val
|
||||||
reload(val)
|
reload(val)
|
||||||
},
|
},
|
||||||
{ debounce: 300, immediate: true }
|
{ debounce: 300, immediate: true },
|
||||||
)
|
)
|
||||||
|
|
||||||
const filterOptions = createResource({
|
const filterOptions = createResource({
|
||||||
url: 'frappe.desk.search.search_link',
|
url: 'crm.api.contact.search_emails',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
cache: [text.value, 'Contact'],
|
cache: [text.value, 'Contact'],
|
||||||
params: {
|
params: { txt: text.value },
|
||||||
txt: text.value,
|
|
||||||
doctype: 'Contact',
|
|
||||||
},
|
|
||||||
transform: (data) => {
|
transform: (data) => {
|
||||||
let allData = data
|
let allData = data
|
||||||
.filter((c) => {
|
|
||||||
return c.description.split(', ')[1]
|
|
||||||
})
|
|
||||||
.map((option) => {
|
.map((option) => {
|
||||||
let email = option.description.split(', ')[1]
|
let fullName = option[0]
|
||||||
|
let email = option[1]
|
||||||
|
let name = option[2]
|
||||||
return {
|
return {
|
||||||
label: option.label || email,
|
label: fullName || name || email,
|
||||||
value: email,
|
value: email,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -177,10 +173,7 @@ const options = computed(() => {
|
|||||||
|
|
||||||
function reload(val) {
|
function reload(val) {
|
||||||
filterOptions.update({
|
filterOptions.update({
|
||||||
params: {
|
params: { txt: val },
|
||||||
txt: val,
|
|
||||||
doctype: 'Contact',
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
filterOptions.reload()
|
filterOptions.reload()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user