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";
|
2023-06-22 14:37:15 +02:00
|
|
|
import {Et2EmailTag} from "../Et2Select/Tag/Et2EmailTag";
|
2022-03-10 09:15:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @customElement et2-url-email_ro
|
|
|
|
*/
|
|
|
|
export class Et2UrlEmailReadonly extends Et2UrlReadonly
|
|
|
|
{
|
2022-03-15 13:39:42 +01:00
|
|
|
/** @type {any} */
|
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
/**
|
|
|
|
* Show full email address if true otherwise show only name and put full address as statustext/tooltip
|
|
|
|
*/
|
2022-07-21 17:57:50 +02:00
|
|
|
fullEmail: {
|
2022-03-15 13:39:42 +01:00
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Show icon to add email as contact to addressbook
|
|
|
|
* @ToDo
|
|
|
|
*/
|
2022-07-21 17:57:50 +02:00
|
|
|
contactPlus: {
|
2022-03-15 13:39:42 +01:00
|
|
|
type: Boolean,
|
|
|
|
},
|
2023-06-22 14:37:15 +02:00
|
|
|
/**
|
|
|
|
* set to true to always show just the email
|
|
|
|
* Mutually exclusive with fullEmail!
|
|
|
|
*/
|
|
|
|
onlyEmail: {
|
|
|
|
type: Boolean
|
|
|
|
}
|
2022-03-15 13:39:42 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
set value(val : string)
|
|
|
|
{
|
|
|
|
this._value = val;
|
|
|
|
// check if we have a "name <email>" value and only show name
|
2022-07-21 17:57:50 +02:00
|
|
|
if (!this.fullEmail && val && val.indexOf('<') !== -1)
|
2022-03-15 13:39:42 +01:00
|
|
|
{
|
|
|
|
const parts = val.split('<');
|
2023-06-22 14:37:15 +02:00
|
|
|
if (parts[0] && !this.onlyEmail)
|
2022-03-15 13:39:42 +01:00
|
|
|
{
|
|
|
|
super.statustext = parts[1].substring(0, parts[1].length-1);
|
|
|
|
val = parts[0].trim();
|
|
|
|
// remove quotes
|
|
|
|
if ((val[0] === '"' || val[0] === "'" ) && val[0] === val.substr(-1))
|
|
|
|
{
|
|
|
|
val = val.substring(1, val.length-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // <email> --> email
|
|
|
|
{
|
|
|
|
super.statustext = '';
|
|
|
|
val = parts[1].substring(0, val.length-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
super.statustext = '';
|
|
|
|
}
|
|
|
|
super.value = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) ||
|
|
|
|
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);
|