@@ -2,22 +2,39 @@ angular.module('schemaForm').directive('bootstrapDecorator',
22 [ '$parse' , '$compile' , '$http' , '$templateCache' ,
33function ( $parse , $compile , $http , $templateCache ) {
44
5- var templateUrl = function ( type ) {
6- if ( type === 'fieldset' ) {
5+ var templateUrl = function ( form ) {
6+ //readonly is a special case
7+ if ( form . readonly && form . key && form . type !== 'fieldset' ) {
8+ return 'directives/decorators/bootstrap/readonly.html' ;
9+ }
10+ if ( form . type === 'textarea' ) {
11+ return 'directives/decorators/bootstrap/textarea.html' ;
12+ }
13+ if ( form . type === 'fieldset' ) {
714 return 'directives/decorators/bootstrap/fieldset.html' ;
815 }
9- if ( type === 'select' ) {
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' ) {
1023 return 'directives/decorators/bootstrap/select.html' ;
1124 }
12- if ( type === 'checkbox' ) {
25+ if ( form . type === 'checkbox' ) {
1326 return 'directives/decorators/bootstrap/checkbox.html' ;
1427 }
15- if ( type === 'number' ) {
16- return 'directives/decorators/bootstrap/number.html' ;
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' ;
1733 }
18- if ( type === 'submit' ) {
34+ if ( form . type === 'submit' ) {
1935 return 'directives/decorators/bootstrap/submit.html' ;
2036 }
37+
2138 return 'directives/decorators/bootstrap/default.html' ;
2239 } ;
2340
@@ -28,7 +45,6 @@ function($parse, $compile, $http, $templateCache){
2845 replace : true ,
2946 transclude : false ,
3047 scope : true ,
31-
3248 link : function ( scope , element , attrs ) {
3349
3450 //rebind our part of the form to the scope.
@@ -38,16 +54,30 @@ function($parse, $compile, $http, $templateCache){
3854 //ok let's replace that template!
3955 //We do this manually since we need to bind ng-model properly and also
4056 //for fieldsets to recurse properly.
41- $http . get ( templateUrl ( form . type ) , { cache : $templateCache } ) . then ( function ( res ) {
42- var template = res . data . replace ( '$ $value$$' , 'model.' + form . key ) ;
57+ $http . get ( templateUrl ( form ) , { cache : $templateCache } ) . then ( function ( res ) {
58+ var template = res . data . replace ( / \$ \ $v a l u e \$ \$ / g , 'model.' + form . key ) ;
4359 $compile ( template ) ( scope , function ( clone ) {
4460 element . replaceWith ( clone ) ;
4561 } ) ;
4662 } ) ;
4763 once ( ) ;
4864 } ) ;
49- }
5065
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+
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+ }
5181 } ;
5282} ] ) ;
5383
0 commit comments