2019-02-04 17:10:22 +01:00
|
|
|
|
import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
import { ValidationType } from '../../../../core/common/enum/validation-type';
|
|
|
|
|
import { Field } from '../../../../core/model/admin/dataset-profile/dataset-profile';
|
|
|
|
|
import { BaseFormModel } from '../../../../core/model/base-form-model';
|
|
|
|
|
import { DefaultValueEditorModel } from './default-value-editor-model';
|
|
|
|
|
import { AutoCompleteFieldDataEditorModel } from './field-data/auto-complete-field-data-editor-model';
|
|
|
|
|
import { BooleanDecisionFieldDataEditorModel } from './field-data/boolean-decision-field-data-editor-model';
|
|
|
|
|
import { CheckBoxFieldDataEditorModel } from './field-data/check-box-field-data-editor-model';
|
|
|
|
|
import { FieldDataEditorModel } from './field-data/field-data-editor-model';
|
|
|
|
|
import { FreeTextFieldDataEditorModel } from './field-data/free-text-field-data-editor-model';
|
|
|
|
|
import { RadioBoxFieldDataEditorModel } from './field-data/radio-box-field-data-editor-model';
|
|
|
|
|
import { TextAreaFieldDataEditorModel } from './field-data/text-area-field-data-editor-model';
|
|
|
|
|
import { WordListFieldDataEditorModel } from './field-data/word-list-field-data-editor-model';
|
|
|
|
|
import { ViewStyleEditorModel } from './view-style-editor-model';
|
|
|
|
|
import { VisibilityEditorModel } from './visibility-editor-model';
|
|
|
|
|
|
|
|
|
|
export class FieldEditorModel extends BaseFormModel {
|
|
|
|
|
|
|
|
|
|
public id: string;
|
|
|
|
|
// public title: string;
|
|
|
|
|
public defaultValue: DefaultValueEditorModel = new DefaultValueEditorModel();
|
|
|
|
|
public viewStyle: ViewStyleEditorModel = new ViewStyleEditorModel();
|
|
|
|
|
public page: number;
|
|
|
|
|
public ordinal: number;
|
|
|
|
|
public visible: VisibilityEditorModel = new VisibilityEditorModel();
|
|
|
|
|
public data: FieldDataEditorModel<any>;
|
2019-01-28 13:18:48 +01:00
|
|
|
|
public validations: ValidationType[] = [];
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
fromModel(item: Field): FieldEditorModel {
|
|
|
|
|
this.id = item.id;
|
|
|
|
|
if (item.defaultValue) { this.defaultValue = new DefaultValueEditorModel().fromModel(item.defaultValue); }
|
|
|
|
|
this.page = item.page;
|
|
|
|
|
this.ordinal = item.ordinal;
|
|
|
|
|
this.validations = item.validations;
|
|
|
|
|
this.viewStyle = new ViewStyleEditorModel().fromModel(item.viewStyle);
|
|
|
|
|
this.visible = new VisibilityEditorModel().fromModel(item.visible);
|
|
|
|
|
|
|
|
|
|
if (item.data) {
|
|
|
|
|
if (this.viewStyle.renderStyle === 'combobox') {
|
|
|
|
|
if (item.data.type === 'autocomplete') { this.data = new AutoCompleteFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (item.data.type === 'wordlist') { this.data = new WordListFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
} else {
|
|
|
|
|
if (this.viewStyle.renderStyle === 'radiobox') { this.data = new RadioBoxFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'checkBox') { this.data = new CheckBoxFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'textarea') { this.data = new TextAreaFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'freetext') { this.data = new FreeTextFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'booleanDecision') { this.data = new BooleanDecisionFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
|
const formGroup = this.formBuilder.group({
|
2019-02-04 17:10:22 +01:00
|
|
|
|
id:[this.id,[Validators.required,Validators.pattern('^[^<_>]+$')]],
|
2019-01-18 18:03:45 +01:00
|
|
|
|
// title: [this.title],
|
|
|
|
|
page: [this.page],
|
|
|
|
|
ordinal: [this.ordinal]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// formGroup.addControl("multiplicity", this.multiplicity.buildForm());
|
|
|
|
|
formGroup.addControl('validations', new FormControl(this.validations));
|
|
|
|
|
formGroup.addControl('defaultValue', this.defaultValue.buildForm());
|
|
|
|
|
formGroup.addControl('viewStyle', this.viewStyle.buildForm());
|
2019-02-04 17:10:22 +01:00
|
|
|
|
formGroup.addControl('visible', this.visible.buildForm());
|
2019-01-18 18:03:45 +01:00
|
|
|
|
//formGroup.addControl("data",this.data? this.data.buildForm():this.formBuilder.group({}));
|
|
|
|
|
if (this.data) { formGroup.addControl('data', this.data.buildForm()); }
|
2019-01-28 14:05:19 +01:00
|
|
|
|
else { formGroup.addControl('data', new WordListFieldDataEditorModel().buildForm()); }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|