Project

General

Profile

1
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3
import { formErrorRequiredFields } from '../../../domain/shared-messages';
4

    
5
@Component ({
6
  selector: 'compatibility-validate-step3',
7
  templateUrl: 'compatibility-validate-step3.component.html'
8
})
9

    
10
export class CompatibilityValidateStep3Component implements OnInit {
11
  errorMessage: string;
12

    
13
  @Input() valSets: string[];
14
  @Output() emmitObject: EventEmitter<any> = new EventEmitter();
15

    
16
  group: FormGroup;
17

    
18
  constructor (private fb: FormBuilder) {}
19

    
20
  ngOnInit () {
21
    this.group = this.fb.group({
22
      noOfRecordsInput : '',
23
      selectValSet : ['',Validators.required],
24
      xpathInput : ''
25
    });
26
    this.group.get('noOfRecordsInput').setValue(10);
27
    this.group.get('noOfRecordsInput').disable();
28
    this.group.get('xpathInput').disable();
29
  }
30

    
31
  chooseAll(all: boolean) {
32
    if (all) {
33
      this.group.get('noOfRecordsInput').disable();
34
    } else {
35
      this.group.get('noOfRecordsInput').enable();
36
    }
37
  }
38

    
39
  addXpath(xpath: boolean) {
40
    if (xpath) {
41
      this.group.get('xpathInput').enable();
42
    } else {
43
      this.group.get('xpathInput').disable();
44
    }
45
  }
46

    
47
  submitChanges() {
48
    if (this.group.valid) {
49
      this.errorMessage = '';
50
      let emitted: string [] = [];
51

    
52
      emitted.push(this.group.get('selectValSet').value);
53

    
54
      if ( this.group.get('noOfRecordsInput').enabled ) {
55
        emitted.push(this.group.get('noOfRecordsInput').value);
56
      } else {
57
        emitted.push('');
58
      }
59

    
60
      if ( this.group.get('xpathInput').enabled ) {
61
        emitted.push(this.group.get('xpathInput').value);
62
      } else {
63
        emitted.push('');
64
      }
65

    
66
      this.emmitObject.emit(emitted);
67

    
68
    } else {
69
      this.errorMessage = formErrorRequiredFields;
70
    }
71
  }
72
}
(6-6/6)