1
|
var module = angular.module('affiliationsUI', []);
|
2
|
|
3
|
module.controller('affiliationsCtrl', function ($scope, $http, $timeout, $sce) {
|
4
|
initSpinner();
|
5
|
|
6
|
$scope.affiliations = [];
|
7
|
$scope.tempAffiliation = {};
|
8
|
$scope.groups = [];
|
9
|
|
10
|
$scope.refresh = function() {
|
11
|
showSpinner();
|
12
|
|
13
|
$scope.affiliations = [];
|
14
|
$http.get('portal/aff_view').success(function(data) {
|
15
|
hideSpinner();
|
16
|
angular.forEach(data, function(persons, name) {
|
17
|
$scope.affiliations.push({'name' : name, 'persons': persons});
|
18
|
});
|
19
|
}).error(function() {
|
20
|
hideSpinner();
|
21
|
show_notification("error","An error occurred while fetching affiliations");
|
22
|
});
|
23
|
|
24
|
$http.get('portal/groups').success(function(data) {
|
25
|
$scope.groups = data;
|
26
|
}).error(function() {
|
27
|
show_notification("error","An error occurred while fetching groups");
|
28
|
});
|
29
|
|
30
|
}
|
31
|
|
32
|
$scope.prepareTempAffiliation = function(pid, pname, year) {
|
33
|
$scope.tempAffiliation = {
|
34
|
'pid' : pid,
|
35
|
'pname' : pname,
|
36
|
'year' : year
|
37
|
}
|
38
|
}
|
39
|
|
40
|
$scope.saveAffiliation = function(aff) {
|
41
|
|
42
|
delete $scope.tempAffiliation['pname'];
|
43
|
|
44
|
if (!aff.gid) {
|
45
|
show_notification("error","Group not selected");
|
46
|
return;
|
47
|
}
|
48
|
|
49
|
showSpinner();
|
50
|
$http.post('portal/addAffiliation', aff).success(function(data) {
|
51
|
hideSpinner();
|
52
|
$scope.refresh();
|
53
|
}).error(function() {
|
54
|
hideSpinner();
|
55
|
show_notification("error","An error occurred saving affiliations");
|
56
|
});
|
57
|
}
|
58
|
|
59
|
$scope.refresh();
|
60
|
|
61
|
});
|
62
|
|