2018-01-03 15:19:38 +01:00
|
|
|
|
import { JsonSerializer } from '../../utilities/JsonSerializer';
|
|
|
|
|
import { FormGroup } from '@angular/forms';
|
2017-12-20 17:46:52 +01:00
|
|
|
|
import { Serializable } from '../interfaces/Serializable';
|
|
|
|
|
import { BaseModel } from '../BaseModel';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
import {Field} from './Field'
|
2017-12-01 15:00:37 +01:00
|
|
|
|
import {Multiplicity} from './Multiplicity'
|
|
|
|
|
|
2018-01-02 17:29:27 +01:00
|
|
|
|
export class FieldSet extends BaseModel implements Serializable<FieldSet> {
|
2017-11-27 14:35:00 +01:00
|
|
|
|
public fields:Array<Field> = new Array<Field>();
|
2017-11-30 09:14:54 +01:00
|
|
|
|
public id:string;
|
|
|
|
|
public ordinal:number;
|
2017-12-01 15:00:37 +01:00
|
|
|
|
public multiplicity: Multiplicity = new Multiplicity();
|
2018-01-02 17:29:27 +01:00
|
|
|
|
public title:string;
|
|
|
|
|
public description:string;
|
|
|
|
|
public extendedDescription:string;
|
2018-01-03 14:42:20 +01:00
|
|
|
|
public hasCommentField:boolean;
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
2018-01-02 17:29:27 +01:00
|
|
|
|
fromJSONObject(item:any):FieldSet{
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
2018-02-01 15:04:36 +01:00
|
|
|
|
this.fields = JsonSerializer.fromJSONArray(item.fields,Field);
|
|
|
|
|
this.multiplicity = JsonSerializer.fromJSONObject(item.multiplicity, Multiplicity);
|
2017-11-30 09:14:54 +01:00
|
|
|
|
this.id = item.id;
|
|
|
|
|
this.ordinal = item.ordinal;
|
2018-01-02 17:29:27 +01:00
|
|
|
|
this.title = item.title;
|
|
|
|
|
this.description = item.description;
|
|
|
|
|
this.extendedDescription = item.extendedDescription;
|
2018-01-03 14:42:20 +01:00
|
|
|
|
this.hasCommentField = item.hasCommentField;
|
2017-11-27 14:35:00 +01:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm():FormGroup{
|
2017-11-28 12:42:30 +01:00
|
|
|
|
let formGroup = this.formBuilder.group({
|
2017-11-30 09:14:54 +01:00
|
|
|
|
id:[this.id],
|
2018-01-02 17:29:27 +01:00
|
|
|
|
ordinal:[this.ordinal],
|
|
|
|
|
title:[this.title],
|
|
|
|
|
description: [this.description],
|
2018-01-03 14:42:20 +01:00
|
|
|
|
extendedDescription:[this.extendedDescription],
|
|
|
|
|
hasCommentField:[this.hasCommentField]
|
2017-11-28 12:42:30 +01:00
|
|
|
|
});
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
|
|
|
|
let fieldsFormArray = new Array<FormGroup>();
|
|
|
|
|
this.fields.forEach(item => {
|
|
|
|
|
let form: FormGroup = item.buildForm();
|
|
|
|
|
fieldsFormArray.push(form)
|
|
|
|
|
})
|
|
|
|
|
formGroup.addControl('fields', this.formBuilder.array(fieldsFormArray));
|
2017-12-01 15:00:37 +01:00
|
|
|
|
formGroup.addControl("multiplicity", this.multiplicity.buildForm());
|
|
|
|
|
|
2017-11-27 14:35:00 +01:00
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|