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: './licensemodestysettings.component.html' }) export class LicenseModestySettings implements OnInit { lstAccountNumbers: any; lstLicenseSites: any; lstLicenseEditionModesty: any; license: License; updateModestySettingsFrm: FormGroup; error: any; alerts: string; modalAlerts: string; modalRef: BsModalRef; selectedSiteId: number = 0; isBuildingLevel: boolean = false; 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.updateModestySettingsFrm = this.fb.group({ licenseId: [0], accountNumber: ['', Validators.required], siteId: [0], lstModesty: [this.fb.array([])], }); this.GetLicenseAccounts(); } openModal(template: TemplateRef) { this.modalRef = this.modalService.show(template); } GetLicenseAccounts() { this.licenseService.GetLicenseAccounts(0) .subscribe(st => { this.lstAccountNumbers = st; }, error => this.error = error); } ShowModestyorSites() { this.lstLicenseEditionModesty = null; this.lstLicenseSites = null; this.selectedSiteId = 0; if(!this.isBuildingLevel){ this.GetLicenseEditionModesty(); } else{ this.licenseService.GetLicenseSites(this.license.AccountNumber) .subscribe(st => { this.lstLicenseSites = st; }, error => this.error = error); } } GetLicenseEditionModesty() { this.licenseService.GetLicenseModestySettings(this.license.LicenseId, this.selectedSiteId) .subscribe(st => { this.lstLicenseEditionModesty = st; this.updateModestySettingsFrm.setControl('lstModesty', this.fb.array(this.lstLicenseEditionModesty)); }, error => this.error = error); } LicenseSiteChanged(siteId: number){ this.selectedSiteId = siteId; if(this.selectedSiteId == 0) { this.lstLicenseEditionModesty = null; return; } this.GetLicenseEditionModesty(); } GetLicenseById() { if(this.license.LicenseId != 0) { this.licenseService.GetLicenseById(this.license.LicenseId) .subscribe(st => { this.license = st; this.updateModestySettingsFrm.controls['licenseId'].setValue(this.license.LicenseId); this.updateModestySettingsFrm.controls['accountNumber'].setValue(this.license.AccountNumber); }, error => this.error = error); } } AccountNumberChanged(LicenseId: number){ this.license.LicenseId = LicenseId; this.lstLicenseEditionModesty = null; this.lstLicenseSites = null; this.selectedSiteId = 0; this.isBuildingLevel = false; this.GetLicenseById(); } AfterUpdateData(data, template) { if (data.Status == "false") { this.alerts = "License modesty setings update unsuccessfull"; } else { this.modalAlerts = "

License modesty setings updated successfully

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