2022-03-08 19:19:33 +01:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Phone input 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 {Et2InvokerMixin} from "./Et2InvokerMixin";
|
|
|
|
import {Et2Textbox} from "../Et2Textbox/Et2Textbox";
|
2022-03-10 17:13:43 +01:00
|
|
|
import {colorsDefStyles} from "../Styles/colorsDefStyles";
|
|
|
|
import {css} from "@lion/core";
|
2022-03-08 19:19:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @customElement et2-url-phone
|
|
|
|
*/
|
|
|
|
export class Et2UrlPhone extends Et2InvokerMixin(Et2Textbox)
|
|
|
|
{
|
2022-03-10 17:13:43 +01:00
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
colorsDefStyles,
|
|
|
|
css`
|
|
|
|
::slotted([slot="suffix"]) {
|
|
|
|
font-size: 133% !important;
|
2022-07-22 15:21:27 +02:00
|
|
|
height: auto;
|
2022-03-10 17:13:43 +01:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-07-22 20:43:09 +02:00
|
|
|
constructor(...args : any[])
|
2022-03-08 19:19:33 +01:00
|
|
|
{
|
2022-07-22 20:43:09 +02:00
|
|
|
super(...args);
|
|
|
|
|
2022-03-08 19:19:33 +01:00
|
|
|
//this.defaultValidators.push(...);
|
|
|
|
this._invokerLabel = '✆';
|
|
|
|
this._invokerTitle = 'Call';
|
2022-03-10 09:15:59 +01:00
|
|
|
this._invokerAction = () => {
|
|
|
|
Et2UrlPhone.action(this.value);
|
|
|
|
}
|
2022-03-08 19:19:33 +01:00
|
|
|
}
|
|
|
|
|
2022-03-10 09:15:59 +01:00
|
|
|
static action(value)
|
2022-03-08 19:19:33 +01:00
|
|
|
{
|
|
|
|
// Clean number
|
|
|
|
value = value.replace('♥','').replace('(0)','');
|
|
|
|
value = value.replace(/[abc]/gi,2).replace(/[def]/gi,3).replace(/[ghi]/gi,4).replace(/[jkl]/gi,5).replace(/[mno]/gi,6);
|
|
|
|
value = value.replace(/[pqrs]/gi,7).replace(/[tuv]/gi,8).replace(/[wxyz]/gi,9);
|
|
|
|
// remove everything but numbers and plus, as telephon software might not like it
|
|
|
|
value = value.replace(/[^0-9+]/g, '');
|
|
|
|
|
2022-03-18 08:53:09 +01:00
|
|
|
if (!value) return; // don't try to dial an empty number
|
|
|
|
|
2022-03-08 19:19:33 +01:00
|
|
|
// mobile Webkit (iPhone, Android) have precedence over server configuration!
|
|
|
|
if (navigator.userAgent.indexOf('AppleWebKit') !== -1 &&
|
|
|
|
(navigator.userAgent.indexOf("iPhone") !== -1 || navigator.userAgent.indexOf("Android") !== -1))
|
|
|
|
{
|
|
|
|
window.open("tel:"+value);
|
|
|
|
}
|
2022-03-10 09:15:59 +01:00
|
|
|
else if (egw.config("call_link"))
|
2022-03-08 19:19:33 +01:00
|
|
|
{
|
2022-03-10 09:15:59 +01:00
|
|
|
var link = egw.config("call_link")
|
2022-03-08 19:19:33 +01:00
|
|
|
// tel: links use no URL encoding according to rfc3966 section-5.1.4
|
2022-03-10 09:15:59 +01:00
|
|
|
.replace("%1", egw.config("call_link").substr(0, 4) == 'tel:' ?
|
2022-03-08 19:19:33 +01:00
|
|
|
value : encodeURIComponent(value))
|
2022-03-10 09:15:59 +01:00
|
|
|
.replace("%u",egw.user('account_lid'))
|
|
|
|
.replace("%t",egw.user('account_phone'));
|
|
|
|
var popup = egw.config("call_popup");
|
2022-03-08 19:19:33 +01:00
|
|
|
if (popup && popup !== '_self' || !link.match(/^https?:/)) // execute non-http(s) links eg. tel: like before
|
|
|
|
{
|
|
|
|
egw.open_link(link, '_phonecall', popup);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No popup, use AJAX. We don't care about the response.
|
|
|
|
window.fetch(link, {
|
|
|
|
headers: { 'Content-Type': 'application/json'},
|
|
|
|
method: "GET",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this is a LitElement
|
|
|
|
customElements.define("et2-url-phone", Et2UrlPhone);
|