1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/**
* @author arnaud marhin<arnaud.marhin@orange.com>
*/
(function() {
'use strict';
angular
.module('moon')
.controller('ProjectMapController', ProjectMapController);
ProjectMapController.$inject = ['$scope', '$translate', 'alertService', 'formService', 'pdpService'];
function ProjectMapController($scope, $translate, alertService, formService, pdpService) {
var map = this;
/*
*
*/
map.form = {};
map.project = $scope.project;
map.pdps = [];
map.pdpsLoading = true;
map.selectedPDP = null;
map.map = mapProject;
activate();
function activate(){
resolvePDPs();
}
/*
*
*/
function resolvePDPs() {
pdpService.findAllWithCallBack(resolveMappedProjects);
}
function resolveMappedProjects(pdps) {
map.pdps = _.filter(pdps, function(pdp){
return _.isNull(pdp.keystone_project_id);
});
map.pdpsLoading = false;
}
function mapProject() {
if(formService.isInvalid(map.form)) {
formService.checkFieldsValidity(map.form);
} else {
map.mappingLoading = true;
pdpService.map( map.selectedPDP, map.project.id, mapSuccess, mapError);
}
function mapSuccess(data) {
map.project.pdp = map.selectedPDP;
$translate('moon.project.map.success', { projectName: map.project.name, pdpName: map.selectedPDP.name }).then(function (translatedValue) {
alertService.alertSuccess(translatedValue);
});
map.mappingLoading = false;
$scope.$emit('event:projectMappedSuccess', map.project);
}
function mapError(response) {
$translate('moon.project.map.error', { projectName: map.project.name, pdpName: map.selectedPDP.name }).then(function (translatedValue) {
alertService.alertError(translatedValue);
});
map.mappingLoading = false;
$scope.$emit('event:projectMappedError', map.project);
}
}
}
})();
|