1
- /*! forms-angular 2015-01-28 */
1
+ /*! forms-angular 2015-02-04 */
2
2
'use strict' ;
3
3
4
4
var formsAngular = angular . module ( 'formsAngular' , [
@@ -591,29 +591,29 @@ formsAngular
591
591
'<div ng-form class="' + ( cssFrameworkService . framework ( ) === 'bs2' ? 'row-fluid ' : '' ) +
592
592
convertFormStyleToClass ( info . formStyle ) + '" name="form_' + niceName + '{{$index}}" class="sub-doc well" id="' + info . id + 'List_{{$index}}" ' +
593
593
' ng-repeat="subDoc in ' + ( options . model || 'record' ) + '.' + info . name + ' track by $index">' +
594
- ' <div class="' + ( cssFrameworkService . framework ( ) === 'bs2' ? 'row-fluid' : 'row' ) + ' sub-doc">' +
595
- ' <div class="pull-left">' + processInstructions ( info . schema , false , { subschema : true , formstyle : info . formStyle , model : options . model , subschemaRoot : info . name } ) +
596
- ' </div>' ;
597
-
594
+ ' <div class="' + ( cssFrameworkService . framework ( ) === 'bs2' ? 'row-fluid' : 'row' ) + ' sub-doc">' ;
598
595
if ( ! info . noRemove || info . customSubDoc ) {
599
- template += ' <div class="pull-left sub-doc-btns">' ;
596
+ template += ' <div class="sub-doc-btns">' ;
600
597
if ( info . customSubDoc ) {
601
598
template += info . customSubDoc ;
602
599
}
603
600
if ( ! info . noRemove ) {
604
601
if ( cssFrameworkService . framework ( ) === 'bs2' ) {
605
602
template += ' <button name="remove_' + info . id + '_btn" class="remove-btn btn btn-mini form-btn" ng-click="remove(\'' + info . name + '\',$index,$event)">' +
606
- ' <i class="icon-minus">' ;
603
+ ' <i class="icon-minus">' ;
607
604
608
605
} else {
609
606
template += ' <button name="remove_' + info . id + '_btn" class="remove-btn btn btn-default btn-xs form-btn" ng-click="remove(\'' + info . name + '\',$index,$event)">' +
610
607
' <i class="glyphicon glyphicon-minus">' ;
611
608
}
612
609
template += ' </i> Remove' +
613
- ' </button>' ;
610
+ ' </button>' ;
614
611
}
615
612
template += ' </div> ' ;
616
613
}
614
+
615
+ template += processInstructions ( info . schema , false , { subschema : true , formstyle : info . formStyle , model : options . model , subschemaRoot : info . name } ) ;
616
+
617
617
template += ' </div>' +
618
618
'</div>' ;
619
619
if ( ! info . noAdd || info . customFooter ) {
@@ -729,6 +729,12 @@ formsAngular
729
729
}
730
730
}
731
731
}
732
+ for ( prop in options ) {
733
+ if ( options . hasOwnProperty ( prop ) && prop [ 0 ] !== '$' ) {
734
+ newElement += ' fng-opt-' + prop + '="' + options [ prop ] . toString ( ) . replace ( / " / g, '"' ) + '"' ;
735
+ }
736
+ }
737
+
732
738
newElement += '></' + directiveName + '>' ;
733
739
result += newElement ;
734
740
callHandleField = false ;
@@ -1217,26 +1223,29 @@ formsAngular.provider('routingService', [ '$injector', '$locationProvider', func
1217
1223
var lastRoute = null ,
1218
1224
lastObject = { } ;
1219
1225
1220
- function _setUpNgRoutes ( routes ) {
1226
+ function _setUpNgRoutes ( routes , prefix , additional ) {
1227
+ prefix = prefix || '' ;
1221
1228
angular . forEach ( routes , function ( routeSpec ) {
1222
- _routeProvider . when ( config . prefix + routeSpec . route , routeSpec . options || { templateUrl : routeSpec . templateUrl } ) ;
1229
+ _routeProvider . when ( prefix + routeSpec . route , angular . extend ( routeSpec . options || { templateUrl : routeSpec . templateUrl } , additional ) ) ;
1223
1230
} ) ;
1224
1231
// This next bit is just for the demo website to allow demonstrating multiple frameworks - not available with other routers
1225
1232
if ( config . variantsForDemoWebsite ) {
1226
1233
angular . forEach ( config . variantsForDemoWebsite , function ( variant ) {
1227
1234
angular . forEach ( routes , function ( routeSpec ) {
1228
- _routeProvider . when ( config . prefix + variant + routeSpec . route , routeSpec . options || { templateUrl : routeSpec . templateUrl } ) ;
1235
+ _routeProvider . when ( prefix + variant + routeSpec . route , angular . extend ( routeSpec . options || { templateUrl : routeSpec . templateUrl } , additional ) ) ;
1229
1236
} ) ;
1230
1237
} ) ;
1231
1238
}
1232
1239
}
1233
1240
1234
- function _setUpUIRoutes ( routes ) {
1241
+ function _setUpUIRoutes ( routes , prefix , additional ) {
1242
+ prefix = prefix || '' ;
1235
1243
angular . forEach ( routes , function ( routeSpec ) {
1236
- _stateProvider . state ( routeSpec . state , routeSpec . options || {
1237
- url : routeSpec . route ,
1244
+ _stateProvider . state ( routeSpec . state , angular . extend ( routeSpec . options || {
1245
+ url : prefix + routeSpec . route ,
1238
1246
templateUrl : routeSpec . templateUrl
1239
- } ) ;
1247
+ } , additional )
1248
+ ) ;
1240
1249
} ) ;
1241
1250
}
1242
1251
@@ -1259,6 +1268,18 @@ formsAngular.provider('routingService', [ '$injector', '$locationProvider', func
1259
1268
}
1260
1269
1261
1270
return {
1271
+ /*
1272
+ options:
1273
+ prefix: A string (such as '/db') that gets prepended to all the generated routes. This can be used to
1274
+ prevent generated routes (which have a lot of parameters) from clashing with other routes in
1275
+ the web app that have nothing to do with CRUD forms
1276
+ add2fngRoutes: An object to add to the generated routes. One user case would be to add {authenticate: true}
1277
+ so that the client authenticates for certain routes
1278
+ html5Mode: boolean
1279
+ routing: Must be 'ngroute' or 'uirouter'
1280
+
1281
+
1282
+ */
1262
1283
start : function ( options ) {
1263
1284
angular . extend ( config , options ) ;
1264
1285
if ( config . prefix [ 0 ] && config . prefix [ 0 ] !== '/' ) { config . prefix = '/' + config . prefix ; }
@@ -1270,13 +1291,13 @@ formsAngular.provider('routingService', [ '$injector', '$locationProvider', func
1270
1291
case 'ngroute' :
1271
1292
_routeProvider = $injector . get ( '$routeProvider' ) ;
1272
1293
if ( config . fixedRoutes ) { _setUpNgRoutes ( config . fixedRoutes ) ; }
1273
- _setUpNgRoutes ( builtInRoutes ) ;
1294
+ _setUpNgRoutes ( builtInRoutes , config . prefix , options . add2fngRoutes ) ;
1274
1295
break ;
1275
1296
case 'uirouter' :
1276
1297
_stateProvider = $injector . get ( '$stateProvider' ) ;
1277
1298
if ( config . fixedRoutes ) { _setUpUIRoutes ( config . fixedRoutes ) ; }
1278
1299
setTimeout ( function ( ) {
1279
- _setUpUIRoutes ( builtInRoutes ) ;
1300
+ _setUpUIRoutes ( builtInRoutes , config . prefix , options . add2fngRoutes ) ;
1280
1301
} ) ;
1281
1302
break ;
1282
1303
}
@@ -2316,31 +2337,65 @@ formsAngular.factory('pluginHelper', ['formMarkupHelper',function (formMarkupHel
2316
2337
2317
2338
exports . extractFromAttr = function ( attr , directiveName ) {
2318
2339
var info = { } ;
2340
+ var options = { formStyle : attr . formstyle } ;
2319
2341
var directiveOptions = { } ;
2320
2342
var directiveNameLength = directiveName . length ;
2321
2343
for ( var prop in attr ) {
2322
2344
if ( attr . hasOwnProperty ( prop ) ) {
2323
2345
if ( prop . slice ( 0 , 6 ) === 'fngFld' ) {
2324
- info [ prop . slice ( 6 ) . toLowerCase ( ) ] = attr [ prop ] . replace ( / & q u o t ; / g, '"' ) ;
2346
+ info [ prop . slice ( 6 ) . toLowerCase ( ) ] = attr [ prop ] . replace ( / & q u o t ; / g, '"' ) ;
2347
+ } else if ( prop . slice ( 0 , 6 ) === 'fngOpt' ) {
2348
+ options [ prop . slice ( 6 ) . toLowerCase ( ) ] = attr [ prop ] . replace ( / & q u o t ; / g, '"' ) ;
2325
2349
} else if ( prop . slice ( 0 , directiveNameLength ) === directiveName ) {
2326
2350
directiveOptions [ prop . slice ( directiveNameLength ) . toLowerCase ( ) ] = attr [ prop ] . replace ( / & q u o t ; / g, '"' ) ;
2327
2351
}
2328
2352
}
2329
2353
}
2330
- var options = { formStyle : attr . formstyle } ;
2331
2354
return { info : info , options : options , directiveOptions : directiveOptions } ;
2332
2355
} ;
2333
2356
2334
2357
exports . buildInputMarkup = function ( scope , model , info , options , addButtons , needsX , generateInputControl ) {
2335
2358
var fieldChrome = formMarkupHelper . fieldChrome ( scope , info , options , ' id="cg_' + info . id + '"' ) ;
2336
2359
var controlDivClasses = formMarkupHelper . controlDivClasses ( options ) ;
2337
2360
var elementHtml = fieldChrome . template + formMarkupHelper . label ( scope , info , addButtons , options ) ;
2338
- var buildingBlocks ;
2361
+ var modelString , idString , nameString ;
2362
+
2339
2363
if ( addButtons ) {
2340
- buildingBlocks = formMarkupHelper . allInputsVars ( scope , info , options , 'arrayItem' + ( needsX ? '.x' : '' ) , info . id + '_{{$index}}' , info . name + '_{{$index}}' ) ;
2364
+ modelString = 'arrayItem' + ( needsX ? '.x' : '' ) ;
2365
+ idString = info . id + '_{{$index}}' ;
2366
+ nameString = info . name + '_{{$index}}' ;
2341
2367
} else {
2342
- buildingBlocks = formMarkupHelper . allInputsVars ( scope , info , options , model + '.' + info . name , info . id , info . name ) ;
2368
+ modelString = model + '.' + info . name ;
2369
+ idString = info . id ;
2370
+ nameString = info . name ;
2343
2371
}
2372
+
2373
+ if ( options . subschema && info . name . indexOf ( '.' ) !== - 1 ) {
2374
+ // Schema handling - need to massage the ngModel and the id
2375
+ var modelBase = model + '.' ;
2376
+ var compoundName = info . name ;
2377
+ var root = options . subschemaroot ;
2378
+ var lastPart = compoundName . slice ( root . length + 1 ) ;
2379
+ modelString = modelBase ;
2380
+
2381
+ if ( options . index ) {
2382
+ modelString += root + '[' + options . index + '].' + lastPart ;
2383
+ idString = 'f_' + modelString . slice ( modelBase . length ) . replace ( / ( \. | \[ | \] \. ) / g, '-' ) ;
2384
+ } else {
2385
+ modelString += root ;
2386
+ if ( options . subkey ) {
2387
+ idString = modelString . slice ( modelBase . length ) . replace ( / \. / g, '-' ) + '-subkey' + options . subkeyno + '-' + lastPart ;
2388
+ modelString += '[' + '$_arrayOffset_' + root . replace ( / \. / g, '_' ) + '_' + options . subkeyno + '].' + lastPart ;
2389
+ } else {
2390
+ modelString += '[$index].' + lastPart ;
2391
+ idString = null ;
2392
+ nameString = compoundName . replace ( / \. / g, '-' ) ;
2393
+ }
2394
+ }
2395
+ }
2396
+
2397
+ var buildingBlocks = formMarkupHelper . allInputsVars ( scope , info , options , modelString , idString , nameString ) ;
2398
+
2344
2399
elementHtml += formMarkupHelper [ 'handle' + ( addButtons ? 'Array' : '' ) + 'InputAndControlDiv' ] (
2345
2400
formMarkupHelper . inputChrome (
2346
2401
generateInputControl ( buildingBlocks ) ,
0 commit comments