@@ -38,67 +38,69 @@ angular.module('schemaForm').config(
38
38
39
39
40
40
} ] )
41
- . directive ( "toggleSingleModel" , function ( ) {
42
- // some how we get this to work ...
43
- return {
44
- require : 'ngModel' ,
45
- restrict : "A" ,
46
- scope : { } ,
47
- replace : true ,
48
- controller : [ '$scope' , function ( $scope ) {
49
- $scope . $parent . $watch ( 'select_model.selected' , function ( ) {
50
- if ( $scope . $parent . select_model . selected != undefined ) {
51
- $scope . $parent . insideModel = $scope . $parent . select_model . selected . value ;
52
- $scope . $parent . ngModel . $setViewValue ( $scope . $parent . select_model . selected . value ) ;
53
- }
54
- } ) ;
55
- } ]
56
- } ;
57
- } )
58
-
59
- . directive ( 'multipleOn' , function ( ) {
60
- return {
61
- link : function ( $scope , $element , $attrs ) {
62
- $scope . $watch (
63
- function ( ) { return $element . attr ( 'multiple-on' ) ; } ,
64
- function ( newVal ) {
65
-
66
- if ( newVal == "true" ) {
67
- var select_scope = angular . element ( $element ) . scope ( ) . $$childTail ;
68
- select_scope . $isMultiple = true ;
69
- select_scope . options . multiple = true ;
70
- select_scope . $select . $element . addClass ( 'select-multiple' ) ;
71
- }
72
- else {
73
- angular . element ( $element ) . scope ( ) . $$childTail . $isMultiple = false ;
74
- }
41
+ . directive ( "toggleSingleModel" , function ( ) {
42
+ // some how we get this to work ...
43
+ return {
44
+ require : 'ngModel' ,
45
+ restrict : "A" ,
46
+ scope : { } ,
47
+ replace : true ,
48
+ controller : [ '$scope' , function ( $scope ) {
49
+ $scope . $parent . $watch ( 'select_model.selected' , function ( ) {
50
+ if ( $scope . $parent . select_model . selected != undefined ) {
51
+ $scope . $parent . insideModel = $scope . $parent . select_model . selected . value ;
52
+ $scope . $parent . ngModel . $setViewValue ( $scope . $parent . select_model . selected . value ) ;
53
+ }
54
+ } ) ;
55
+ } ]
56
+ } ;
57
+ } )
58
+
59
+ . directive ( 'multipleOn' , function ( ) {
60
+ return {
61
+ link : function ( $scope , $element , $attrs ) {
62
+ $scope . $watch (
63
+ function ( ) {
64
+ return $element . attr ( 'multiple-on' ) ;
65
+ } ,
66
+ function ( newVal ) {
67
+
68
+ if ( newVal == "true" ) {
69
+ var select_scope = angular . element ( $element ) . scope ( ) . $$childTail ;
70
+ select_scope . $isMultiple = true ;
71
+ select_scope . options . multiple = true ;
72
+ select_scope . $select . $element . addClass ( 'select-multiple' ) ;
73
+ }
74
+ else {
75
+ angular . element ( $element ) . scope ( ) . $$childTail . $isMultiple = false ;
76
+ }
77
+ }
78
+ ) ;
75
79
}
76
- ) ;
77
- }
78
- } ;
79
- } )
80
- . filter ( 'whereMulti' , function ( ) {
81
- return function ( items , key , values ) {
82
- var out = [ ] ;
83
-
84
- if ( angular . isArray ( values ) && items !== undefined ) {
85
- values . forEach ( function ( value ) {
86
- for ( var i = 0 ; i < items . length ; i ++ ) {
87
- if ( value == items [ i ] [ key ] ) {
88
- out . push ( items [ i ] ) ;
89
- break ;
90
- }
91
- }
92
- } ) ;
93
- } else {
94
- // Let the output be the input untouched
95
- out = items ;
96
- }
97
-
98
- return out ;
99
- } ;
100
- } )
101
- . filter ( 'propsFilter' , function ( ) {
80
+ } ;
81
+ } )
82
+ . filter ( 'whereMulti' , function ( ) {
83
+ return function ( items , key , values ) {
84
+ var out = [ ] ;
85
+
86
+ if ( angular . isArray ( values ) && items !== undefined ) {
87
+ values . forEach ( function ( value ) {
88
+ for ( var i = 0 ; i < items . length ; i ++ ) {
89
+ if ( value == items [ i ] [ key ] ) {
90
+ out . push ( items [ i ] ) ;
91
+ break ;
92
+ }
93
+ }
94
+ } ) ;
95
+ } else {
96
+ // Let the output be the input untouched
97
+ out = items ;
98
+ }
99
+
100
+ return out ;
101
+ } ;
102
+ } )
103
+ . filter ( 'propsFilter' , function ( ) {
102
104
return function ( items , props ) {
103
105
var out = [ ] ;
104
106
@@ -148,7 +150,9 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
148
150
console . log ( "listener triggered" ) ;
149
151
// Ugly workaround to trigger titleMap expression re-evaluation so that the selectFilter it reapplied.
150
152
$scope . form . titleMap . push ( { "value" : "345890u340598u3405u9" , "name" : "34095u3p4ouij" } )
151
- $timeout ( function ( ) { $scope . form . titleMap . pop ( ) } )
153
+ $timeout ( function ( ) {
154
+ $scope . form . titleMap . pop ( )
155
+ } )
152
156
153
157
} ;
154
158
@@ -160,7 +164,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
160
164
} ) ;
161
165
}
162
166
// This is set here, as the model value may become unitialized and typeless if validation fails.
163
- $scope . localModelType = Object . prototype . toString . call ( localModel ) ;
167
+ $scope . localModelType = Object . prototype . toString . call ( localModel ) ;
164
168
$scope . filteringInitialized = true ;
165
169
} ;
166
170
@@ -170,25 +174,27 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
170
174
171
175
form . titleMap = [ ] ;
172
176
173
- if ( newOptions && "map" in newOptions && newOptions . map ) {
177
+ if ( newOptions && "map" in newOptions && newOptions . map ) {
174
178
var current_row = null ,
175
- final = newOptions . map . nameProperty . length - 1 ,
176
- separator = newOptions . map . separatorValue ? newOptions . map . separatorValue : ' - ' ;
177
- data . forEach ( function ( current_row ) {
178
- current_row [ "value" ] = current_row [ newOptions . map . valueProperty ] ;
179
- current_row [ "name" ] = "" ; //init the 'name' property
180
- //check if the value passed is a string or not
181
- if ( typeof newOptions . map . nameProperty != 'string' ) {
182
- //loop through the object/array
183
- for ( var i in newOptions . map . nameProperty ) {
184
- current_row [ "name" ] += current_row [ newOptions . map . nameProperty [ i ] ] ;
185
- if ( i != final ) { current_row [ "name" ] += separator } ;
186
- }
187
- }
188
- else {
189
- //if it is a string
190
- current_row [ "name" ] = current_row [ newOptions . map . nameProperty ] ;
191
- }
179
+ final = newOptions . map . nameProperty . length - 1 ,
180
+ separator = newOptions . map . separatorValue ? newOptions . map . separatorValue : ' - ' ;
181
+ data . forEach ( function ( current_row ) {
182
+ current_row [ "value" ] = current_row [ newOptions . map . valueProperty ] ;
183
+ current_row [ "name" ] = "" ; //init the 'name' property
184
+ //check if the value passed is a string or not
185
+ if ( typeof newOptions . map . nameProperty != 'string' ) {
186
+ //loop through the object/array
187
+ for ( var i in newOptions . map . nameProperty ) {
188
+ current_row [ "name" ] += current_row [ newOptions . map . nameProperty [ i ] ] ;
189
+ if ( i != final ) {
190
+ current_row [ "name" ] += separator
191
+ } ;
192
+ }
193
+ }
194
+ else {
195
+ //if it is a string
196
+ current_row [ "name" ] = current_row [ newOptions . map . nameProperty ] ;
197
+ }
192
198
form . titleMap . push ( current_row ) ;
193
199
} ) ;
194
200
@@ -204,7 +210,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
204
210
}
205
211
206
212
if ( $scope . insideModel && $scope . select_model . selected === undefined ) {
207
- $scope . select_model . selected = $scope . find_in_titleMap ( $scope . insideModel ) ;
213
+ $scope . select_model . selected = $scope . find_in_titleMap ( $scope . insideModel ) ;
208
214
}
209
215
210
216
// The ui-selects needs to be reinitialized (UI select sets the internalModel and externalModel.
@@ -286,7 +292,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
286
292
}
287
293
else if ( form . options . callback ) {
288
294
form . titleMap = $scope . getCallback ( form . options . callback ) ( form . options , search ) ;
289
- $scope . finalizeTitleMap ( form , form . titleMap , form . options ) ;
295
+ $scope . finalizeTitleMap ( form , form . titleMap , form . options ) ;
290
296
console . log ( "callback items: " , form . titleMap ) ;
291
297
}
292
298
else if ( form . options . asyncCallback ) {
@@ -301,7 +307,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
301
307
}
302
308
else {
303
309
alert ( "Loading select items failed(Key(field): " + form . key + "Options: '" + String ( form . options ) +
304
- "\nError: " + status ) ;
310
+ "\nError: " + status ) ;
305
311
}
306
312
307
313
} ) ;
@@ -321,7 +327,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
321
327
}
322
328
else {
323
329
alert ( "Loading select items failed (Key(field): " + form . key + " URL: '" + String ( finalOptions . httpPost . url ) +
324
- "' Parameter: " + String ( finalOptions . httpPost . parameter ) + "\nStatus: " + status ) ;
330
+ "' Parameter: " + String ( finalOptions . httpPost . parameter ) + "\nStatus: " + status ) ;
325
331
}
326
332
327
333
} ) ;
@@ -355,15 +361,14 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
355
361
356
362
} ;
357
363
358
- $scope . uiMultiSelectInitInternalModel = function ( supplied_model )
359
- {
364
+ $scope . uiMultiSelectInitInternalModel = function ( supplied_model ) {
360
365
361
366
362
- console . log ( "$scope.externalModel: Key: " + $scope . form . key . toString ( ) + " Model: " + supplied_model . toString ( ) ) ;
367
+ console . log ( "$scope.externalModel: Key: " + $scope . form . key . toString ( ) + " Model: " + supplied_model . toString ( ) ) ;
363
368
$scope . externalModel = supplied_model ;
364
369
$scope . internalModel = [ ] ;
365
370
if ( $scope . form . titleMap ) {
366
- if ( supplied_model !== undefined && angular . isArray ( supplied_model ) ) {
371
+ if ( supplied_model !== undefined && angular . isArray ( supplied_model ) ) {
367
372
supplied_model . forEach ( function ( value ) {
368
373
$scope . internalModel . push ( $scope . find_in_titleMap ( value ) ) ;
369
374
}
@@ -381,14 +386,12 @@ angular.module('schemaForm').filter('selectFilter', [function ($filter) {
381
386
// its string representation as well as we do not know its name. A typical value if strLocalModel is model['groups']
382
387
// This is very ugly, though. TODO: Find out why the model is set to undefined after validation failure.
383
388
384
- if ( ! angular . isDefined ( inputArray ) || ! angular . isDefined ( controller . form . options ) ||
385
- ! angular . isDefined ( controller . form . options . filter ) || controller . form . options . filter == '' ) {
389
+ if ( ! angular . isDefined ( inputArray ) || ! angular . isDefined ( controller . form . options ) || ! angular . isDefined ( controller . form . options . filter ) || controller . form . options . filter == '' ) {
386
390
return inputArray ;
387
391
}
388
392
389
393
390
-
391
- console . log ( "----- In filtering for " + controller . form . key + "(" + controller . form . title + "), model value: " + JSON . stringify ( localModel ) + "----" ) ;
394
+ console . log ( "----- In filtering for " + controller . form . key + "(" + controller . form . title + "), model value: " + JSON . stringify ( localModel ) + "----" ) ;
392
395
console . log ( "Filter:" + controller . form . options . filter ) ;
393
396
if ( ! controller . filteringInitialized ) {
394
397
console . log ( "Initialize filter" ) ;
@@ -412,15 +415,15 @@ angular.module('schemaForm').filter('selectFilter', [function ($filter) {
412
415
localModel . splice ( localModel . indexOf ( curr_item . value ) , 1 ) ;
413
416
}
414
417
else if ( localModel == curr_item . value ) {
415
- console . log ( "Setting model of type " + controller . localModelType + "to null." ) ;
418
+ console . log ( "Setting model of type " + controller . localModelType + "to null." ) ;
416
419
localModel = null ;
417
420
}
418
421
}
419
422
} ) ;
420
423
421
424
if ( controller . localModelType == "[object Array]" && ! localModel ) {
422
425
// An undefined local model seems to mess up bootstrap select's indicators
423
- console . log ( "Resetting model of type " + controller . localModelType + " to []." ) ;
426
+ console . log ( "Resetting model of type " + controller . localModelType + " to []." ) ;
424
427
425
428
controller . $eval ( strLocalModel + "=[]" ) ;
426
429
}
0 commit comments