-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.ts
More file actions
62 lines (57 loc) · 1.82 KB
/
send.ts
File metadata and controls
62 lines (57 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
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
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
@Component({
templateUrl: './send.html',
})
export class EmbedSendDocumentComponent implements OnInit {
userForm!: FormGroup;
showiframe!: boolean;
showLoading!: boolean;
src!: SafeResourceUrl;
selectedFile!: File;
constructor(
private formBuilder: FormBuilder,
private http: HttpClient,
private sanitizer: DomSanitizer
) {}
onFileSelct(event: any): void {
this.selectedFile = <File>event.target.files[0];
}
onSubmit(): void {
if (this.userForm.invalid) {
console.warn('Fill required fields');
} else {
this.showLoading = true;
const formData = new FormData();
formData.append('name', this.userForm.value.name);
formData.append('email', this.userForm.value.email);
formData.append('file', this.selectedFile, this.selectedFile.name);
this.http
.post(
'http://localhost:8080/api/document/createEmbeddedRequestUrl',
formData
)
.subscribe((data: any) => {
sessionStorage.setItem('documentId', data.documentId);
sessionStorage.setItem('status', 'SEND');
this.userForm.reset();
this.showLoading = false;
this.showiframe = true;
this.src = this.sanitizer.bypassSecurityTrustResourceUrl(
data.sendUrl.toString()
);
});
}
}
ngOnInit() {
this.showiframe = false;
this.showLoading = false;
this.userForm = this.formBuilder.group({
file: ['', Validators.required],
name: ['', Validators.required],
email: ['', [Validators.required, Validators.email]],
});
}
}