diff --git a/src/app/components/field-set/field-set.component.ts b/src/app/components/field-set/field-set.component.ts index ebb0c3d6d6704e43bd82396b26761d623758d4f0..9674b3f3fa26ac4479e3964eb17e0a350ba0cfaf 100644 --- a/src/app/components/field-set/field-set.component.ts +++ b/src/app/components/field-set/field-set.component.ts @@ -231,7 +231,7 @@ export class FieldSetComponent implements DoCheck { * clic sur le bouton ajouter */ private onAddClick() { - this.addFieldset.emit(); + this.addFieldset.emit(this._fieldSet); } /** diff --git a/src/app/components/fieldset-container/fieldset-container.component.html b/src/app/components/fieldset-container/fieldset-container.component.html index 9dfad64d4cf179703be12046116893d2724e6611..a1e13d4769c672544e2eaef88bbe62b1eb4d836d 100644 --- a/src/app/components/fieldset-container/fieldset-container.component.html +++ b/src/app/components/fieldset-container/fieldset-container.component.html @@ -4,6 +4,6 @@ </div> <field-set *ngFor="let fs of fieldsets" [fieldSet]=fs (onRadio)=onRadioClick($event) (onValid)=onFieldsetValid() (inputChange)=onInputChange() - (addFieldset)=onAddFieldset() (removeFieldset)=onRemoveFieldset($event)> + (addFieldset)=onAddFieldset($event) (removeFieldset)=onRemoveFieldset($event)> </field-set> </div> \ No newline at end of file diff --git a/src/app/components/fieldset-container/fieldset-container.component.ts b/src/app/components/fieldset-container/fieldset-container.component.ts index a323c28eb6ebf1c0f96f4fad0ad6d7f2343bf096..20f7ad5c154f4547acd9c1b64df20f23eb522109 100644 --- a/src/app/components/fieldset-container/fieldset-container.component.ts +++ b/src/app/components/fieldset-container/fieldset-container.component.ts @@ -34,24 +34,28 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { return this._container.fieldsets; } - private addStructure() { - this._container.addFromTemplate(0); + private addStructure(after?: FieldSet) { + if (after) + this._container.addFromTemplate(0, after.indexAsKid()); + else + this._container.addFromTemplate(0); } - private onFielsetListChange(val: any) { + private onFielsetListChange() { // affichage des boutons ajouter, supprimer, monter, descendre - const fs = val.last as FieldSetComponent; - fs.showButtons = true; + this._fieldsetComponents.forEach(fs => fs.showButtons = true); // désactivation du bouton supprimer s'il n'en reste qu'un - if (this._fieldsetComponents.length == 1) + if (this._fieldsetComponents.length == 1) { + const fs = this._fieldsetComponents.last as FieldSetComponent; fs.enableRemoveButton = false; + } else this._fieldsetComponents.forEach(fs => fs.enableRemoveButton = true); } public ngAfterViewInit() { - this._fieldsetComponents.changes.subscribe(value => this.onFielsetListChange(value)); + this._fieldsetComponents.changes.subscribe(_ => this.onFielsetListChange()); this.addStructure(); } @@ -142,8 +146,8 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { /** * réception d'un événement de demande d'ajout d'un FieldSet */ - private onAddFieldset() { - this.addStructure(); + private onAddFieldset(fs: FieldSet) { + this.addStructure(fs); } /** diff --git a/src/app/formulaire/definition/concrete/form-parallel-structures.ts b/src/app/formulaire/definition/concrete/form-parallel-structures.ts index bfd3de2c3d62f4004c1e400cfa1716e5a508b42f..4b4165fe489642ef2fb9ae701186f0cb725c9336 100644 --- a/src/app/formulaire/definition/concrete/form-parallel-structures.ts +++ b/src/app/formulaire/definition/concrete/form-parallel-structures.ts @@ -52,8 +52,13 @@ export class FormulaireParallelStructure extends FormulaireDefinition { return paramService.createSessionNub(params); } - private addStructureNub(st: Structure) { - this.parallelStructureNub.addStructure(st); + /** + * ajoute un Nub Structure + * @param st structure à ajouter + * @param after position après laquelle insérer la structure, à la fin sinon + */ + private addStructureNub(st: Structure, after?: number) { + this.parallelStructureNub.addStructure(st, after); } private get parallelStructureNub(): ParallelStructure { @@ -66,15 +71,23 @@ export class FormulaireParallelStructure extends FormulaireDefinition { public createFieldset(parent: FormulaireNode, json: {}, data?: {}): FieldSet { if (json["calcType"] === "Structure") { + // indice après lequel insérer le nouveau FieldSet + const after = data["after"]; + const res: FieldSet = new FieldSet(parent); const sn = this.createStructNub(data["template"]); - this.addStructureNub(sn.nub as Structure); + this.addStructureNub(sn.nub as Structure, after); res.setSessionNub(sn, false); - parent.kids.push(res); + + if (after !== undefined) + parent.kids.splice(after + 1, 0, res); + else + parent.kids.push(res); + return res; } else - return super.createFieldset(parent, json); + return super.createFieldset(parent, json, data); } protected initParse() { diff --git a/src/app/formulaire/fieldset-container.ts b/src/app/formulaire/fieldset-container.ts index 27ac22d03cd572d569cbb99424870bb4f8490b14..5f2ecf308db23b3796a296357aa51ed5de3990ab 100644 --- a/src/app/formulaire/fieldset-container.ts +++ b/src/app/formulaire/fieldset-container.ts @@ -37,10 +37,15 @@ export class FieldsetContainer extends FormulaireElement { this.kids.splice(i, 1); } - public addFromTemplate(index: number) { - const templ: FieldsetTemplate = this._templates[index]; - - const inst: FieldSet = templ.instantiateTemplate(this); + /** + * crée un FieldSet à partir d'un template + * @param templateIndex indice du template dans la liste + * @param after insère le nouveau FieldSet après cette position, à la fin sinon + */ + public addFromTemplate(templateIndex: number, after?: number) { + const templ: FieldsetTemplate = this._templates[templateIndex]; + + const inst: FieldSet = templ.instantiateTemplate(this, after); this.updateLocalisation(); diff --git a/src/app/formulaire/fieldset-template.ts b/src/app/formulaire/fieldset-template.ts index c21455761a1f062442e62b817c7573f9eb5f9546..a5d61834921dcdeb5408047af79db76c29386f53 100644 --- a/src/app/formulaire/fieldset-template.ts +++ b/src/app/formulaire/fieldset-template.ts @@ -38,9 +38,14 @@ export class FieldsetTemplate { return nodeType; } - public instantiateTemplate(cont: FieldsetContainer): FieldSet { + /** + * crée une instance de Fieldset et l'ajoute dans un conteneur + * @param cont conteneur + * @param at position à laquelle on ajoute le nouveau FieldSet + */ + public instantiateTemplate(cont: FieldsetContainer, after: number): FieldSet { const parentForm = cont.parent as FormulaireDefinition; - const res = parentForm.createFieldset(cont, this._jsonConfig, { "template": this }); + const res = parentForm.createFieldset(cont, this._jsonConfig, { "template": this, "after": after }); res.parseConfig(this._jsonConfig, { "parentForm": parentForm }); parentForm.afterParseFieldset(res); return res;