Skip to content
Snippets Groups Projects
Commit 232fb2a7 authored by François Grand's avatar François Grand
Browse files

feat: add FormulaireDefinition.parseSelectDefaultValue()

refs #585
parent f11b78e9
No related branches found
No related tags found
2 merge requests!225Release v4.17.0,!193Resolve "Restructurer Lechapt et Calmon pour de nouvelles lois de pertes de charge"
......@@ -25,6 +25,7 @@ import { ServiceFactory } from "../../services/service-factory";
import { SelectEntry } from "../elements/select/select-entry";
import { SelectField } from "../elements/select/select-field";
import { DeepSelectFieldIterator } from "../form-iterator/deep-selectfield-iterator";
import { ConfigParser } from "./config-parser";
/**
* classe de base pour tous les formulaires
......@@ -146,6 +147,24 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs
Session.getInstance().deleteNub(sn);
}
/**
* parse calculator JSON configuration for select default value
* @param selectId select id, ie. "id" field value
* @return select "default" field value
*/
protected parseSelectDefaultValue(json: {}, selectId: string): string {
const jp = new ConfigParser(json);
for (const fs of jp.forAll("fieldset")) {
const fsp = new ConfigParser(fs["fields"]);
for (const sel of fsp.forAll("select")) {
if (sel["id"] === selectId) {
return sel["default"];
}
}
}
return undefined;
}
/**
* prepare options parsing
*/
......
......@@ -3,7 +3,6 @@ import { FieldSet } from "../elements/fieldset";
import { ServiceFactory } from "../../services/service-factory";
import { IObservable, Session, SectionNub, Props, CalculatorType, Prop_NullParameters, acSection } from "jalhyd";
import { ConfigParser } from "./config-parser";
import { SectionType } from "jalhyd";
export class FormulaireSection extends FormulaireFixedVar {
......@@ -16,17 +15,8 @@ export class FormulaireSection extends FormulaireFixedVar {
*/
private parseDefaultSectionType() {
if (this._defaultSectionType === undefined) {
const jp = new ConfigParser(this._jsonConfig);
for (const fs of jp.forAll("fieldset")) {
const fsp = new ConfigParser(fs["fields"]);
for (const sel of fsp.forAll("select")) {
if (sel["id"] === "select_section") {
const st = sel["default"];
this._defaultSectionType = SectionType[st];
return;
}
}
}
const def = this.parseSelectDefaultValue(this._jsonConfig, "select_section");
this._defaultSectionType = SectionType[def];
}
}
......
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