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
			'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
				alert('todo');
71
			}		
72
		}
73
	}
74
});
75
		
76
orgsModule.directive('orgTabsMenu', function($http) {
77
	return {
78
		restrict: 'E',
79
		scope: {
80
			'orgId'    : '@',
81
			'info'     : '=',
82
			'selected' : '=',
83
			'org'      : '=',
84
			'events'   : '=',
85
		},
86
		templateUrl: 'resources/html/menu/org_tabs_menu.html',
87
		link: function(scope, element, attrs, ctrl) {
88

    
89
			scope.loadOrg = function() {
90
				scope.org = {};
91
				$http.get('api/organizations/get?id=' + scope.orgId).then(function successCallback(res) {
92
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
93
					scope.org = res.data;
94
				}, function errorCallback(res) {
95
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
96
				});
97
				scope.selected = 1;
98
			}
99
			
100
			scope.loadDedupEvents = function() {
101
				scope.events = {};
102

    
103
				$http.get('api/organizations/conflicts?id=' + scope.orgId).then(function successCallback(res) {
104
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
105
					scope.events.conflicts = res.data;
106
					$http.get('api/organizations/duplicates?id=' + scope.orgId).then(function successCallback(res) {
107
						if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
108
						scope.events.duplicates = res.data;
109
					}, function errorCallback(res) {
110
						alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
111
					});
112
				}, function errorCallback(res) {
113
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
114
				});
115
				scope.selected = 2;
116
			};
117
								
118
			scope.loadOrg();
119
		}
120
     }
121
});
122

    
123

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

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

    
209

    
210
orgsModule.directive('orgDetails', function($http, $location, $route) {
211
	return {
212
		restrict: 'E',
213
		scope: {
214
			'org'      : '=',
215
			'orgTitle' : '@',
216
			'show'     : '@'
217
		},
218
		templateUrl: 'resources/html/parts/org_details.html',
219
		link: function(scope, element, attrs, ctrl) {}
220
     }
221
});
222

    
223
orgsModule.directive('orgResults', function($http, $location, $route) {
224
	return {
225
		restrict: 'E',
226
		scope: {
227
			'searchMessage' : '@',
228
			'orgs'          : '=',
229
			'nextFunction'  : '&',
230
			'prevFunction'  : '&',
231
			'selectedOrg'   : '=',
232
			'mode'          : '@'
233
		},
234
		templateUrl: 'resources/html/parts/org_results.html',
235
		link: function(scope, element, attrs, ctrl) {
236
			scope.selectOrg = function(o) {
237
				scope.selectedOrg = o;
238
			}
239
		}
240
     }
241
});
242

    
243

    
244
orgsModule.directive('allConflicts', function($http, $location, $route, $q) {
245
	return {
246
		restrict: 'E',
247
		scope: {
248
			'conflicts'    : '=',
249
			'country'      : '@',
250
			'info'         : '=',
251
			'infoMethod'   : '&'
252
		},
253
		templateUrl: 'resources/html/forms/all_conflicts.html',
254
		link: function(scope, element, attrs, ctrl) {
255
			scope.orgs = [];
256
			
257
			scope.prepareConflictsModal = function(list) {
258
				scope.orgs = [];
259
				scope.selectedOrgs = [];
260
				
261
				var gets = list.map((o) => $http.get('api/organizations/get?id=' + o.id));
262
				
263
				$q.all(gets).then(function(responses) {
264
					scope.orgs = responses.map((resp) => resp.data);
265
					angular.forEach(scope.orgs, function(org) { org.show = 'secondary'; });
266
				});
267
			}
268
			
269
		}
270
     }
271
});
272

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

    
286
orgsModule.directive('orgFormConflicts', function($http, $location, $route, $q) {
287
	return {
288
		restrict: 'E',
289
		scope: {
290
			'orgId'          : '@',   
291
			'conflicts'      : '=',
292
			'showSaveButton' : '@',
293
			'saveFunction'   : '&'
294
		},
295
		templateUrl: 'resources/html/forms/org_conflicts.html',
296
		link: function(scope, element, attrs, ctrl) {
297
			scope.candidateConflicts = [];
298
			scope.selectedConflicts = [];
299
			
300
			scope.prepareConflictsModal = function() {
301
				scope.candidateConflicts = [];
302
				scope.selectedConflicts = [];
303
				
304
				var gets = [ $http.get('api/organizations/get?id=' + scope.orgId) ];
305
				angular.forEach(scope.conflicts, function(c) { gets.push($http.get('api/organizations/get?id=' + c.id)); });
306
				
307
				$q.all(gets).then(function(responses) {
308
					scope.candidateConflicts = responses.map((resp) => resp.data);
309
					angular.forEach(scope.candidateConflicts, function(org) { org.show = 'secondary'; });
310
				});
311
			}
312
		}
313
     }
314
});
315

    
316
orgsModule.directive('allDuplicates', function($http, $location, $route) {
317
	return {
318
		restrict: 'E',
319
		scope: {
320
			'duplicates'   : '=',
321
			'country'      : '@',
322
			'info'         : '=',
323
			'infoMethod'   : '&'
324
		},
325
		templateUrl: 'resources/html/forms/all_duplicates.html',
326
		link: function(scope, element, attrs, ctrl) {
327
			scope.currentOrg = {};
328
			scope.currentOrgDetails = {};
329
			scope.currentDuplicates = [];
330
			
331
			scope.prepareDuplicatesModal = function(org) {
332
				scope.currentOrg = org;
333
				scope.currentOrgDetails = {};
334
				scope.currentDuplicates = [];
335
				
336
				$http.get('api/organizations/get?id=' + org.id).then(function successCallback(res) {
337
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
338
					scope.currentOrgDetails = res.data;
339
				}, function errorCallback(res) {
340
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
341
				});
342
				
343
				$http.get('api/organizations/duplicates?id=' + org.id).then(function successCallback(res) {
344
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
345
					scope.currentDuplicates = res.data;
346
				}, function errorCallback(res) {
347
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
348
				});
349
			};
350
			
351
			scope.saveCurrentDuplicates = function() {
352
				$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
353
				$http.post('api/organizations/duplicates', scope.currentDuplicates).then(function successCallback(res) {
354
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
355
					if (scope.infoMethod)             { scope.infoMethod(); }
356
					scope.currentOrg.numberOfDuplicates = 0;
357
					for (var i=0; i<res.data.length; i++) {
358
						if (res.data[i].relType == 'suggested') {
359
							scope.currentOrg.numberOfDuplicates++;
360
						}
361
					}
362
					scope.currentDuplicates = [];
363
				}, function errorCallback(res) {
364
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
365
				});
366
			};
367
		}
368
    }
369
});
370

    
371
orgsModule.config(function($routeProvider) {
372
	$routeProvider
373
		.when('/new',                              { templateUrl: 'resources/html/new.html',              controller: 'newOrgCtrl' })
374
		.when('/search',                           { templateUrl: 'resources/html/search.html',           controller: 'searchCtrl' })
375
		.when('/searchResults/:page/:size/:text*', { templateUrl: 'resources/html/searchResults.html',    controller: 'searchResultsCtrl' })
376
		.when('/countries',                        { templateUrl: 'resources/html/browse.html',           controller: 'countriesCtrl' })
377
		.when('/byCountry/:page/:size/:code*',     { templateUrl: 'resources/html/resultsByCountry.html', controller: 'byCountryCtrl' })
378
		.when('/types',                            { templateUrl: 'resources/html/browse.html',           controller: 'typesCtrl' })
379
		.when('/byType/:page/:size/:type*',        { templateUrl: 'resources/html/resultsByType.html',    controller: 'byTypeCtrl' })
380
		.when('/edit/:msg/:id',                    { templateUrl: 'resources/html/edit.html',             controller: 'showEditCtrl' })
381
		.when('/suggestions/:country/:tab',        { templateUrl: 'resources/html/suggestions.html',      controller: 'showSuggestionsCtrl' })
382
		.when('/users',                            { templateUrl: 'resources/html/users.html',            controller: 'usersCtrl' })
383
		.otherwise({ redirectTo: '/suggestions/_/1' });
384
});
385

    
386
orgsModule.filter('escape', function() {
387
	return function(input) {
388
		return encodeURIComponent(encodeURIComponent(input));
389
	}; 
390
});
391

    
392
orgsModule.filter('unescape', function() {
393
	return function(input) {
394
		return decodeURIComponent(input);
395
	};
396
});
397

    
398
orgsModule.controller('newOrgCtrl', function ($scope, $http, $routeParams, $location, vocabulariesService) {
399
	$scope.org = {
400
		"id": "",
401
		"name": "",
402
		"type": null,
403
		"lat": 0.0,
404
		"lng": 0.0,
405
		"city": "",
406
		"country": "",
407
		"source": "user",
408
		"otherIdentifiers": [],
409
		"otherNames": [],
410
		"relations": [],
411
		"acronyms": [],
412
		"urls": [],
413
		"relations": []
414
	};
415
	
416
	$scope.vocabularies = {};
417
	vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
418
	
419
});
420

    
421
orgsModule.controller('searchCtrl', function ($scope, $location) {
422
	$scope.searchText = '';
423
	$scope.search = function() {
424
		$location.url('/searchResults/0/50/' + encodeURIComponent(encodeURIComponent($scope.searchText)));
425
	}
426
});
427

    
428
orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams, $location) {
429
	$scope.searchText = decodeURIComponent($routeParams.text);
430
	$scope.orgs = {};
431
	
432
	$http.get('api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.searchText).then(function successCallback(res) {
433
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
434
		$scope.orgs = res.data;
435
	}, function errorCallback(res) {
436
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
437
	});
438
	
439
	$scope.prev = function() {
440
		$location.url('/searchResults/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
441
	}
442
	
443
	$scope.next = function() {
444
		$location.url('/searchResults/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
445
	}
446
});
447

    
448
orgsModule.controller('countriesCtrl', function ($scope, $http, $routeParams) {
449
	$scope.field = 'Country';
450
	$scope.resultsBasePath = '/byCountry'
451
	$scope.entries = [];
452
	
453
	$http.get('api/organizations/browse/countries').then(function successCallback(res) {
454
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
455
		$scope.entries = res.data;
456
	}, function errorCallback(res) {
457
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
458
	});
459
	
460
});
461

    
462
orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams, $location) {
463
	$scope.fieldValue = decodeURIComponent($routeParams.code);
464
	$scope.orgs = {};
465
	
466
	$http.get('api/organizations/byCountry/' + $routeParams.code + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
467
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
468
		$scope.orgs = res.data;
469
	}, function errorCallback(res) {
470
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
471
	});
472
	
473
	$scope.prev = function() {
474
		$location.url('/byCountry/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
475
	}
476
	
477
	$scope.next = function() {
478
		$location.url('/byCountry/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
479
	}
480

    
481
});
482

    
483
orgsModule.controller('typesCtrl', function ($scope, $http, $routeParams) {
484
	$scope.field = 'Organization type';
485
	$scope.resultsBasePath = '/byType'
486
	$scope.entries = [];
487
	
488
	$http.get('api/organizations/browse/types').then(function successCallback(res) {
489
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
490
		$scope.entries = res.data;
491
	}, function errorCallback(res) {
492
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
493
	});
494
	
495
});
496

    
497
orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams, $location) {
498
	
499
	$scope.fieldValue = $routeParams.type;
500
	
501
	$scope.orgs = {};
502
	
503
	$http.get('api/organizations/byType/' + $routeParams.type + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
504
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
505
		$scope.orgs = res.data;
506
	}, function errorCallback(res) {
507
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
508
	});
509
	
510
	$scope.prev = function() {
511
		$location.url('/byType/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
512
	}
513
	
514
	$scope.next = function() {
515
		$location.url('/byType/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue));
516
	}
517
});
518

    
519

    
520
orgsModule.controller('showEditCtrl', function ($scope, $http, $routeParams, $route, $location, $timeout, vocabulariesService) {
521
	$scope.orgId = $routeParams.id;
522
	$scope.org = {};
523
	$scope.events = {};
524
	$scope.info = {};
525
	
526
	$scope.getInfo = function() {
527
    	$http.get('api/organizations/info?id=' + $scope.orgId).then(function successCallback(res) {
528
    		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
529
    		$scope.info = res.data;
530
		}, function errorCallback(res) {
531
			alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
532
		});
533
    };
534
	
535
    $scope.getInfo();
536
	
537
	$scope.vocabularies = {};
538
	vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
539
	
540
	if      ($routeParams.msg == 1) { $scope.message = 'New organization registered !!!'; }
541
	else if ($routeParams.msg == 2) { $scope.message = 'Organization updated !!!';        }
542
	else                            { $scope.message = '';                                }
543
	
544
	$timeout(function() { $scope.message = ''; }, 3000)
545
		
546
});
547

    
548
orgsModule.controller('showSuggestionsCtrl', function ($scope, $http, $routeParams, $location) {
549
	$scope.info = {};
550
	$scope.conflicts = [];
551
	$scope.duplicates = [];
552
	$scope.newGroups = [];
553
	$scope.currentTab = $routeParams.tab;
554
	$scope.country = $routeParams.country;
555
	
556
	$scope.getInfo = function() {
557
    	$http.get('api/organizations/suggestionsInfo').then(function successCallback(res) {
558
    		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
559
    		$scope.info = res.data;
560
    		if ($scope.country == '_') {
561
    			var found = '';
562
    			
563
    			angular.forEach($scope.info.byCountry, function(values, c) {
564
    				if (!found && (($scope.currentTab == 1 && values.nGroups > 0) || ($scope.currentTab == 2 && values.nDuplicates > 0) || ($scope.currentTab == 3 && values.nConflicts > 0))) {
565
    					found = c;
566
    				}
567
    			});
568
    			if (found) { $location.url('/suggestions/' + found + '/' + $scope.currentTab); }
569
    		}
570
 		}, function errorCallback(res) {
571
			alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
572
		});
573
	};
574
	
575

    
576
	$scope.refresh = function() {
577
		$scope.conflicts = [];
578
		$scope.duplicates = [];
579
		$scope.newGroups = [];
580
		
581
		if ($scope.country != '_') {
582
			if ($scope.currentTab == 1) {
583
				$scope.groups = []; //TODO
584
			} else if ($scope.currentTab == 2) {
585
				$http.get('api/organizations/duplicates/byCountry/' + $scope.country).then(function successCallback(res) {
586
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
587
					$scope.duplicates = res.data;
588
					if ($scope.duplicates.length > 0) {
589
						//$scope.currentCountry = $scope.duplicates.
590
					}
591
				}, function errorCallback(res) {
592
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
593
				});
594
			} else if ($scope.currentTab == 3) {
595
				$http.get('api/organizations/conflicts/byCountry/' + $scope.country).then(function successCallback(res) {
596
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
597
					$scope.conflicts = res.data;
598
				}, function errorCallback(res) {
599
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
600
				});
601
			} else {  }
602
		}
603
		$scope.getInfo();
604
	}
605
	
606
	$scope.refresh();
607
});
608

    
609

    
610
orgsModule.controller('usersCtrl', function ($scope, $http, $timeout, $route, vocabulariesService) {
611
	$scope.users = [];
612
	$scope.vocs = {};
613
	$scope.currentUser = {};
614
	$scope.superAdminMode = superAdminMode();
615
	
616
	$scope.vocabularies = {};
617
	vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
618
	
619
	$http.get('api/users').then(function successCallback(res) {
620
		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
621
		$scope.users = res.data;
622
	}, function errorCallback(res) {
623
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
624
	});
625
		
626
	$scope.setCurrentUser = function(user) {
627
		angular.copy(user, $scope.currentUser);
628
		if (!$scope.currentUser.role || $scope.currentUser.role == 'PENDING') {		
629
			$scope.currentUser.role = 'USER';
630
		}
631
	}
632
	
633
	$scope.saveUser = function(user) {
634
		$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
635
		$http.post('api/users', user).then(function successCallback(res) {
636
			if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
637
			$scope.users = res.data;
638
		}, function errorCallback(res) {
639
			alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
640
		});
641
	}
642
	
643
	$scope.deleteUser = function(email) {
644
		if (confirm("Are you sure ?")) {
645
			$http.delete('api/users?email=' + email).then(function successCallback(res) {
646
				if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
647
				$scope.users = res.data;
648
			}, function errorCallback(res) {
649
				alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
650
			});
651
		}
652
	}
653
});
(10-10/12)