diff --git a/src/app/calculators/section-param/section-param.config.json b/src/app/calculators/section-param/section-param.config.json index 9740f86d109f9793560f6fb942687e9c907d3871..eaf075531f98fb1c951aa0cf7301cea462ee4081 100644 --- a/src/app/calculators/section-param/section-param.config.json +++ b/src/app/calculators/section-param/section-param.config.json @@ -289,6 +289,6 @@ }, { "type": "options", - "sectionSelectId": "select_section" + "sectionSourceId": "fs_section" } ] \ No newline at end of file diff --git a/src/app/formulaire/definition/form-def-section.ts b/src/app/formulaire/definition/form-def-section.ts index bfc65ea32d11577e60dd2b5a3e8d8cd85c61d354..ac9050d134cabb875c0b71542bdb8d3f00e9765f 100644 --- a/src/app/formulaire/definition/form-def-section.ts +++ b/src/app/formulaire/definition/form-def-section.ts @@ -8,12 +8,13 @@ import { Field } from "../field"; import { IObservable, Observer } from "../../services/observer"; import { NgParameter, ParamRadioConfig } from "../ngparam"; import { FormulaireDefinition } from "./form-definition"; +import { FieldSet } from "../fieldset"; export class FormDefSection implements Observer { /** - * id du SelectField configurant le type de section + * id de l'élément configurant le type de section */ - private _sectionSelectFieldId: string; + private _sectionSourceId: string; /** * Type de noeud de calcul actuel de la section (si la calculette est basée sur une section et qu'un menu permet @@ -27,8 +28,8 @@ export class FormDefSection implements Observer { this._formBase = base; } - private get hasSectionNodeTypeSelect(): boolean { - return this._sectionSelectFieldId != undefined; + private get hasSectionNodeTypeSource(): boolean { + return this._sectionSourceId != undefined; } public get sectionNodeType(): ComputeNodeType { @@ -36,7 +37,7 @@ export class FormDefSection implements Observer { } private updateSectionNodeType() { - const nt = this.getNodeTypeFromSelectField(); + const nt = this.getNodeTypeFromSourceElement(); if (this._sectionNodeType !== nt) { this._sectionNodeType = nt; this._formBase.reset(); @@ -53,26 +54,37 @@ export class FormDefSection implements Observer { return { symbol, label }; } - private getNodeTypeFromSelectField(): ComputeNodeType { - return this._formBase.getSelectedValue(this._sectionSelectFieldId); + /** + * @return l'élément déterminant le type de section + */ + private getSectionSourceElement(): FieldSet { + const fs = this._formBase.getFormulaireNodeById(this._sectionSourceId); + if (fs === undefined || !(fs instanceof FieldSet)) + throw new Error(`le champ ${this._sectionSourceId} n'est pas du type FieldSet`); + return fs; + } + + /** + * @return le type de section déterminé par l'élément source + */ + private getNodeTypeFromSourceElement(): ComputeNodeType { + const fs: FieldSet = this.getSectionSourceElement(); + return fs.getPropValue("nodeType"); } public initParse() { } public parseOptions(json: {}) { - // id du SelectField configurant le type de section - this._sectionSelectFieldId = this._formBase.getOption(json, "sectionSelectId"); + // id de l'élément configurant le type de section + this._sectionSourceId = this._formBase.getOption(json, "sectionSourceId"); } public completeParse() { // si le formulaire a un menu pour le type de section, on s'abonne à la valeur du champ correspondant - if (this.hasSectionNodeTypeSelect) { - const f: Field = this._formBase.getFieldById(this._sectionSelectFieldId); - if (f == undefined || !(f instanceof SelectField)) - throw new Error(`le champ ${this._sectionSelectFieldId} n'est pas du type SelectField`); - const sectTypeField: SelectField = f as SelectField; - sectTypeField.addObserver(this); + if (this.hasSectionNodeTypeSource) { + const se = this.getSectionSourceElement(); + se.addObserver(this); this.updateSectionNodeType() } } @@ -80,7 +92,7 @@ export class FormDefSection implements Observer { // interface Observer update(sender: any, data: any): void { - if (sender instanceof SelectField) { + if (data.action == "propertyChange") { this.updateSectionNodeType(); } } diff --git a/src/app/formulaire/fieldset.ts b/src/app/formulaire/fieldset.ts index 4a4eb4ddb98f2c93fcd9811f45559f9a46f7f473..3b098f78ae160580bb30bf1f0655b253570bd64e 100644 --- a/src/app/formulaire/fieldset.ts +++ b/src/app/formulaire/fieldset.ts @@ -106,10 +106,19 @@ export class FieldSet extends FormulaireElement implements Observer { return this._props.getPropValue(key); } + private notifyPropChange(prop: string, val: any) { + this.notifyObservers({ + "action": "propertyChange", + "name": prop, + "value": val + }, this) + } + public setPropValue(key: string, val: any): boolean { const changed = this._props.getPropValue(key) !== val; if (changed) { this._props.setPropValue(key, val); + this.notifyPropChange(key, val); // si prop=type d'ouvrage, on prend une loi de débit compatible avec (spécifique aux ouvrages //) comme valeur par défaut if (key === "structureType") {