Merge pull request #217 from shariquerik/email-signature
fix: append user email signature if content is empty
This commit is contained in:
commit
bc80e54fe3
@ -1,5 +1,7 @@
|
|||||||
|
from bs4 import BeautifulSoup
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.translate import get_all_translations
|
from frappe.translate import get_all_translations
|
||||||
|
from frappe.utils import cstr
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
@ -10,3 +12,36 @@ def get_translations():
|
|||||||
language = frappe.db.get_single_value("System Settings", "language")
|
language = frappe.db.get_single_value("System Settings", "language")
|
||||||
|
|
||||||
return get_all_translations(language)
|
return get_all_translations(language)
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_user_signature():
|
||||||
|
user = frappe.session.user
|
||||||
|
user_email_signature = (
|
||||||
|
frappe.db.get_value(
|
||||||
|
"User",
|
||||||
|
user,
|
||||||
|
"email_signature",
|
||||||
|
)
|
||||||
|
if user
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
|
signature = user_email_signature or frappe.db.get_value(
|
||||||
|
"Email Account",
|
||||||
|
{"default_outgoing": 1, "add_signature": 1},
|
||||||
|
"signature",
|
||||||
|
)
|
||||||
|
|
||||||
|
if not signature:
|
||||||
|
return
|
||||||
|
|
||||||
|
soup = BeautifulSoup(signature, "html.parser")
|
||||||
|
html_signature = soup.find("div", {"class": "ql-editor read-mode"})
|
||||||
|
_signature = None
|
||||||
|
if html_signature:
|
||||||
|
_signature = html_signature.renderContents()
|
||||||
|
content = ""
|
||||||
|
if (cstr(_signature) or signature):
|
||||||
|
content = f'<br><p class="signature">{signature}</p>'
|
||||||
|
return content
|
||||||
@ -479,22 +479,26 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex gap-0.5">
|
<div class="flex gap-0.5">
|
||||||
<Tooltip :text="__('Reply')">
|
<Tooltip :text="__('Reply')">
|
||||||
<Button
|
<div>
|
||||||
variant="ghost"
|
<Button
|
||||||
class="text-gray-700"
|
variant="ghost"
|
||||||
@click="reply(activity.data)"
|
class="text-gray-700"
|
||||||
>
|
@click="reply(activity.data)"
|
||||||
<ReplyIcon class="h-4 w-4" />
|
>
|
||||||
</Button>
|
<ReplyIcon class="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip :text="__('Reply All')">
|
<Tooltip :text="__('Reply All')">
|
||||||
<Button
|
<div>
|
||||||
variant="ghost"
|
<Button
|
||||||
class="text-gray-700"
|
variant="ghost"
|
||||||
@click="reply(activity.data, true)"
|
class="text-gray-700"
|
||||||
>
|
@click="reply(activity.data, true)"
|
||||||
<ReplyAllIcon class="h-4 w-4" />
|
>
|
||||||
</Button>
|
<ReplyAllIcon class="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex justify-between gap-3 border-t sm:px-10 px-4 py-2.5">
|
<div class="flex justify-between gap-3 border-t px-4 py-2.5 sm:px-10">
|
||||||
<div class="flex gap-1.5">
|
<div class="flex gap-1.5">
|
||||||
<Button
|
<Button
|
||||||
ref="sendEmailRef"
|
ref="sendEmailRef"
|
||||||
@ -102,7 +102,7 @@ import CommentIcon from '@/components/Icons/CommentIcon.vue'
|
|||||||
import EmailIcon from '@/components/Icons/EmailIcon.vue'
|
import EmailIcon from '@/components/Icons/EmailIcon.vue'
|
||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
import { useStorage } from '@vueuse/core'
|
import { useStorage } from '@vueuse/core'
|
||||||
import { call } from 'frappe-ui'
|
import { call, createResource } from 'frappe-ui'
|
||||||
import { ref, watch, computed, nextTick } from 'vue'
|
import { ref, watch, computed, nextTick } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -138,11 +138,29 @@ const subject = computed(() => {
|
|||||||
return `${prefix} (#${doc.value.data.name})`
|
return `${prefix} (#${doc.value.data.name})`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const signature = createResource({
|
||||||
|
url: 'crm.api.get_user_signature',
|
||||||
|
cache: 'user-email-signature',
|
||||||
|
auto: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
function setSignature(editor) {
|
||||||
|
signature.data = signature.data.replace(/\n/g, '<br>')
|
||||||
|
let emailContent = editor.getHTML()
|
||||||
|
emailContent = emailContent.startsWith('<p></p>')
|
||||||
|
? emailContent.slice(7)
|
||||||
|
: emailContent
|
||||||
|
editor.commands.setContent(signature.data + emailContent)
|
||||||
|
editor.commands.focus('start')
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => showEmailBox.value,
|
() => showEmailBox.value,
|
||||||
(value) => {
|
(value) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
newEmailEditor.value.editor.commands.focus()
|
let editor = newEmailEditor.value.editor
|
||||||
|
editor.commands.focus()
|
||||||
|
setSignature(editor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -248,5 +266,9 @@ function toggleCommentBox() {
|
|||||||
showCommentBox.value = !showCommentBox.value
|
showCommentBox.value = !showCommentBox.value
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({ show: showEmailBox, showComment: showCommentBox, editor: newEmailEditor })
|
defineExpose({
|
||||||
|
show: showEmailBox,
|
||||||
|
showComment: showCommentBox,
|
||||||
|
editor: newEmailEditor,
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user