31 lines
1019 B
TypeScript
31 lines
1019 B
TypeScript
import { Section } from '../models/Section';
|
|
import { BaseModel } from './BaseModel';
|
|
import { FormGenerator } from './interfaces/FormGenerator';
|
|
import { Serializable } from './interfaces/Serializable';
|
|
import { JsonSerializer } from '../utilities/JsonSerializer';
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
|
|
export class Page extends BaseModel implements Serializable<Page> {
|
|
public ordinal: number;
|
|
public title: string;
|
|
public sections: Array<Section>;
|
|
|
|
fromJSONObject(item: any): Page {
|
|
this.ordinal = item.ordinal;
|
|
this.title = item.title;
|
|
this.sections = JsonSerializer.fromJSONArray(item.sections, Section);
|
|
return this;
|
|
}
|
|
|
|
buildForm(): FormGroup {
|
|
const formGroup: FormGroup = new FormBuilder().group({});
|
|
const sectionsFormArray = new Array<FormGroup>();
|
|
this.sections.forEach(item => {
|
|
const form: FormGroup = item.buildForm();
|
|
sectionsFormArray.push(form);
|
|
});
|
|
formGroup.addControl('sections', this.formBuilder.array(sectionsFormArray));
|
|
return formGroup;
|
|
}
|
|
}
|