licensemodestysettings.component.ts
4.58 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
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<any>) {
this.modalRef = this.modalService.show(template);
}
GetLicenseAccounts() {
this.licenseService.GetLicenseAccounts(0)
.subscribe(st => { this.lstAccountNumbers = st; }, error => this.error = <any>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 = <any>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 = <any>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 = <any>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 = "<span>License modesty setings update unsuccessfull</span>";
} else {
this.modalAlerts = "<p>License modesty setings updated successfully</p>";
this.modalRef = this.modalService.show(template);
}
}
UpdateLicenseModestySettings(template: TemplateRef<any>){
this.alerts = '';
if(this.alerts == ''){
var obj = this.updateModestySettingsFrm.value;
return this.licenseService.UpdateLicenseModestySettings(obj)
.subscribe(
n => (this.AfterUpdateData(n, template)),
error => this.error = <any>error);
}
}
}