argos/dmp-admin/src/app/section-form/section-form.component.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-11-27 14:35:00 +01:00
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Section } from '../models/Section';
import { FieldGroup } from '../models/FieldGroup';
import { FormArray } from '@angular/forms/src/model';
import { DatasetProfileModel } from '../models/DatasetProfileModel';
2017-11-27 14:35:00 +01:00
@Component({
selector: 'section-form',
templateUrl: './section-form.component.html',
styleUrls: []
})
export class SectionFormComponent {
@Input() form: FormGroup;
@Input() dataModel:Section;
@Input() index:number;
2017-11-27 14:35:00 +01:00
constructor(){ }
ngOnInit(){
2017-11-27 17:42:26 +01:00
//this.addGroupField(); //for new DatasetProfile
2017-11-27 14:35:00 +01:00
}
addGroupField(){
let fieldGroup:FieldGroup = new FieldGroup();
2017-11-27 17:42:26 +01:00
if(this.dataModel.fieldGroups)
this.dataModel.fieldGroups.push(fieldGroup);
2017-11-27 14:35:00 +01:00
(<FormArray>this.form.get("fieldGroups")).push(fieldGroup.buildForm());
}
DeleteFieldGroup(index){
this.dataModel.fieldGroups.splice(index, 1);
(<FormArray>this.form.get("fieldGroups")).removeAt(index)
}
addSectioninSection(){
let section:Section = new Section();
this.dataModel.sections.push(section);
(<FormArray>this.form.get("sections")).push(section.buildForm());
}
DeleteSectionInSection(index){
this.dataModel.sections.splice(index);
(<FormArray>this.form.get("sections")).removeAt(index);
}
2017-11-27 14:35:00 +01:00
}