amka-fill.ts 2.53 KB
Newer Older
Open Source Developer's avatar
Open Source Developer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Rx';
import { Injectable } from "@angular/core";
import { AmkaFillsActions } from '../../actions/amkafill.actions';
import { NgRedux, select } from 'ng2-redux';
import { IAmkaFills } from '../../store/amkafill/amkafills.types';
import { IAppState } from '../../store/store';
import { AmkaCheckService} from '../../services/amkacheck-service';
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray
} from '@angular/forms';
import {AppSettings} from '../../app.settings';
Open Source Developer's avatar
commit    
Open Source Developer committed
17
 
Open Source Developer's avatar
Open Source Developer committed
18
19
20
21
22
23

@Component({
    selector: 'amka-fill',
    template: `
    
    <form [formGroup]="formGroup">
Open Source Developer's avatar
commit    
Open Source Developer committed
24
      
Open Source Developer's avatar
Open Source Developer committed
25
26
27
28
29
30
31
32
33
            <div class="form-group">
              <label for="studentAmka">ΑΜΚΑ μαθητή</label><input class="form-control" type="text" formControlName="name">
            </div>  
        <div class="row">
            <div class="col-md-2 col-md-offset-5">
                <button type="button" class="btn-primary btn-lg pull-center" (click)="saveSelected()">
                Συνέχεια<span class="glyphicon glyphicon-menu-right"></span>
                </button>
            </div>
Open Source Developer's avatar
commit    
Open Source Developer committed
34
35
36
            <div *ngIf="emptyselection==true">
                 Παρακαλώ συμπληρώστε το ΑΜΚΑ του μαθητή
            </div>
Open Source Developer's avatar
Open Source Developer committed
37
        </div>
Open Source Developer's avatar
a    
Open Source Developer committed
38
     </form>
Open Source Developer's avatar
Open Source Developer committed
39
40
41
42
43
44
45
46
   `
})

@Injectable() export default class AmkaFill implements OnInit {
    private amkafills$: Observable<IAmkaFills>;

    public formGroup: FormGroup;
    private respond: any;
Open Source Developer's avatar
commit    
Open Source Developer committed
47
    emptyselection = false ;
Open Source Developer's avatar
Open Source Developer committed
48
49
50
51
52
53
54
55
56
57
58
59
60

       constructor(private fb: FormBuilder,
                private _cas: AmkaCheckService,   
                private _cfa: AmkaFillsActions,
                private _ngRedux: NgRedux<IAppState>,
                private router: Router) {
       this.formGroup = this.fb.group({
            name: []
            });
        };

    ngOnInit() {

Open Source Developer's avatar
commit    
Open Source Developer committed
61
    
Open Source Developer's avatar
Open Source Developer committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

          this.amkafills$ = this._ngRedux.select(state => {
            if (state.amkafills.size > 0) {
                state.amkafills.reduce(({}, amkafill) => {
                    this.formGroup.setValue(amkafill);
                    return amkafill;
                }, {});
            }
            return state.amkafills;
        });

    }


    saveSelected() {
Open Source Developer's avatar
commit    
Open Source Developer committed
77
78
79
80
81
     if (this.formGroup.value.name == undefined) { 
              this.emptyselection = true;
       } 
      else
      { 
Open Source Developer's avatar
Open Source Developer committed
82
83
        this._cfa.saveAmkaFills(this.formGroup.value);  
        this.router.navigate(['/epal-class-select']);
Open Source Developer's avatar
commit    
Open Source Developer committed
84
      }
Open Source Developer's avatar
Open Source Developer committed
85
86
87
    }

}