Project

General

Profile

« Previous | Next » 

Revision 57804

View differences:

organizations.js
1 1
var orgsModule = angular.module('orgs', ['ngRoute', 'checklist-model']);
2 2

  
3
orgsModule.service('orgInfoService', function($http) {
4
    this.info = {};
5
    this.getInfo = function(id, f) {
6
    	if (id) {
7
    		if (this.info.id == id) {
8
    			f(this.info);
9
    		} else {
10
		    	$http.get('api/organizations/info?id=' + id).then(function successCallback(res) {
11
		    		if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
12
		    		this.info = res.data;
13
		    		f(angular.copy(this.info));
14
				}, function errorCallback(res) {
15
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
16
				});
17
	    	}
18
    	} else {
19
    		f({});
20
    	}
21
    };
22
});
23

  
24 3
orgsModule.service('vocabulariesService', function($http) {
25 4
    this.vocs = {};
26 5
    this.getVocs = function(f) {
......
42 21
	return {
43 22
		restrict: 'E',
44 23
		scope: {
45
			info : '='
24
			'info'    : '=',
25
			'message' : '='
46 26
		},
47 27
		templateUrl: 'resources/html/part/org_info.html'
48 28
     }
......
95 75
			'orgId'        : '@',
96 76
			'org'          : '=',
97 77
			'vocabularies' : '=',
98
			'mode'         : '@'  // insert or update
78
			'mode'         : '@',  // insert or update
79
			'infoMethod'   : '&'
99 80
		},
100 81
		templateUrl: 'resources/html/part/org_form_metadata.html',
101 82
		link: function(scope, element, attrs, ctrl) {
......
159 140
		scope: {
160 141
			'orgId'        : '@',
161 142
			'events'       : '=',
162
			'vocabularies' : '='
143
			'vocabularies' : '=',
144
			'infoMethod'   : '&'
163 145
		},
164 146
		templateUrl: 'resources/html/part/org_form_dedup_events.html',
165 147
		link: function(scope, element, attrs, ctrl) {
......
167 149
				$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
168 150
				$http.post('api/organizations/duplicates', scope.events.duplicates).then(function successCallback(res) {
169 151
					if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
152
					if (scope.infoMethod)             { scope.infoMethod(); }
170 153
					alert('Events updated !!!');
171
					scope.events = res.data;
154
					scope.events.duplicates = res.data;
172 155
				}, function errorCallback(res) {
173 156
					alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
174 157
				});
......
305 288
});
306 289

  
307 290

  
308
orgsModule.controller('showEditCtrl', function ($scope, $http, $routeParams, $route, $location, $timeout, orgInfoService, vocabulariesService) {
291
orgsModule.controller('showEditCtrl', function ($scope, $http, $routeParams, $route, $location, $timeout, vocabulariesService) {
309 292
	$scope.orgId = $routeParams.id;
310 293
	$scope.org = {};
311 294
	$scope.events = {};
312
	
313 295
	$scope.info = {};
314
	orgInfoService.getInfo($scope.orgId, function(info) { $scope.info = info; });
315 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
	
316 308
	$scope.vocabularies = {};
317 309
	vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
318 310
	

Also available in: Unified diff