2021-12-17 18:06:37 +01:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Readonly date WebComponent
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-09-13 19:55:33 +02:00
|
|
|
import {html, LitElement} from "lit";
|
2021-12-17 18:06:37 +01:00
|
|
|
import {formatDate, parseDate} from "./Et2Date";
|
|
|
|
import {et2_IDetachedDOM} from "../et2_core_interfaces";
|
|
|
|
import {Et2Widget} from "../Et2Widget/Et2Widget";
|
|
|
|
import {dateStyles} from "./DateStyles";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a stripped-down read-only widget used in nextmatch
|
|
|
|
*/
|
|
|
|
export class Et2DateReadonly extends Et2Widget(LitElement) implements et2_IDetachedDOM
|
|
|
|
{
|
|
|
|
protected parser : Function;
|
|
|
|
protected formatter : Function;
|
|
|
|
|
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
dateStyles
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
value: String,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.parser = parseDate;
|
|
|
|
this.formatter = formatDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_value(value)
|
|
|
|
{
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
render()
|
|
|
|
{
|
2024-07-27 13:20:24 +02:00
|
|
|
let parsed : Date | Boolean = this.value ? this.parser(this.value, this.dataFormat) : false
|
2021-12-17 18:06:37 +01:00
|
|
|
|
|
|
|
return html`
|
2022-06-24 22:08:06 +02:00
|
|
|
<span slot="label">${this.label}</span>
|
2021-12-17 18:06:37 +01:00
|
|
|
<time ${this.id ? html`id="${this._dom_id}"` : ''}
|
|
|
|
datetime="${parsed ? this.formatter(<Date>parsed, {dateFormat: "Y-m-d", timeFormat: "H:i:s"}) : ""}">
|
|
|
|
${this.value ? this.formatter(<Date>parsed) : ''}
|
|
|
|
</time>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
getDetachedAttributes(attrs)
|
|
|
|
{
|
2023-04-25 21:53:16 +02:00
|
|
|
attrs.push("id", "value", "class", "statustext");
|
2021-12-17 18:06:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getDetachedNodes() : HTMLElement[]
|
|
|
|
{
|
|
|
|
return [<HTMLElement><unknown>this];
|
|
|
|
}
|
|
|
|
|
|
|
|
setDetachedAttributes(_nodes : HTMLElement[], _values : object, _data? : any) : void
|
|
|
|
{
|
2022-05-03 19:01:42 +02:00
|
|
|
for(let attr in _values)
|
|
|
|
{
|
|
|
|
this[attr] = _values[attr];
|
|
|
|
}
|
2021-12-17 18:06:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
loadFromXML()
|
|
|
|
{
|
|
|
|
// nope
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-date_ro", Et2DateReadonly);
|