application.form.main.ts 4.07 KB
Newer Older
1
import { Component, OnInit } from '@angular/core';
2
import { Observable } from 'rxjs/Rx';
3
4
5
6
import { Injectable } from "@angular/core";
import { StudentDataFieldsActions } from '../../actions/studentdatafields.actions';
import { Router } from '@angular/router';
import { NgRedux, select } from 'ng2-redux';
7
8
9
import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types';
import { ICourseFields } from '../../store/coursefields/coursefields.types';
import { IAppState } from '../../store/store';
10
import { VALID_NAMES_PATTERN, VALID_ADDRESS_PATTERN, VALID_ADDRESSTK_PATTERN, VALID_AMKA_PATTERN } from '../../constants';
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

import {
    FormBuilder,
    FormGroup,
    FormControl,
    Validators,
} from '@angular/forms';

@Component({
    selector: 'application-form-main',
    templateUrl: './application.form.main.html'
})

@Injectable() export default class StudentApplicationMain implements OnInit {

    private studentDataFields$: Observable<IStudentDataFields>;
    private courseFields$: Observable<ICourseFields>;

    public studentDataGroup: FormGroup;

31
32
33
34
    constructor(private fb: FormBuilder,
                private _sdfa: StudentDataFieldsActions,
                private _ngRedux: NgRedux<IAppState>,
                private router: Router) {
35
        this.studentDataGroup = this.fb.group({
36
            /*
37
38
39
40
41
42
43
44
45
46
            studentAmka: ['12346', Validators.required],
            studentFirstname: ['ΝΙΚΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            studentSurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            guardianFirstname: ['ΑΝΑΣΤΑΣΙΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            guardianSurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            regionAddress: ['ΓΙΑΝΝΙΤΣΩΝ 5', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            regionTK: ['26334', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            regionArea: ['ΠΑΤΡΑ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            certificateType: ['Απολυτήριο Λυκείου', Validators.required],
            relationToStudent: ['Μαθητής', Validators.required],
47
48
49
50
51
52
53
54
55
56
57
            */
            studentAmka: ['12346', [Validators.pattern(VALID_AMKA_PATTERN),Validators.required]],
            studentFirstname: ['ΝΙΚΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            studentSurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            guardianFirstname: ['ΑΝΑΣΤΑΣΙΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            guardianSurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            regionAddress: ['ΓΙΑΝΝΙΤΣΩΝ 5', [Validators.pattern(VALID_ADDRESS_PATTERN),Validators.required]],
            regionTK: ['26334', [Validators.pattern(VALID_ADDRESSTK_PATTERN),Validators.required]],
            regionArea: ['ΠΑΤΡΑ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
            certificateType: ['Απολυτήριο Λυκείου', Validators.required],
            relationToStudent: ['Μαθητής', Validators.required],
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        });
    };

    ngOnInit() {
        this.studentDataFields$ = this._ngRedux.select(state => {
            if (state.studentDataFields.size > 0) {
                state.studentDataFields.reduce(({}, studentDataField) => {
                    this.studentDataGroup.setValue(studentDataField);
                    return studentDataField;
                }, {});
            }
            return state.studentDataFields;
        });
    }

    saveSelected() {
        this._sdfa.saveStudentDataFields([this.studentDataGroup.value]);
75
76
77
78
79
        this.router.navigate(['/region-schools-select']);
    }
    submitSelected() {
        this._sdfa.saveStudentDataFields([this.studentDataGroup.value]);
        this.router.navigate(['/application-preview']);
80
81
    }
}