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' @Component({ templateUrl: './editlicensebasicsettings.component.html' }) export class EditLicenseBasicSettings implements OnInit { lstAccountNumbers: any; lstCountry: any; lstState: any; license: License; updateLicenseBasicSettingsFrm: FormGroup; error: any; alerts: string; modalAlerts: string; modalRef: BsModalRef; constructor(private licenseService: LicenseService, private globalService: GlobalService, private router: Router, private activeRoute: ActivatedRoute, private fb: FormBuilder, private modalService: BsModalService) { } ngOnInit(): void { this.license = new License(); this.alerts = ''; this.updateLicenseBasicSettingsFrm = this.fb.group({ licenseId: [0], accountNumber: ['', Validators.required], licenseeFirstName: ['', Validators.required], licenseeLastName: ['', Validators.required], institutionName: ['', Validators.required], address1: ['', Validators.required], address2: [''], city: ['', Validators.required], stateId: [0], countryId: [0], zip: ['', Validators.required], emailId: ['', Validators.required], phone: ['', Validators.required], }); this.GetCountry(); this.GetState(); this.GetLicenseAccounts(); } openModal(template: TemplateRef) { this.modalRef = this.modalService.show(template); } 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); } GetLicenseAccounts() { this.licenseService.GetLicenseAccounts(0) .subscribe(st => { this.lstAccountNumbers = st; console.log(this.lstAccountNumbers); }, error => this.error = error); } GetLicenseById() { if(this.license.LicenseId != 0) { this.licenseService.GetLicenseById(this.license.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); }, error => this.error = error); } } AccountNumberChanged(LicenseId: number){ this.license.LicenseId = LicenseId; this.GetLicenseById(); } AfterUpdateData(data, template) { if (data.Status == "false") { this.alerts = "License update unsuccessfull"; } else { this.modalAlerts = "

License updated successfully

"; this.modalRef = this.modalService.show(template); } } UpdateLicenseBasicSettings(template: TemplateRef){ this.alerts = ''; if(this.alerts == ''){ var obj = this.updateLicenseBasicSettingsFrm.value; return this.licenseService.UpdateLicenseBasicSettings(obj) .subscribe( n => (this.AfterUpdateData(n, template)), error => this.error = error); } } }