licensemodulesettings.component.ts
4.72 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
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 { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
import { ConfirmService } from '../../shared/confirm/confirm.service';
import { LoadingService } from '../../shared/loading.service';
declare var $:JQueryStatic;
@Component({
templateUrl: './licensemodulesettings.component.html'
})
export class LicenseModuleSettings implements OnInit {
tempLstAccountNumbers: any;
lstModuleStatus: any;
license: License;
updateModuleSettingsFrm: FormGroup;
error: any;
alerts: string;
modalAlerts: string;
modalRef: BsModalRef;
LicenseId:number=0;
AccountNumber:string='';
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:'200px',placeholder_text_single:'Select Account',search_contains:true });
this.license = new License();
this.alerts = '';
this.updateModuleSettingsFrm = this.fb.group({
licenseId: [0],
accountNumber: [''],
lstModuleStatus: [this.fb.array([])],
});
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);
});
}
openModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template);
}
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);
}
GetLicenseModulesStatus() {
this.licenseService.GetLicenseModulesStatus(this.LicenseId)
.subscribe(st => {
this.lstModuleStatus = st;
this.updateModuleSettingsFrm.setControl('lstModuleStatus', this.fb.array(this.lstModuleStatus));
this._loadingService.HideLoading("global-loading");
}, error => this.error = <any>error);
}
AccountNumberChanged(LicenseId: number,AccountNumber:string) {
this._loadingService.ShowLoading("global-loading");
this.lstModuleStatus = null;
this.LicenseId=LicenseId;
this.AccountNumber=AccountNumber;
this.updateModuleSettingsFrm.controls['licenseId'].setValue(LicenseId);
this.updateModuleSettingsFrm.controls['accountNumber'].setValue(AccountNumber);
this.GetLicenseModulesStatus();
}
AfterUpdateData(data, template) {
if (data.Status == "false") {
this.alerts = "<span>License module status update unsuccessfull</span>";
} else {
this._confirmService.activate("License module status updated successfully.", "alertMsg");
}
this._loadingService.HideLoading("global-loading");
}
UpdateLicenseModulesStatus(template: TemplateRef<any>) {
this.alerts = '';
if (this.alerts == '') {
this._loadingService.ShowLoading("global-loading");
var obj = this.updateModuleSettingsFrm.value;
return this.licenseService.UpdateLicenseModulesStatus(obj)
.subscribe(
n => (this.AfterUpdateData(n, template)),
error => this.error = <any>error);
}
}
}