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
|
(function() {
'use strict';
angular
.module('moon')
.controller('ModelAddController', ModelAddController);
ModelAddController.$inject = ['$scope', 'modelService', 'alertService', '$translate', 'formService', 'utilService'];
function ModelAddController($scope, modelService, alertService, $translate, formService, utilService) {
var add = this;
/*
*
*/
add.form = {};
add.loading = false;
add.model = { name: null, description: null, meta_rules : [] };
add.create = createModel;
function createModel() {
if(formService.isInvalid(add.form)) {
formService.checkFieldsValidity(add.form);
} else {
add.loading = true;
modelService.data.create({}, add.model, createSuccess, createError);
}
function createSuccess(data) {
var createdModel = utilService.transformOne(data, 'models');
$translate('moon.model.add.success', { modelName: createdModel.name }).then(function (translatedValue) {
alertService.alertSuccess(translatedValue);
});
add.loading = false;
$scope.$emit('event:modelCreatedSuccess', createdModel);
}
function createError(reason) {
$translate('moon.model.add.error', { modelName: add.model.name }).then(function (translatedValue) {
alertService.alertError(translatedValue);
});
add.loading = false;
$scope.$emit('event:modelCreatedError', add.project);
}
}
}
})();
|