diff --git a/src/app/components/base-param-input/base-param-input.component.ts b/src/app/components/base-param-input/base-param-input.component.ts index 001a186d784d62138e45772d9570d56c08e56a0b..9b69dd05e391011096aaf618e79b1b2960769130 100644 --- a/src/app/components/base-param-input/base-param-input.component.ts +++ b/src/app/components/base-param-input/base-param-input.component.ts @@ -92,8 +92,8 @@ export class NgBaseParam extends Observable { templateUrl: "../generic-input/generic-input.component.html", }) export class BaseParamInputComponent extends GenericInputComponent { - constructor(private intlService: I18nService, cdRef: ChangeDetectorRef) { - super(cdRef); + constructor(intlService: I18nService, cdRef: ChangeDetectorRef) { + super(cdRef, intlService); } /** diff --git a/src/app/components/generic-calculator/calc-name.component.ts b/src/app/components/generic-calculator/calc-name.component.ts index 3de415d2ee7fd03474c43fe0ffd7768fdc644a7e..309526b7770694a0e3cf4cd778c6a53937d7b96e 100644 --- a/src/app/components/generic-calculator/calc-name.component.ts +++ b/src/app/components/generic-calculator/calc-name.component.ts @@ -1,6 +1,7 @@ -import { Component, Input } from "@angular/core"; +import { Component } from "@angular/core"; import { GenericInputComponent } from "../generic-input/generic-input.component"; import { FormulaireDefinition } from "../../formulaire/definition/form-definition"; +import { I18nService } from "../../services/internationalisation/internationalisation.service"; @Component({ selector: "calc-name", @@ -11,8 +12,8 @@ import { FormulaireDefinition } from "../../formulaire/definition/form-definitio }) export class CalculatorNameComponent extends GenericInputComponent { - constructor() { - super(null); + constructor(intlService: I18nService) { + super(null, intlService); } /** @@ -39,41 +40,27 @@ export class CalculatorNameComponent extends GenericInputComponent { this.updateAndValidateUI(); } - /** - * valide une valeur de modèle : est ce une valeur acceptable ? (par ex, nombre dans un intervalle, valeur dans une liste, ...) - * @param v valide la valeur du modèle - * @returns isValid : true si la valeur est valide, false sinon - * @returns message : message d'erreur - */ protected validateModelValue(v: any): { isValid: boolean, message: string } { - let msg; - let valid = false; - - if (!(typeof (v) === "string") || v.length < 1) { - msg = "Veuillez entrer un nom"; - } else { - valid = true; - } - - return { isValid: valid, message: msg }; + // no model validation for a simple string + return { isValid: true, message: undefined }; } - /** - * valide une valeur saisie dans l'UI (forme de la saisie : est ce bien une date, un nombre, ...) - * @param ui valide la valeur saisie - * @returns isValid : true si la valeur est valide, false sinon - * @returns message : message d'erreur - */ protected validateUIValue(ui: string): { isValid: boolean, message: string } { let valid = false; let msg: string; if (ui === undefined || ui.length < 1) { - msg = "Veuillez entrer un nom"; + msg = "Veuillez entrer un nom tralala"; } else { valid = true; } return { isValid: valid, message: msg }; } + + public updateModelFromUI() { + if (this.validateUI()) { + this.setAndValidateModel(this, this.uiValue); // do NOT cast UI value to Number + } + } } diff --git a/src/app/components/generic-input/generic-input.component.ts b/src/app/components/generic-input/generic-input.component.ts index 213dfeeaa18e9e6579f6820fd9ab6968d9c082c3..1bac270188ab49a87be7951a421abad277d45947 100644 --- a/src/app/components/generic-input/generic-input.component.ts +++ b/src/app/components/generic-input/generic-input.component.ts @@ -4,6 +4,7 @@ import { BaseComponent } from "../base/base.component"; import { isNumeric } from "jalhyd"; import { FormulaireDefinition } from "../../formulaire/definition/form-definition"; import { NgParameter } from "../../formulaire/ngparam"; +import { I18nService } from "../../services/internationalisation/internationalisation.service"; /** * classe de gestion générique d'un champ de saisie avec titre, validation et message d'erreur @@ -88,7 +89,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC @ViewChild("inputControl") inputField: NgModel; - constructor(private cdRef: ChangeDetectorRef) { + constructor(private cdRef: ChangeDetectorRef, protected intlService: I18nService) { super(); } @@ -129,7 +130,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC } } - private validateUI() { + protected validateUI() { const { isValid, message } = this.validateUIValue(this._uiValue); this._errorMessageUI = message; this.detectChanges(); @@ -185,7 +186,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC this.change.emit({ "action": "model", "value": this.getModelValue() }); } - private setAndValidateModel(sender: any, v: any) { + protected setAndValidateModel(sender: any, v: any) { this.setModelValue(sender, v); this.emitModelChanged(); @@ -281,7 +282,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC let msg: string; if (! isNumeric(ui)) { - msg = "Veuillez entrer une valeur numérique"; + msg = this.intlService.localizeText("ERROR_PARAM_MUST_BE_A_NUMBER"); } else { valid = true; } diff --git a/src/app/components/ngparam-input/ngparam-input.component.ts b/src/app/components/ngparam-input/ngparam-input.component.ts index 7e1af55cead345ce13871671d3174e359cfbc07f..2717729d82fb4eb87e2ba8d810d656c9da122167 100644 --- a/src/app/components/ngparam-input/ngparam-input.component.ts +++ b/src/app/components/ngparam-input/ngparam-input.component.ts @@ -29,8 +29,8 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse */ private _tmp: number; - constructor(private intlService: I18nService, cdRef: ChangeDetectorRef) { - super(cdRef); + constructor(intlService: I18nService, cdRef: ChangeDetectorRef) { + super(cdRef, intlService); } /**