2022-03-10 09:15:59 +01:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Email url/compose widget
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Ralf Becker
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
|
|
import {IsEmail} from "../Validators/IsEmail";
|
|
|
|
import {Et2UrlEmail} from "./Et2UrlEmail";
|
|
|
|
import {Et2UrlReadonly} from "./Et2UrlReadonly";
|
2024-01-16 23:29:12 +01:00
|
|
|
import {property} from "lit/decorators/property.js";
|
|
|
|
import {formatEmailAddress, splitEmail} from "../Et2Email/utils";
|
2022-03-10 09:15:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @customElement et2-url-email_ro
|
|
|
|
*/
|
|
|
|
export class Et2UrlEmailReadonly extends Et2UrlReadonly
|
|
|
|
{
|
2024-01-16 23:29:12 +01:00
|
|
|
/**
|
|
|
|
* What to display for the selected email addresses
|
|
|
|
*
|
|
|
|
* - full: "Mr Test User <test@example.com>
|
|
|
|
* - name: "Mr Test User"
|
|
|
|
* - domain: "Mr Test User (example.com)"
|
|
|
|
* - email: "test@example.com"
|
|
|
|
*
|
|
|
|
* If name is unknown, we'll use the email instead.
|
|
|
|
*/
|
|
|
|
@property({type: String})
|
|
|
|
emailDisplay : "full" | "email" | "name" | "domain";
|
2022-03-15 13:39:42 +01:00
|
|
|
|
|
|
|
set value(val : string)
|
|
|
|
{
|
|
|
|
this._value = val;
|
2024-01-16 23:29:12 +01:00
|
|
|
const split = splitEmail(this._value);
|
|
|
|
super.statustext = split.name ? split.email : "";
|
|
|
|
formatEmailAddress(val, this.emailDisplay).then((value) => super.value = value);
|
2022-03-15 13:39:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get value()
|
|
|
|
{
|
|
|
|
return super.value;
|
|
|
|
}
|
|
|
|
|
2022-03-10 09:15:59 +01:00
|
|
|
transformAttributes(attrs)
|
|
|
|
{
|
|
|
|
if (typeof attrs.onclick === 'undefined')
|
|
|
|
{
|
|
|
|
attrs.onclick = () =>
|
|
|
|
{
|
2022-03-15 13:39:42 +01:00
|
|
|
let email;
|
|
|
|
if (IsEmail.EMAIL_PREG.exec(email=this.value) ||
|
2023-08-04 00:57:53 +02:00
|
|
|
IsEmail.EMAIL_PREG.exec(email = '"' + this.value + '" <' + this.statustext + '>'))
|
2022-03-10 09:15:59 +01:00
|
|
|
{
|
2022-03-15 13:39:42 +01:00
|
|
|
Et2UrlEmail.action(email);
|
2022-03-10 09:15:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.transformAttributes(attrs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this is a LitElement
|
|
|
|
customElements.define("et2-url-email_ro", Et2UrlEmailReadonly);
|