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
|
|
|
|
*
|
2024-01-22 16:11:53 +01:00
|
|
|
* - email: "test@example.com" (default)
|
2024-01-16 23:29:12 +01:00
|
|
|
* - full: "Mr Test User <test@example.com>
|
|
|
|
* - name: "Mr Test User"
|
|
|
|
* - domain: "Mr Test User (example.com)"
|
2024-01-22 16:11:53 +01:00
|
|
|
* - preference: use the users preference, like et2-email does
|
2024-01-16 23:29:12 +01:00
|
|
|
*
|
|
|
|
* If name is unknown, we'll use the email instead.
|
|
|
|
*/
|
|
|
|
@property({type: String})
|
2024-01-22 16:11:53 +01:00
|
|
|
emailDisplay : "email" | "full" | "name" | "domain" | "preference";
|
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);
|
2024-07-27 12:52:14 +02:00
|
|
|
super.statustext = !egwIsMobile() && split.name ? split.email : "";
|
2024-01-22 16:11:53 +01:00
|
|
|
formatEmailAddress(val, !this.emailDisplay ? "email" :
|
|
|
|
(this.emailDisplay === 'preference' ? null : 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 = () =>
|
|
|
|
{
|
2024-01-22 21:11:42 +01:00
|
|
|
let email=this._value;
|
|
|
|
if (!IsEmail.EMAIL_PREG.exec(email))
|
|
|
|
{
|
|
|
|
let name = this._value;
|
|
|
|
// do we need to remove the domain in brackets again?
|
|
|
|
if ((this.emailDisplay === 'preference' ? window.egw.preference("emailTag", "mail") : this.emailDisplay) === 'domain')
|
|
|
|
{
|
|
|
|
name = this._value.replace(/ \([^@. ]+\.[^@ )]+\)$/, '');
|
|
|
|
}
|
|
|
|
email = '"' + name + '" <' + this.statustext + '>'
|
|
|
|
}
|
|
|
|
if (IsEmail.EMAIL_PREG.exec(email))
|
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);
|