From 649645ab0f23ee23e316b6c4ca9e3025b1894560 Mon Sep 17 00:00:00 2001 From: ralf Date: Tue, 11 Apr 2023 15:01:40 +0200 Subject: [PATCH] * Mail: allow placeholders in compose instead of email-addresses to be able to create mail templates --- api/js/etemplate/Et2Select/Et2SelectEmail.ts | 23 ++++++++++++++++++-- api/js/etemplate/Validators/IsEmail.ts | 18 +++++++++++++-- mail/templates/default/compose.xet | 15 +++++++++---- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2SelectEmail.ts b/api/js/etemplate/Et2Select/Et2SelectEmail.ts index b11669bf03..f06e6024d0 100644 --- a/api/js/etemplate/Et2Select/Et2SelectEmail.ts +++ b/api/js/etemplate/Et2Select/Et2SelectEmail.ts @@ -8,9 +8,10 @@ */ import {Et2Select} from "./Et2Select"; -import {css, html, nothing} from "@lion/core"; +import {css, html, nothing, PropertyValues} from "@lion/core"; import {IsEmail} from "../Validators/IsEmail"; import interact from "@interactjs/interact"; +import {Validator} from "@lion/form-core"; /** * Select email address(es) @@ -55,6 +56,11 @@ export class Et2SelectEmail extends Et2Select */ allowDragAndDrop: {type: Boolean}, + /** + * Allow placeholders like {{email}}, beside real email-addresses + */ + allowPlaceholder: {type: Boolean}, + /** * Include mailing lists: returns them with their integer list_id */ @@ -73,12 +79,25 @@ export class Et2SelectEmail extends Et2Select this.search = true; this.searchUrl = "EGroupware\\Api\\Etemplate\\Widget\\Taglist::ajax_email"; this.allowFreeEntries = true; + this.allowPlaceholder = false; this.editModeEnabled = true; this.allowDragAndDrop = false; this.includeLists = false; this.multiple = false; this.fullEmail = false; - this.defaultValidators.push(new IsEmail()); + this.defaultValidators.push(new IsEmail(this.allowPlaceholder)); + } + + /** @param {import('@lion/core').PropertyValues } changedProperties */ + willUpdate(changedProperties : PropertyValues) + { + super.willUpdate(changedProperties); + + if(changedProperties.has('allowPlaceholder')) + { + this.defaultValidators = (>this.defaultValidators).filter(v => !(v instanceof IsEmail)); + this.defaultValidators.push(new IsEmail(this.allowPlaceholder)); + } } connectedCallback() diff --git a/api/js/etemplate/Validators/IsEmail.ts b/api/js/etemplate/Validators/IsEmail.ts index 7a174c550b..df91e9d743 100644 --- a/api/js/etemplate/Validators/IsEmail.ts +++ b/api/js/etemplate/Validators/IsEmail.ts @@ -27,9 +27,23 @@ export class IsEmail extends Pattern */ static EMAIL_PREG : RegExp = /^(([^\042',<][^,<]+|\042[^\042]+\042|\'[^\']+\'|"(?:[^"\\]|\\.)*")\s?<)?[^\x00-\x20()\xe2\x80\x8b<>@,;:\042\[\]\x80-\xff]+@([a-z0-9ÄÖÜäöüß](|[a-z0-9ÄÖÜäöüß_-]*[a-z0-9ÄÖÜäöüß])\.)+[a-z]{2,}>?$/i; - constructor() + /** + * Allow everything containing at least one placeholder e.g.: + * - "{{email}}" + * - "{{n_fn}} <{{email}}" + * - "{{#}}" + * - we do NOT check if the placeholder is implemented by addressbook or a valid custom-field name! + * - "test" or "{test}}" are NOT valid + */ + static EMAIL_PLACEHOLDER_PREG = new RegExp('^(.*{{#?[a-z0-9_]+}}.*|'+IsEmail.EMAIL_PREG.source.substr(1, IsEmail.EMAIL_PREG.source.length-2)+')$', 'i'); + + /** + * + * @param _allowPlaceholders true: allow valid email-addresses OR something with placeholder(s) + */ + constructor(_allowPlaceholders: boolean) { - super(IsEmail.EMAIL_PREG); + super(_allowPlaceholders ? IsEmail.EMAIL_PLACEHOLDER_PREG : IsEmail.EMAIL_PREG); } /** diff --git a/mail/templates/default/compose.xet b/mail/templates/default/compose.xet index 856e7e2474..7399f60021 100644 --- a/mail/templates/default/compose.xet +++ b/mail/templates/default/compose.xet @@ -46,7 +46,8 @@ - + @@ -56,7 +57,9 @@ - + @@ -64,12 +67,16 @@ - + - +