1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
app.controller('TenantTypeController', function( |
4
|
|
|
$scope, |
5
|
|
|
$rootScope, |
6
|
|
|
$window, |
7
|
|
|
$translate, |
8
|
|
|
$uibModal, |
9
|
|
|
TenantTypeService, |
10
|
|
|
toaster, |
11
|
|
|
SweetAlert) { |
12
|
|
|
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); |
13
|
|
|
$scope.getAllTenantTypes = function() { |
14
|
|
|
let headers = { |
15
|
|
|
"User-UUID": $scope.cur_user.uuid, |
16
|
|
|
"Token": $scope.cur_user.token |
17
|
|
|
}; |
18
|
|
|
TenantTypeService.getAllTenantTypes(headers, function(response) { |
19
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
20
|
|
|
$scope.tenantTypes = response.data; |
21
|
|
|
} else { |
22
|
|
|
$scope.tenantTypes = []; |
23
|
|
|
} |
24
|
|
|
}); |
25
|
|
|
}; |
26
|
|
|
|
27
|
|
|
$scope.addTenantType = function() { |
28
|
|
|
var modalInstance = $uibModal.open({ |
29
|
|
|
templateUrl: 'views/settings/tenant/tenanttype.model.html', |
30
|
|
|
controller: 'ModalAddTenantTypeCtrl', |
31
|
|
|
windowClass: "animated fadeIn", |
32
|
|
|
resolve: { |
33
|
|
|
params: function() { |
34
|
|
|
return { |
35
|
|
|
tenantTypes: angular.copy($scope.tenantTypes) |
36
|
|
|
}; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
}); |
40
|
|
|
modalInstance.result.then(function(tenantType) { |
41
|
|
|
let headers = { |
42
|
|
|
"User-UUID": $scope.cur_user.uuid, |
43
|
|
|
"Token": $scope.cur_user.token |
44
|
|
|
}; |
45
|
|
|
TenantTypeService.addTenantType(tenantType, headers, function(response) { |
46
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
47
|
|
|
toaster.pop({ |
48
|
|
|
type: "success", |
49
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
50
|
|
|
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY",{template: $translate.instant("SETTING.TENANT_TYPE")}), |
51
|
|
|
showCloseButton: true, |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$scope.getAllTenantTypes(); |
55
|
|
|
$scope.$emit('handleEmitTenantTypeChanged'); |
56
|
|
|
} else { |
57
|
|
|
toaster.pop({ |
58
|
|
|
type: "error", |
59
|
|
|
title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("SETTING.TENANT_TYPE")}), |
60
|
|
|
body: $translate.instant(response.data.description), |
61
|
|
|
showCloseButton: true, |
62
|
|
|
}); |
63
|
|
|
} |
64
|
|
|
}); |
65
|
|
|
}, function() { |
66
|
|
|
|
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
$rootScope.modalInstance = modalInstance; |
70
|
|
|
}; |
71
|
|
|
|
72
|
|
|
$scope.editTenantType = function(tenantType) { |
73
|
|
|
var modalInstance = $uibModal.open({ |
74
|
|
|
templateUrl: 'views/settings/tenant/tenanttype.model.html', |
75
|
|
|
controller: 'ModalEditTenantTypeCtrl', |
76
|
|
|
windowClass: "animated fadeIn", |
77
|
|
|
resolve: { |
78
|
|
|
params: function() { |
79
|
|
|
return { |
80
|
|
|
tenantType: angular.copy(tenantType), |
81
|
|
|
tenantTypes: angular.copy($scope.tenantTypes) |
82
|
|
|
}; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
}); |
86
|
|
|
|
87
|
|
|
modalInstance.result.then(function(modifiedTenantType) { |
88
|
|
|
let headers = { |
89
|
|
|
"User-UUID": $scope.cur_user.uuid, |
90
|
|
|
"Token": $scope.cur_user.token }; |
91
|
|
|
TenantTypeService.editTenantType(modifiedTenantType, headers, function(response) { |
92
|
|
|
if(angular.isDefined(response.status) && response.status === 200){ |
93
|
|
|
toaster.pop({ |
94
|
|
|
type: "success", |
95
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
96
|
|
|
body: $translate.instant("TOASTER.SUCCESS_UPDATE_BODY", {template: $translate.instant("SETTING.TENANT_TYPE")}), |
97
|
|
|
showCloseButton: true, |
98
|
|
|
}); |
99
|
|
|
|
100
|
|
|
$scope.getAllTenantTypes(); |
101
|
|
|
$scope.$emit('handleEmitTenantTypeChanged'); |
102
|
|
|
}else{ |
103
|
|
|
toaster.pop({ |
104
|
|
|
type: "error", |
105
|
|
|
title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", {template: $translate.instant("SETTING.TENANT_TYPE")}), |
106
|
|
|
body: $translate.instant(response.data.description), |
107
|
|
|
showCloseButton: true, |
108
|
|
|
}); |
109
|
|
|
} |
110
|
|
|
}); |
111
|
|
|
}, function () { |
112
|
|
|
|
113
|
|
|
}); |
114
|
|
|
$rootScope.modalInstance = modalInstance; |
115
|
|
|
}; |
116
|
|
|
|
117
|
|
|
$scope.deleteTenantType = function(tenantType) { |
118
|
|
|
SweetAlert.swal({ |
119
|
|
|
title: $translate.instant("SWEET.TITLE"), |
120
|
|
|
text: $translate.instant("SWEET.TEXT"), |
121
|
|
|
type: "warning", |
122
|
|
|
showCancelButton: true, |
123
|
|
|
confirmButtonColor: "#DD6B55", |
124
|
|
|
confirmButtonText: $translate.instant("SWEET.CONFIRM_BUTTON_TEXT"), |
125
|
|
|
cancelButtonText: $translate.instant("SWEET.CANCEL_BUTTON_TEXT"), |
126
|
|
|
closeOnConfirm: true, |
127
|
|
|
closeOnCancel: true |
128
|
|
|
}, function(isConfirm) { |
129
|
|
|
if (isConfirm) { |
130
|
|
|
const headers = { |
131
|
|
|
"User-UUID": $scope.cur_user.uuid, |
132
|
|
|
"Token": $scope.cur_user.token |
133
|
|
|
}; |
134
|
|
|
TenantTypeService.deleteTenantType(tenantType, headers, function(response) { |
135
|
|
|
if (response.status === 204) { |
136
|
|
|
toaster.pop('success', $translate.instant("TOASTER.SUCCESS_TITLE"), |
137
|
|
|
$translate.instant("TOASTER.SUCCESS_DELETE_BODY", { template: $translate.instant("SETTING.TENANT_TYPE") }) |
138
|
|
|
); |
139
|
|
|
$scope.getAllTenantTypes(); |
140
|
|
|
} else { |
141
|
|
|
toaster.pop('error', $translate.instant("TOASTER.ERROR_TITLE"), |
142
|
|
|
$translate.instant("TOASTER.ERROR_DELETE_BODY", { template: $translate.instant("SETTING.TENANT_TYPE") }) |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
}); |
146
|
|
|
} |
147
|
|
|
}); |
148
|
|
|
}; |
149
|
|
|
|
150
|
|
|
$scope.getAllTenantTypes(); |
151
|
|
|
}); |
152
|
|
|
|
153
|
|
|
app.controller('ModalAddTenantTypeCtrl', function( |
154
|
|
|
$scope, |
155
|
|
|
$uibModalInstance, |
156
|
|
|
params |
157
|
|
|
) { |
158
|
|
|
$scope.operation = "SETTING.ADD_TENANT_TYPE"; |
159
|
|
|
$scope.tenantTypes = params.tenantTypes; |
160
|
|
|
$scope.tenantType = {}; |
161
|
|
|
|
162
|
|
|
$scope.ok = function() { |
163
|
|
|
$uibModalInstance.close($scope.tenantType); |
164
|
|
|
}; |
165
|
|
|
|
166
|
|
|
$scope.cancel = function() { |
167
|
|
|
$uibModalInstance.dismiss('cancel'); |
168
|
|
|
}; |
169
|
|
|
}); |
170
|
|
|
|
171
|
|
|
app.controller('ModalEditTenantTypeCtrl', function( |
172
|
|
|
$scope, |
173
|
|
|
$uibModalInstance, |
174
|
|
|
params |
175
|
|
|
) { |
176
|
|
|
$scope.operation = "SETTING.EDIT_TENANT_TYPE"; |
177
|
|
|
$scope.tenantType = params.tenantType; |
178
|
|
|
$scope.tenantTypes = params.tenantTypes; |
179
|
|
|
|
180
|
|
|
$scope.ok = function() { |
181
|
|
|
$uibModalInstance.close($scope.tenantType); |
182
|
|
|
}; |
183
|
|
|
|
184
|
|
|
$scope.cancel = function() { |
185
|
|
|
$uibModalInstance.dismiss('cancel'); |
186
|
|
|
}; |
187
|
|
|
}); |