1
|
var orgsModule = angular.module('orgs', ['ngRoute', 'checklist-model']);
|
2
|
|
3
|
orgsModule.service('vocabulariesService', function($http) {
|
4
|
this.vocs = {};
|
5
|
this.getVocs = function(f) {
|
6
|
if (Object.keys(this.vocs).length === 0) {
|
7
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
8
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
9
|
this.vocs = res.data;
|
10
|
f(angular.copy(this.vocs));
|
11
|
}, function errorCallback(res) {
|
12
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
13
|
});
|
14
|
} else {
|
15
|
f(this.vocs);
|
16
|
}
|
17
|
};
|
18
|
});
|
19
|
|
20
|
orgsModule.directive('selectOrgModal', function($http) {
|
21
|
return {
|
22
|
restrict: 'E',
|
23
|
scope: {
|
24
|
'modalId' : '@',
|
25
|
'selectedOrg' : '='
|
26
|
},
|
27
|
templateUrl: 'resources/html/modals/select_org.html',
|
28
|
link: function(scope, element, attrs, ctrl) {
|
29
|
scope.searchOrgs = {};
|
30
|
scope.searchValue = '';
|
31
|
|
32
|
scope.search = function(text, page, size) {
|
33
|
scope.searchOrgs = {};
|
34
|
$http.get('api/organizations/search/' + page + '/' + size + '?q=' + text).then(function successCallback(res) {
|
35
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
36
|
scope.searchValue = text;
|
37
|
scope.searchOrgs = res.data;
|
38
|
}, function errorCallback(res) {
|
39
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
40
|
});
|
41
|
}
|
42
|
}
|
43
|
}
|
44
|
});
|
45
|
|
46
|
orgsModule.directive('resolveConflictsModal', function($http, $route) {
|
47
|
return {
|
48
|
restrict: 'E',
|
49
|
scope: {
|
50
|
'modalId' : '@',
|
51
|
'orgs' : '=',
|
52
|
'selectedOrgs' : '='
|
53
|
},
|
54
|
templateUrl: 'resources/html/modals/resolve_conflicts.html',
|
55
|
link: function(scope, element, attrs, ctrl) {
|
56
|
scope.selectOrg = function(org) {
|
57
|
var sel = angular.copy(org);
|
58
|
if (scope.selectedOrgs.length == 0) { sel.show = 'success'; }
|
59
|
else { sel.show = 'info'; }
|
60
|
scope.selectedOrgs.push(sel);
|
61
|
org.show = 'hidden';
|
62
|
}
|
63
|
|
64
|
scope.reset = function() {
|
65
|
scope.selectedOrgs = [];
|
66
|
angular.forEach(scope.orgs, function(org) { org.show = 'secondary'; });
|
67
|
}
|
68
|
|
69
|
scope.createGroup = function() {
|
70
|
var masterId = '';
|
71
|
var otherIds = [];
|
72
|
angular.forEach(scope.selectedOrgs, function(o, pos) {
|
73
|
if (pos == 0) { masterId = o.id; }
|
74
|
else { otherIds.push(o.id); }
|
75
|
});
|
76
|
if (masterId && otherIds.length > 0) {
|
77
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
78
|
$http.post('api/organizations/conflicts/fix/' + masterId, otherIds).then(function successCallback(res) {
|
79
|
if ((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
80
|
$('#' + scope.modalId).modal('hide');
|
81
|
$('#' + scope.modalId).on('hidden.bs.modal', function (e) {
|
82
|
$route.reload();
|
83
|
});
|
84
|
}, function errorCallback(res) {
|
85
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
86
|
});
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
});
|
92
|
|
93
|
orgsModule.directive('orgTabsMenu', function($http) {
|
94
|
return {
|
95
|
restrict: 'E',
|
96
|
scope: {
|
97
|
'orgId' : '@',
|
98
|
'info' : '=',
|
99
|
'selected' : '=',
|
100
|
'org' : '=',
|
101
|
'events' : '=',
|
102
|
},
|
103
|
templateUrl: 'resources/html/menu/org_tabs_menu.html',
|
104
|
link: function(scope, element, attrs, ctrl) {
|
105
|
|
106
|
scope.loadOrg = function() {
|
107
|
scope.org = {};
|
108
|
$http.get('api/organizations/get?id=' + scope.orgId).then(function successCallback(res) {
|
109
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
110
|
scope.org = res.data;
|
111
|
}, function errorCallback(res) {
|
112
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
113
|
});
|
114
|
scope.selected = 1;
|
115
|
}
|
116
|
|
117
|
scope.loadDedupEvents = function() {
|
118
|
scope.events = {};
|
119
|
|
120
|
$http.get('api/organizations/conflicts?id=' + scope.orgId).then(function successCallback(res) {
|
121
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
122
|
scope.events.conflicts = res.data;
|
123
|
$http.get('api/organizations/duplicates?id=' + scope.orgId).then(function successCallback(res) {
|
124
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
125
|
scope.events.duplicates = res.data;
|
126
|
}, function errorCallback(res) {
|
127
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
128
|
});
|
129
|
}, function errorCallback(res) {
|
130
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
131
|
});
|
132
|
scope.selected = 2;
|
133
|
};
|
134
|
|
135
|
scope.loadOrg();
|
136
|
}
|
137
|
}
|
138
|
});
|
139
|
|
140
|
|
141
|
orgsModule.directive('orgFormMetadata', function($http, $location, $route, $routeParams) {
|
142
|
return {
|
143
|
restrict: 'E',
|
144
|
scope: {
|
145
|
'orgId' : '@',
|
146
|
'org' : '=',
|
147
|
'vocabularies' : '=',
|
148
|
'mode' : '@', // insert or update
|
149
|
'infoMethod' : '&'
|
150
|
},
|
151
|
templateUrl: 'resources/html/forms/org_metadata.html',
|
152
|
link: function(scope, element, attrs, ctrl) {
|
153
|
|
154
|
scope.newRelation = {};
|
155
|
scope.newRelType = '';
|
156
|
|
157
|
scope.resetSelectedRelation = function() {
|
158
|
scope.newRelation = {};
|
159
|
}
|
160
|
|
161
|
scope.addNewRelation = function(r) {
|
162
|
scope.org.relations.push({
|
163
|
'relatedOrgId' : scope.newRelation.id,
|
164
|
'relatedOrgName' : scope.newRelation.name,
|
165
|
'type' : scope.newRelType
|
166
|
});
|
167
|
scope.newRelation = {};
|
168
|
scope.newRelType = '';
|
169
|
}
|
170
|
|
171
|
scope.save = function() {
|
172
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
173
|
$http.post('api/organizations/save', scope.org).then(function successCallback(res) {
|
174
|
if ((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
175
|
else if (scope.mode == 'insert') { $location.url('/edit/1/' + res.data[0]); }
|
176
|
else if ($routeParams.msg == 2) { $route.reload(); }
|
177
|
else { $location.url('/edit/2/' + res.data[0]); }
|
178
|
}, function errorCallback(res) {
|
179
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
180
|
});
|
181
|
}
|
182
|
}
|
183
|
}
|
184
|
});
|
185
|
|
186
|
orgsModule.directive('orgDedupEvents', function($http, $location, $route) {
|
187
|
return {
|
188
|
restrict: 'E',
|
189
|
scope: {
|
190
|
'orgId' : '@',
|
191
|
'events' : '=',
|
192
|
'vocabularies' : '=',
|
193
|
'infoMethod' : '&'
|
194
|
},
|
195
|
templateUrl: 'resources/html/parts/org_dedup_events.html',
|
196
|
link: function(scope, element, attrs, ctrl) {
|
197
|
|
198
|
scope.currentOrgDetails = {};
|
199
|
|
200
|
$http.get('api/organizations/get?id=' + scope.orgId).then(function successCallback(res) {
|
201
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
202
|
scope.currentOrgDetails = res.data;
|
203
|
}, function errorCallback(res) {
|
204
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
205
|
});
|
206
|
|
207
|
scope.saveDuplicates = function() {
|
208
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
209
|
$http.post('api/organizations/duplicates', scope.events.duplicates).then(function successCallback(res) {
|
210
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
211
|
if (scope.infoMethod) { scope.infoMethod(); }
|
212
|
alert('Events updated !!!');
|
213
|
scope.events.duplicates = res.data;
|
214
|
}, function errorCallback(res) {
|
215
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
216
|
});
|
217
|
}
|
218
|
|
219
|
scope.saveConflicts = function() {
|
220
|
alert('todo');
|
221
|
}
|
222
|
}
|
223
|
}
|
224
|
});
|
225
|
|
226
|
|
227
|
orgsModule.directive('orgDetails', function($http, $location, $route) {
|
228
|
return {
|
229
|
restrict: 'E',
|
230
|
scope: {
|
231
|
'org' : '=',
|
232
|
'orgTitle' : '@',
|
233
|
'show' : '@'
|
234
|
},
|
235
|
templateUrl: 'resources/html/parts/org_details.html',
|
236
|
link: function(scope, element, attrs, ctrl) {}
|
237
|
}
|
238
|
});
|
239
|
|
240
|
orgsModule.directive('orgResults', function($http, $location, $route) {
|
241
|
return {
|
242
|
restrict: 'E',
|
243
|
scope: {
|
244
|
'searchMessage' : '@',
|
245
|
'orgs' : '=',
|
246
|
'nextFunction' : '&',
|
247
|
'prevFunction' : '&',
|
248
|
'selectedOrg' : '=',
|
249
|
'mode' : '@'
|
250
|
},
|
251
|
templateUrl: 'resources/html/parts/org_results.html',
|
252
|
link: function(scope, element, attrs, ctrl) {
|
253
|
scope.selectOrg = function(o) {
|
254
|
scope.selectedOrg = o;
|
255
|
}
|
256
|
}
|
257
|
}
|
258
|
});
|
259
|
|
260
|
|
261
|
orgsModule.directive('allConflicts', function($http, $location, $route, $q) {
|
262
|
return {
|
263
|
restrict: 'E',
|
264
|
scope: {
|
265
|
'conflicts' : '=',
|
266
|
'country' : '@',
|
267
|
'info' : '=',
|
268
|
'infoMethod' : '&'
|
269
|
},
|
270
|
templateUrl: 'resources/html/forms/all_conflicts.html',
|
271
|
link: function(scope, element, attrs, ctrl) {
|
272
|
scope.orgs = [];
|
273
|
|
274
|
scope.prepareConflictsModal = function(list) {
|
275
|
scope.orgs = [];
|
276
|
scope.selectedOrgs = [];
|
277
|
|
278
|
var gets = list.map((o) => $http.get('api/organizations/get?id=' + o.id));
|
279
|
|
280
|
$q.all(gets).then(function(responses) {
|
281
|
scope.orgs = responses.map((resp) => resp.data);
|
282
|
angular.forEach(scope.orgs, function(org) { org.show = 'secondary'; });
|
283
|
});
|
284
|
}
|
285
|
|
286
|
}
|
287
|
}
|
288
|
});
|
289
|
|
290
|
orgsModule.directive('orgFormDuplicates', function($http, $location, $route) {
|
291
|
return {
|
292
|
restrict: 'E',
|
293
|
scope: {
|
294
|
'duplicates' : '=',
|
295
|
'showSaveButton' : '@',
|
296
|
'saveFunction' : '&'
|
297
|
},
|
298
|
templateUrl: 'resources/html/forms/org_duplicates.html',
|
299
|
link: function(scope, element, attrs, ctrl) {}
|
300
|
}
|
301
|
});
|
302
|
|
303
|
orgsModule.directive('orgFormConflicts', function($http, $location, $route, $q) {
|
304
|
return {
|
305
|
restrict: 'E',
|
306
|
scope: {
|
307
|
'orgId' : '@',
|
308
|
'conflicts' : '=',
|
309
|
'showSaveButton' : '@',
|
310
|
'saveFunction' : '&'
|
311
|
},
|
312
|
templateUrl: 'resources/html/forms/org_conflicts.html',
|
313
|
link: function(scope, element, attrs, ctrl) {
|
314
|
scope.candidateConflicts = [];
|
315
|
scope.selectedConflicts = [];
|
316
|
|
317
|
scope.prepareConflictsModal = function() {
|
318
|
scope.candidateConflicts = [];
|
319
|
scope.selectedConflicts = [];
|
320
|
|
321
|
var gets = [ $http.get('api/organizations/get?id=' + scope.orgId) ];
|
322
|
angular.forEach(scope.conflicts, function(c) { gets.push($http.get('api/organizations/get?id=' + c.id)); });
|
323
|
|
324
|
$q.all(gets).then(function(responses) {
|
325
|
scope.candidateConflicts = responses.map((resp) => resp.data);
|
326
|
angular.forEach(scope.candidateConflicts, function(org) { org.show = 'secondary'; });
|
327
|
});
|
328
|
}
|
329
|
}
|
330
|
}
|
331
|
});
|
332
|
|
333
|
orgsModule.directive('allDuplicates', function($http, $location, $route) {
|
334
|
return {
|
335
|
restrict: 'E',
|
336
|
scope: {
|
337
|
'duplicates' : '=',
|
338
|
'country' : '@',
|
339
|
'info' : '=',
|
340
|
'infoMethod' : '&'
|
341
|
},
|
342
|
templateUrl: 'resources/html/forms/all_duplicates.html',
|
343
|
link: function(scope, element, attrs, ctrl) {
|
344
|
scope.currentOrg = {};
|
345
|
scope.currentOrgDetails = {};
|
346
|
scope.currentDuplicates = [];
|
347
|
|
348
|
scope.prepareDuplicatesModal = function(org) {
|
349
|
scope.currentOrg = org;
|
350
|
scope.currentOrgDetails = {};
|
351
|
scope.currentDuplicates = [];
|
352
|
|
353
|
$http.get('api/organizations/get?id=' + org.id).then(function successCallback(res) {
|
354
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
355
|
scope.currentOrgDetails = res.data;
|
356
|
}, function errorCallback(res) {
|
357
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
358
|
});
|
359
|
|
360
|
$http.get('api/organizations/duplicates?id=' + org.id).then(function successCallback(res) {
|
361
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
362
|
scope.currentDuplicates = res.data;
|
363
|
}, function errorCallback(res) {
|
364
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
365
|
});
|
366
|
};
|
367
|
|
368
|
scope.saveCurrentDuplicates = function() {
|
369
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
370
|
$http.post('api/organizations/duplicates', scope.currentDuplicates).then(function successCallback(res) {
|
371
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
372
|
if (scope.infoMethod) { scope.infoMethod(); }
|
373
|
scope.currentOrg.numberOfDuplicates = 0;
|
374
|
for (var i=0; i<res.data.length; i++) {
|
375
|
if (res.data[i].relType == 'suggested') {
|
376
|
scope.currentOrg.numberOfDuplicates++;
|
377
|
}
|
378
|
}
|
379
|
scope.currentDuplicates = [];
|
380
|
}, function errorCallback(res) {
|
381
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
382
|
});
|
383
|
};
|
384
|
}
|
385
|
}
|
386
|
});
|
387
|
|
388
|
orgsModule.config(function($routeProvider) {
|
389
|
$routeProvider
|
390
|
.when('/new', { templateUrl: 'resources/html/new.html', controller: 'newOrgCtrl' })
|
391
|
.when('/search', { templateUrl: 'resources/html/search.html', controller: 'searchCtrl' })
|
392
|
.when('/searchResults/:page/:size/:text*', { templateUrl: 'resources/html/searchResults.html', controller: 'searchResultsCtrl' })
|
393
|
.when('/countries', { templateUrl: 'resources/html/browse.html', controller: 'countriesCtrl' })
|
394
|
.when('/byCountry/:page/:size/:code*', { templateUrl: 'resources/html/resultsByCountry.html', controller: 'byCountryCtrl' })
|
395
|
.when('/types', { templateUrl: 'resources/html/browse.html', controller: 'typesCtrl' })
|
396
|
.when('/byType/:page/:size/:type*', { templateUrl: 'resources/html/resultsByType.html', controller: 'byTypeCtrl' })
|
397
|
.when('/edit/:msg/:id', { templateUrl: 'resources/html/edit.html', controller: 'showEditCtrl' })
|
398
|
.when('/suggestions/:country/:tab', { templateUrl: 'resources/html/suggestions.html', controller: 'showSuggestionsCtrl' })
|
399
|
.when('/users', { templateUrl: 'resources/html/users.html', controller: 'usersCtrl' })
|
400
|
.otherwise({ redirectTo: '/suggestions/_/1' });
|
401
|
});
|
402
|
|
403
|
orgsModule.filter('escape', function() {
|
404
|
return function(input) {
|
405
|
return encodeURIComponent(encodeURIComponent(input));
|
406
|
};
|
407
|
});
|
408
|
|
409
|
orgsModule.filter('unescape', function() {
|
410
|
return function(input) {
|
411
|
return decodeURIComponent(input);
|
412
|
};
|
413
|
});
|
414
|
|
415
|
orgsModule.controller('newOrgCtrl', function ($scope, $http, $routeParams, $location, vocabulariesService) {
|
416
|
$scope.org = {
|
417
|
"id": "",
|
418
|
"name": "",
|
419
|
"type": null,
|
420
|
"lat": 0.0,
|
421
|
"lng": 0.0,
|
422
|
"city": "",
|
423
|
"country": "",
|
424
|
"source": "user",
|
425
|
"otherIdentifiers": [],
|
426
|
"otherNames": [],
|
427
|
"relations": [],
|
428
|
"acronyms": [],
|
429
|
"urls": [],
|
430
|
"relations": []
|
431
|
};
|
432
|
|
433
|
$scope.vocabularies = {};
|
434
|
vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
|
435
|
|
436
|
});
|
437
|
|
438
|
orgsModule.controller('searchCtrl', function ($scope, $location) {
|
439
|
$scope.searchText = '';
|
440
|
$scope.search = function() {
|
441
|
$location.url('/searchResults/0/50/' + encodeURIComponent(encodeURIComponent($scope.searchText)));
|
442
|
}
|
443
|
});
|
444
|
|
445
|
orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams, $location) {
|
446
|
$scope.searchText = decodeURIComponent($routeParams.text);
|
447
|
$scope.orgs = {};
|
448
|
|
449
|
$http.get('api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.searchText).then(function successCallback(res) {
|
450
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
451
|
$scope.orgs = res.data;
|
452
|
}, function errorCallback(res) {
|
453
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
454
|
});
|
455
|
|
456
|
$scope.prev = function() {
|
457
|
$location.url('/searchResults/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
|
458
|
}
|
459
|
|
460
|
$scope.next = function() {
|
461
|
$location.url('/searchResults/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
|
462
|
}
|
463
|
});
|
464
|
|
465
|
orgsModule.controller('countriesCtrl', function ($scope, $http, $routeParams) {
|
466
|
$scope.field = 'Country';
|
467
|
$scope.resultsBasePath = '/byCountry'
|
468
|
$scope.entries = [];
|
469
|
|
470
|
$http.get('api/organizations/browse/countries').then(function successCallback(res) {
|
471
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
472
|
$scope.entries = res.data;
|
473
|
}, function errorCallback(res) {
|
474
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
475
|
});
|
476
|
|
477
|
});
|
478
|
|
479
|
orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams, $location) {
|
480
|
$scope.fieldValue = decodeURIComponent($routeParams.code);
|
481
|
$scope.orgs = {};
|
482
|
|
483
|
$http.get('api/organizations/byCountry/' + $routeParams.code + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
484
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
485
|
$scope.orgs = res.data;
|
486
|
}, function errorCallback(res) {
|
487
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
488
|
});
|
489
|
|
490
|
$scope.prev = function() {
|
491
|
$location.url('/byCountry/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
|
492
|
}
|
493
|
|
494
|
$scope.next = function() {
|
495
|
$location.url('/byCountry/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
|
496
|
}
|
497
|
|
498
|
});
|
499
|
|
500
|
orgsModule.controller('typesCtrl', function ($scope, $http, $routeParams) {
|
501
|
$scope.field = 'Organization type';
|
502
|
$scope.resultsBasePath = '/byType'
|
503
|
$scope.entries = [];
|
504
|
|
505
|
$http.get('api/organizations/browse/types').then(function successCallback(res) {
|
506
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
507
|
$scope.entries = res.data;
|
508
|
}, function errorCallback(res) {
|
509
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
510
|
});
|
511
|
|
512
|
});
|
513
|
|
514
|
orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams, $location) {
|
515
|
|
516
|
$scope.fieldValue = $routeParams.type;
|
517
|
|
518
|
$scope.orgs = {};
|
519
|
|
520
|
$http.get('api/organizations/byType/' + $routeParams.type + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
521
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
522
|
$scope.orgs = res.data;
|
523
|
}, function errorCallback(res) {
|
524
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
525
|
});
|
526
|
|
527
|
$scope.prev = function() {
|
528
|
$location.url('/byType/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
|
529
|
}
|
530
|
|
531
|
$scope.next = function() {
|
532
|
$location.url('/byType/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
|
533
|
}
|
534
|
});
|
535
|
|
536
|
|
537
|
orgsModule.controller('showEditCtrl', function ($scope, $http, $routeParams, $route, $location, $timeout, vocabulariesService) {
|
538
|
$scope.orgId = $routeParams.id;
|
539
|
$scope.org = {};
|
540
|
$scope.events = {};
|
541
|
$scope.info = {};
|
542
|
|
543
|
$scope.getInfo = function() {
|
544
|
$http.get('api/organizations/info?id=' + $scope.orgId).then(function successCallback(res) {
|
545
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
546
|
$scope.info = res.data;
|
547
|
}, function errorCallback(res) {
|
548
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
549
|
});
|
550
|
};
|
551
|
|
552
|
$scope.getInfo();
|
553
|
|
554
|
$scope.vocabularies = {};
|
555
|
vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
|
556
|
|
557
|
if ($routeParams.msg == 1) { $scope.message = 'New organization registered !!!'; }
|
558
|
else if ($routeParams.msg == 2) { $scope.message = 'Organization updated !!!'; }
|
559
|
else { $scope.message = ''; }
|
560
|
|
561
|
$timeout(function() { $scope.message = ''; }, 3000)
|
562
|
|
563
|
});
|
564
|
|
565
|
orgsModule.controller('showSuggestionsCtrl', function ($scope, $http, $routeParams, $location) {
|
566
|
$scope.info = {};
|
567
|
$scope.conflicts = [];
|
568
|
$scope.duplicates = [];
|
569
|
$scope.currentTab = $routeParams.tab;
|
570
|
$scope.country = $routeParams.country;
|
571
|
|
572
|
$scope.getInfo = function() {
|
573
|
$http.get('api/organizations/suggestionsInfo').then(function successCallback(res) {
|
574
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
575
|
$scope.info = res.data;
|
576
|
if ($scope.country == '_') {
|
577
|
var found = '';
|
578
|
|
579
|
angular.forEach($scope.info.byCountry, function(values, c) {
|
580
|
if (!found && (($scope.currentTab == 1 && values.nDuplicates > 0) || ($scope.currentTab == 2 && values.nConflicts > 0))) {
|
581
|
found = c;
|
582
|
}
|
583
|
});
|
584
|
if (found) { $location.url('/suggestions/' + found + '/' + $scope.currentTab); }
|
585
|
}
|
586
|
}, function errorCallback(res) {
|
587
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
588
|
});
|
589
|
};
|
590
|
|
591
|
|
592
|
$scope.refresh = function() {
|
593
|
$scope.conflicts = [];
|
594
|
$scope.duplicates = [];
|
595
|
|
596
|
if ($scope.country != '_') {
|
597
|
if ($scope.currentTab == 1) {
|
598
|
$http.get('api/organizations/duplicates/byCountry/' + $scope.country).then(function successCallback(res) {
|
599
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
600
|
$scope.duplicates = res.data;
|
601
|
if ($scope.duplicates.length > 0) {
|
602
|
//$scope.currentCountry = $scope.duplicates.
|
603
|
}
|
604
|
}, function errorCallback(res) {
|
605
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
606
|
});
|
607
|
} else if ($scope.currentTab == 2) {
|
608
|
$http.get('api/organizations/conflicts/byCountry/' + $scope.country).then(function successCallback(res) {
|
609
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
610
|
$scope.conflicts = res.data;
|
611
|
}, function errorCallback(res) {
|
612
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
613
|
});
|
614
|
} else { }
|
615
|
}
|
616
|
$scope.getInfo();
|
617
|
}
|
618
|
|
619
|
$scope.refresh();
|
620
|
});
|
621
|
|
622
|
|
623
|
orgsModule.controller('usersCtrl', function ($scope, $http, $timeout, $route, vocabulariesService) {
|
624
|
$scope.users = [];
|
625
|
$scope.vocs = {};
|
626
|
$scope.currentUser = {};
|
627
|
$scope.superAdminMode = superAdminMode();
|
628
|
|
629
|
$scope.vocabularies = {};
|
630
|
vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
|
631
|
|
632
|
$http.get('api/users').then(function successCallback(res) {
|
633
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
634
|
$scope.users = res.data;
|
635
|
}, function errorCallback(res) {
|
636
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
637
|
});
|
638
|
|
639
|
$scope.setCurrentUser = function(user) {
|
640
|
angular.copy(user, $scope.currentUser);
|
641
|
if (!$scope.currentUser.role || $scope.currentUser.role == 'PENDING') {
|
642
|
$scope.currentUser.role = 'USER';
|
643
|
}
|
644
|
}
|
645
|
|
646
|
$scope.saveUser = function(user) {
|
647
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
648
|
$http.post('api/users', user).then(function successCallback(res) {
|
649
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
650
|
$scope.users = res.data;
|
651
|
}, function errorCallback(res) {
|
652
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
653
|
});
|
654
|
}
|
655
|
|
656
|
$scope.deleteUser = function(email) {
|
657
|
if (confirm("Are you sure ?")) {
|
658
|
$http.delete('api/users?email=' + email).then(function successCallback(res) {
|
659
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
660
|
$scope.users = res.data;
|
661
|
}, function errorCallback(res) {
|
662
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
663
|
});
|
664
|
}
|
665
|
}
|
666
|
});
|