2018-01-03 15:19:38 +01:00
|
|
|
|
import { BooleanDecisionData } from '../DataField/BooleanDecisionData';
|
|
|
|
|
import { FreeTextData } from '../DataField/FreeTextData';
|
|
|
|
|
import { TextArea } from '../DataField/TextArea';
|
|
|
|
|
import { CheckBoxData } from '../DataField/CheckBoxData';
|
|
|
|
|
import { RadioBoxData } from '../DataField/RadioBoxData';
|
2017-12-20 17:46:52 +01:00
|
|
|
|
import { WordListData } from '../DataField/WordListData';
|
|
|
|
|
import { AutocompleteData } from '../DataField/AutocompleteData';
|
|
|
|
|
import { DataField } from '../DataField/DataField';
|
|
|
|
|
import { BaseModel } from '../BaseModel';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
import { FormGroup } from '@angular/forms';
|
2017-12-20 17:46:52 +01:00
|
|
|
|
import { FormGenerator } from '../interfaces/FormGenerator';
|
|
|
|
|
import { JsonSerializer } from 'app/utilities/JsonSerializer';
|
|
|
|
|
import { Serializable } from '../interfaces/Serializable';
|
2017-12-01 15:00:37 +01:00
|
|
|
|
import {Rule} from './Rule';
|
|
|
|
|
import {Multiplicity} from './Multiplicity';
|
|
|
|
|
import {DefaultValue} from './DefaultValue';
|
|
|
|
|
import {ViewStyle} from './ViewStyle';
|
|
|
|
|
import {Visibility} from './Visibility';
|
2018-01-03 15:20:22 +01:00
|
|
|
|
import { ValidationTypes } from 'app/common/validationTypes';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
|
|
|
|
export class Field extends BaseModel implements Serializable<Field>,FormGenerator<FormGroup>{
|
|
|
|
|
|
|
|
|
|
public id:string;
|
|
|
|
|
public title:string;
|
2018-01-02 17:29:27 +01:00
|
|
|
|
public defaultValue:DefaultValue = new DefaultValue;
|
2017-12-01 15:00:37 +01:00
|
|
|
|
public viewStyle:ViewStyle = new ViewStyle();
|
2017-11-27 14:35:00 +01:00
|
|
|
|
public page:number;
|
2018-01-02 17:29:27 +01:00
|
|
|
|
//public multiplicity: Multiplicity = new Multiplicity();
|
2017-11-28 12:42:30 +01:00
|
|
|
|
public ordinal: number;
|
2017-12-01 15:00:37 +01:00
|
|
|
|
public visible: Visibility = new Visibility();
|
2017-12-01 17:31:47 +01:00
|
|
|
|
public data:DataField<any>;
|
2018-01-03 16:46:23 +01:00
|
|
|
|
public validations: Array<ValidationTypes>;
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
|
|
|
|
fromJSONObject(item:any):Field{
|
|
|
|
|
this.id = item.id;
|
|
|
|
|
this.title = item.title;
|
2018-01-02 17:29:27 +01:00
|
|
|
|
this.defaultValue = new JsonSerializer<DefaultValue>().fromJSONObject(item.defaultValue, DefaultValue);
|
2017-11-27 14:35:00 +01:00
|
|
|
|
this.page = item.page;
|
2018-01-02 17:29:27 +01:00
|
|
|
|
// this.multiplicity = new JsonSerializer<Multiplicity>().fromJSONObject(item.multiplicity, Multiplicity);
|
2017-11-28 12:42:30 +01:00
|
|
|
|
this.ordinal = item.ordinal;
|
2018-01-03 16:46:23 +01:00
|
|
|
|
this.validations = item.validations;
|
2017-12-01 15:00:37 +01:00
|
|
|
|
this.viewStyle = new JsonSerializer<ViewStyle>().fromJSONObject(item.viewStyle, ViewStyle);
|
|
|
|
|
this.visible = new JsonSerializer<Visibility>().fromJSONObject(item.visible, Visibility);
|
2017-12-01 17:31:47 +01:00
|
|
|
|
if(item.data) {
|
|
|
|
|
if(this.viewStyle.renderStyle === "combobox"){
|
|
|
|
|
if(item.data.type === "autocomplete") this.data = new JsonSerializer<AutocompleteData>().fromJSONObject(item.data,AutocompleteData);
|
|
|
|
|
if(item.data.type === "wordlist")this.data = new JsonSerializer<WordListData>().fromJSONObject(item.data,WordListData);
|
|
|
|
|
}else{
|
|
|
|
|
if(this.viewStyle.renderStyle === "radiobox") this.data = new JsonSerializer<RadioBoxData>().fromJSONObject(item.data,RadioBoxData);
|
2018-01-03 15:19:38 +01:00
|
|
|
|
if(this.viewStyle.renderStyle === "checkBox") this.data = new JsonSerializer<CheckBoxData>().fromJSONObject(item.data,CheckBoxData);
|
|
|
|
|
if(this.viewStyle.renderStyle === "textarea") this.data = new JsonSerializer<TextArea>().fromJSONObject(item.data,TextArea);
|
|
|
|
|
if(this.viewStyle.renderStyle === "freetext") this.data = new JsonSerializer<FreeTextData>().fromJSONObject(item.data,FreeTextData);
|
|
|
|
|
if(this.viewStyle.renderStyle === "booleanDecision") this.data = new JsonSerializer<BooleanDecisionData>().fromJSONObject(item.data,BooleanDecisionData);
|
2017-12-01 17:31:47 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-27 14:35:00 +01:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm():FormGroup{
|
|
|
|
|
let formGroup = this.formBuilder.group({
|
|
|
|
|
id: [this.id],
|
2018-01-02 17:29:27 +01:00
|
|
|
|
title: [this.title],
|
2017-11-28 12:42:30 +01:00
|
|
|
|
page:[this.page] ,
|
2018-01-03 15:20:22 +01:00
|
|
|
|
ordinal:[this.ordinal],
|
2018-01-03 16:46:23 +01:00
|
|
|
|
validations:[this.validations]
|
|
|
|
|
});
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
2018-01-02 17:29:27 +01:00
|
|
|
|
//formGroup.addControl("multiplicity", this.multiplicity.buildForm());
|
2017-12-01 15:00:37 +01:00
|
|
|
|
formGroup.addControl("defaultValue", this.defaultValue.buildForm());
|
|
|
|
|
formGroup.addControl("viewStyle", this.viewStyle.buildForm());
|
2017-12-01 17:31:47 +01:00
|
|
|
|
formGroup.addControl("visible", this.visible.buildForm());
|
2017-12-04 16:02:52 +01:00
|
|
|
|
//formGroup.addControl("data",this.data? this.data.buildForm():this.formBuilder.group({}));
|
|
|
|
|
if(this.data)formGroup.addControl("data",this.data.buildForm());
|
2017-12-07 14:44:17 +01:00
|
|
|
|
|
2017-11-27 14:35:00 +01:00
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|