@@ -27,39 +27,41 @@ angular
27
27
. module ( 'schemaForm' )
28
28
. run ( function ( $templateCache ) {
29
29
// A template to use
30
- $templateCache . put ( 'calculated-fields.html' , '<calculate sf-field-model model="model" form="form" />' ) ;
30
+ $templateCache . put ( 'calculated-fields.html' , '<calculate sf-field-model model="model" form="form" />' ) ;
31
31
} )
32
- . directive ( 'calculate' , [ '$compile' , '$http' , 'sfBuilder' , 'sfSelect' , '$interpolate' , 'schemaFormDecorators' ,
32
+ . directive ( 'calculate' , [ '$compile' , '$http' , 'sfBuilder' , 'sfSelect' , '$interpolate' , 'schemaFormDecorators' ,
33
33
function ( $compile , $http , sfBuilder , sfSelect , $interpolate , schemaFormDecoratorsProvider ) {
34
34
return {
35
35
restrict : 'E' ,
36
36
scope : true ,
37
37
link : {
38
38
post : function ( scope , element , attrs , ctrl ) {
39
- var watchKeys = scope . form . watch ,
40
- key , keyFixed , exec ,
41
- i ;
39
+ let watchKeys = scope . form . watch ;
40
+ let key ;
41
+ let keyFixed ;
42
+ let i ;
42
43
43
44
scope . form . format = scope . form . format || 'number' ;
44
45
45
46
for ( i = 0 ; i < watchKeys . length ; i ++ ) {
46
47
key = watchKeys [ i ] . split ( '[]' ) ;
47
- keyFixed = key . reduce ( function ( pv , cv , ci , ta ) {
48
+ keyFixed = key . reduce ( function ( pv , cv , ci , ta ) {
48
49
return '' + pv + ( ( cv [ 0 ] == '.' ) ? '[' + scope . $i [ ci - 1 ] + ']' + cv : cv ) ;
49
50
} ) ;
50
51
51
52
scope . $watch ( keyFixed ,
52
53
function ( val , old ) {
53
- var newValue = $interpolate ( '{{' + scope . form . calculate + '}}' , false , null , true ) ( {
54
+ let newValue = $interpolate ( '{{' + scope . form . calculate + '}}' , false , null , true ) ( {
54
55
model : scope . model ,
55
56
$i : scope . $i ,
56
57
$index : scope . $index ,
57
- path : scope . path
58
+ path : scope . path ,
58
59
} ) ;
59
60
60
61
if ( scope . form . lookup ) {
61
62
scope . model . calculated = encodeURIComponent ( newValue ) ;
62
- var lookup = $interpolate ( scope . form . lookup , false , null , true ) ( scope . model ) ;
63
+ let lookup = $interpolate ( scope . form . lookup , false , null , true ) ( scope . model ) ;
64
+
63
65
$http . get ( lookup , { responseType : 'json' } )
64
66
. success ( function ( response , status ) {
65
67
if ( response . data ) update ( response . data ) ;
@@ -73,29 +75,33 @@ angular
73
75
update ( newValue ) ;
74
76
} ;
75
77
78
+ /**
79
+ * I update the model for the key
80
+ *
81
+ * @param {[type] } value [description]
82
+ */
76
83
function update ( value ) {
77
84
if ( scope . form . format == 'number' ) value = Number ( value ) ;
78
85
sfSelect ( scope . form . key , scope . model , value ) ;
79
86
} ;
80
87
} ) ;
81
88
} ;
82
- }
83
- }
89
+ } ,
90
+ } ,
84
91
} ;
85
- }
92
+ } ,
86
93
] )
87
94
. config ( [ 'schemaFormDecoratorsProvider' , 'sfBuilderProvider' ,
88
95
function ( schemaFormDecoratorsProvider , sfBuilderProvider ) {
89
- var sfField = sfBuilderProvider . builders . sfField ;
90
- var ngModel = sfBuilderProvider . builders . ngModel ;
91
- var ngModelOptions = sfBuilderProvider . builders . ngModelOptions ;
92
- var defaults = [ sfField , ngModel ] ;
96
+ let sfField = sfBuilderProvider . builders . sfField ;
97
+ let ngModel = sfBuilderProvider . builders . ngModel ;
98
+ let defaults = [ sfField , ngModel ] ;
93
99
94
100
schemaFormDecoratorsProvider . defineAddOn (
95
101
'bootstrapDecorator' ,
96
102
'calculate' ,
97
103
'calculated-fields.html' ,
98
104
defaults
99
105
) ;
100
- }
106
+ } ,
101
107
] ) ;
0 commit comments