2017-11-27 14:35:00 +01:00
|
|
|
import { Component, Input } from '@angular/core';
|
2017-12-07 14:57:20 +01:00
|
|
|
import { FormGroup, FormControl } from '@angular/forms';
|
2017-11-27 14:35:00 +01:00
|
|
|
import { Field } from '../models/Field';
|
|
|
|
import { Rule } from '../models/Rule';
|
2017-11-29 17:51:28 +01:00
|
|
|
import { Multiplicity } from '../models/Multiplicity';
|
2017-11-27 14:35:00 +01:00
|
|
|
import { FormArray } from '@angular/forms/src/model';
|
2017-12-07 14:57:20 +01:00
|
|
|
import { ComboboxComponent } from '../combobox/combobox-component';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'field-form',
|
|
|
|
templateUrl: './field-form.component.html',
|
|
|
|
styleUrls: []
|
|
|
|
})
|
|
|
|
|
|
|
|
export class FieldFormComponent {
|
2017-12-07 14:57:20 +01:00
|
|
|
@Input() form: FormGroup;
|
|
|
|
@Input() dataModel: Field;
|
|
|
|
@Input() showMultiplicity: boolean = true;
|
|
|
|
@Input() indexPath: string;
|
|
|
|
|
|
|
|
isFieldMultiplicityEnabled: boolean = false;
|
2017-11-27 14:35:00 +01:00
|
|
|
|
2017-12-07 14:57:20 +01:00
|
|
|
constructon() { }
|
2017-11-27 14:35:00 +01:00
|
|
|
|
2017-12-07 14:57:20 +01:00
|
|
|
ngOnInit() {
|
2017-12-13 13:57:19 +01:00
|
|
|
if(this.form.get("multiplicity"))
|
|
|
|
if (this.form.get("multiplicity").value.min >1 || this.form.get("multiplicity").value.max >1)
|
|
|
|
this.isFieldMultiplicityEnabled = true;
|
2017-12-07 14:57:20 +01:00
|
|
|
// this.addNewRule();
|
|
|
|
}
|
2017-11-27 14:35:00 +01:00
|
|
|
|
2017-12-07 14:57:20 +01:00
|
|
|
onIsFieldMultiplicityEnabledChange(isFieldMultiplicityEnabled: boolean) {
|
|
|
|
if (!isFieldMultiplicityEnabled) {
|
|
|
|
(<FormControl>this.form.get('multiplicity').get("min")).setValue(0);
|
|
|
|
(<FormControl>this.form.get('multiplicity').get("max")).setValue(0);
|
|
|
|
}
|
|
|
|
}
|
2017-11-29 17:51:28 +01:00
|
|
|
|
2017-12-07 14:57:20 +01:00
|
|
|
addNewRule() {
|
|
|
|
let rule: Rule = new Rule();
|
|
|
|
this.dataModel.visible.rules.push(rule);
|
|
|
|
(<FormArray>this.form.get("visible").get("rules")).push(rule.buildForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteRule(index) {
|
|
|
|
this.dataModel.visible.rules.splice(index, 1);
|
|
|
|
(<FormArray>this.form.get("visible").get("rules")).removeAt(index);
|
|
|
|
}
|
2017-11-27 14:35:00 +01:00
|
|
|
}
|