|
1 | | -angular.module('schemaForm').directive('bootstrapDecorator', |
2 | | - ['$parse','$compile','$http','$templateCache', |
3 | | -function($parse, $compile, $http, $templateCache){ |
4 | | - |
5 | | - var templateUrl = function(form) { |
6 | | - //readonly is a special case |
| 1 | +angular.module('schemaForm').config(['schemaFormDecoratorsProvider',function(decoratorsProvider){ |
| 2 | + |
| 3 | + decoratorsProvider.create('bootstrapDecorator',{ |
| 4 | + textarea: 'directives/decorators/bootstrap/textarea.html', |
| 5 | + fieldset: 'directives/decorators/bootstrap/fieldset.html', |
| 6 | + section: 'directives/decorators/bootstrap/section.html', |
| 7 | + actions: 'directives/decorators/bootstrap/actions.html', |
| 8 | + select: 'directives/decorators/bootstrap/select.html', |
| 9 | + checkbox: 'directives/decorators/bootstrap/checkbox.html', |
| 10 | + checkboxes: 'directives/decorators/bootstrap/checkboxes.html', |
| 11 | + number: 'directives/decorators/bootstrap/default.html', |
| 12 | + submit: 'directives/decorators/bootstrap/submit.html', |
| 13 | + 'default': 'directives/decorators/bootstrap/default.html' |
| 14 | + },[ |
| 15 | + function(form){ |
7 | 16 | if (form.readonly && form.key && form.type !== 'fieldset') { |
8 | 17 | return 'directives/decorators/bootstrap/readonly.html'; |
9 | 18 | } |
10 | | - if (form.type === 'textarea') { |
11 | | - return 'directives/decorators/bootstrap/textarea.html'; |
12 | | - } |
13 | | - if (form.type === 'fieldset') { |
14 | | - return 'directives/decorators/bootstrap/fieldset.html'; |
15 | | - } |
16 | | - if (form.type === 'section') { |
17 | | - return 'directives/decorators/bootstrap/section.html'; |
18 | | - } |
19 | | - if (form.type === 'actions') { |
20 | | - return 'directives/decorators/bootstrap/actions.html'; |
21 | | - } |
22 | | - if (form.type === 'select') { |
23 | | - return 'directives/decorators/bootstrap/select.html'; |
24 | | - } |
25 | | - if (form.type === 'checkbox') { |
26 | | - return 'directives/decorators/bootstrap/checkbox.html'; |
27 | | - } |
28 | | - if (form.type === 'checkboxes') { |
29 | | - return 'directives/decorators/bootstrap/checkboxes.html'; |
30 | | - } |
31 | | - if (form.type === 'number') { |
32 | | - return 'directives/decorators/bootstrap/default.html'; |
33 | | - } |
34 | | - if (form.type === 'submit') { |
35 | | - return 'directives/decorators/bootstrap/submit.html'; |
36 | | - } |
37 | | - |
38 | | - return 'directives/decorators/bootstrap/default.html'; |
39 | | - }; |
40 | | - |
41 | | - |
42 | | - |
43 | | - return { |
44 | | - restrict: 'AE', |
45 | | - replace: true, |
46 | | - transclude: false, |
47 | | - scope: true, |
48 | | - link: function(scope,element,attrs) { |
49 | | - |
50 | | - //rebind our part of the form to the scope. |
51 | | - var once = scope.$watch(attrs.form,function(form){ |
52 | | - scope.form = form; |
| 19 | + } |
| 20 | + ]); |
53 | 21 |
|
54 | | - //ok let's replace that template! |
55 | | - //We do this manually since we need to bind ng-model properly and also |
56 | | - //for fieldsets to recurse properly. |
57 | | - $http.get(templateUrl(form),{ cache: $templateCache }).then(function(res){ |
58 | | - var template = res.data.replace(/\$\$value\$\$/g,'model.'+form.key); |
59 | | - $compile(template)(scope,function(clone){ |
60 | | - element.replaceWith(clone); |
61 | | - }); |
62 | | - }); |
63 | | - once(); |
64 | | - }); |
| 22 | +}]); |
65 | 23 |
|
66 | | - //Keep error prone logic from the template |
67 | | - scope.showTitle = function() { |
68 | | - return scope.form && scope.form.notitle !== true && scope.form.title; |
69 | | - }; |
70 | 24 |
|
71 | | - scope.checkboxValuesToList = function(values){ |
72 | | - var lst = []; |
73 | | - angular.forEach(values,function(v,k){ |
74 | | - if (v) { |
75 | | - lst.push(k); |
76 | | - } |
77 | | - }); |
78 | | - return lst; |
79 | | - }; |
80 | | - } |
81 | | - }; |
82 | | -}]); |
83 | 25 |
|
0 commit comments