From b492ed5c15da715dc27bb2b287d0f9887f1b61d2 Mon Sep 17 00:00:00 2001 From: ralf Date: Mon, 22 Jan 2024 17:11:53 +0200 Subject: [PATCH] use "email" as default for emailDisplay attribute in et2-url-email (like before) add new attribute value "preference" to use the user preference (like et2-email does) --- api/js/etemplate/Et2Email/utils.ts | 2 +- api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/api/js/etemplate/Et2Email/utils.ts b/api/js/etemplate/Et2Email/utils.ts index 3b8bc46c51..effaf22f01 100644 --- a/api/js/etemplate/Et2Email/utils.ts +++ b/api/js/etemplate/Et2Email/utils.ts @@ -138,7 +138,7 @@ export async function formatEmailAddress(address : string, emailDisplayFormat? : const split = splitEmail(address); let content = address; let contact; - if(!split.name && (contact = await checkContact(address))) + if(emailDisplayFormat !== 'email' && !split.name && (contact = await checkContact(address))) { split.name = contact.n_fn; } diff --git a/api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts b/api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts index 1738ad6f6e..cda3a1bc4e 100644 --- a/api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts +++ b/api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts @@ -22,22 +22,25 @@ export class Et2UrlEmailReadonly extends Et2UrlReadonly /** * What to display for the selected email addresses * + * - email: "test@example.com" (default) * - full: "Mr Test User * - name: "Mr Test User" * - domain: "Mr Test User (example.com)" - * - email: "test@example.com" + * - preference: use the users preference, like et2-email does * * If name is unknown, we'll use the email instead. */ @property({type: String}) - emailDisplay : "full" | "email" | "name" | "domain"; + emailDisplay : "email" | "full" | "name" | "domain" | "preference"; set value(val : string) { this._value = val; const split = splitEmail(this._value); super.statustext = split.name ? split.email : ""; - formatEmailAddress(val, this.emailDisplay).then((value) => super.value = value); + formatEmailAddress(val, !this.emailDisplay ? "email" : + (this.emailDisplay === 'preference' ? null : this.emailDisplay)).then( + (value) => super.value = value); } get value() @@ -52,8 +55,8 @@ export class Et2UrlEmailReadonly extends Et2UrlReadonly attrs.onclick = () => { let email; - if (IsEmail.EMAIL_PREG.exec(email=this.value) || - IsEmail.EMAIL_PREG.exec(email = '"' + this.value + '" <' + this.statustext + '>')) + if (IsEmail.EMAIL_PREG.exec(email=this._value) || + IsEmail.EMAIL_PREG.exec(email = '"' + this._value + '" <' + this.statustext + '>')) { Et2UrlEmail.action(email); }