Skip to content
Snippets Groups Projects
ngparam-step.component.ts 2.06 KiB
Newer Older
import { Component, Input } from "@angular/core";
import { NumericalString } from "jalhyd";

import { GenericInputComponent } from "../generic-input/generic-input.component";
import { InternationalisationService } from "../../services/internationalisation/internationalisation.service";
import { NgParameter } from "../../formulaire/ngparam";

@Component({
    selector: "ngparam-step",
    templateUrl: "../generic-input/generic-input.component.html"
})
export class NgParamStepComponent extends GenericInputComponent {
    constructor(private intlService: InternationalisationService) {
        super();
    }

    /**
     * paramètre géré
     */
    private get _param(): NgParameter {
        return this._model;
    }

        return this._param.stepValue;
        this._param.stepValue = v;
    }

    protected validateModelValue(v: any): { isValid: boolean, message: string } {
        let msg = undefined;
        let valid = false;

        if (this._param.isMinMaxValid) {
            if (!this._param.checkStep(v)) {
                msg = "La valeur n'est pas dans " + this._param.stepRefValue.toString();
            }
            else {
                valid = v > 0;
                if (!valid)
                    msg = "La valeur ne peut pas être <= 0";
            }
        else
            msg = "Veuillez corriger le min/max";

        return { isValid: valid, message: msg };
    }

    protected modelToUI(v: any): string {
        if (typeof (v) == "number")
            return String(v);
        return "<invalid>";
    }

    protected validateUIValue(ui: string): { isValid: boolean, message: string } {
        let valid: boolean = false;
        let msg: string = undefined;

        let v: NumericalString = new NumericalString(ui);
        if (!v.isNumerical)
            msg = "Veuillez entrer une valeur numérique";
        else
            valid = true;

        return { isValid: valid, message: msg };
    }

    protected uiToModel(ui: string) {
        return +ui;
    }
}