import { Component, OnInit, AfterViewInit, Input, Output, EventEmitter, Pipe, PipeTransform,HostListener, 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, BsDatepickerConfig } 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 { NumberOnlyDirective } from '../../shared/numberonlydirective'; import { ConfirmService } from '../../shared/confirm/confirm.service'; import { LoadingService } from '../../shared/loading.service'; @Component({ templateUrl: './addlicense.component.html' }) export class AddLicense implements OnInit { lstLicenceType: any; lstCountry: any; lstState: any; lstLicense: any; lstAccountType: any; lstEdition: any; lstSecurityQuestion: any; lstEditionLogins: any; totalLogins: number = 0; license: License; insertUpdateLicenseFrm: FormGroup; error: any; alerts: string; modalAlerts: string; divClass: string = ''; topPos: string = '2000px'; datePipe: DatePipe = new DatePipe('en-US'); bsValue1: Date =new Date(); bsValue2: Date = null;//new Date(); bsValue3: Date = null;//new Date(); modalRef: BsModalRef; editionLoginsText: string; rowIndex: number = 0; ParamsObj: any; minDate = new Date(); startDate= new Date(); maxDate = new Date(9999, 11, 31); bsConfig: Partial; dateStartInvalid: boolean = false; dateEndInvalid: boolean = false; dateRenewInvalid: boolean = false; IsUniteState:Boolean=false; NumberOfRows:number=0; constructor(private _loadingService: LoadingService,private licenseService: LicenseService, private globalService: GlobalService, private router: Router, private activeRoute: ActivatedRoute, private fb: FormBuilder, private modalService: BsModalService,private _confirmService: ConfirmService) { } ngOnInit(): void { this.bsConfig = Object.assign({}, { containerClass: 'theme-dark-blue' }); this.divClass = 'col-sm-12'; this.license = new License(); this.license.TotalLogins = 0; this.alerts = ''; this.editionLoginsText = ''; this.insertUpdateLicenseFrm = this.fb.group({ licenseId: [0], accountNumber: ['', [Validators.required]], accountTypeId: [0, Validators.min(1)], productId: [''], licenseeFirstName: ['', [Validators.required,this.noWhitespaceValidator]], licenseeLastName: ['', [Validators.required,this.noWhitespaceValidator]], licenseTypeId: [1], institutionName: ['', [Validators.required,this.noWhitespaceValidator]], address1: ['', [Validators.required,this.noWhitespaceValidator]], address2: [''], city: ['', [Validators.required,this.noWhitespaceValidator]], stateId: [0, [Validators.min(1)]], countryId: [0, Validators.min(1)], zip: ['', [Validators.required]], emailId: ['', [Validators.required]], //phone: ['', [Validators.required, Validators.pattern('^([0-9]{3})-([0-9]{3})-([0-9]{4})$')]], phone: ['', [Validators.required]], editionLoginArr: this.fb.array([]), editionLogins: [''], totalLogins: [0], subscriptionPrice: [0, [Validators.required, Validators.pattern('[0-9.]*')]], subscriptionStartDate: [this.startDate, Validators.required], subscriptionEndDate: ['', Validators.required], noOfImages: ['', [Validators.required, Validators.pattern('[0-9]*')]], masterSiteUrl: ['a', [Validators.required]], siteUrlFrom: [''], siteUrlTo: [''], login: ['a', [Validators.required, Validators.minLength(8)]], password: ['a', [Validators.required, Validators.minLength(8)]], securityQuestionId: [0, Validators.min(1)], answer: ['a', [Validators.required,this.noWhitespaceValidator]], testLicenseEditionId: [1], creatorId: [this.globalService.loggedInUser.Id], renew: [false], renewDate: [''], //renewDate: ['', Validators.required], totalRenewals: [0], isActive: ['false'] }); this.GetLicenseType(); this.GetCountry(); this.GetState(); this.GetAccountType(); this.GetSecurityQuestions(); this.license.LicenseId = 0; this.license.LoginId = 'abcdefgh'; this.license.Password = 'abcdefgh'; this.license.SecurityQuestionId = 1; this.license.Answer = 'a'; this.insertUpdateLicenseFrm.controls['login'].setValue('abcdefgh'); this.insertUpdateLicenseFrm.controls['password'].setValue('abcdefgh'); this.insertUpdateLicenseFrm.controls['securityQuestionId'].setValue(1); this.insertUpdateLicenseFrm.controls['answer'].setValue('a'); this.licenseService.GetEditions() .subscribe(x => { this.lstEdition = x; this.lstEditionLogins = new Array(); this.lstEdition.forEach(element => { this.lstEditionLogins.push({ Id: element.Id, Title: element.Title, Login: 0 }); }); this.insertUpdateLicenseFrm.setControl('editionLoginArr', this.fb.array(this.lstEditionLogins)); this.activeRoute.queryParams .subscribe(params => { if (params['Id'] != null) { this.ParamsObj = params; this.license.LicenseId = +params['Id']; this.rowIndex = +params['row']; this.minDate = new Date(1110, 11, 1); this.GetLicenseById(); } }); }, error => this.error = error); } public ClearWhitespaceValidator(control: FormControl) { // clear white space //****Birendra *****/ var isValid=false; if(control.value!=null) { var inputvalue=control.value; var controlLen=inputvalue.length; if(controlLen==undefined)//undefined for integer value { isValid=true; } else if(controlLen!=0) { const isWhitespace = controlLen!=inputvalue.trim().length; isValid = !isWhitespace; if(!isValid) { control.setValue(inputvalue.trim()); } } } // can use also on page of input control // return isValid ? null: { 'whitespace': true }; } public noWhitespaceValidator(control: FormControl) { // new validation for intial white 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.insertUpdateLicenseFrm.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) { this.modalRef = this.modalService.show(template); } onChange(item: any, isChecked: boolean) { if (isChecked) { if (this.insertUpdateLicenseFrm.controls['licenseTypeId'].value == 3) { item.Checked = 1; item.Login = 0; } else { item.Checked = 1; item.Login = 1; } } else { item.Checked = 0; item.Login = 0; } this.OnLoginBlur(); } // clear alert on check/uncheck renew checkbox reNewChange(isChecked: boolean) { this.alerts = ''; this.NumberOfRows=0; //renew date if(isChecked) { this.insertUpdateLicenseFrm.controls['renewDate'].clearValidators(); this.insertUpdateLicenseFrm.controls['renewDate'].setValidators(Validators.required); } else { this.insertUpdateLicenseFrm.controls['renewDate'].clearValidators(); } this.insertUpdateLicenseFrm.controls['renewDate'].updateValueAndValidity(); if (this.insertUpdateLicenseFrm.controls['licenseTypeId'].value == 2) { this.insertUpdateLicenseFrm.controls['editionLoginArr'].value.forEach(element => { if(this.NumberOfRows >1) { this.alerts = "Please select one edition only."; } else{ if (element.Checked == 1 && element.Login > 0) { this.NumberOfRows+=1 } else if (element.Checked == 1) { this.NumberOfRows+=1 } } }); if(this.totalLogins>1) { this.alerts += "
For single license total login can not be more than one."; } } } DateChange(dateValue: any) { this.alerts = ''; this.NumberOfRows=0; if (this.insertUpdateLicenseFrm.controls['licenseTypeId'].value == 2) { this.insertUpdateLicenseFrm.controls['editionLoginArr'].value.forEach(element => { if(this.NumberOfRows >1) { this.alerts = "Please select one edition only."; } else{ if (element.Checked == 1 && element.Login > 0) { this.NumberOfRows+=1 } else if (element.Checked == 1) { this.NumberOfRows+=1 } } }); if(this.totalLogins>1) { this.alerts += "
For single license total login can not be more than one."; } } if (this.insertUpdateLicenseFrm.dirty) { if (dateValue._datepicker._elementRef.nativeElement.id == 'SubscriptionStartDate') { if (dateValue._bsValue == null) { if (dateValue._datepicker._elementRef.nativeElement.value != '') { this.dateStartInvalid = true; } else { this.dateStartInvalid = false; } } else { this.dateStartInvalid = false; this.insertUpdateLicenseFrm.controls['subscriptionStartDate'].setValue(dateValue._bsValue); } } if (dateValue._datepicker._elementRef.nativeElement.id == 'SubscriptionEndDate') { if (dateValue._bsValue == null) { if (dateValue._datepicker._elementRef.nativeElement.value != '') { this.dateEndInvalid = true; } else { this.dateEndInvalid = false; } } else { this.dateEndInvalid = false; this.insertUpdateLicenseFrm.controls['subscriptionEndDate'].setValue(dateValue._bsValue); } } if (dateValue._datepicker._elementRef.nativeElement.id == 'RenewDate') { if (dateValue._bsValue == null) { if (dateValue._datepicker._elementRef.nativeElement.value != '') { this.dateRenewInvalid = true; } else { this.dateRenewInvalid = false; } } else { this.dateRenewInvalid = false; this.insertUpdateLicenseFrm.controls['renewDate'].setValue(dateValue._bsValue); } } if (!this.dateStartInvalid && !this.dateEndInvalid && !this.dateRenewInvalid) { if (Date.parse(this.insertUpdateLicenseFrm.controls['subscriptionStartDate'].value) > Date.parse(this.insertUpdateLicenseFrm.controls['subscriptionEndDate'].value)) { this.alerts += 'Subscription start date must be less than the subscription end date
'; } } } } GetLicenseType() { this.licenseService.GetLicenceType() .subscribe(x => { this.lstLicenceType = x; }, error => this.error = error); } GetAccountType() { this.licenseService.GetAccountType() .subscribe(x => { this.lstAccountType = x; }, error => this.error = error); } GetSecurityQuestions() { this.licenseService.GetSecurityQuestions() .subscribe(x => { this.lstSecurityQuestion = x; }, error => this.error = error); } GetCountry() { this.licenseService.GetCountry() .subscribe(y => { this.lstCountry = y; }, error => this.error = error); } GetState() { this.licenseService.GetState() .subscribe(st => { this.lstState = st; }, error => this.error = error); } GetLicenseById() { if (this.license.LicenseId != 0) { this.licenseService.GetLicenseById(this.license.LicenseId) .subscribe(st => { this.license = st; if (this.license.LicenseId > 0) { this.license.LoginId = 'abcdefgh'; this.license.Password = 'abcdefgh'; this.license.SecurityQuestionId = 1; this.license.Answer = 'a'; } if (this.license.ProductKey == null) { this.license.ProductKey = ''; } if (this.license.LicenseTypeId != 3) { this.license.MasterSiteUrl = 'a'; } if (this.license.SiteUrlFrom == null) { this.license.SiteUrlFrom = ''; } if (this.license.SiteUrlTo == null) { this.license.SiteUrlTo = ''; } this.LicenseTypeChanged(this.license.LicenseTypeId,this.license.SubscriptionStartDate); this.insertUpdateLicenseFrm.controls['licenseId'].setValue(this.license.LicenseId); this.insertUpdateLicenseFrm.controls['licenseTypeId'].setValue(this.license.LicenseTypeId); this.insertUpdateLicenseFrm.controls['accountNumber'].setValue(this.license.AccountNumber); this.insertUpdateLicenseFrm.controls['accountTypeId'].setValue(this.license.AccountTypeId); this.insertUpdateLicenseFrm.controls['productId'].setValue(this.license.ProductKey); this.insertUpdateLicenseFrm.controls['licenseeFirstName'].setValue(this.license.LicenseeFirstName); this.insertUpdateLicenseFrm.controls['licenseeLastName'].setValue(this.license.LicenseeLastName); this.insertUpdateLicenseFrm.controls['institutionName'].setValue(this.license.InstitutionName); this.insertUpdateLicenseFrm.controls['address1'].setValue(this.license.Address1); this.insertUpdateLicenseFrm.controls['address2'].setValue(this.license.Address2); this.insertUpdateLicenseFrm.controls['city'].setValue(this.license.City); this.insertUpdateLicenseFrm.controls['stateId'].setValue(this.license.StateId); this.insertUpdateLicenseFrm.controls['countryId'].setValue(this.license.CountryId); this.insertUpdateLicenseFrm.controls['zip'].setValue(this.license.Zip); this.insertUpdateLicenseFrm.controls['emailId'].setValue(this.license.EmailId); this.insertUpdateLicenseFrm.controls['editionLogins'].setValue(this.license.EditionLogins); this.insertUpdateLicenseFrm.controls['totalLogins'].setValue(this.license.TotalLogins); this.insertUpdateLicenseFrm.controls['subscriptionPrice'].setValue(this.license.Price); this.insertUpdateLicenseFrm.controls['subscriptionStartDate'].setValue(this.datePipe.transform(this.license.SubscriptionStartDate, 'MM/dd/yyyy')); this.insertUpdateLicenseFrm.controls['subscriptionEndDate'].setValue(this.datePipe.transform(this.license.SubscriptionEndDate, 'MM/dd/yyyy')); this.insertUpdateLicenseFrm.controls['renewDate'].setValue(this.datePipe.transform(this.license.RenewDate, 'MM/dd/yyyy')); this.insertUpdateLicenseFrm.controls['noOfImages'].setValue(this.license.NoOfImages); this.insertUpdateLicenseFrm.controls['masterSiteUrl'].setValue(this.license.MasterSiteUrl); this.insertUpdateLicenseFrm.controls['siteUrlFrom'].setValue(this.license.SiteUrlFrom); this.insertUpdateLicenseFrm.controls['siteUrlTo'].setValue(this.license.SiteUrlTo); this.insertUpdateLicenseFrm.controls['login'].setValue(this.license.LoginId); this.insertUpdateLicenseFrm.controls['password'].setValue(this.license.Password); this.insertUpdateLicenseFrm.controls['securityQuestionId'].setValue(this.license.SecurityQuestionId); this.insertUpdateLicenseFrm.controls['answer'].setValue(this.license.Answer); this.insertUpdateLicenseFrm.controls['totalRenewals'].setValue(this.license.TotalRenewals); this.insertUpdateLicenseFrm.controls['renew'].setValue(false); //this.insertUpdateLicenseFrm.controls['creatorId'].setValue(this.license.UserId); if (this.license.IsActive) { this.insertUpdateLicenseFrm.controls['isActive'].setValue('true'); } else { this.insertUpdateLicenseFrm.controls['isActive'].setValue('false'); } this.insertUpdateLicenseFrm.controls['phone'].setValue(this.license.Phone); // validate first phone number this.UpdatePhoneValidation(); if (this.license.EditionLogins == null) return; var TempArr = this.license.EditionLogins.split('|'); this.lstEditionLogins = new Array(); this.lstEdition.forEach(element => { if (this.license.LicenseTypeId == 4) { if (element.Id == 1 || element.Id == 3) { var Check: boolean = false; TempArr.forEach(elm => { var TempInnerArr = elm.split('-'); if (TempInnerArr[0] == element.Id) { this.lstEditionLogins.push({ Id: element.Id, Title: element.Title, Login: parseInt(TempInnerArr[1]), Checked: 1 }); Check = true; } }); if (!Check) { this.lstEditionLogins.push({ Id: element.Id, Title: element.Title, Login: 0, Checked: 0 }); } } } else { var Check: boolean = false; TempArr.forEach(elm => { var TempInnerArr = elm.split('-'); if (TempInnerArr[0] == element.Id) { this.lstEditionLogins.push({ Id: element.Id, Title: element.Title, Login: parseInt(TempInnerArr[1]), Checked: 1 }); Check = true; } }); if (!Check) { this.lstEditionLogins.push({ Id: element.Id, Title: element.Title, Login: 0, Checked: 0 }); } } }); this.insertUpdateLicenseFrm.setControl('editionLoginArr', this.fb.array(this.lstEditionLogins)); this.OnLoginBlur(); }, error => this.error = error); } } AfterInsertData(data, template) { if (data.Status == "false") { this.alerts = "License save unsuccessfull."; } else { if(this.insertUpdateLicenseFrm.controls['licenseTypeId'].value==4) { this._confirmService.activate("License saved successfully. Mail has been sent", "alertMsg"); } else{ this._confirmService.activate("License saved successfully.", "alertMsg"); } } this._loadingService.HideLoading("global-loading"); } AfterUpdateData(data, template) { if (data.Status == "false") { this.alerts = "License update unsuccessfull."; } else { this._confirmService.activate("License updated successfully.", "alertMsg"); } this._loadingService.HideLoading("global-loading"); } OnLoginBlur() { this.totalLogins = 0; this.NumberOfRows=0; this.alerts=''; this.editionLoginsText = ''; if (this.insertUpdateLicenseFrm.controls['licenseTypeId'].value == 3) { this.insertUpdateLicenseFrm.controls['editionLoginArr'].value.forEach(element => { if (element.Checked == 1) { this.editionLoginsText += element.Id.toString() + '-' + element.Login + '|'; } }); } else if (this.insertUpdateLicenseFrm.controls['licenseTypeId'].value == 2) { this.insertUpdateLicenseFrm.controls['editionLoginArr'].value.forEach(element => { if(this.NumberOfRows >1) { this.alerts = "Please select one edition only."; } else{ if (element.Checked == 1 && element.Login > 0) { this.editionLoginsText += element.Id.toString() + '-' + element.Login + '|'; this.totalLogins += parseInt(element.Login); this.NumberOfRows+=1 } else if (element.Checked == 1) { this.NumberOfRows+=1 } } }); if(this.totalLogins>1) { this.alerts += "
For single license total login can not be more than one."; } } else { this.insertUpdateLicenseFrm.controls['editionLoginArr'].value.forEach(element => { if (element.Checked == 1 && element.Login > 0) { this.editionLoginsText += element.Id.toString() + '-' + element.Login + '|'; this.totalLogins += parseInt(element.Login); } }); } if (this.editionLoginsText != '') { this.editionLoginsText = this.editionLoginsText.substr(0, this.editionLoginsText.length - 1); } this.license.TotalLogins = this.totalLogins; this.insertUpdateLicenseFrm.controls['totalLogins'].setValue(this.totalLogins); } OnAccountNoBlur(AccountNo: string) { if (this.license.LicenseId == 0) { this.alerts = this.alerts.replace('Account number already exists. Enter a different account number.', ''); this.licenseService.CheckAccountNumber(AccountNo) .subscribe( response => { if (response == 'True') { this.alerts += 'Account number already exists. Enter a different account number.'; } }, error => this.error = error); } } LicenseTypeChanged(LicenseTypeId: number,startDate: Date) { var currentDate = new Date(); if(startDate==undefined) { this.insertUpdateLicenseFrm.controls['subscriptionStartDate'].setValue(currentDate); } this.totalLogins = 0; this.editionLoginsText = ''; this.license.TotalLogins = this.totalLogins; this.insertUpdateLicenseFrm.controls['noOfImages'].setValue(''); this.insertUpdateLicenseFrm.controls['securityQuestionId'].setValue(0); this.insertUpdateLicenseFrm.controls['answer'].setValue(''); this.insertUpdateLicenseFrm.controls['login'].setValue(''); this.insertUpdateLicenseFrm.controls['password'].setValue(''); this.insertUpdateLicenseFrm.controls['subscriptionPrice'].setValue(''); this.insertUpdateLicenseFrm.controls['masterSiteUrl'].setValue(''); this.insertUpdateLicenseFrm.controls['accountNumber'].setValue(''); this.lstEditionLogins = new Array(); this.lstEdition.forEach(element => { this.lstEditionLogins.push({ Id: element.Id, Title: element.Title, Login: 0 }); }); this.insertUpdateLicenseFrm.setControl('editionLoginArr', this.fb.array(this.lstEditionLogins)); if (LicenseTypeId == 1) { this.insertUpdateLicenseFrm.controls['securityQuestionId'].setValue(1); this.insertUpdateLicenseFrm.controls['answer'].setValue('a'); this.insertUpdateLicenseFrm.controls['login'].setValue('abcdefgh'); this.insertUpdateLicenseFrm.controls['password'].setValue('abcdefgh'); this.insertUpdateLicenseFrm.controls['masterSiteUrl'].setValue('a'); } if (LicenseTypeId == 2) { this.insertUpdateLicenseFrm.controls['masterSiteUrl'].setValue('a'); } if (LicenseTypeId == 3) { this.insertUpdateLicenseFrm.controls['securityQuestionId'].setValue(1); this.insertUpdateLicenseFrm.controls['answer'].setValue('a'); this.insertUpdateLicenseFrm.controls['login'].setValue('abcdefgh'); this.insertUpdateLicenseFrm.controls['password'].setValue('abcdefgh'); } if (LicenseTypeId == 4) { this.lstEditionLogins = new Array(); this.lstEdition.forEach(element => { if (element.Id == 1 || element.Id == 3) { this.lstEditionLogins.push({ Id: element.Id, Title: element.Title, Login: 0 }); } }); this.insertUpdateLicenseFrm.setControl('editionLoginArr', this.fb.array(this.lstEditionLogins)); this.insertUpdateLicenseFrm.controls['securityQuestionId'].setValue(1); this.insertUpdateLicenseFrm.controls['answer'].setValue('a'); this.insertUpdateLicenseFrm.controls['login'].setValue('abcdefgh'); this.insertUpdateLicenseFrm.controls['password'].setValue('abcdefgh'); this.insertUpdateLicenseFrm.controls['masterSiteUrl'].setValue('a'); this.insertUpdateLicenseFrm.controls['accountNumber'].setValue('a'); } if (LicenseTypeId == 5) { this.insertUpdateLicenseFrm.controls['noOfImages'].setValue('5'); this.insertUpdateLicenseFrm.controls['securityQuestionId'].setValue(1); this.insertUpdateLicenseFrm.controls['answer'].setValue('a'); this.insertUpdateLicenseFrm.controls['subscriptionPrice'].setValue('5'); this.insertUpdateLicenseFrm.controls['masterSiteUrl'].setValue('a'); this.editionLoginsText = ' '; } } TestLicenseEditionChanged(EditionId: number) { this.insertUpdateLicenseFrm.controls['testLicenseEditionId'].setValue(EditionId); } InsertUpdateLicense(template: TemplateRef) { this.alerts = ''; if (Date.parse(this.insertUpdateLicenseFrm.controls['subscriptionStartDate'].value) > Date.parse(this.insertUpdateLicenseFrm.controls['subscriptionEndDate'].value)) { this.alerts = 'Subscription start date must be lower than subscription end date
'; } if (this.insertUpdateLicenseFrm.controls['renew'].value == true){ if (Date.parse(this.insertUpdateLicenseFrm.controls['subscriptionStartDate'].value) < Date.parse(this.license.SubscriptionEndDate.toString())) { this.alerts += 'The new subscription start date should be greater than the previous subscription end date('+this.datePipe.transform(this.license.SubscriptionEndDate, 'MM/dd/yyyy')+')'; } } this.editionLoginsText = ''; if (this.insertUpdateLicenseFrm.controls['licenseTypeId'].value == 3) { this.insertUpdateLicenseFrm.controls['editionLoginArr'].value.forEach(element => { if (element.Checked == 1) { this.editionLoginsText += element.Id.toString() + '-' + element.Login + '|'; } }); } else { this.insertUpdateLicenseFrm.controls['editionLoginArr'].value.forEach(element => { if (element.Checked > 0) { if(element.Login=='') { //set 0 edition for update license this.editionLoginsText += element.Id.toString() + '-' + 0 + '|'; } else { this.editionLoginsText += element.Id.toString() + '-' + element.Login + '|'; } } }); } if (this.editionLoginsText != '') { this.editionLoginsText = this.editionLoginsText.substr(0, this.editionLoginsText.length - 1); } this.insertUpdateLicenseFrm.controls['editionLogins'].setValue(this.editionLoginsText); var obj = this.insertUpdateLicenseFrm.value; if (obj.licenseId == 0) { this.licenseService.CheckAccountNumber(this.insertUpdateLicenseFrm.controls['accountNumber'].value) .subscribe( response => { if (response == 'True') { this.alerts += 'Account number already exists. Enter a different account number.'; } if (this.alerts == '') { this._loadingService.ShowLoading("global-loading"); return this.licenseService.InsertLicense(obj) .subscribe( n => (this.AfterInsertData(n, template)), error => this.error = error); } }, error => this.error = error); } else { if (this.insertUpdateLicenseFrm.controls['renew'].value && this.insertUpdateLicenseFrm.controls['renewDate'].value == undefined) { this.alerts = 'Renew date is required'; } if (this.alerts == '') { //console.log(this.insertUpdateLicenseFrm.controls['subscriptionStartDate'].value + ', ' + this.insertUpdateLicenseFrm.controls['subscriptionEndDate'].value + ', ' + this.insertUpdateLicenseFrm.controls['renewDate'].value); // console.log(obj.subscriptionStartDate + ', ' + obj.subscriptionEndDate + ', ' + obj.renewDate); this._loadingService.ShowLoading("global-loading"); return this.licenseService.UpdateLicense(obj) .subscribe( n => (this.AfterUpdateData(n, template)), error => this.error = error); } } } CancelAddEdit() { this.router.navigate(['/searchlicense'], { queryParams: this.ParamsObj , skipLocationChange: true }); } OnCountryChange(element: any) { this.license.CountryId = parseInt(element.value); if (this.lstCountry.find(C => C.Id == this.license.CountryId).CountryName != "United States") { this.license.StateId = this.lstState.find(C => C.StateName == "Other").Id; this.insertUpdateLicenseFrm.controls['stateId'].setValue(this.license.StateId); } else { this.license.StateId = 0; this.insertUpdateLicenseFrm.controls['stateId'].setValue(this.license.StateId); } this.UpdatePhoneValidation(); } OnStateChange(element: any) { this.license.StateId = parseInt(element.value); if (this.lstState.find(C => C.Id == this.license.StateId).StateName != "Other") { this.license.CountryId = this.lstCountry.find(C => C.CountryName == "United States").Id; this.insertUpdateLicenseFrm.controls['countryId'].setValue(this.license.CountryId); } else { this.license.CountryId = 0; this.insertUpdateLicenseFrm.controls['countryId'].setValue(this.license.CountryId); } } SubscriptionPriceBlur() { if(isNaN(parseFloat(this.insertUpdateLicenseFrm.controls['subscriptionPrice'].value))) return; this.insertUpdateLicenseFrm.controls['subscriptionPrice'].setValue(parseFloat( this.insertUpdateLicenseFrm.controls['subscriptionPrice'].value).toFixed(2)); } onKeyPress($event) { if ($event.key == '.') { var tempArr = this.insertUpdateLicenseFrm.controls['subscriptionPrice'].value.split('.'); if (tempArr.length > 2) { this.insertUpdateLicenseFrm.controls['subscriptionPrice'].setValue(tempArr[0] + '.' + tempArr[1]); } } if(this.insertUpdateLicenseFrm.controls['subscriptionPrice'].value.length > 8){ this.insertUpdateLicenseFrm.controls['subscriptionPrice'].setValue(this.insertUpdateLicenseFrm.controls['subscriptionPrice'].value.substr(0, 8)); } } }