application.form.main.ts 3.11 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
import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types';
8
//import { ICourseFields } from '../../store/coursefields/coursefields.types';
9
import { IAppState } from '../../store/store';
10
import { VALID_NAMES_PATTERN, VALID_ADDRESS_PATTERN, VALID_ADDRESSTK_PATTERN, VALID_DIGITS_PATTERN } from '../../constants';
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

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>;
27
    //private courseFields$: Observable<ICourseFields>;
28
29
30

    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
            epaluser_id: [1,[]],
            name: ['ΝΙΚΟΣ', [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],
            telnum:  ['2610789789', [Validators.pattern(VALID_DIGITS_PATTERN),Validators.required]],
47
        });
48
      
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    };

    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;
        });
    }

63

64
65
    saveSelected() {
        this._sdfa.saveStudentDataFields([this.studentDataGroup.value]);
66
67
        this.router.navigate(['/region-schools-select']);
    }
68
69


70
71
    submitSelected() {
        this._sdfa.saveStudentDataFields([this.studentDataGroup.value]);
72
        this.router.navigate(['/application-submit']);
73
74
    }
}