default value in field model
This commit is contained in:
parent
0dd1f6771c
commit
22f621383b
|
@ -0,0 +1,24 @@
|
||||||
|
import { BaseModel } from './BaseModel';
|
||||||
|
import { FormGroup } from '@angular/forms';
|
||||||
|
import { FormGenerator } from './interfaces/FormGenerator';
|
||||||
|
import { Serializable } from './interfaces/Serializable';
|
||||||
|
|
||||||
|
export class DefaultValue extends BaseModel implements Serializable<DefaultValue>, FormGenerator<FormGroup>{
|
||||||
|
public type: string;
|
||||||
|
public value: string;
|
||||||
|
|
||||||
|
fromJSONObject(item: any): DefaultValue {
|
||||||
|
this.type = item.type;
|
||||||
|
this.value = item.value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildForm(): FormGroup {
|
||||||
|
let formGroup = this.formBuilder.group({
|
||||||
|
type: [this.type],
|
||||||
|
value: [this.value]
|
||||||
|
|
||||||
|
});
|
||||||
|
return formGroup;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,11 +4,13 @@ import { FormGenerator } from './interfaces/FormGenerator';
|
||||||
import { JsonSerializer } from '../utilities/JsonSerializer';
|
import { JsonSerializer } from '../utilities/JsonSerializer';
|
||||||
import { Serializable } from './interfaces/Serializable';
|
import { Serializable } from './interfaces/Serializable';
|
||||||
import { Multiplicity } from './Multiplicity';
|
import { Multiplicity } from './Multiplicity';
|
||||||
|
import { DefaultValue } from './DefaultValue';
|
||||||
export class Field extends BaseModel implements Serializable<Field>, FormGenerator<FormGroup>{
|
export class Field extends BaseModel implements Serializable<Field>, FormGenerator<FormGroup>{
|
||||||
|
|
||||||
public id: string;
|
public id: string;
|
||||||
public title: string;
|
public title: string;
|
||||||
public value: string;
|
public value: string;
|
||||||
|
public defaultValue: DefaultValue;
|
||||||
public description: string;
|
public description: string;
|
||||||
public extendedDescription: string;
|
public extendedDescription: string;
|
||||||
public viewStyle: string;
|
public viewStyle: string;
|
||||||
|
@ -17,16 +19,19 @@ export class Field extends BaseModel implements Serializable<Field>, FormGenerat
|
||||||
public multiplicity: Multiplicity;
|
public multiplicity: Multiplicity;
|
||||||
public multiplicityItems: Array<Field> = new Array<Field>();
|
public multiplicityItems: Array<Field> = new Array<Field>();
|
||||||
public data: any;
|
public data: any;
|
||||||
|
|
||||||
fromJSONObject(item: any): Field {
|
fromJSONObject(item: any): Field {
|
||||||
this.id = item.id;
|
this.id = item.id;
|
||||||
this.title = item.title;
|
this.title = item.title;
|
||||||
this.value = item.value;
|
//this.value = item.value;
|
||||||
this.description = item.description;
|
this.description = item.description;
|
||||||
this.extendedDescription = item.extendedDescription;
|
this.extendedDescription = item.extendedDescription;
|
||||||
this.viewStyle = item.viewStyle;
|
this.viewStyle = item.viewStyle;
|
||||||
this.defaultVisibility = item.defaultVisibility;
|
this.defaultVisibility = item.defaultVisibility;
|
||||||
this.page = item.page;
|
this.page = item.page;
|
||||||
//this.multiplicity = new JsonSerializer<Multiplicity>().fromJSONObject(item.multiplicity, Multiplicity);
|
//this.multiplicity = new JsonSerializer<Multiplicity>().fromJSONObject(item.multiplicity, Multiplicity);
|
||||||
|
this.defaultValue = new JsonSerializer<DefaultValue>().fromJSONObject(item.defaultValue, DefaultValue);
|
||||||
|
this.value = this.defaultValue.value && !item.value? this.defaultValue.value: item.value;
|
||||||
this.multiplicity = new Multiplicity();
|
this.multiplicity = new Multiplicity();
|
||||||
this.multiplicity.max = 2;
|
this.multiplicity.max = 2;
|
||||||
this.multiplicityItems = new JsonSerializer<Field>().fromJSONArray(item.multiplicityItems, Field);
|
this.multiplicityItems = new JsonSerializer<Field>().fromJSONArray(item.multiplicityItems, Field);
|
||||||
|
|
Loading…
Reference in New Issue