-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollers.js
More file actions
70 lines (61 loc) · 1.78 KB
/
controllers.js
File metadata and controls
70 lines (61 loc) · 1.78 KB
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
var app = angular.module('test', []);
app.controller('formCtr', function($scope,$location){
$scope.location = $location;
$scope.forms = [{name:'Entreprise', inputs:[{label:"Raison Sociale",required:true},{label:"Contact"},{label:"Téléphone"}],datas:[]},
{name:'Particuliers', inputs:[{label:"Nom",required:true},{label:"Prénom"},{label:"Téléphone"}],datas:[]}
];
$scope.submitForm=function(form){
var newEntry = [];
form.inputs.forEach(function(input){
newEntry.push(input.value);
input.value = "";
})
form.datas.push(newEntry);
}
$scope.addLabel=function(form){
var newInput={};
var formInputsLength;
newInput['label']=form.newLabel;
form.newLabel='';
form.inputs.push(newInput);
formInputsLength = form.inputs.length;
/*Ajout d'un item pour les anciennes entrées.
SALE ? */
for (var i in form.datas){
while(form.datas[i].length < formInputsLength){
form.datas[i].push('');
}
}
}
$scope.addForm=function(){
var newForm = createForm($scope.newFormName); /* newFormName : déclarée dans le html*/
$scope.forms.push(newForm);
$location.path(newForm.name);
$scope.newFormName = '';
}
$scope.deleteData=function(datas, index){
datas.splice(index,1);
}
$scope.editData=function(form, data){
data.isEditing = true;
}
$scope.saveData=function(data){
data.isEditing = false;
}
$scope.labelOnFocus = function(elem){
elem.isFocus = true;
}
$scope.labelOnBlur = function(elem){
elem.isFocus = false;
}
$scope.$watch("location.path()",function(path){
$scope.displayedForm = path.replace('/','');
})
var createForm = function(formName/*str*/,inputs/*list arr*/, datas/*string arr*/){
form = {};
form['name'] = formName;
form['inputs'] = datas || [];
form['datas'] = inputs || [];
return form;
}
});