-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
69 lines (60 loc) · 1.75 KB
/
app.js
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
angular.module('selectExample', ['schemaForm', 'mgcrea.ngStrap'])
.controller('FormController', function($scope, $http, $q) {
var selectLinkedChange = function(key, model) {
$scope[model.childItem].splice(0);
var service = model.option.uri;
if (model.option.params == "contexto") {
service = service + "/" + key;
}
$http.get(service)
.then(function(result) {
result.data.forEach(function(item, index) {
var map = model.option.map;
if (model.option.params == "compare") {
if (item[map.compareField] == key) {
$scope[model.childItem].push({
value: item[map.valueField],
name: item[map.nameField]
});
}
} else {
$scope[model.childItem].push({
value: item[map.valueField],
name: item[map.nameField]
});
}
});
});
};
$scope.addLogic = function(form) {
var formObject = {};
if (typeof form == "string") {
formObject = JSON.parse(form);
} else {
formObject = form;
}
formObject.forEach(function(item, index) {
if (item.items) {
$scope.addLogic(item.items);
}
if (item.tabs) {
$scope.addLogic(item.tabs);
}
if (item.type == "select" || item.type == "strapselect") {
if (item.selectLinked) {
item.onChange = selectLinkedChange;
}
if (item.createTitleMap) {
$scope[item.key] = [];
item.titleMap = $scope[item.key];
}
}
});
return formObject;
}
$http.get('data/form-2.json').then(function(response) {
$scope.schema = response.data.schema;
$scope.form = $scope.addLogic(response.data.form);
});
$scope.model = {};
});