33 lines
933 B
TypeScript
33 lines
933 B
TypeScript
import { JsonSerializer } from '../../utilities/JsonSerializer';
|
|
import { ListingItem } from '../common/ListingItem';
|
|
import { DataField } from './DataField';
|
|
import { FormGroup } from '@angular/forms';
|
|
|
|
export class WordListData extends DataField<WordListData> {
|
|
public type: string;
|
|
public options: Array<ListingItem>;
|
|
buildForm(): FormGroup {
|
|
const formGroup = this.formBuilder.group({
|
|
type: [this.type],
|
|
label: [this.label]
|
|
});
|
|
const optionsFormArray = new Array<FormGroup>();
|
|
if (this.options) {
|
|
this.options.forEach(item => {
|
|
const form: FormGroup = item.buildForm();
|
|
optionsFormArray.push(form);
|
|
});
|
|
}
|
|
formGroup.addControl('options', this.formBuilder.array(optionsFormArray));
|
|
|
|
return formGroup;
|
|
}
|
|
|
|
fromJSONObject(item: any): WordListData {
|
|
this.type = item.type;
|
|
this.options = JsonSerializer.fromJSONArray(item.options, ListingItem);
|
|
this.label = item.label;
|
|
return this;
|
|
}
|
|
}
|