2021-12-17 22:47:19 +01:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Description WebComponent
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {Et2Widget} from "../Et2Widget/Et2Widget";
|
2022-04-21 00:23:53 +02:00
|
|
|
import {css, html, LitElement, render} from "@lion/core";
|
2021-12-17 22:47:19 +01:00
|
|
|
import {et2_IDetachedDOM} from "../et2_core_interfaces";
|
|
|
|
import {activateLinks} from "../ActivateLinksDirective";
|
|
|
|
|
|
|
|
export class Et2Description extends Et2Widget(LitElement) implements et2_IDetachedDOM
|
|
|
|
{
|
|
|
|
|
|
|
|
protected _value : string = "";
|
|
|
|
|
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
css`
|
|
|
|
:host {
|
2022-04-21 00:23:53 +02:00
|
|
|
white-space: pre-line;
|
2021-12-20 23:15:32 +01:00
|
|
|
}
|
|
|
|
:host a {
|
|
|
|
cursor: pointer;
|
|
|
|
color: #26537c;
|
|
|
|
text-decoration: none;
|
2021-12-17 22:47:19 +01:00
|
|
|
}`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
2021-12-20 23:15:32 +01:00
|
|
|
/**
|
|
|
|
* Scan the value, and if there are any links (URL, mailto:) then wrap them in a clickable
|
|
|
|
* <a/> tag
|
|
|
|
*/
|
|
|
|
activate_links: {
|
|
|
|
type: Boolean,
|
|
|
|
reflect: true
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Extra link target
|
|
|
|
* Goes with href. If provided, that's the target for opening the link.
|
|
|
|
*/
|
|
|
|
extra_link_target: {
|
2021-12-21 19:16:58 +01:00
|
|
|
type: String,
|
|
|
|
reflect: true
|
2021-12-20 23:15:32 +01:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* widthxheight, if popup should be used, eg. 640x480
|
|
|
|
*/
|
|
|
|
extra_link_popup: {
|
2021-12-21 19:16:58 +01:00
|
|
|
type: String,
|
|
|
|
reflect: true
|
2021-12-20 23:15:32 +01:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Link URL
|
|
|
|
* If provided, will be clickable and open this URL
|
|
|
|
*/
|
|
|
|
href: {
|
2021-12-21 19:16:58 +01:00
|
|
|
type: String,
|
|
|
|
reflect: true
|
2021-12-20 23:15:32 +01:00
|
|
|
},
|
2021-12-17 22:47:19 +01:00
|
|
|
value: String,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 23:15:32 +01:00
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
|
|
|
// Initialize properties
|
|
|
|
this.activate_links = false;
|
|
|
|
this.extra_link_popup = "";
|
|
|
|
this.extra_link_target = "_browser";
|
2022-02-03 21:52:14 +01:00
|
|
|
// Don't initialize this to avoid href(unknown) when rendered
|
|
|
|
//this.href = "";
|
2021-12-20 23:15:32 +01:00
|
|
|
this.value = "";
|
2021-12-21 18:52:39 +01:00
|
|
|
|
|
|
|
this._handleClick = this._handleClick.bind(this);
|
2021-12-20 23:15:32 +01:00
|
|
|
}
|
|
|
|
|
2022-04-21 00:23:53 +02:00
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
|
|
|
|
|
|
|
// Put content directly in DOM
|
|
|
|
if(this.value)
|
|
|
|
{
|
|
|
|
render(this._renderContent(), this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-17 22:47:19 +01:00
|
|
|
set_value(value)
|
|
|
|
{
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
get value()
|
|
|
|
{
|
|
|
|
return this._value;
|
|
|
|
}
|
|
|
|
|
|
|
|
set value(_value : string)
|
|
|
|
{
|
|
|
|
let oldValue = this.value;
|
|
|
|
|
|
|
|
if(!_value)
|
|
|
|
{
|
|
|
|
_value = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we do this here, or in transformAttributes()?
|
2021-12-21 18:52:39 +01:00
|
|
|
if(_value && !this.no_lang)
|
2021-12-17 22:47:19 +01:00
|
|
|
{
|
|
|
|
_value = this.egw().lang(_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_value && (_value + "").indexOf('%s') != -1)
|
|
|
|
{
|
|
|
|
_value = _value.replace(/%s/g, _value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._value = _value;
|
|
|
|
this.requestUpdate('value', oldValue);
|
|
|
|
}
|
|
|
|
|
2022-04-21 00:23:53 +02:00
|
|
|
_renderContent()
|
2021-12-17 22:47:19 +01:00
|
|
|
{
|
2021-12-20 23:15:32 +01:00
|
|
|
let render = null;
|
2021-12-17 22:47:19 +01:00
|
|
|
|
|
|
|
// Add hover action button (Edit)
|
|
|
|
if(this.hover_action)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
2021-12-20 23:15:32 +01:00
|
|
|
|
2021-12-17 22:47:19 +01:00
|
|
|
|
|
|
|
// If there's a link, wrap that
|
|
|
|
if(this.href && this._value)
|
|
|
|
{
|
2021-12-20 23:15:32 +01:00
|
|
|
render = this.wrapLink(this.href, this._value);
|
2021-12-17 22:47:19 +01:00
|
|
|
}
|
|
|
|
// If we want to activate links inside, do that
|
2021-12-20 23:15:32 +01:00
|
|
|
else if(this.activate_links && this._value)
|
2021-12-17 22:47:19 +01:00
|
|
|
{
|
2021-12-20 23:15:32 +01:00
|
|
|
render = this.getActivatedValue(this._value, this.href ? this.extra_link_target : '_blank');
|
2021-12-17 22:47:19 +01:00
|
|
|
}
|
|
|
|
// Just do the value
|
|
|
|
else
|
|
|
|
{
|
2021-12-20 23:15:32 +01:00
|
|
|
render = html`${this._value}`;
|
|
|
|
}
|
2022-04-21 00:23:53 +02:00
|
|
|
return render;
|
2021-12-20 23:15:32 +01:00
|
|
|
}
|
|
|
|
|
2022-04-21 00:23:53 +02:00
|
|
|
render()
|
2022-04-13 00:28:36 +02:00
|
|
|
{
|
2022-04-21 00:23:53 +02:00
|
|
|
return html`
|
|
|
|
<slot></slot>`;
|
2022-04-13 00:28:36 +02:00
|
|
|
}
|
|
|
|
|
2022-04-21 00:23:53 +02:00
|
|
|
|
2021-12-20 23:15:32 +01:00
|
|
|
async firstUpdated()
|
|
|
|
{
|
2021-12-21 18:52:39 +01:00
|
|
|
this.removeEventListener('click.extra_link', this._handleClick);
|
2021-12-20 23:15:32 +01:00
|
|
|
if(this.extra_link_popup || this.mime)
|
|
|
|
{
|
|
|
|
// Add click listener
|
2021-12-21 18:52:39 +01:00
|
|
|
this.addEventListener('click.extra_link', this._handleClick);
|
2021-12-20 23:15:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleClick(_ev : MouseEvent) : boolean
|
|
|
|
{
|
2022-02-25 11:33:04 +01:00
|
|
|
// call super to get the onclick handling running
|
|
|
|
super._handleClick(_ev);
|
|
|
|
|
2022-03-23 14:26:16 +01:00
|
|
|
if(this.expose_view && typeof this.mime != 'undefined' && this.mime_regexp && this.mime.match(this.mime_regexp, 'ig'))
|
2021-12-20 23:15:32 +01:00
|
|
|
{
|
|
|
|
this._init_blueimp_gallery(_ev, this.href);
|
|
|
|
}
|
2022-02-03 21:52:14 +01:00
|
|
|
else if(this.mime_data || this.href)
|
2021-12-20 23:15:32 +01:00
|
|
|
{
|
|
|
|
egw(window).open_link(this.mime_data || this.href, this.extra_link_target, this.extra_link_popup, null, null, this.mime);
|
2021-12-17 22:47:19 +01:00
|
|
|
}
|
2021-12-20 23:15:32 +01:00
|
|
|
_ev.preventDefault();
|
|
|
|
return false;
|
2021-12-17 22:47:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected wrapLink(href, value)
|
|
|
|
{
|
|
|
|
if(href.indexOf('/') == -1 && href.split('.').length >= 3 &&
|
|
|
|
!(href.indexOf('mailto:') != -1 || href.indexOf('://') != -1 || href.indexOf('javascript:') != -1)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
href = "/index.php?menuaction=" + href;
|
|
|
|
}
|
|
|
|
if(href.charAt(0) == '/') // link relative to eGW
|
|
|
|
{
|
|
|
|
href = egw.link(href);
|
|
|
|
}
|
|
|
|
return html`<a href="${href}" target="${this.target ?? "_blank"}">${value}</a>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected getActivatedValue(value, target)
|
|
|
|
{
|
|
|
|
return html`${activateLinks(value, target)}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
getDetachedAttributes(attrs)
|
|
|
|
{
|
2021-12-20 23:15:32 +01:00
|
|
|
attrs.push("id", "value", "class", "href");
|
2021-12-17 22:47:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getDetachedNodes() : HTMLElement[]
|
|
|
|
{
|
|
|
|
return [<HTMLElement><unknown>this];
|
|
|
|
}
|
|
|
|
|
|
|
|
setDetachedAttributes(_nodes : HTMLElement[], _values : object, _data? : any) : void
|
|
|
|
{
|
|
|
|
// Do nothing, since we can't actually stop being a DOM node...
|
|
|
|
}
|
|
|
|
|
|
|
|
loadFromXML()
|
|
|
|
{
|
|
|
|
// nope
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-description", Et2Description);
|