1 | 'use strict'; |
||
2 | |||
3 | app.controller('ShopfloorController', function ( |
||
4 | $scope, |
||
5 | $rootScope, |
||
6 | $window, |
||
7 | $translate, |
||
8 | $uibModal, |
||
9 | CostCenterService, |
||
10 | ContactService, |
||
11 | ShopfloorService, |
||
12 | toaster, |
||
13 | SweetAlert) { |
||
14 | $scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); |
||
15 | $scope.exportdata = ''; |
||
16 | $scope.importdata = ''; |
||
17 | |||
18 | $scope.getAllCostCenters = function () { |
||
19 | let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
||
20 | CostCenterService.getAllCostCenters(headers, function (response) { |
||
21 | if (angular.isDefined(response.status) && response.status === 200) { |
||
22 | $scope.costcenters = response.data; |
||
23 | } else { |
||
24 | $scope.costcenters = []; |
||
25 | } |
||
26 | }); |
||
27 | }; |
||
28 | |||
29 | $scope.getAllContacts = function () { |
||
30 | let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
||
31 | ContactService.getAllContacts(headers, function (response) { |
||
32 | if (angular.isDefined(response.status) && response.status === 200) { |
||
33 | $scope.contacts = response.data; |
||
34 | } else { |
||
35 | $scope.contacts = []; |
||
36 | } |
||
37 | }); |
||
38 | }; |
||
39 | |||
40 | $scope.getAllShopfloors = function () { |
||
41 | let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
||
42 | ShopfloorService.getAllShopfloors(headers,function (response) { |
||
43 | if (angular.isDefined(response.status) && response.status === 200) { |
||
44 | $scope.shopfloors = response.data; |
||
45 | } else { |
||
46 | $scope.shopfloors = []; |
||
47 | } |
||
48 | }); |
||
49 | }; |
||
50 | |||
51 | $scope.addShopfloor = function () { |
||
52 | var modalInstance = $uibModal.open({ |
||
53 | templateUrl: 'views/settings/shopfloor/shopfloor.model.html', |
||
54 | controller: 'ModalAddShopfloorCtrl', |
||
55 | windowClass: "animated fadeIn", |
||
56 | resolve: { |
||
57 | params: function () { |
||
58 | return { |
||
59 | shopfloors: angular.copy($scope.shopfloors), |
||
60 | costcenters: angular.copy($scope.costcenters), |
||
61 | contacts: angular.copy($scope.contacts), |
||
62 | }; |
||
63 | } |
||
64 | } |
||
65 | }); |
||
66 | modalInstance.result.then(function (shopfloor) { |
||
67 | shopfloor.cost_center_id = shopfloor.cost_center.id; |
||
68 | shopfloor.contact_id = shopfloor.contact.id; |
||
69 | if (angular.isDefined(shopfloor.is_input_counted) == false) { |
||
70 | shopfloor.is_input_counted = false; |
||
71 | } |
||
72 | let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
||
73 | ShopfloorService.addShopfloor(shopfloor, headers, function (response) { |
||
74 | if (angular.isDefined(response.status) && response.status === 201) { |
||
75 | toaster.pop({ |
||
76 | type: "success", |
||
77 | title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
||
78 | body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", { template: $translate.instant("COMMON.SHOPFLOOR") }), |
||
79 | showCloseButton: true, |
||
80 | }); |
||
81 | $scope.$emit('handleEmitShopfloorChanged'); |
||
82 | } else { |
||
83 | toaster.pop({ |
||
84 | type: "error", |
||
85 | title: $translate.instant("TOASTER.ERROR_ADD_BODY", { template: $translate.instant("COMMON.SHOPFLOOR") }), |
||
86 | body: $translate.instant(response.data.description), |
||
87 | showCloseButton: true, |
||
88 | }); |
||
89 | } |
||
90 | }); |
||
91 | }, function () { |
||
92 | |||
93 | }); |
||
94 | $rootScope.modalInstance = modalInstance; |
||
95 | }; |
||
96 | |||
97 | $scope.editShopfloor = function(shopfloor) { |
||
98 | var modalInstance = $uibModal.open({ |
||
99 | windowClass: "animated fadeIn", |
||
100 | templateUrl: 'views/settings/shopfloor/shopfloor.model.html', |
||
101 | controller: 'ModalEditShopfloorCtrl', |
||
102 | resolve: { |
||
103 | params: function () { |
||
104 | return { |
||
105 | shopfloor: angular.copy(shopfloor), |
||
106 | costcenters: angular.copy($scope.costcenters), |
||
107 | contacts: angular.copy($scope.contacts) |
||
108 | }; |
||
109 | } |
||
110 | } |
||
111 | }); |
||
112 | |||
113 | modalInstance.result.then(function(modifiedShopfloor) { |
||
114 | console.log(modifiedShopfloor); |
||
0 ignored issues
–
show
Debugging Code
introduced
by
Loading history...
|
|||
115 | modifiedShopfloor.cost_center_id = modifiedShopfloor.cost_center.id; |
||
116 | modifiedShopfloor.contact_id = modifiedShopfloor.contact.id; |
||
117 | if (angular.isDefined(shopfloor.is_input_counted) == false) { |
||
118 | shopfloor.is_input_counted = false; |
||
119 | } |
||
120 | let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
||
121 | ShopfloorService.editShopfloor(modifiedShopfloor, headers, function (response) { |
||
122 | if (angular.isDefined(response.status) && response.status === 200) { |
||
123 | toaster.pop({ |
||
124 | type: "success", |
||
125 | title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
||
126 | body: $translate.instant("TOASTER.SUCCESS_UPDATE_BODY", { template: $translate.instant("COMMON.SHOPFLOOR") }), |
||
127 | showCloseButton: true, |
||
128 | }); |
||
129 | $scope.$emit('handleEmitShopfloorChanged'); |
||
130 | } else { |
||
131 | toaster.pop({ |
||
132 | type: "error", |
||
133 | title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", { template: $translate.instant("COMMON.SHOPFLOOR") }), |
||
134 | body: $translate.instant(response.data.description), |
||
135 | showCloseButton: true, |
||
136 | }); |
||
137 | } |
||
138 | }); |
||
139 | }, function () { |
||
140 | //do nothing; |
||
141 | }); |
||
142 | $rootScope.modalInstance = modalInstance; |
||
143 | }; |
||
144 | |||
145 | $scope.deleteShopfloor = function (shopfloor) { |
||
146 | SweetAlert.swal({ |
||
147 | title: $translate.instant("SWEET.TITLE"), |
||
148 | text: $translate.instant("SWEET.TEXT"), |
||
149 | type: "warning", |
||
150 | showCancelButton: true, |
||
151 | confirmButtonColor: "#DD6B55", |
||
152 | confirmButtonText: $translate.instant("SWEET.CONFIRM_BUTTON_TEXT"), |
||
153 | cancelButtonText: $translate.instant("SWEET.CANCEL_BUTTON_TEXT"), |
||
154 | closeOnConfirm: true, |
||
155 | closeOnCancel: true |
||
156 | }, |
||
157 | function (isConfirm) { |
||
158 | if (isConfirm) { |
||
159 | let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
||
160 | ShopfloorService.deleteShopfloor(shopfloor, headers, function (response) { |
||
161 | if (angular.isDefined(response.status) && response.status === 204) { |
||
162 | toaster.pop({ |
||
163 | type: "success", |
||
164 | title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
||
165 | body: $translate.instant("TOASTER.SUCCESS_DELETE_BODY", { template: $translate.instant("COMMON.SHOPFLOOR") }), |
||
166 | showCloseButton: true, |
||
167 | }); |
||
168 | $scope.$emit('handleEmitShopfloorChanged'); |
||
169 | } else { |
||
170 | toaster.pop({ |
||
171 | type: "error", |
||
172 | title: $translate.instant("TOASTER.ERROR_DELETE_BODY", { template: $translate.instant("COMMON.SHOPFLOOR") }), |
||
173 | body: $translate.instant(response.data.description), |
||
174 | showCloseButton: true, |
||
175 | }); |
||
176 | } |
||
177 | }); |
||
178 | } |
||
179 | }); |
||
180 | }; |
||
181 | |||
182 | $scope.exportShopfloor = function(shopfloor) { |
||
183 | let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
||
184 | ShopfloorService.exportShopfloor(shopfloor, headers, function(response) { |
||
185 | if (angular.isDefined(response.status) && response.status === 200) { |
||
186 | $scope.exportdata = JSON.stringify(response.data); |
||
187 | var modalInstance = $uibModal.open({ |
||
188 | windowClass: "animated fadeIn", |
||
189 | templateUrl: 'views/common/export.html', |
||
190 | controller: 'ModalExportCtrl', |
||
191 | resolve: { |
||
192 | params: function() { |
||
193 | return { |
||
194 | exportdata: angular.copy($scope.exportdata) |
||
195 | }; |
||
196 | } |
||
197 | } |
||
198 | }); |
||
199 | modalInstance.result.then(function() { |
||
200 | //do nothing; |
||
201 | }, function() { |
||
202 | //do nothing; |
||
203 | }); |
||
204 | $rootScope.modalInstance = modalInstance; |
||
205 | } else { |
||
206 | $scope.exportdata = null; |
||
207 | } |
||
208 | }); |
||
209 | }; |
||
210 | |||
211 | $scope.cloneShopfloor = function(shopfloor){ |
||
212 | let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
||
213 | ShopfloorService.cloneShopfloor(shopfloor, headers, function(response) { |
||
214 | if (angular.isDefined(response.status) && response.status === 201) { |
||
215 | toaster.pop({ |
||
216 | type: "success", |
||
217 | title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
||
218 | body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("COMMON.DATA_SOURCE")}), |
||
219 | showCloseButton: true, |
||
220 | }); |
||
221 | $scope.getAllShopfloors(); |
||
222 | $scope.$emit('handleEmitShopfloorChanged'); |
||
223 | }else { |
||
224 | toaster.pop({ |
||
225 | type: "error", |
||
226 | title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("COMMON.DATA_SOURCE")}), |
||
227 | body: $translate.instant(response.data.description), |
||
228 | showCloseButton: true, |
||
229 | }); |
||
230 | } |
||
231 | }); |
||
232 | }; |
||
233 | |||
234 | $scope.importShopfloor = function() { |
||
235 | var modalInstance = $uibModal.open({ |
||
236 | templateUrl: 'views/common/import.html', |
||
237 | controller: 'ModalImportCtrl', |
||
238 | windowClass: "animated fadeIn", |
||
239 | resolve: { |
||
240 | params: function() { |
||
241 | return { |
||
242 | }; |
||
243 | } |
||
244 | } |
||
245 | }); |
||
246 | modalInstance.result.then(function(importdata) { |
||
247 | let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
||
248 | ShopfloorService.importShopfloor(importdata, headers, function(response) { |
||
249 | if (angular.isDefined(response.status) && response.status === 201) { |
||
250 | toaster.pop({ |
||
251 | type: "success", |
||
252 | title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
||
253 | body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("COMMON.DATA_SOURCE")}), |
||
254 | showCloseButton: true, |
||
255 | }); |
||
256 | $scope.getAllShopfloors(); |
||
257 | $scope.$emit('handleEmitShopfloorChanged'); |
||
258 | } else { |
||
259 | toaster.pop({ |
||
260 | type: "error", |
||
261 | title: $translate.instant("TOASTER.ERROR_ADD_BODY", { template: $translate.instant("COMMON.DATA_SOURCE") }), |
||
262 | body: $translate.instant(response.data.description), |
||
263 | showCloseButton: true, |
||
264 | }); |
||
265 | } |
||
266 | }); |
||
267 | }, function() { |
||
268 | |||
269 | }); |
||
270 | $rootScope.modalInstance = modalInstance; |
||
271 | }; |
||
272 | |||
273 | $scope.getAllShopfloors(); |
||
274 | $scope.getAllCostCenters(); |
||
275 | $scope.getAllContacts(); |
||
276 | $scope.$on('handleBroadcastShopfloorChanged', function (event) { |
||
277 | $scope.getAllShopfloors(); |
||
278 | }); |
||
279 | }); |
||
280 | |||
281 | app.controller('ModalAddShopfloorCtrl', function ($scope, $uibModalInstance, params) { |
||
282 | |||
283 | $scope.operation = "SHOPFLOOR.ADD_SHOPFLOOR"; |
||
284 | $scope.costcenters = params.costcenters; |
||
285 | $scope.contacts = params.contacts; |
||
286 | $scope.ok = function () { |
||
287 | $uibModalInstance.close($scope.shopfloor); |
||
288 | }; |
||
289 | |||
290 | $scope.cancel = function () { |
||
291 | $uibModalInstance.dismiss('cancel'); |
||
292 | }; |
||
293 | }); |
||
294 | |||
295 | app.controller('ModalEditShopfloorCtrl', function ($scope, $uibModalInstance, params) { |
||
296 | $scope.operation = "SHOPFLOOR.EDIT_SHOPFLOOR"; |
||
297 | $scope.shopfloor = params.shopfloor; |
||
298 | $scope.costcenters = params.costcenters; |
||
299 | $scope.contacts = params.contacts; |
||
300 | |||
301 | $scope.ok = function () { |
||
302 | $uibModalInstance.close($scope.shopfloor); |
||
303 | }; |
||
304 | |||
305 | $scope.cancel = function () { |
||
306 | $uibModalInstance.dismiss('cancel'); |
||
307 | }; |
||
308 | }); |
||
309 |