egroupware_official/api/js/etemplate/Et2Textbox/Et2NumberReadonly.ts

57 lines
1.3 KiB
TypeScript
Raw Normal View History

/**
* EGroupware eTemplate2 - Number widget (WebComponent)
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link https://www.egroupware.org
* @author Ralf Becker
*/
import {Et2TextboxReadonly} from "./Et2TextboxReadonly";
import {formatNumber} from "./Et2Number";
2024-08-07 23:15:58 +02:00
import {property} from "lit/decorators/property.js";
import {css} from "lit";
export class Et2NumberReadonly extends Et2TextboxReadonly
{
2024-08-07 23:15:58 +02:00
static get styles()
{
2024-08-07 23:15:58 +02:00
return [
...(super.styles ? (Array.isArray(super.styles) ? super.styles : [super.styles]) : []),
css`
::slotted(*) {
flex: 1 1 auto;
text-align: right;
padding-right: var(--sl-spacing-small);
}
`,
];
}
2024-08-07 23:15:58 +02:00
/**
* Precision of float number or 0 for integer
*/
@property({type: Number})
precision;
set_value(val)
{
if(val === null)
{
val = "";
}
else if("" + val !== "")
{
// use decimal separator from user prefs
const format = this.egw().preference('number_format') ?? ".";
val = formatNumber(parseFloat(val), format[0], format[1], this.precision);
}
// can not call super.set_value(), as it does not call the setter for value
super.value = val;
}
}
// @ts-ignore TypeScript is not recognizing that Et2Textbox is a LitElement
customElements.define("et2-number_ro", Et2NumberReadonly);