Project

General

Profile

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) {
47
	return {
48
		restrict: 'E',
49
		scope: {
50
			'modalId' : '@',
51
			'orgs'    : '='
52
		},
53
		templateUrl: 'resources/html/modals/resolve_conflicts.html',
54
		link: function(scope, element, attrs, ctrl) {
55
			
56
			
57
			scope.resolveConflicts = function() {
58
				alert('todo');
59
			}		
60
		}
61
	}
62
});
63
		
64
orgsModule.directive('orgTabsMenu', function($http) {
65
	return {
66
		restrict: 'E',
67
		scope: {
68
			'orgId'    : '@',
69
			'info'     : '=',
70
			'selected' : '=',
71
			'org'      : '=',
72
			'events'   : '=',
73
		},
74
		templateUrl: 'resources/html/menu/org_tabs_menu.html',
75
		link: function(scope, element, attrs, ctrl) {
76

    
77
			scope.loadOrg = function() {
78
				scope.org = {};
79
				$http.get('api/organizations/get?id=' + scope.orgId).then(function successCallback(res) {
80
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
81
					scope.org = res.data;
82
				}, function errorCallback(res) {
83
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
84
				});
85
				scope.selected = 1;
86
			}
87
			
88
			scope.loadDedupEvents = function() {
89
				scope.events = {};
90

    
91
				$http.get('api/organizations/conflicts?id=' + scope.orgId).then(function successCallback(res) {
92
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
93
					scope.events.conflicts = res.data;
94
					$http.get('api/organizations/duplicates?id=' + scope.orgId).then(function successCallback(res) {
95
						if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
96
						scope.events.duplicates = res.data;
97
					}, function errorCallback(res) {
98
						alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
99
					});
100
				}, function errorCallback(res) {
101
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
102
				});
103
				scope.selected = 2;
104
			};
105
								
106
			scope.loadOrg();
107
		}
108
     }
109
});
110

    
111

    
112
orgsModule.directive('orgFormMetadata', function($http, $location, $route, $routeParams) {
113
	return {
114
		restrict: 'E',
115
		scope: {
116
			'orgId'        : '@',
117
			'org'          : '=',
118
			'vocabularies' : '=',
119
			'mode'         : '@',  // insert or update
120
			'infoMethod'   : '&'
121
		},
122
		templateUrl: 'resources/html/forms/org_metadata.html',
123
		link: function(scope, element, attrs, ctrl) {
124
			
125
			scope.newRelation = {};
126
			scope.newRelType = '';
127
							
128
			scope.resetSelectedRelation = function() {
129
				scope.newRelation = {};
130
			}
131
		
132
			scope.addNewRelation = function(r) {
133
				scope.org.relations.push({
134
					'relatedOrgId'   : scope.newRelation.id,
135
					'relatedOrgName' : scope.newRelation.name,
136
					'type'           : scope.newRelType
137
				});
138
				scope.newRelation = {};
139
				scope.newRelType = '';
140
			}
141
			
142
			scope.save = function() {
143
				$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
144
				$http.post('api/organizations/save', scope.org).then(function successCallback(res) {
145
					if      ((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
146
					else if (scope.mode == 'insert')        { $location.url('/edit/1/' + res.data[0]);    }
147
					else if ($routeParams.msg == 2)         { $route.reload(); }
148
					else                                    { $location.url('/edit/2/' + res.data[0]); }
149
				}, function errorCallback(res) {
150
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
151
				}); 
152
			}
153
		}
154
     }
155
});
156

    
157
orgsModule.directive('orgDedupEvents', function($http, $location, $route) {
158
	return {
159
		restrict: 'E',
160
		scope: {
161
			'orgId'        : '@',
162
			'events'       : '=',
163
			'vocabularies' : '=',
164
			'infoMethod'   : '&'
165
		},
166
		templateUrl: 'resources/html/parts/org_dedup_events.html',
167
		link: function(scope, element, attrs, ctrl) {
168
			
169
			scope.currentOrgDetails = {};
170
			
171
			$http.get('api/organizations/get?id=' + scope.orgId).then(function successCallback(res) {
172
				if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
173
				scope.currentOrgDetails = res.data;
174
			}, function errorCallback(res) {
175
				alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
176
			});
177
			
178
			scope.saveDuplicates = function() {
179
				$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
180
				$http.post('api/organizations/duplicates', scope.events.duplicates).then(function successCallback(res) {
181
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
182
					if (scope.infoMethod)             { scope.infoMethod(); }
183
					alert('Events updated !!!');
184
					scope.events.duplicates = res.data;
185
				}, function errorCallback(res) {
186
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
187
				});
188
			}
189
			
190
			scope.saveConflicts = function() {
191
				alert('todo');
192
			}
193
		}
194
     }
195
});
196

    
197

    
198
orgsModule.directive('orgDetails', function($http, $location, $route) {
199
	return {
200
		restrict: 'E',
201
		scope: {
202
			'org'      : '=',
203
			'orgTitle' : '@'
204
		},
205
		templateUrl: 'resources/html/parts/org_details.html',
206
		link: function(scope, element, attrs, ctrl) {}
207
     }
208
});
209

    
210
orgsModule.directive('orgResults', function($http, $location, $route) {
211
	return {
212
		restrict: 'E',
213
		scope: {
214
			'searchMessage' : '@',
215
			'orgs'          : '=',
216
			'nextFunction'  : '&',
217
			'prevFunction'  : '&',
218
			'selectedOrg'   : '=',
219
			'mode'          : '@'
220
		},
221
		templateUrl: 'resources/html/parts/org_results.html',
222
		link: function(scope, element, attrs, ctrl) {
223
			scope.selectOrg = function(o) {
224
				scope.selectedOrg = o;
225
			}
226
		}
227
     }
228
});
229

    
230

    
231
orgsModule.directive('allConflicts', function($http, $location, $route, $q) {
232
	return {
233
		restrict: 'E',
234
		scope: {
235
			'conflicts'    : '=',
236
			'country'      : '@',
237
			'info'         : '=',
238
			'infoMethod'   : '&'
239
		},
240
		templateUrl: 'resources/html/forms/all_conflicts.html',
241
		link: function(scope, element, attrs, ctrl) {
242
			scope.orgs = [];
243
			
244
			scope.prepareConflictsModal = function(list) {
245
				scope.orgs = [];
246
				
247
				var gets = list.map((o) => $http.get('api/organizations/get?id=' + o.id));
248
				
249
				$q.all(gets).then(function(responses) {
250
					scope.orgs = responses.map((resp) => resp.data);
251
				});
252
				
253
				scope.orgs = list;
254
			}
255
			
256
		}
257
     }
258
});
259

    
260
orgsModule.directive('orgFormDuplicates', function($http, $location, $route) {
261
	return {
262
		restrict: 'E',
263
		scope: {
264
			'duplicates'     : '=',
265
			'showSaveButton' : '@',
266
			'saveFunction'   : '&'
267
		},
268
		templateUrl: 'resources/html/forms/org_duplicates.html',
269
		link: function(scope, element, attrs, ctrl) {}
270
     }
271
});
272

    
273
orgsModule.directive('orgFormConflicts', function($http, $location, $route) {
274
	return {
275
		restrict: 'E',
276
		scope: {
277
			'conflicts'      : '=',
278
			'showSaveButton' : '@',
279
			'saveFunction'   : '&'
280
		},
281
		templateUrl: 'resources/html/forms/org_conflicts.html',
282
		link: function(scope, element, attrs, ctrl) {}
283
     }
284
});
285

    
286
orgsModule.directive('allDuplicates', function($http, $location, $route) {
287
	return {
288
		restrict: 'E',
289
		scope: {
290
			'duplicates'   : '=',
291
			'country'      : '@',
292
			'info'         : '=',
293
			'infoMethod'   : '&'
294
		},
295
		templateUrl: 'resources/html/forms/all_duplicates.html',
296
		link: function(scope, element, attrs, ctrl) {
297
			scope.currentOrg = {};
298
			scope.currentOrgDetails = {};
299
			scope.currentDuplicates = [];
300
			
301
			scope.prepareDuplicatesModal = function(org) {
302
				scope.currentOrg = org;
303
				scope.currentOrgDetails = {};
304
				scope.currentDuplicates = [];
305
				
306
				$http.get('api/organizations/get?id=' + org.id).then(function successCallback(res) {
307
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
308
					scope.currentOrgDetails = res.data;
309
				}, function errorCallback(res) {
310
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
311
				});
312
				
313
				$http.get('api/organizations/duplicates?id=' + org.id).then(function successCallback(res) {
314
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
315
					scope.currentDuplicates = res.data;
316
				}, function errorCallback(res) {
317
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
318
				});
319
			};
320
			
321
			scope.saveCurrentDuplicates = function() {
322
				$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
323
				$http.post('api/organizations/duplicates', scope.currentDuplicates).then(function successCallback(res) {
324
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
325
					if (scope.infoMethod)             { scope.infoMethod(); }
326
					scope.currentOrg.numberOfDuplicates = 0;
327
					for (var i=0; i<res.data.length; i++) {
328
						if (res.data[i].relType == 'suggested') {
329
							scope.currentOrg.numberOfDuplicates++;
330
						}
331
					}
332
					scope.currentDuplicates = [];
333
				}, function errorCallback(res) {
334
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
335
				});
336
			};
337
		}
338
    }
339
});
340

    
341
orgsModule.config(function($routeProvider) {
342
	$routeProvider
343
		.when('/new',                              { templateUrl: 'resources/html/new.html',              controller: 'newOrgCtrl' })
344
		.when('/search',                           { templateUrl: 'resources/html/search.html',           controller: 'searchCtrl' })
345
		.when('/searchResults/:page/:size/:text*', { templateUrl: 'resources/html/searchResults.html',    controller: 'searchResultsCtrl' })
346
		.when('/countries',                        { templateUrl: 'resources/html/browse.html',           controller: 'countriesCtrl' })
347
		.when('/byCountry/:page/:size/:code*',     { templateUrl: 'resources/html/resultsByCountry.html', controller: 'byCountryCtrl' })
348
		.when('/types',                            { templateUrl: 'resources/html/browse.html',           controller: 'typesCtrl' })
349
		.when('/byType/:page/:size/:type*',        { templateUrl: 'resources/html/resultsByType.html',    controller: 'byTypeCtrl' })
350
		.when('/edit/:msg/:id',                    { templateUrl: 'resources/html/edit.html',             controller: 'showEditCtrl' })
351
		.when('/suggestions/:country/:tab',        { templateUrl: 'resources/html/suggestions.html',      controller: 'showSuggestionsCtrl' })
352
		.when('/users',                            { templateUrl: 'resources/html/users.html',            controller: 'usersCtrl' })
353
		.otherwise({ redirectTo: '/suggestions/_/1' });
354
});
355

    
356
orgsModule.filter('escape', function() {
357
	return function(input) {
358
		return encodeURIComponent(encodeURIComponent(input));
359
	}; 
360
});
361

    
362
orgsModule.filter('unescape', function() {
363
	return function(input) {
364
		return decodeURIComponent(input);
365
	};
366
});
367

    
368
orgsModule.controller('newOrgCtrl', function ($scope, $http, $routeParams, $location, vocabulariesService) {
369
	$scope.org = {
370
		"id": "",
371
		"name": "",
372
		"type": null,
373
		"lat": 0.0,
374
		"lng": 0.0,
375
		"city": "",
376
		"country": "",
377
		"source": "user",
378
		"otherIdentifiers": [],
379
		"otherNames": [],
380
		"relations": [],
381
		"acronyms": [],
382
		"urls": [],
383
		"relations": []
384
	};
385
	
386
	$scope.vocabularies = {};
387
	vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
388
	
389
});
390

    
391
orgsModule.controller('searchCtrl', function ($scope, $location) {
392
	$scope.searchText = '';
393
	$scope.search = function() {
394
		$location.url('/searchResults/0/50/' + encodeURIComponent(encodeURIComponent($scope.searchText)));
395
	}
396
});
397

    
398
orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams, $location) {
399
	$scope.searchText = decodeURIComponent($routeParams.text);
400
	$scope.orgs = {};
401
	
402
	$http.get('api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.searchText).then(function successCallback(res) {
403
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
404
		$scope.orgs = res.data;
405
	}, function errorCallback(res) {
406
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
407
	});
408
	
409
	$scope.prev = function() {
410
		$location.url('/searchResults/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
411
	}
412
	
413
	$scope.next = function() {
414
		$location.url('/searchResults/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
415
	}
416
});
417

    
418
orgsModule.controller('countriesCtrl', function ($scope, $http, $routeParams) {
419
	$scope.field = 'Country';
420
	$scope.resultsBasePath = '/byCountry'
421
	$scope.entries = [];
422
	
423
	$http.get('api/organizations/browse/countries').then(function successCallback(res) {
424
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
425
		$scope.entries = res.data;
426
	}, function errorCallback(res) {
427
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
428
	});
429
	
430
});
431

    
432
orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams, $location) {
433
	$scope.fieldValue = decodeURIComponent($routeParams.code);
434
	$scope.orgs = {};
435
	
436
	$http.get('api/organizations/byCountry/' + $routeParams.code + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
437
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
438
		$scope.orgs = res.data;
439
	}, function errorCallback(res) {
440
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
441
	});
442
	
443
	$scope.prev = function() {
444
		$location.url('/byCountry/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
445
	}
446
	
447
	$scope.next = function() {
448
		$location.url('/byCountry/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
449
	}
450

    
451
});
452

    
453
orgsModule.controller('typesCtrl', function ($scope, $http, $routeParams) {
454
	$scope.field = 'Organization type';
455
	$scope.resultsBasePath = '/byType'
456
	$scope.entries = [];
457
	
458
	$http.get('api/organizations/browse/types').then(function successCallback(res) {
459
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
460
		$scope.entries = res.data;
461
	}, function errorCallback(res) {
462
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
463
	});
464
	
465
});
466

    
467
orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams, $location) {
468
	
469
	$scope.fieldValue = $routeParams.type;
470
	
471
	$scope.orgs = {};
472
	
473
	$http.get('api/organizations/byType/' + $routeParams.type + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
474
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
475
		$scope.orgs = res.data;
476
	}, function errorCallback(res) {
477
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
478
	});
479
	
480
	$scope.prev = function() {
481
		$location.url('/byType/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
482
	}
483
	
484
	$scope.next = function() {
485
		$location.url('/byType/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
486
	}
487
});
488

    
489

    
490
orgsModule.controller('showEditCtrl', function ($scope, $http, $routeParams, $route, $location, $timeout, vocabulariesService) {
491
	$scope.orgId = $routeParams.id;
492
	$scope.org = {};
493
	$scope.events = {};
494
	$scope.info = {};
495
	
496
	$scope.getInfo = function() {
497
    	$http.get('api/organizations/info?id=' + $scope.orgId).then(function successCallback(res) {
498
    		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
499
    		$scope.info = res.data;
500
		}, function errorCallback(res) {
501
			alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
502
		});
503
    };
504
	
505
    $scope.getInfo();
506
	
507
	$scope.vocabularies = {};
508
	vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
509
	
510
	if      ($routeParams.msg == 1) { $scope.message = 'New organization registered !!!'; }
511
	else if ($routeParams.msg == 2) { $scope.message = 'Organization updated !!!';        }
512
	else                            { $scope.message = '';                                }
513
	
514
	$timeout(function() { $scope.message = ''; }, 3000)
515
		
516
});
517

    
518
orgsModule.controller('showSuggestionsCtrl', function ($scope, $http, $routeParams, $location) {
519
	$scope.info = {};
520
	$scope.conflicts = [];
521
	$scope.duplicates = [];
522
	$scope.newGroups = [];
523
	$scope.currentTab = $routeParams.tab;
524
	$scope.country = $routeParams.country;
525
	
526
	$scope.getInfo = function() {
527
    	$http.get('api/organizations/suggestionsInfo').then(function successCallback(res) {
528
    		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
529
    		$scope.info = res.data;
530
    		if ($scope.country == '_') {
531
    			var found = '';
532
    			
533
    			angular.forEach($scope.info.byCountry, function(values, c) {
534
    				if (!found && (($scope.currentTab == 1 && values.nGroups > 0) || ($scope.currentTab == 2 && values.nDuplicates > 0) || ($scope.currentTab == 3 && values.nConflicts > 0))) {
535
    					found = c;
536
    				}
537
    			});
538
    			if (found) { $location.url('/suggestions/' + found + '/' + $scope.currentTab); }
539
    		}
540
 		}, function errorCallback(res) {
541
			alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
542
		});
543
	};
544
	
545

    
546
	$scope.refresh = function() {
547
		$scope.conflicts = [];
548
		$scope.duplicates = [];
549
		$scope.newGroups = [];
550
		
551
		if ($scope.country != '_') {
552
			if ($scope.currentTab == 1) {
553
				$scope.groups = []; //TODO
554
			} else if ($scope.currentTab == 2) {
555
				$http.get('api/organizations/duplicates/byCountry/' + $scope.country).then(function successCallback(res) {
556
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
557
					$scope.duplicates = res.data;
558
					if ($scope.duplicates.length > 0) {
559
						//$scope.currentCountry = $scope.duplicates.
560
					}
561
				}, function errorCallback(res) {
562
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
563
				});
564
			} else if ($scope.currentTab == 3) {
565
				$http.get('api/organizations/conflicts/byCountry/' + $scope.country).then(function successCallback(res) {
566
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
567
					$scope.conflicts = res.data;
568
				}, function errorCallback(res) {
569
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
570
				});
571
			} else {  }
572
		}
573
		$scope.getInfo();
574
	}
575
	
576
	$scope.refresh();
577
});
578

    
579

    
580
orgsModule.controller('usersCtrl', function ($scope, $http, $timeout, $route, vocabulariesService) {
581
	$scope.users = [];
582
	$scope.vocs = {};
583
	$scope.currentUser = {};
584
	$scope.superAdminMode = superAdminMode();
585
	
586
	$scope.vocabularies = {};
587
	vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
588
	
589
	$http.get('api/users').then(function successCallback(res) {
590
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
591
		$scope.users = res.data;
592
	}, function errorCallback(res) {
593
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
594
	});
595
		
596
	$scope.setCurrentUser = function(user) {
597
		angular.copy(user, $scope.currentUser);
598
		if (!$scope.currentUser.role || $scope.currentUser.role == 'PENDING') {		
599
			$scope.currentUser.role = 'USER';
600
		}
601
	}
602
	
603
	$scope.saveUser = function(user) {
604
		$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
605
		$http.post('api/users', user).then(function successCallback(res) {
606
			if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
607
			$scope.users = res.data;
608
		}, function errorCallback(res) {
609
			alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
610
		});
611
	}
612
	
613
	$scope.deleteUser = function(email) {
614
		if (confirm("Are you sure ?")) {
615
			$http.delete('api/users?email=' + email).then(function successCallback(res) {
616
				if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
617
				$scope.users = res.data;
618
			}, function errorCallback(res) {
619
				alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
620
			});
621
		}
622
	}
623
});
(10-10/12)