2022-01-21 21:45:12 +01:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Readonly duration 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 {css, html} from "lit";
|
2022-01-21 21:45:12 +01:00
|
|
|
import {Et2DateDuration, formatOptions} from "./Et2DateDuration";
|
2022-02-17 00:44:57 +01:00
|
|
|
import {dateStyles} from "./DateStyles";
|
2022-01-21 21:45:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a stripped-down read-only widget used in nextmatch
|
|
|
|
*/
|
|
|
|
export class Et2DateDurationReadonly extends Et2DateDuration
|
|
|
|
{
|
2022-02-17 00:44:57 +01:00
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
...dateStyles,
|
|
|
|
css`
|
|
|
|
:host {
|
|
|
|
border: none;
|
|
|
|
min-width: 2em;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:16:28 +01:00
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
|
|
|
// Property defaults
|
2022-07-21 17:57:50 +02:00
|
|
|
this.selectUnit = false; // otherwise just best matching unit will be used for eg. display_format "h:m:s"
|
2022-02-25 09:16:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-17 00:44:57 +01:00
|
|
|
get value()
|
|
|
|
{
|
|
|
|
return this.__value;
|
|
|
|
}
|
|
|
|
|
|
|
|
set value(_value)
|
|
|
|
{
|
2023-04-12 01:09:36 +02:00
|
|
|
const old_value = this.__value;
|
2022-02-17 00:44:57 +01:00
|
|
|
this.__value = _value;
|
2023-04-12 01:09:36 +02:00
|
|
|
this.requestUpdate("value", old_value);
|
2022-02-17 00:44:57 +01:00
|
|
|
}
|
|
|
|
|
2022-01-21 21:45:12 +01:00
|
|
|
render()
|
|
|
|
{
|
2022-02-17 00:44:57 +01:00
|
|
|
let parsed = this.__value;
|
2022-01-21 21:45:12 +01:00
|
|
|
|
|
|
|
const format_options = <formatOptions>{
|
2022-07-21 17:57:50 +02:00
|
|
|
selectUnit: this.selectUnit,
|
|
|
|
displayFormat: this.displayFormat,
|
|
|
|
dataFormat: this.dataFormat,
|
|
|
|
numberFormat: this.egw().preference("number_format"),
|
|
|
|
hoursPerDay: this.hoursPerDay,
|
|
|
|
emptyNot0: this.emptyNot0
|
2022-01-21 21:45:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const display = this.formatter(parsed, format_options);
|
|
|
|
return html`
|
|
|
|
<span ${this.id ? html`id="${this._dom_id}"` : ''}>
|
|
|
|
${display.value}${display.unit}
|
|
|
|
</span>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2022-03-09 18:17:59 +01:00
|
|
|
/**
|
|
|
|
* These are the attributes we allow to change for each row
|
|
|
|
*
|
|
|
|
* @param attrs
|
|
|
|
*/
|
2022-01-21 21:45:12 +01:00
|
|
|
getDetachedAttributes(attrs)
|
|
|
|
{
|
2022-03-09 18:17:59 +01:00
|
|
|
attrs.push("id", "value", "class", "disabled");
|
2022-01-21 21:45:12 +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];
|
|
|
|
}
|
2022-01-21 21:45:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-date-duration_ro", Et2DateDurationReadonly);
|