Project

General

Profile

1
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3
import { didntChooseBaseUrl, invalidCustomBaseUrl } from '../../../domain/shared-messages';
4
import { ValidatorService } from '../../../services/validator.service';
5

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

    
11
export class CompatibilityValidateStep1Component implements OnInit {
12
  group: FormGroup;
13
  errorMessage: string;
14

    
15
  @Input() baseUrlList: string[];
16

    
17
  @Output() emitObject: EventEmitter<any> = new EventEmitter();
18

    
19
  constructor(private fb: FormBuilder) {}
20

    
21
  ngOnInit() {
22
    this.group = this.fb.group({
23
      selectBaseUrl : '',
24
      customBaseUrl : ''
25
    });
26
    this.group.get('customBaseUrl').disable();
27
  }
28

    
29
  chooseUrl(choice: boolean){
30
    if (choice) {
31
      this.group.get('selectBaseUrl').enable();
32
      this.group.get('customBaseUrl').disable();
33
    } else {
34
      this.group.get('selectBaseUrl').disable();
35
      this.group.get('customBaseUrl').enable();
36
    }
37
  }
38

    
39
  submitForm() {
40
    if (this.group.get('selectBaseUrl').enabled){
41
      if ( this.group.get('selectBaseUrl').value) {
42
        this.emitObject.emit(this.group.get('selectBaseUrl').value);
43
        console.log(`selected baseUrl!`);
44
        this.errorMessage = '';
45
        return true;
46
      } else {
47
        this.errorMessage = didntChooseBaseUrl;
48
        return false;
49
      }
50
    } else {
51
      if ( this.group.get('customBaseUrl').value ) {
52
        this.emitObject.emit(this.group.get('customBaseUrl').value);
53
        console.log('added new baseUrl!');
54
        this.errorMessage = '';
55
        return true;
56
      } else {
57
        this.errorMessage = didntChooseBaseUrl;
58
        return false;
59
      }
60
    }
61
  }
62
}
(2-2/8)