1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
app.controller('SVGController', function( |
4
|
|
|
$scope, |
5
|
|
|
$rootScope, |
6
|
|
|
$window, |
7
|
|
|
$translate, |
8
|
|
|
$uibModal, |
9
|
|
|
SVGService, |
10
|
|
|
toaster, |
11
|
|
|
SweetAlert) { |
12
|
|
|
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); |
13
|
|
|
$scope.exportdata = ''; |
14
|
|
|
$scope.importdata = ''; |
15
|
|
|
$scope.current_svg = null; |
16
|
|
|
|
17
|
|
|
$scope.getAllSVGs = function() { |
18
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token, "QUICKMODE": true }; |
19
|
|
|
SVGService.getAllSVGs(headers, function(response) { |
20
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
21
|
|
|
$scope.svgs = response.data; |
22
|
|
|
} else { |
23
|
|
|
$scope.svgs = []; |
24
|
|
|
} |
25
|
|
|
}); |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
$scope.addSVG = function() { |
29
|
|
|
var modalInstance = $uibModal.open({ |
30
|
|
|
templateUrl: 'views/settings/svg/svg.model.html', |
31
|
|
|
controller: 'ModalAddSVGCtrl', |
32
|
|
|
windowClass: "animated fadeIn", |
33
|
|
|
}); |
34
|
|
|
modalInstance.result.then(function(svg) { |
35
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
36
|
|
|
SVGService.addSVG(svg, headers, function (response) { |
37
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
38
|
|
|
toaster.pop({ |
39
|
|
|
type: "success", |
40
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
41
|
|
|
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("COMMON.SVG")}), |
42
|
|
|
showCloseButton: true, |
43
|
|
|
}); |
44
|
|
|
$scope.getAllSVGs(); |
45
|
|
|
$scope.$emit('handleEmitSVGChanged'); |
46
|
|
|
} else { |
47
|
|
|
toaster.pop({ |
48
|
|
|
type: "error", |
49
|
|
|
title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("COMMON.SVG")}), |
50
|
|
|
body: $translate.instant(response.data.description), |
51
|
|
|
showCloseButton: true, |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
}); |
55
|
|
|
}, function() { |
56
|
|
|
|
57
|
|
|
}); |
58
|
|
|
$rootScope.modalInstance = modalInstance; |
59
|
|
|
}; |
60
|
|
|
|
61
|
|
|
$scope.editSVG = function(svg) { |
62
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
63
|
|
|
SVGService.getSVG(svg.id, headers, function (response) { |
64
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
65
|
|
|
console.log(response); |
|
|
|
|
66
|
|
|
$scope.current_svg = response.data; |
67
|
|
|
var modalInstance = $uibModal.open({ |
68
|
|
|
windowClass: "animated fadeIn", |
69
|
|
|
templateUrl: 'views/settings/svg/svg.model.html', |
70
|
|
|
controller: 'ModalEditSVGCtrl', |
71
|
|
|
resolve: { |
72
|
|
|
params: function() { |
73
|
|
|
return { |
74
|
|
|
svg: angular.copy($scope.current_svg ) |
75
|
|
|
}; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
}); |
79
|
|
|
|
80
|
|
|
modalInstance.result.then(function(modifiedSVG) { |
81
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
82
|
|
|
SVGService.editSVG(modifiedSVG, headers, function (response) { |
83
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
84
|
|
|
toaster.pop({ |
85
|
|
|
type: "success", |
86
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
87
|
|
|
body: $translate.instant("TOASTER.SUCCESS_UPDATE_BODY", {template: $translate.instant("COMMON.SVG")}), |
88
|
|
|
showCloseButton: true, |
89
|
|
|
}); |
90
|
|
|
$scope.getAllSVGs(); |
91
|
|
|
$scope.$emit('handleEmitSVGChanged'); |
92
|
|
|
} else { |
93
|
|
|
toaster.pop({ |
94
|
|
|
type: "error", |
95
|
|
|
title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", {template: $translate.instant("COMMON.SVG")}), |
96
|
|
|
body: $translate.instant(response.data.description), |
97
|
|
|
showCloseButton: true, |
98
|
|
|
}); |
99
|
|
|
} |
100
|
|
|
}); |
101
|
|
|
}, function() { |
102
|
|
|
//do nothing; |
103
|
|
|
}); |
104
|
|
|
$rootScope.modalInstance = modalInstance; |
105
|
|
|
} else { |
106
|
|
|
toaster.pop({ |
107
|
|
|
type: "error", |
108
|
|
|
title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", {template: $translate.instant("COMMON.SVG")}), |
109
|
|
|
body: $translate.instant(response.data.description), |
110
|
|
|
showCloseButton: true, |
111
|
|
|
}); |
112
|
|
|
} |
113
|
|
|
}); |
114
|
|
|
}; |
115
|
|
|
|
116
|
|
|
$scope.deleteSVG=function(svg){ |
117
|
|
|
SweetAlert.swal({ |
118
|
|
|
title: $translate.instant("SWEET.TITLE"), |
119
|
|
|
text: $translate.instant("SWEET.TEXT"), |
120
|
|
|
type: "warning", |
121
|
|
|
showCancelButton: true, |
122
|
|
|
confirmButtonColor: "#DD6B55", |
123
|
|
|
confirmButtonText: $translate.instant("SWEET.CONFIRM_BUTTON_TEXT"), |
124
|
|
|
cancelButtonText: $translate.instant("SWEET.CANCEL_BUTTON_TEXT"), |
125
|
|
|
closeOnConfirm: true, |
126
|
|
|
closeOnCancel: true }, |
127
|
|
|
function (isConfirm) { |
128
|
|
|
if (isConfirm) { |
129
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
130
|
|
|
SVGService.deleteSVG(svg, headers, function (response) { |
131
|
|
|
if (angular.isDefined(response.status) && response.status === 204) { |
132
|
|
|
toaster.pop({ |
133
|
|
|
type: "success", |
134
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
135
|
|
|
body: $translate.instant("TOASTER.SUCCESS_DELETE_BODY", {template: $translate.instant("COMMON.SVG")}), |
136
|
|
|
showCloseButton: true, |
137
|
|
|
}); |
138
|
|
|
$scope.getAllSVGs(); |
139
|
|
|
$scope.$emit('handleEmitSVGChanged'); |
140
|
|
|
$window.location.reload(); |
141
|
|
|
} else { |
142
|
|
|
toaster.pop({ |
143
|
|
|
type: "error", |
144
|
|
|
title: $translate.instant("TOASTER.ERROR_DELETE_BODY", {template: $translate.instant("COMMON.SVG")}), |
145
|
|
|
body: $translate.instant(response.data.description), |
146
|
|
|
showCloseButton: true, |
147
|
|
|
}); |
148
|
|
|
} |
149
|
|
|
}); |
150
|
|
|
} |
151
|
|
|
}); |
152
|
|
|
}; |
153
|
|
|
|
154
|
|
|
$scope.exportSVG = function(svg) { |
155
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
156
|
|
|
SVGService.exportSVG(svg, headers, function(response) { |
157
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
158
|
|
|
$scope.exportdata = JSON.stringify(response.data); |
159
|
|
|
var modalInstance = $uibModal.open({ |
160
|
|
|
windowClass: "animated fadeIn", |
161
|
|
|
templateUrl: 'views/common/export.html', |
162
|
|
|
controller: 'ModalExportCtrl', |
163
|
|
|
resolve: { |
164
|
|
|
params: function() { |
165
|
|
|
return { |
166
|
|
|
exportdata: angular.copy($scope.exportdata) |
167
|
|
|
}; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
}); |
171
|
|
|
modalInstance.result.then(function() { |
172
|
|
|
//do nothing; |
173
|
|
|
}, function() { |
174
|
|
|
//do nothing; |
175
|
|
|
}); |
176
|
|
|
$rootScope.modalInstance = modalInstance; |
177
|
|
|
} else { |
178
|
|
|
$scope.exportdata = null; |
179
|
|
|
} |
180
|
|
|
}); |
181
|
|
|
}; |
182
|
|
|
|
183
|
|
|
$scope.cloneSVG = function(svg){ |
184
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
185
|
|
|
SVGService.cloneSVG(svg, headers, function(response) { |
186
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
187
|
|
|
toaster.pop({ |
188
|
|
|
type: "success", |
189
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
190
|
|
|
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("COMMON.SVG")}), |
191
|
|
|
showCloseButton: true, |
192
|
|
|
}); |
193
|
|
|
$scope.getAllSVGs(); |
194
|
|
|
$scope.$emit('handleEmitSVGChanged'); |
195
|
|
|
}else { |
196
|
|
|
toaster.pop({ |
197
|
|
|
type: "error", |
198
|
|
|
title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("COMMON.SVG")}), |
199
|
|
|
body: $translate.instant(response.data.description), |
200
|
|
|
showCloseButton: true, |
201
|
|
|
}); |
202
|
|
|
} |
203
|
|
|
}); |
204
|
|
|
}; |
205
|
|
|
|
206
|
|
|
$scope.importSVG = function() { |
207
|
|
|
var modalInstance = $uibModal.open({ |
208
|
|
|
templateUrl: 'views/common/import.html', |
209
|
|
|
controller: 'ModalImportCtrl', |
210
|
|
|
windowClass: "animated fadeIn", |
211
|
|
|
resolve: { |
212
|
|
|
params: function() { |
213
|
|
|
return { |
214
|
|
|
}; |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
}); |
218
|
|
|
modalInstance.result.then(function(importdata) { |
219
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
220
|
|
|
SVGService.importSVG(importdata, headers, function(response) { |
221
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
222
|
|
|
toaster.pop({ |
223
|
|
|
type: "success", |
224
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
225
|
|
|
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("COMMON.SVG")}), |
226
|
|
|
showCloseButton: true, |
227
|
|
|
}); |
228
|
|
|
$scope.getAllSVGs(); |
229
|
|
|
$scope.$emit('handleEmitSVGChanged'); |
230
|
|
|
} else { |
231
|
|
|
toaster.pop({ |
232
|
|
|
type: "error", |
233
|
|
|
title: $translate.instant("TOASTER.ERROR_ADD_BODY", { template: $translate.instant("COMMON.SVG") }), |
234
|
|
|
body: $translate.instant(response.data.description), |
235
|
|
|
showCloseButton: true, |
236
|
|
|
}); |
237
|
|
|
} |
238
|
|
|
}); |
239
|
|
|
}, function() { |
240
|
|
|
|
241
|
|
|
}); |
242
|
|
|
$rootScope.modalInstance = modalInstance; |
243
|
|
|
}; |
244
|
|
|
|
245
|
|
|
$scope.getAllSVGs(); |
246
|
|
|
}); |
247
|
|
|
|
248
|
|
|
app.controller("ModalAddSVGCtrl", function( $scope, $uibModalInstance) { |
249
|
|
|
$scope.operation = "SVG.ADD_SVG"; |
250
|
|
|
$scope.ok = function() { |
251
|
|
|
$uibModalInstance.close($scope.svg); |
252
|
|
|
}; |
253
|
|
|
|
254
|
|
|
$scope.cancel = function() { |
255
|
|
|
$uibModalInstance.dismiss("cancel"); |
256
|
|
|
}; |
257
|
|
|
}); |
258
|
|
|
|
259
|
|
|
app.controller("ModalEditSVGCtrl", function($scope, $uibModalInstance, params) { |
260
|
|
|
$scope.operation = "SVG.EDIT_SVG"; |
261
|
|
|
$scope.svg = params.svg; |
262
|
|
|
|
263
|
|
|
$scope.ok = function() { |
264
|
|
|
$uibModalInstance.close($scope.svg); |
265
|
|
|
}; |
266
|
|
|
|
267
|
|
|
$scope.cancel = function() { |
268
|
|
|
$uibModalInstance.dismiss("cancel"); |
269
|
|
|
}; |
270
|
|
|
}); |
271
|
|
|
|