-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformgen.js
41 lines (36 loc) · 1.26 KB
/
formgen.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
app.directive('formGen', function ($parse){
return {
'controller': function ($scope, $element, $attrs, $transclude) {
$scope.params = {
"view": $attrs.formGen || "formgen/",
"formClass": "form-horizontal",
"fieldsetClass": "form-group",
"formcontrolClass": "col-lg-9 col-md-8 col-sm-8 col-xs-12",
"labelClass": "col-lg-9 col-md-8 col-sm-8 col-xs-12",
"inputClass": "form-control"
};
$scope.expr = function (expr) {
return $scope.$eval(expr);
};
$scope.resolveTemplate = function (tag, formKey) {
return $scope.forms[formKey].extend.view + tag + '.html';
}
$scope.resolveClass = function (value, module, formKey) {
return value ? value : $scope.forms[formKey].extend[module + 'Class'];
}
angular.forEach($scope.forms, function(form, formKey) {
form.extend = form.extend || {};
form.formData = form.formData || {};
angular.extend(form.extend, $scope.params);
});
},
'controllerAs': 'formGenCtrl',
'transclude': 'element',
'restrict': 'A',
'replace': true,
'scope': '=',
'templateUrl': function (element, attr) {
return (attr.formGen ? attr.formGen : 'formgen/') + 'layout.html';
}
}
});