Newer
Older
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {FormBuilder, FormGroup, ValidatorFn, Validators} from '@angular/forms';
import {catchError, tap} from 'rxjs/operators';
import { of } from 'rxjs/internal/observable/of';
import { NotificationService } from '../../../service/notification/notification.service';
import { HeaderService } from '../../../service/header.service';
import { FunctionsService } from '../../../service/functions.service';
import {AppService} from '../../../service/app.service';
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import {TranslateService} from '@ngx-translate/core';
import {ActivatedRoute} from '@angular/router';
@Component({
selector: 'app-acknowledgement-reception',
templateUrl: 'acknowledgement-reception.component.html'
})
export class AcknowledgementReceptionComponent implements OnInit {
loading: boolean = false;
type: any;
number: any;
receivedDate: any;
reason: any;
reasonOther: any;
today: Date = new Date();
adminFormGroup: FormGroup;
constructor(
public http: HttpClient,
private notify: NotificationService,
private headerService: HeaderService,
public functions: FunctionsService,
public appService: AppService,
public translate: TranslateService,
private _formBuilder: FormBuilder,
private route: ActivatedRoute
) {
}
ngOnInit() {
this.route.params.subscribe(async () => {
this.headerService.setHeader(this.translate.instant('lang.arReception'));
const validatorNumber: ValidatorFn[] = [Validators.pattern(/(2C|2D|RW) ([0-9]{3} [0-9]{3} [0-9]{4}) ([0-9])/), Validators.required];
this.adminFormGroup = this._formBuilder.group({
type: ['', Validators.required],
number: ['', validatorNumber],
receivedDate: ['', Validators.required],
returnReason: ['', Validators.required],
returnReasonOther: ['', Validators.required]
});
this.loading = false;
});
}
receiveAcknowledgement() {
const data = {
type: this.type,
number: this.number,
receivedDate: this.receivedDate,
returnReason: this.reason,
returnReasonOther: this.reasonOther
};
if (this.type === 'distributed') {
if (!this.adminFormGroup.get('number').valid) {
this.notify.error(this.translate.instant('lang.fieldsNotValid'));
return;
}
} else {
if (!this.adminFormGroup.get('number').valid || !this.adminFormGroup.get('receivedDate').valid || !this.adminFormGroup.get('returnReason').valid) {
this.notify.error(this.translate.instant('lang.fieldsNotValid'));
return;
}
}
this.http.put('../rest/registeredMails/acknowledgement', data).pipe(
tap(() => {
this.type = '';
this.number = '';
this.receivedDate = '';
this.reason = '';
this.reasonOther = '';
}),
catchError((err) => {
this.notify.handleSoftErrors(err);
return of(false);
})
).subscribe();
}
}