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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { WebService } from './../../providers/web.service';
import { ValidationService } from './../../providers/validation.service';
import { FormControl, FormGroup, FormBuilder, Validators, ValidationErrors } from '@angular/forms';
@Component({
selector: 'app-currency-add',
templateUrl: './currency-add.component.html',
styleUrls: ['./currency-add.component.scss']
})
export class CurrencyAddComponent implements OnInit {
currencyForm: FormGroup;
mobnumPattern = '^((\\+?)|0)?[0-9]{8,15}$';
emailPattern = '^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$';
currencySubmit: boolean;
lang = 'en';
error_msg: any[];
funcName: any;
loader: boolean;
responseError: any;
error: boolean;
success: boolean;
file: File;
constructor(
private router: Router,
private route: ActivatedRoute,
public vs: ValidationService,
public service: WebService,
private formBuilder: FormBuilder
) {
this.loader = false;
this.error = false;
this.success = false;
this.currencySubmit = false;
this.error_msg = this.vs.errorList[this.lang];
}
ngOnInit() {
this.currencyForm = this.formBuilder.group({
'name': ['', Validators.compose([Validators.required])],
'symbol': ['', Validators.compose([Validators.required])],
'flag': ['', Validators.compose([Validators.required])],
'rate': ['', Validators.compose([Validators.required])],
'start_from': ['', Validators.compose([Validators.required])]
});
}
onFileChange(event) {
if (event.target.files.length > 0) {
this.file = event.target.files[0];
}
console.log(this.file);
}
currencyProcess() {
const This = this;
this.error = false;
this.success = false;
console.log(this.currencyForm.value);
this.currencySubmit = true;
if (this.currencyForm.valid) {
this.loader = true;
const providerObj = this.currencyForm.value;
const post_data = this.prepareSave(providerObj);
this.funcName = 'currency_create';
this.service.post_data(this.funcName, post_data).subscribe(response => {
this.loader = false;
console.log(response);
if (response.code === 1) {
this.success = true;
this.currencySubmit = false;
this.currencyForm.reset();
} else {
this.error = true;
this.responseError = this.vs.errorCode[this.lang][response.errorCode];
}
}, (error) => {
this.error = false;
this.responseError = this.vs.errorCode[this.lang]['ER08'];
});
}
console.log('tested');
}
prepareSave(formHasImage): any {
const input = new FormData();
input.append('flag', this.file);
input.append('name', formHasImage.name);
input.append('symbol', formHasImage.symbol);
input.append('rate', formHasImage.rate);
input.append('start_from', formHasImage.start_from);
console.log(input);
return input;
}
cancelClick() {
this.router.navigate(['/checker/currency_list']);
}
goToPage(path: any, data = null) {
console.log(data);
this.router.navigateByUrl(path, {queryParams: data});
document.body.scrollTop = document.documentElement.scrollTop = 0;
}
logout() {
this.service.logout();
}
}