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
No related tags found
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 @@
},
{
"type": "options",
"sectionSelectId": "select_section"
"sectionSourceId": "fs_section"
}
]
\ No newline at end of file
......@@ -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();
}
}
......
......@@ -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") {
......
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