import { BaseModel } from './BaseModel'; import { FormGenerator } from './interfaces/FormGenerator'; import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { JsonSerializer } from '../utilities/JsonSerializer'; import { Serializable } from './interfaces/Serializable'; import { FieldGroup } from './FieldGroup'; import { CompositeField } from './CompositeField'; export class Section extends BaseModel implements Serializable
, FormGenerator { public sections: Array
= new Array
(); //public fieldGroups: Array; public defaultVisibility: boolean; public page: number; public ordinal: number; public id: string; public title: string; public description: string; public compositeFields: Array = new Array(); fromJSONObject(item: any): Section { this.sections = JsonSerializer.fromJSONArray(item.sections, Section); //this.fieldGroups = new JsonSerializer().fromJSONArray(item.fieldGroups, FieldGroup); this.page = item.page; this.defaultVisibility = item.defaultVisibility; this.id = item.id; this.title = item.title; this.ordinal = item.ordinal; this.description = item.description; this.compositeFields = JsonSerializer.fromJSONArray(item.compositeFields, CompositeField); return this; } buildForm(): FormGroup { const formGroup: FormGroup = new FormBuilder().group({}); const sectionsFormArray = new Array(); if (this.sections) { this.sections.forEach(item => { const form: FormGroup = item.buildForm(); sectionsFormArray.push(form); }); } const fieldGroupsFormArray = new Array(); // if (this.fieldGroups) { // this.fieldGroups.forEach(item => { // let form: FormGroup = item.buildForm(); // fieldGroupsFormArray.push(form) // }) // } const compositeFieldsFormArray = new Array(); if (this.compositeFields) { this.compositeFields.forEach(item => { const form: FormGroup = item.buildForm(); compositeFieldsFormArray.push(form); }); } formGroup.addControl('compositeFields', this.formBuilder.array(compositeFieldsFormArray)); formGroup.addControl('sections', this.formBuilder.array(sectionsFormArray)); // formGroup.addControl('fieldGroups', this.formBuilder.array(fieldGroupsFormArray)); /* formGroup.addControl('defaultVisibility', new FormControl(this.defaultVisibility)) formGroup.addControl('page', new FormControl(this.page)) formGroup.addControl('id', new FormControl(this.id)) formGroup.addControl('title', new FormControl(this.title)) formGroup.addControl('description', new FormControl(this.description)) */ return formGroup; } }