Skip to content
Snippets Groups Projects
Commit 02482c8a authored by francois.grand's avatar francois.grand
Browse files

#77 sections paramétrées : le changement de type de section est détecté par...

 #77 sections paramétrées : le changement de type de section est détecté par abonnement au propriétés du fieldset contenant le select, plus au select lui même
parent 57042c78
No related branches found
Tags 4.16.0
1 merge request!15Resolve "faire les modifications nécessaires prendre en compte le ticket cassiopee/jalhyd#46 (Gestion de la session dans la lib)"
...@@ -289,6 +289,6 @@ ...@@ -289,6 +289,6 @@
}, },
{ {
"type": "options", "type": "options",
"sectionSelectId": "select_section" "sectionSourceId": "fs_section"
} }
] ]
\ No newline at end of file
...@@ -8,12 +8,13 @@ import { Field } from "../field"; ...@@ -8,12 +8,13 @@ import { Field } from "../field";
import { IObservable, Observer } from "../../services/observer"; import { IObservable, Observer } from "../../services/observer";
import { NgParameter, ParamRadioConfig } from "../ngparam"; import { NgParameter, ParamRadioConfig } from "../ngparam";
import { FormulaireDefinition } from "./form-definition"; import { FormulaireDefinition } from "./form-definition";
import { FieldSet } from "../fieldset";
export class FormDefSection implements Observer { 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 * 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 { ...@@ -27,8 +28,8 @@ export class FormDefSection implements Observer {
this._formBase = base; this._formBase = base;
} }
private get hasSectionNodeTypeSelect(): boolean { private get hasSectionNodeTypeSource(): boolean {
return this._sectionSelectFieldId != undefined; return this._sectionSourceId != undefined;
} }
public get sectionNodeType(): ComputeNodeType { public get sectionNodeType(): ComputeNodeType {
...@@ -36,7 +37,7 @@ export class FormDefSection implements Observer { ...@@ -36,7 +37,7 @@ export class FormDefSection implements Observer {
} }
private updateSectionNodeType() { private updateSectionNodeType() {
const nt = this.getNodeTypeFromSelectField(); const nt = this.getNodeTypeFromSourceElement();
if (this._sectionNodeType !== nt) { if (this._sectionNodeType !== nt) {
this._sectionNodeType = nt; this._sectionNodeType = nt;
this._formBase.reset(); this._formBase.reset();
...@@ -53,26 +54,37 @@ export class FormDefSection implements Observer { ...@@ -53,26 +54,37 @@ export class FormDefSection implements Observer {
return { symbol, label }; 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 initParse() {
} }
public parseOptions(json: {}) { public parseOptions(json: {}) {
// id du SelectField configurant le type de section // id de l'élément configurant le type de section
this._sectionSelectFieldId = this._formBase.getOption(json, "sectionSelectId"); this._sectionSourceId = this._formBase.getOption(json, "sectionSourceId");
} }
public completeParse() { public completeParse() {
// si le formulaire a un menu pour le type de section, on s'abonne à la valeur du champ correspondant // si le formulaire a un menu pour le type de section, on s'abonne à la valeur du champ correspondant
if (this.hasSectionNodeTypeSelect) { if (this.hasSectionNodeTypeSource) {
const f: Field = this._formBase.getFieldById(this._sectionSelectFieldId); const se = this.getSectionSourceElement();
if (f == undefined || !(f instanceof SelectField)) se.addObserver(this);
throw new Error(`le champ ${this._sectionSelectFieldId} n'est pas du type SelectField`);
const sectTypeField: SelectField = f as SelectField;
sectTypeField.addObserver(this);
this.updateSectionNodeType() this.updateSectionNodeType()
} }
} }
...@@ -80,7 +92,7 @@ export class FormDefSection implements Observer { ...@@ -80,7 +92,7 @@ export class FormDefSection implements Observer {
// interface Observer // interface Observer
update(sender: any, data: any): void { update(sender: any, data: any): void {
if (sender instanceof SelectField) { if (data.action == "propertyChange") {
this.updateSectionNodeType(); this.updateSectionNodeType();
} }
} }
......
...@@ -106,10 +106,19 @@ export class FieldSet extends FormulaireElement implements Observer { ...@@ -106,10 +106,19 @@ export class FieldSet extends FormulaireElement implements Observer {
return this._props.getPropValue(key); 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 { public setPropValue(key: string, val: any): boolean {
const changed = this._props.getPropValue(key) !== val; const changed = this._props.getPropValue(key) !== val;
if (changed) { if (changed) {
this._props.setPropValue(key, val); 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 // 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") { if (key === "structureType") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment