editlicensebasicsettings.component.ts
10.3 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import { Component, OnInit, AfterViewInit, Input, Output, EventEmitter, Pipe, PipeTransform, TemplateRef } from '@angular/core';
import { LicenseService } from './license.service';
import { GlobalService } from '../../shared/global';
import { Router, ActivatedRoute } from '@angular/router';
import { FormControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { License } from '../userentity/datamodel';
import { BsDatepickerModule } from 'ngx-bootstrap';
import { Http, Response } from '@angular/http';
import { DatePipe } from '@angular/common';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
import { ContenteditableModelDirective } from '../../shared/contenteditabledirective'
import { ConfirmService } from '../../shared/confirm/confirm.service';
import { LoadingService } from '../../shared/loading.service';
declare var $:JQueryStatic;
@Component({
templateUrl: './editlicensebasicsettings.component.html'
})
export class EditLicenseBasicSettings implements OnInit {
tempLstAccountNumbers: any;
lstCountry: any;
lstState: any;
license: License;
updateLicenseBasicSettingsFrm: FormGroup;
error: any;
alerts: string;
modalAlerts: string;
modalRef: BsModalRef;
ConvertedPhoneno: string;
MinusCharater: number;
LicenseId:number=0;
AccountNumber:string='';
IsUniteState:Boolean=false;
constructor(private _loadingService: LoadingService,private licenseService: LicenseService,
public globalService: GlobalService, private router: Router,
private activeRoute: ActivatedRoute, private fb: FormBuilder,
private modalService: BsModalService, private _confirmService: ConfirmService) { }
ngOnInit(): void {
this._loadingService.ShowLoading("global-loading");
$('#accountSelect').chosen({allow_single_deselect:true,width:'300px',placeholder_text_single:'Select Account',search_contains:true});
this.license = new License();
this.alerts = '';
this.updateLicenseBasicSettingsFrm = this.fb.group({
licenseId: [0],
accountNumber: ['', [Validators.required,this.noWhitespaceValidator]],
licenseeFirstName: ['', [Validators.required,this.noWhitespaceValidator]],
licenseeLastName: ['', [Validators.required,this.noWhitespaceValidator]],
institutionName: ['', [Validators.required,this.noWhitespaceValidator]],
address1: ['', [Validators.required,this.noWhitespaceValidator]],
address2: [''],
city: ['', [Validators.required,this.noWhitespaceValidator]],
stateId: [0, [Validators.min(1)]],
countryId: [0],
zip: ['', [Validators.required]],
emailId: ['', [Validators.required]],
//phone: ['', [Validators.required, Validators.pattern('^([0-9]{3})-([0-9]{3})-([0-9]{4})$')]],
phone: ['', [Validators.required]]
});
this.GetCountry();
this.GetState();
if (this.globalService.UserType > 2) {
this.tempLstAccountNumbers=[];
this.tempLstAccountNumbers.push({m_Item1:this.globalService.AccLicId,m_Item2:this.globalService.AccountNumber});
this.AccountNumberChanged(this.globalService.AccLicId,this.globalService.AccountNumber);
setTimeout(function(){
$('#accountSelect').prop('disabled', true).trigger("chosen:updated");
$('#accountSelect').trigger('chosen:updated');
}, 500);
this._loadingService.HideLoading("global-loading");
}
else
{
this.GetLicenseAccounts();
}
$('#accountSelect')
.on('change', (e, args) => {
var selectedValue = Number(args.selected);
var selectedText= $(".chosen-single span" ).text();
this.AccountNumberChanged(selectedValue,selectedText);
});
}
public noWhitespaceValidator(control: FormControl) {
// new validation for intial whaite space
//****Birendra *****/
var isValid=false;
if(control.value!=null)
{
var controlLen=control.value.length;
if(controlLen==undefined)//undefined for integer value
{
isValid=true;
}
else if(controlLen!=0)
{
const isWhitespace = (control.value || '').trim().length === 0;
isValid = !isWhitespace;
if(!isValid)
{
control.setValue('');
}
}
}
// can use also on page of input control
//
return isValid ? null: { 'whitespace': true };
}
onKeyUp(event: any) {
var mobno = event.target.value;
var countryName =$("#Country option:selected").text().trim();
if(mobno!="" && event.key!="Backspace")
{
if(countryName=="United States")
{
this.USFormatPhoneNumber(mobno);
}
else
{
this.OtherFormatPhoneNumber(mobno);
}
}
};
OtherFormatPhoneNumber(mobno:any)
{
//var regex = /\d+/g;
//var matches = mobno.match(regex); //extract digit only
//var currentNum= matches==null?"" :matches.join('');
this.updateLicenseBasicSettingsFrm.controls['phone'].setValue(mobno);
}
USFormatPhoneNumber(mobno:any)
{
var newformat="";
if(mobno!="" && mobno!=null)
{
var regex = /\d+/g;
var matches = mobno.match(regex); //extract digit only
var currentNum= matches==null?"" :matches.join('');
for(var ind=0;ind<currentNum.length;ind++)
{
if(newformat.length==3)
{
newformat=newformat+"-";
}
else if(newformat.length==7)
{
newformat=newformat+"-";
}
newformat=newformat+currentNum[ind];
}
}
this.updateLicenseBasicSettingsFrm.controls['phone'].setValue(newformat);
}
//get Property
get PhoneNumber() {
return this.updateLicenseBasicSettingsFrm.get('phone');
}
onCountryChange(event: any) {
//let contryName = event.target.options[event.target.options.selectedIndex].text;
this.UpdatePhoneValidation()
};
UpdatePhoneValidation()
{
var phoneno=this.PhoneNumber.value==null?"":this.PhoneNumber.value;
var countryName =$("#Country option:selected").text().trim();
if(countryName=="United States")
{
// validate first phone number
this.IsUniteState=true;
this.PhoneNumber.setValidators([Validators.required, Validators.pattern('^([0-9]{3})-([0-9]{3})-([0-9]{4})$')]);
this.PhoneNumber.updateValueAndValidity();
this.USFormatPhoneNumber(phoneno);
}
else
{
this.IsUniteState=false;
// this.PhoneNumber.setValidators([Validators.required, Validators.pattern('^[0-9]*$')]);
this.PhoneNumber.setValidators([Validators.required]);
this.PhoneNumber.updateValueAndValidity();
this.OtherFormatPhoneNumber(phoneno);
}
}
openModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template);
}
GetCountry() {
this.licenseService.GetCountry()
.subscribe(y => {
this.lstCountry = y;
}, error => this.error = <any>error);
}
GetState() {
this.licenseService.GetState()
.subscribe(st => { this.lstState = st; }, error => this.error = <any>error);
}
GetLicenseAccounts() {
this.tempLstAccountNumbers=[];
this.licenseService.GetLicenseAccounts(0)
.subscribe(st => {
var newOption = $('<option value=""></option>');
$('#accountSelect').append(newOption);
this.tempLstAccountNumbers=st;
setTimeout(function(){
$('#accountSelect').trigger('chosen:updated');
}, 500);
this._loadingService.HideLoading("global-loading");
}, error => this.error = <any>error);
}
GetLicenseById() {
if (this.LicenseId != 0) {
this.licenseService.GetLicenseById(this.LicenseId)
.subscribe(st => {
this.license = st;
this.updateLicenseBasicSettingsFrm.controls['licenseId'].setValue(this.license.LicenseId);
this.updateLicenseBasicSettingsFrm.controls['accountNumber'].setValue(this.license.AccountNumber);
this.updateLicenseBasicSettingsFrm.controls['licenseeFirstName'].setValue(this.license.LicenseeFirstName);
this.updateLicenseBasicSettingsFrm.controls['licenseeLastName'].setValue(this.license.LicenseeLastName);
this.updateLicenseBasicSettingsFrm.controls['institutionName'].setValue(this.license.InstitutionName);
this.updateLicenseBasicSettingsFrm.controls['address1'].setValue(this.license.Address1);
this.updateLicenseBasicSettingsFrm.controls['address2'].setValue(this.license.Address2);
this.updateLicenseBasicSettingsFrm.controls['city'].setValue(this.license.City);
this.updateLicenseBasicSettingsFrm.controls['stateId'].setValue(this.license.StateId);
this.updateLicenseBasicSettingsFrm.controls['countryId'].setValue(this.license.CountryId);
this.updateLicenseBasicSettingsFrm.controls['zip'].setValue(this.license.Zip);
this.updateLicenseBasicSettingsFrm.controls['emailId'].setValue(this.license.EmailId);
this.updateLicenseBasicSettingsFrm.controls['phone'].setValue(this.license.Phone);
this._loadingService.HideLoading("global-loading");
this.UpdatePhoneValidation();
},
error => this.error = <any>error);
}
}
AccountNumberChanged(LicenseId: number,AccountNumber:string) {
if (LicenseId == 0) {
this.updateLicenseBasicSettingsFrm.reset();
this.updateLicenseBasicSettingsFrm.controls['licenseId'].setValue(0);
this.updateLicenseBasicSettingsFrm.controls['countryId'].setValue(0);
this.updateLicenseBasicSettingsFrm.controls['stateId'].setValue(0);
return;
}
this._loadingService.ShowLoading("global-loading");
this.LicenseId=LicenseId;
this.AccountNumber=AccountNumber;
this.GetLicenseById();
return false;
}
AfterUpdateData(data, template) {
if (data.Status == "false") {
this.alerts = "<span>License profile update unsuccessfull.</span>";
} else {
this._confirmService.activate("License profile updated successfully.", "alertMsg");
}
this._loadingService.HideLoading("global-loading");
}
UpdateLicenseBasicSettings(template: TemplateRef<any>) {
this.alerts = '';
if (this.alerts == '') {
this._loadingService.ShowLoading("global-loading");
var obj = this.updateLicenseBasicSettingsFrm.value;
return this.licenseService.UpdateLicenseBasicSettings(obj)
.subscribe(
n => (this.AfterUpdateData(n, template)),
error => this.error = <any>error);
}
}
}