From a4109439e162ccc513c356e810f36b7bcfaff596 Mon Sep 17 00:00:00 2001 From: hadi Date: Thu, 22 Jun 2023 14:37:15 +0200 Subject: [PATCH] Implement onlyEmail option for UrlEmailReadonly --- api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts | 8 ++++---- api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts b/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts index e16ad92cb5..982802a1a8 100644 --- a/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts +++ b/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts @@ -195,16 +195,16 @@ export class Et2EmailTag extends Et2Tag if(!this.onlyEmail && Et2EmailTag.email_cache[this.value]) { // Append current value as email, data may have work & home email in it - content = (Et2EmailTag.email_cache[this.value]?.n_fn || "") + " <" + (this.splitEmail(this.value)?.email || this.value) + ">" + content = (Et2EmailTag.email_cache[this.value]?.n_fn || "") + " <" + (Et2EmailTag.splitEmail(this.value)?.email || this.value) + ">" } if (this.onlyEmail) { - const split = this.splitEmail(content); + const split = Et2EmailTag.splitEmail(content); content = split.email || this.value; } else if(!this.fullEmail) { - const split = this.splitEmail(content); + const split = Et2EmailTag.splitEmail(content); content = split.name || split.email; } return html` @@ -264,7 +264,7 @@ export class Et2EmailTag extends Et2Tag * * @return {name:string, email:string} */ - public splitEmail(email_string) : { name : string, email : string } + public static splitEmail(email_string) : { name : string, email : string } { let split = {name: "", email: email_string}; if(email_string && email_string.indexOf('<') !== -1) diff --git a/api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts b/api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts index b154ca2edf..15fead0065 100644 --- a/api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts +++ b/api/js/etemplate/Et2Url/Et2UrlEmailReadonly.ts @@ -11,6 +11,7 @@ import {IsEmail} from "../Validators/IsEmail"; import {Et2UrlEmail} from "./Et2UrlEmail"; import {Et2UrlReadonly} from "./Et2UrlReadonly"; +import {Et2EmailTag} from "../Et2Select/Tag/Et2EmailTag"; /** * @customElement et2-url-email_ro @@ -35,6 +36,13 @@ export class Et2UrlEmailReadonly extends Et2UrlReadonly contactPlus: { type: Boolean, }, + /** + * set to true to always show just the email + * Mutually exclusive with fullEmail! + */ + onlyEmail: { + type: Boolean + } }; } @@ -45,7 +53,7 @@ export class Et2UrlEmailReadonly extends Et2UrlReadonly if (!this.fullEmail && val && val.indexOf('<') !== -1) { const parts = val.split('<'); - if (parts[0]) + if (parts[0] && !this.onlyEmail) { super.statustext = parts[1].substring(0, parts[1].length-1); val = parts[0].trim();