2022-03-06 19:14:53 +01:00
|
|
|
/**
|
|
|
|
* 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";
|
2024-08-03 00:24:52 +02:00
|
|
|
import {formatNumber} from "./Et2Number";
|
2024-08-07 23:15:58 +02:00
|
|
|
import {property} from "lit/decorators/property.js";
|
|
|
|
import {css} from "lit";
|
2022-03-06 19:14:53 +01:00
|
|
|
|
|
|
|
export class Et2NumberReadonly extends Et2TextboxReadonly
|
|
|
|
{
|
2024-08-07 23:15:58 +02:00
|
|
|
static get styles()
|
2022-03-06 19:14:53 +01:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
];
|
2022-03-06 19:14:53 +01:00
|
|
|
}
|
|
|
|
|
2024-08-07 23:15:58 +02:00
|
|
|
/**
|
|
|
|
* Precision of float number or 0 for integer
|
|
|
|
*/
|
|
|
|
@property({type: Number})
|
|
|
|
precision;
|
|
|
|
|
2022-03-06 19:14:53 +01:00
|
|
|
set_value(val)
|
|
|
|
{
|
2023-04-12 01:08:18 +02:00
|
|
|
if(val === null)
|
2022-03-06 19:14:53 +01:00
|
|
|
{
|
2023-04-12 01:08:18 +02:00
|
|
|
val = "";
|
|
|
|
}
|
|
|
|
else if("" + val !== "")
|
|
|
|
{
|
2024-08-03 00:24:52 +02:00
|
|
|
// use decimal separator from user prefs
|
|
|
|
const format = this.egw().preference('number_format') ?? ".";
|
2024-08-07 00:09:18 +02:00
|
|
|
val = formatNumber(parseFloat(val), format[0], format[1], this.precision);
|
2022-03-06 19:14:53 +01:00
|
|
|
}
|
2024-08-03 00:24:52 +02:00
|
|
|
|
2022-03-06 19:14:53 +01:00
|
|
|
// 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);
|