diff --git a/src/app/formulaire/elements/select/select-entry.ts b/src/app/formulaire/elements/select/select-entry.ts index cb4082fa3596be1db9fee16e080b987defcb7388..753e94108c8249b2d59a290a98786c160b49c20f 100644 --- a/src/app/formulaire/elements/select/select-entry.ts +++ b/src/app/formulaire/elements/select/select-entry.ts @@ -12,12 +12,17 @@ export class SelectEntry { /** * texte affiché pour cette entrée */ - public label: string; + private _label: string; + + /** + * informations (code, symbole, ...) de traduction + */ + private _intlInfo: any; constructor(id: string, val: any, lbl?: string) { this._id = id; this._value = val; - this.label = lbl; // redéfini par SelectField.updateLocalisation() plus tard + this._label = lbl; } get id(): string { @@ -27,4 +32,20 @@ export class SelectEntry { get value(): any { return this._value; } + + get label(): string { + return this._label; + } + + set label(l: string) { + this._label = l; + } + + public get intlInfo(): any { + return this._intlInfo; + } + + public set intlInfo(i: any) { + this._intlInfo = i; + } } diff --git a/src/app/formulaire/elements/select/select-field-downstream-basin.ts b/src/app/formulaire/elements/select/select-field-downstream-basin.ts index 05675917d12907d7dbd408e7a72dcd3062b5e1d5..dd39ce85724ea830962b6abfa61d7564db7c72a5 100644 --- a/src/app/formulaire/elements/select/select-field-downstream-basin.ts +++ b/src/app/formulaire/elements/select/select-field-downstream-basin.ts @@ -7,7 +7,7 @@ import { SelectField } from "./select-field"; "id": "select_downstream_basin", "type": "select_custom", "source": "downstream_basin" -*/ +*/ // PbCloisons, bassin aval export class SelectFieldDownstreamBasin extends SelectField { @@ -19,27 +19,30 @@ export class SelectFieldDownstreamBasin extends SelectField { for (const b of preBarrageD.bassins) { const pos = b.findPositionInParent(); if (posUb === undefined || pos > posUb) { - this.addEntry( - new SelectEntry( - this._entriesBaseId + b.uid, - b.uid, - ServiceFactory.i18nService.localizeMessage(b.description) - ) - ); + const e = new SelectEntry(this._entriesBaseId + b.uid, b.uid); + e.intlInfo = b.description; + this.addEntry(e); } } // river downstream - this.addEntry( - new SelectEntry( - this._entriesBaseId + "none", - undefined, - ServiceFactory.i18nService.localizeText("INFO_LIB_AVAL") - ) - ); + const e = new SelectEntry(this._entriesBaseId + "none", undefined); + e.intlInfo = "INFO_LIB_AVAL"; + this.addEntry(e); } protected initSelectedValue() { const db = (this.nub as PbCloison).bassinAval; this.setValueFromId(this._entriesBaseId + (db ? db.uid : "none")); } + + public updateLocalisation() { + for (const e of this._entries) { + if (e.id === this._entriesBaseId + "none") { + e.label = ServiceFactory.i18nService.localizeText(e.intlInfo) + } + else { + e.label = ServiceFactory.i18nService.localizeMessage(e.intlInfo) + } + } + } } diff --git a/src/app/formulaire/elements/select/select-field-species-list.ts b/src/app/formulaire/elements/select/select-field-species-list.ts index 602a5685493dbfd44762bfa4660e81d92e65ec9f..9401148c35ace8289cb150c5b2c8691f9dfc681e 100644 --- a/src/app/formulaire/elements/select/select-field-species-list.ts +++ b/src/app/formulaire/elements/select/select-field-species-list.ts @@ -24,27 +24,16 @@ export class SelectFieldSpeciesList extends SelectField { const especeNubs = Session.getInstance().getAllNubs().filter((element) => element.calcType === CalculatorType.Espece); for (const en of especeNubs) { const form = ServiceFactory.formulaireService.getFormulaireFromNubId(en.uid); - this.addEntry( - new SelectEntry( - this._entriesBaseId + en.uid, - en.uid, - sprintf( - ServiceFactory.i18nService.localizeText("INFO_VERIFICATEUR_CUSTOM_SPECIES"), - form ? form.calculatorName : "*** form not loaded yet ***" - ) - ) - ); + const e = new SelectEntry(this._entriesBaseId + en.uid, en.uid); + e.intlInfo = { "isnub": true, "code": "INFO_VERIFICATEUR_CUSTOM_SPECIES", "id": en.uid }; + this.addEntry(e); } // add all FishSpecies for (let j = 1; j < Object.keys(FishSpecies).length / 2; j++) { // exclude "0" (SPECIES_CUSTOM) const spgId = FishSpecies[j].substring(FishSpecies[j].lastIndexOf("_") + 1); - this.addEntry( - new SelectEntry( - this._entriesBaseId + spgId, - FishSpecies[j], - ServiceFactory.i18nService.localizeText("INFO_ENUM_" + FishSpecies[j]) - ) - ); + const e = new SelectEntry(this._entriesBaseId + spgId, FishSpecies[j]); + e.intlInfo = { "isnub": false, "code": FishSpecies[j] } + this.addEntry(e); } } @@ -61,5 +50,19 @@ export class SelectFieldSpeciesList extends SelectField { public updateLocalisation() { // do not override localisation done in populate() // ie. avoid what is done by SelectField.updateLocalisation() + + for (const e of this._entries) { + if (e.intlInfo.isnub) { + const id = e.intlInfo.id; + const form = ServiceFactory.formulaireService.getFormulaireFromNubId(id); + e.label = sprintf( + ServiceFactory.i18nService.localizeText(e.intlInfo.code), + form ? form.calculatorName : "*** form not loaded yet ***" + ); + } + else { + e.label = ServiceFactory.i18nService.localizeText("INFO_ENUM_" + e.intlInfo.code); + } + } } } diff --git a/src/app/formulaire/elements/select/select-field-upstream-basin.ts b/src/app/formulaire/elements/select/select-field-upstream-basin.ts index 0eeb6b605b2e3565baf8bcb20bacead7bc7825d8..d240d097c39d795647ab3cda6a4f0a78cac18b14 100644 --- a/src/app/formulaire/elements/select/select-field-upstream-basin.ts +++ b/src/app/formulaire/elements/select/select-field-upstream-basin.ts @@ -15,25 +15,19 @@ export class SelectFieldUpstreamBasin extends SelectField { const pbWallU = this.parentForm.currentNub as PbCloison; const preBarrageU = pbWallU.parent as PreBarrage; const posDb = pbWallU.bassinAval?.findPositionInParent(); + // river upstream - this.addEntry( - new SelectEntry( - this._entriesBaseId + "none", - undefined, - ServiceFactory.i18nService.localizeText("INFO_LIB_AMONT") - ) - ); + const e = new SelectEntry(this._entriesBaseId + "none", undefined); + e.intlInfo = "INFO_LIB_AMONT"; + this.addEntry(e); + // all available basins, depending on current downstream basin for (const b of preBarrageU.bassins) { const pos = b.findPositionInParent(); if (posDb === undefined || pos < posDb) { - this.addEntry( - new SelectEntry( - this._entriesBaseId + b.uid, - b.uid, - ServiceFactory.i18nService.localizeMessage(b.description) - ) - ); + const e = new SelectEntry(this._entriesBaseId + b.uid, b.uid); + e.intlInfo = b.description; + this.addEntry(e); } } } @@ -42,4 +36,14 @@ export class SelectFieldUpstreamBasin extends SelectField { const ub = (this.nub as PbCloison).bassinAmont; this.setValueFromId(this._entriesBaseId + (ub ? ub.uid : "none")); } + + public updateLocalisation() { + for (const e of this._entries) { + if (e.id === this._entriesBaseId + "none") { + e.label = ServiceFactory.i18nService.localizeText(e.intlInfo); + } else { + e.label = ServiceFactory.i18nService.localizeMessage(e.intlInfo); + } + } + } }