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
|
/**
* @author arnaud marhin<arnaud.marhin@orange.com>
*/
(function() {
'use strict';
angular
.module('moon')
.controller('ProjectAddController', ProjectAddController);
ProjectAddController.$inject = ['$scope', '$translate', 'alertService', 'formService', 'projectService', 'DEFAULT_CST'];
function ProjectAddController($scope, $translate, alertService, formService, projectService, DEFAULT_CST) {
var add = this;
/*
*
*/
add.form = {};
add.loading = false;
//@todo: verify if enable argument is understood serrver-side
add.project = { project: {name: null, description: null, enabled: true, domain: DEFAULT_CST.DOMAIN.DEFAULT} };
add.create= createProject;
/*
* ---- create
*/
function createProject() {
if(formService.isInvalid(add.form)) {
formService.checkFieldsValidity(add.form);
} else {
add.loading = true;
projectService.data.projects.create({}, add.project, createSuccess, createError);
}
function createSuccess(data) {
var created = data.project;
$translate('moon.project.add.success', { projectName: created.name }).then(function (translatedValue) {
alertService.alertSuccess(translatedValue);
});
add.loading = false;
$scope.$emit('event:projectCreatedSuccess', created);
}
function createError(reason) {
$translate('moon.project.add.error', { projectName: add.project.project.name }).then(function (translatedValue) {
alertService.alertError(translatedValue);
});
add.loading = false;
$scope.$emit('event:projectCreatedError', add.project);
}
}
}
})();
|