import { RadioBoxData } from './DataField/RadioBoxData'; import { WordListData } from './DataField/WordListData'; import { AutocompleteData } from './DataField/AutocompleteData'; import { DataField } from './DataField/DataField'; import { BaseModel } from './BaseModel'; import { FormGroup } from '@angular/forms'; import { FormGenerator } from './interfaces/FormGenerator'; import { JsonSerializer } from '../utilities/JsonSerializer'; import { Serializable } from './interfaces/Serializable'; import {Rule} from './Rule'; import {Multiplicity} from './Multiplicity'; import {DefaultValue} from './DefaultValue'; import {ViewStyle} from './ViewStyle'; import {Visibility} from './Visibility'; export class Field extends BaseModel implements Serializable,FormGenerator{ public id:string; public title:string; public defaultValue:DefaultValue = new DefaultValue; public description:string; public extendedDescription:string; public viewStyle:ViewStyle = new ViewStyle(); public defaultVisibility:boolean; public page:number; public multiplicity: Multiplicity = new Multiplicity(); public ordinal: number; public visible: Visibility = new Visibility(); public data:DataField; fromJSONObject(item:any):Field{ this.id = item.id; this.title = item.title; this.defaultValue = new JsonSerializer().fromJSONObject(item.defaultValue, DefaultValue); this.description = item.description; this.extendedDescription = item.extendedDescription; this.defaultVisibility = item.defaultVisibility !==null ? item.defaultVisibility : true; this.page = item.page; this.multiplicity = new JsonSerializer().fromJSONObject(item.multiplicity, Multiplicity); this.ordinal = item.ordinal; this.viewStyle = new JsonSerializer().fromJSONObject(item.viewStyle, ViewStyle); this.visible = new JsonSerializer().fromJSONObject(item.visible, Visibility); if(item.data) { if(this.viewStyle.renderStyle === "combobox"){ if(item.data.type === "autocomplete") this.data = new JsonSerializer().fromJSONObject(item.data,AutocompleteData); if(item.data.type === "wordlist")this.data = new JsonSerializer().fromJSONObject(item.data,WordListData); }else{ if(this.viewStyle.renderStyle === "radiobox") this.data = new JsonSerializer().fromJSONObject(item.data,RadioBoxData); } } return this; } buildForm():FormGroup{ let formGroup = this.formBuilder.group({ id: [this.id], title: [this.title], description: [this.description], extendedDescription:[this.extendedDescription], defaultVisibility:[this.defaultVisibility], page:[this.page] , ordinal:[this.ordinal] }); formGroup.addControl("multiplicity", this.multiplicity.buildForm()); formGroup.addControl("defaultValue", this.defaultValue.buildForm()); formGroup.addControl("viewStyle", this.viewStyle.buildForm()); formGroup.addControl("visible", this.visible.buildForm()); //formGroup.addControl("data",this.data? this.data.buildForm():this.formBuilder.group({})); if(this.data)formGroup.addControl("data",this.data.buildForm()); if( formGroup.controls["defaultVisibility"].value == null) formGroup.controls["defaultVisibility"].setValue(true); return formGroup; } }