2018-02-02 11:57:24 +01:00
|
|
|
|
import { JsonSerializer } from '../../utilities/JsonSerializer';
|
|
|
|
|
import { FormGroup } from '@angular/forms';
|
|
|
|
|
import { Serializable } from '../interfaces/Serializable';
|
|
|
|
|
import { BaseModel } from '../BaseModel';
|
2018-10-05 17:00:54 +02:00
|
|
|
|
import { Field } from './Field';
|
|
|
|
|
import { Multiplicity } from './Multiplicity';
|
2018-02-02 11:57:24 +01:00
|
|
|
|
|
|
|
|
|
export class FieldSet extends BaseModel implements Serializable<FieldSet> {
|
2018-10-05 17:00:54 +02:00
|
|
|
|
public fields: Array<Field> = new Array<Field>();
|
|
|
|
|
public id: string;
|
|
|
|
|
public ordinal: number;
|
|
|
|
|
public multiplicity: Multiplicity = new Multiplicity();
|
|
|
|
|
public title: string;
|
|
|
|
|
public description: string;
|
|
|
|
|
public extendedDescription: string;
|
|
|
|
|
public hasCommentField: boolean;
|
2018-02-02 11:57:24 +01:00
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
|
fromJSONObject(item: any): FieldSet {
|
2018-02-02 11:57:24 +01:00
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
|
this.fields = JsonSerializer.fromJSONArray(item.fields, Field);
|
|
|
|
|
this.multiplicity = JsonSerializer.fromJSONObject(item.multiplicity, Multiplicity);
|
|
|
|
|
this.id = item.id;
|
|
|
|
|
this.ordinal = item.ordinal;
|
|
|
|
|
this.title = item.title;
|
|
|
|
|
this.description = item.description;
|
|
|
|
|
this.extendedDescription = item.extendedDescription;
|
|
|
|
|
this.hasCommentField = item.hasCommentField;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2018-02-02 11:57:24 +01:00
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
|
const formGroup = this.formBuilder.group({
|
|
|
|
|
id: [this.id],
|
|
|
|
|
ordinal: [this.ordinal],
|
|
|
|
|
title: [this.title],
|
|
|
|
|
description: [this.description],
|
|
|
|
|
extendedDescription: [this.extendedDescription],
|
|
|
|
|
hasCommentField: [this.hasCommentField]
|
|
|
|
|
});
|
2018-02-02 11:57:24 +01:00
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
|
const fieldsFormArray = new Array<FormGroup>();
|
|
|
|
|
this.fields.forEach(item => {
|
|
|
|
|
const form: FormGroup = item.buildForm();
|
|
|
|
|
fieldsFormArray.push(form);
|
|
|
|
|
});
|
|
|
|
|
formGroup.addControl('fields', this.formBuilder.array(fieldsFormArray));
|
|
|
|
|
formGroup.addControl('multiplicity', this.multiplicity.buildForm());
|
|
|
|
|
|
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|