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('organizationInfo', function() {
|
21
|
return {
|
22
|
restrict: 'E',
|
23
|
scope: {
|
24
|
'info' : '=',
|
25
|
'message' : '='
|
26
|
},
|
27
|
templateUrl: 'resources/html/part/org_info.html'
|
28
|
}
|
29
|
});
|
30
|
|
31
|
orgsModule.directive('orgTabsMenu', function($http) {
|
32
|
return {
|
33
|
restrict: 'E',
|
34
|
scope: {
|
35
|
'orgId' : '@',
|
36
|
'info' : '=',
|
37
|
'selected' : '=',
|
38
|
'org' : '=',
|
39
|
'events' : '=',
|
40
|
},
|
41
|
templateUrl: 'resources/html/part/org_tabs_menu.html',
|
42
|
link: function(scope, element, attrs, ctrl) {
|
43
|
|
44
|
scope.loadOrg = function() {
|
45
|
scope.org = {};
|
46
|
$http.get('api/organizations/get?id=' + scope.orgId).then(function successCallback(res) {
|
47
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
48
|
scope.org = res.data;
|
49
|
}, function errorCallback(res) {
|
50
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
51
|
});
|
52
|
scope.selected = 1;
|
53
|
}
|
54
|
|
55
|
scope.loadDedupEvents = function() {
|
56
|
scope.events = [];
|
57
|
$http.get('api/organizations/dedupEvents?id=' + scope.orgId).then(function successCallback(res) {
|
58
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
59
|
scope.events = res.data;
|
60
|
}, function errorCallback(res) {
|
61
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
62
|
});
|
63
|
scope.selected = 2;
|
64
|
};
|
65
|
|
66
|
scope.loadOrg();
|
67
|
}
|
68
|
}
|
69
|
});
|
70
|
|
71
|
orgsModule.directive('orgFormMetadata', function($http, $location, $route, $routeParams) {
|
72
|
return {
|
73
|
restrict: 'E',
|
74
|
scope: {
|
75
|
'orgId' : '@',
|
76
|
'org' : '=',
|
77
|
'vocabularies' : '=',
|
78
|
'mode' : '@', // insert or update
|
79
|
'infoMethod' : '&'
|
80
|
},
|
81
|
templateUrl: 'resources/html/part/org_form_metadata.html',
|
82
|
link: function(scope, element, attrs, ctrl) {
|
83
|
|
84
|
scope.searchOrgs = [];
|
85
|
scope.searchValue = '';
|
86
|
|
87
|
scope.newRelation = {};
|
88
|
scope.newRelType = '';
|
89
|
|
90
|
scope.resetSelectedRelation = function() {
|
91
|
scope.newRelation = {};
|
92
|
}
|
93
|
|
94
|
scope.selectNewRelation = function(r) {
|
95
|
scope.newRelation = r;
|
96
|
}
|
97
|
|
98
|
scope.addNewRelation = function(r) {
|
99
|
scope.org.relations.push({
|
100
|
'relatedOrgId' : scope.newRelation.id,
|
101
|
'relatedOrgName' : scope.newRelation.name,
|
102
|
'type' : scope.newRelType
|
103
|
});
|
104
|
scope.newRelation = {};
|
105
|
scope.newRelType = '';
|
106
|
}
|
107
|
|
108
|
|
109
|
scope.search = function(text, page, size) {
|
110
|
scope.orgs = [];
|
111
|
$http.get('api/organizations/search/' + page + '/' + size + '?q=' + text).then(function successCallback(res) {
|
112
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
113
|
scope.searchValue = text;
|
114
|
scope.searchOrgs = res.data;
|
115
|
}, function errorCallback(res) {
|
116
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
117
|
});
|
118
|
}
|
119
|
|
120
|
scope.save = function() {
|
121
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
122
|
$http.post('api/organizations/save', scope.org).then(function successCallback(res) {
|
123
|
if ((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
124
|
else if (scope.mode == 'insert') { $location.url('/edit/1/' + res.data[0]); }
|
125
|
else if ($routeParams.msg == 2) { $route.reload(); }
|
126
|
else { $location.url('/edit/2/' + res.data[0]); }
|
127
|
}, function errorCallback(res) {
|
128
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
129
|
});
|
130
|
}
|
131
|
}
|
132
|
}
|
133
|
});
|
134
|
|
135
|
|
136
|
|
137
|
orgsModule.directive('orgFormDedupEvents', function($http, $location, $route) {
|
138
|
return {
|
139
|
restrict: 'E',
|
140
|
scope: {
|
141
|
'orgId' : '@',
|
142
|
'events' : '=',
|
143
|
'vocabularies' : '=',
|
144
|
'infoMethod' : '&'
|
145
|
},
|
146
|
templateUrl: 'resources/html/part/org_form_dedup_events.html',
|
147
|
link: function(scope, element, attrs, ctrl) {
|
148
|
scope.saveDuplicates = function() {
|
149
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
150
|
$http.post('api/organizations/duplicates', scope.events.duplicates).then(function successCallback(res) {
|
151
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
152
|
if (scope.infoMethod) { scope.infoMethod(); }
|
153
|
alert('Events updated !!!');
|
154
|
scope.events.duplicates = res.data;
|
155
|
}, function errorCallback(res) {
|
156
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
157
|
});
|
158
|
}
|
159
|
}
|
160
|
}
|
161
|
});
|
162
|
|
163
|
orgsModule.config(function($routeProvider) {
|
164
|
$routeProvider
|
165
|
.when('/new', { templateUrl: 'resources/html/new.html', controller: 'newOrgCtrl' })
|
166
|
.when('/search', { templateUrl: 'resources/html/search.html', controller: 'searchCtrl' })
|
167
|
.when('/searchResults/:page/:size/:text*', { templateUrl: 'resources/html/list.html', controller: 'searchResultsCtrl' })
|
168
|
.when('/countries', { templateUrl: 'resources/html/browse.html', controller: 'countriesCtrl' })
|
169
|
.when('/byCountry/:page/:size/:code*', { templateUrl: 'resources/html/list.html', controller: 'byCountryCtrl' })
|
170
|
.when('/types', { templateUrl: 'resources/html/browse.html', controller: 'typesCtrl' })
|
171
|
.when('/byType/:page/:size/:type*', { templateUrl: 'resources/html/list.html', controller: 'byTypeCtrl' })
|
172
|
.when('/edit/:msg/:id', { templateUrl: 'resources/html/edit.html', controller: 'showEditCtrl' })
|
173
|
.when('/allConflicts', { templateUrl: 'resources/html/allConflicts.html', controller: 'showAllConflictsCtrl' })
|
174
|
.when('/users', { templateUrl: 'resources/html/users.html', controller: 'usersCtrl' })
|
175
|
.otherwise({ redirectTo: '/search' });
|
176
|
});
|
177
|
|
178
|
orgsModule.filter('escape', function() {
|
179
|
return function(input) {
|
180
|
return encodeURIComponent(encodeURIComponent(input));
|
181
|
};
|
182
|
});
|
183
|
|
184
|
orgsModule.filter('unescape', function() {
|
185
|
return function(input) {
|
186
|
return decodeURIComponent(input);
|
187
|
};
|
188
|
});
|
189
|
|
190
|
orgsModule.controller('newOrgCtrl', function ($scope, $http, $routeParams, $location, vocabulariesService) {
|
191
|
$scope.org = {
|
192
|
"id": "",
|
193
|
"name": "",
|
194
|
"type": null,
|
195
|
"lat": 0.0,
|
196
|
"lng": 0.0,
|
197
|
"city": "",
|
198
|
"country": "",
|
199
|
"source": "user",
|
200
|
"otherIdentifiers": [],
|
201
|
"otherNames": [],
|
202
|
"relations": [],
|
203
|
"acronyms": [],
|
204
|
"urls": [],
|
205
|
"relations": []
|
206
|
};
|
207
|
|
208
|
$scope.vocabularies = {};
|
209
|
vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
|
210
|
|
211
|
});
|
212
|
|
213
|
orgsModule.controller('searchCtrl', function ($scope, $location) {
|
214
|
$scope.textSearch = '';
|
215
|
$scope.search = function() {
|
216
|
$location.url('/searchResults/0/50/' + encodeURIComponent(encodeURIComponent($scope.textSearch)));
|
217
|
}
|
218
|
});
|
219
|
|
220
|
orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams) {
|
221
|
$scope.basepath = '/searchResults';
|
222
|
$scope.fieldValue = decodeURIComponent($routeParams.text);
|
223
|
|
224
|
$scope.orgs = {};
|
225
|
|
226
|
$http.get('api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.fieldValue).then(function successCallback(res) {
|
227
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
228
|
$scope.orgs = res.data;
|
229
|
}, function errorCallback(res) {
|
230
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
231
|
});
|
232
|
});
|
233
|
|
234
|
orgsModule.controller('countriesCtrl', function ($scope, $http, $routeParams) {
|
235
|
$scope.field = 'Country';
|
236
|
$scope.resultsBasePath = '/byCountry'
|
237
|
$scope.entries = [];
|
238
|
|
239
|
$http.get('api/organizations/browse/countries').then(function successCallback(res) {
|
240
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
241
|
$scope.entries = res.data;
|
242
|
}, function errorCallback(res) {
|
243
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
244
|
});
|
245
|
|
246
|
});
|
247
|
|
248
|
orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams) {
|
249
|
$scope.basepath = '/byCountry';
|
250
|
$scope.fieldValue = $routeParams.code;
|
251
|
|
252
|
$scope.orgs = [];
|
253
|
|
254
|
$http.get('api/organizations/byCountry/' + $routeParams.code + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
255
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
256
|
$scope.orgs = res.data;
|
257
|
}, function errorCallback(res) {
|
258
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
259
|
});
|
260
|
});
|
261
|
|
262
|
orgsModule.controller('typesCtrl', function ($scope, $http, $routeParams) {
|
263
|
$scope.field = 'Organization type';
|
264
|
$scope.resultsBasePath = '/byType'
|
265
|
$scope.entries = [];
|
266
|
|
267
|
$http.get('api/organizations/browse/types').then(function successCallback(res) {
|
268
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
269
|
$scope.entries = res.data;
|
270
|
}, function errorCallback(res) {
|
271
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
272
|
});
|
273
|
|
274
|
});
|
275
|
|
276
|
orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams) {
|
277
|
$scope.basepath = '/byType';
|
278
|
$scope.fieldValue = $routeParams.type;
|
279
|
|
280
|
$scope.orgs = [];
|
281
|
|
282
|
$http.get('api/organizations/byType/' + $routeParams.type + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
283
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
284
|
$scope.orgs = res.data;
|
285
|
}, function errorCallback(res) {
|
286
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
287
|
});
|
288
|
});
|
289
|
|
290
|
|
291
|
orgsModule.controller('showEditCtrl', function ($scope, $http, $routeParams, $route, $location, $timeout, vocabulariesService) {
|
292
|
$scope.orgId = $routeParams.id;
|
293
|
$scope.org = {};
|
294
|
$scope.events = {};
|
295
|
$scope.info = {};
|
296
|
|
297
|
$scope.getInfo = function() {
|
298
|
$http.get('api/organizations/info?id=' + $scope.orgId).then(function successCallback(res) {
|
299
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
300
|
$scope.info = res.data;
|
301
|
}, function errorCallback(res) {
|
302
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
303
|
});
|
304
|
};
|
305
|
|
306
|
$scope.getInfo();
|
307
|
|
308
|
$scope.vocabularies = {};
|
309
|
vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
|
310
|
|
311
|
if ($routeParams.msg == 1) { $scope.message = 'New organization registered !!!'; }
|
312
|
else if ($routeParams.msg == 2) { $scope.message = 'Organization updated !!!'; }
|
313
|
else { $scope.message = ''; }
|
314
|
|
315
|
$timeout(function() { $scope.message = ''; }, 3000)
|
316
|
|
317
|
});
|
318
|
|
319
|
orgsModule.controller('showAllConflictsCtrl', function ($scope, $http) {
|
320
|
$scope.conflicts = [];
|
321
|
$http.get('api/organizations/conflicts/all').then(function successCallback(res) {
|
322
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
323
|
$scope.conflicts = res.data;
|
324
|
}, function errorCallback(res) {
|
325
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
326
|
});
|
327
|
});
|
328
|
|
329
|
orgsModule.controller('usersCtrl', function ($scope, $http, $timeout, $route, vocabulariesService) {
|
330
|
$scope.users = [];
|
331
|
$scope.vocs = {};
|
332
|
$scope.currentUser = {};
|
333
|
$scope.superAdminMode = superAdminMode();
|
334
|
|
335
|
$scope.vocabularies = {};
|
336
|
vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
|
337
|
|
338
|
$http.get('api/users').then(function successCallback(res) {
|
339
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
340
|
$scope.users = res.data;
|
341
|
}, function errorCallback(res) {
|
342
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
343
|
});
|
344
|
|
345
|
$scope.setCurrentUser = function(user) {
|
346
|
angular.copy(user, $scope.currentUser);
|
347
|
if (!$scope.currentUser.role || $scope.currentUser.role == 'PENDING') {
|
348
|
$scope.currentUser.role = 'USER';
|
349
|
}
|
350
|
}
|
351
|
|
352
|
$scope.saveUser = function(user) {
|
353
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
354
|
$http.post('api/users', user).then(function successCallback(res) {
|
355
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
356
|
$scope.users = res.data;
|
357
|
}, function errorCallback(res) {
|
358
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
359
|
});
|
360
|
}
|
361
|
|
362
|
$scope.deleteUser = function(email) {
|
363
|
if (confirm("Are you sure ?")) {
|
364
|
$http.delete('api/users?email=' + email).then(function successCallback(res) {
|
365
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
366
|
$scope.users = res.data;
|
367
|
}, function errorCallback(res) {
|
368
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
369
|
});
|
370
|
}
|
371
|
}
|
372
|
});
|