@@ -60,9 +60,9 @@ var fng;
60
60
ModelCtrl . $inject = [ "$scope" , "$http" , "$location" , "routingService" ] ;
61
61
function ModelCtrl ( $scope , $http , $location , routingService ) {
62
62
$scope . models = [ ] ;
63
- $http . get ( '/api/models' ) . success ( function ( data ) {
64
- $scope . models = data ;
65
- } ) . error ( function ( ) {
63
+ $http . get ( '/api/models' ) . then ( function ( response ) {
64
+ $scope . models = response . data ;
65
+ } , function ( ) {
66
66
$location . path ( '/404' ) ;
67
67
} ) ;
68
68
$scope . newUrl = function ( model ) {
@@ -369,7 +369,8 @@ var fng;
369
369
$scope . $watch ( 'searchTarget' , function ( newValue ) {
370
370
if ( newValue && newValue . length > 0 ) {
371
371
currentRequest = newValue ;
372
- $http . get ( '/api/search?q=' + newValue ) . success ( function ( data ) {
372
+ $http . get ( '/api/search?q=' + newValue ) . then ( function ( response ) {
373
+ var data = response . data ;
373
374
// Check that we haven't fired off a subsequent request, in which
374
375
// case we are no longer interested in these results
375
376
if ( currentRequest === newValue ) {
@@ -386,8 +387,8 @@ var fng;
386
387
clearSearchResults ( ) ;
387
388
}
388
389
}
389
- } ) . error ( function ( data , status ) {
390
- console . log ( 'Error in searchbox.js : ' + data + ' (status=' + status + ')' ) ;
390
+ } , function ( response ) {
391
+ console . log ( 'Error in searchbox.js : ' + response . data + ' (status=' + response . status + ')' ) ;
391
392
} ) ;
392
393
}
393
394
else {
@@ -476,15 +477,16 @@ var fng;
476
477
}
477
478
scope [ 'link' ] = routingService . buildUrl ( ref + '/' + form + newVal + '/edit' ) ;
478
479
if ( ! scope [ 'text' ] ) {
479
- SubmissionsService . getListAttributes ( ref , newVal ) . success ( function ( data ) {
480
+ SubmissionsService . getListAttributes ( ref , newVal ) . then ( function ( response ) {
481
+ var data = response . data ;
480
482
if ( data . success === false ) {
481
483
scope [ 'text' ] = data . err ;
482
484
}
483
485
else {
484
486
scope [ 'text' ] = data . list ;
485
487
}
486
- } ) . error ( function ( status , err ) {
487
- scope [ 'text' ] = 'Error ' + status + ': ' + err ;
488
+ } , function ( response ) {
489
+ scope [ 'text' ] = 'Error ' + response . status + ': ' + response . data ;
488
490
} ) ;
489
491
}
490
492
}
@@ -1563,6 +1565,9 @@ var fng;
1563
1565
if ( config . hashPrefix !== '' ) {
1564
1566
$locationProvider . hashPrefix ( config . hashPrefix ) ;
1565
1567
}
1568
+ else if ( ! config . html5Mode ) {
1569
+ $locationProvider . hashPrefix ( '' ) ;
1570
+ }
1566
1571
switch ( config . routing ) {
1567
1572
case 'ngroute' :
1568
1573
_routeProvider = $injector . get ( '$routeProvider' ) ;
@@ -1732,6 +1737,7 @@ var fng;
1732
1737
services . routingService = routingService ;
1733
1738
} ) ( services = fng . services || ( fng . services = { } ) ) ;
1734
1739
} ) ( fng || ( fng = { } ) ) ;
1740
+ /// <reference path="../../typings/globals/jquery/index.d.ts" />
1735
1741
/// <reference path="../../typings/globals/angular/index.d.ts" />
1736
1742
/// <reference path="../../typings/globals/underscore/index.d.ts" />
1737
1743
/// <reference path="../fng-types.ts" />
@@ -1992,15 +1998,16 @@ var fng;
1992
1998
var theId = element . val ( ) ;
1993
1999
if ( theId && theId !== '' ) {
1994
2000
SubmissionsService . getListAttributes ( mongooseOptions . ref , theId )
1995
- . success ( function ( data ) {
2001
+ . then ( function ( response ) {
2002
+ var data = response . data ;
1996
2003
if ( data . success === false ) {
1997
2004
$location . path ( '/404' ) ;
1998
2005
}
1999
2006
var display = { id : theId , text : data . list } ;
2000
2007
recordHandler . preservePristine ( element , function ( ) {
2001
2008
callback ( display ) ;
2002
2009
} ) ;
2003
- } ) . error ( $scope . handleHttpError ) ;
2010
+ } , $scope . handleHttpError ) ;
2004
2011
}
2005
2012
} ,
2006
2013
ajax : {
@@ -3200,41 +3207,42 @@ var fng;
3200
3207
}
3201
3208
}
3202
3209
function handleError ( $scope ) {
3203
- return function ( data , status ) {
3204
- if ( [ 200 , 400 ] . indexOf ( status ) !== - 1 ) {
3210
+ return function ( response ) {
3211
+ if ( [ 200 , 400 ] . indexOf ( response . status ) !== - 1 ) {
3205
3212
var errorMessage = '' ;
3206
- for ( var errorField in data . errors ) {
3207
- if ( data . errors . hasOwnProperty ( errorField ) ) {
3213
+ for ( var errorField in response . data . errors ) {
3214
+ if ( response . data . errors . hasOwnProperty ( errorField ) ) {
3208
3215
errorMessage += '<li><b>' + $filter ( 'titleCase' ) ( errorField ) + ': </b> ' ;
3209
- switch ( data . errors [ errorField ] . type ) {
3216
+ switch ( response . data . errors [ errorField ] . type ) {
3210
3217
case 'enum' :
3211
3218
errorMessage += 'You need to select from the list of values' ;
3212
3219
break ;
3213
3220
default :
3214
- errorMessage += data . errors [ errorField ] . message ;
3221
+ errorMessage += response . data . errors [ errorField ] . message ;
3215
3222
break ;
3216
3223
}
3217
3224
errorMessage += '</li>' ;
3218
3225
}
3219
3226
}
3220
3227
if ( errorMessage . length > 0 ) {
3221
- errorMessage = data . message + '<br /><ul>' + errorMessage + '</ul>' ;
3228
+ errorMessage = response . data . message + '<br /><ul>' + errorMessage + '</ul>' ;
3222
3229
}
3223
3230
else {
3224
- errorMessage = data . message || 'Error! Sorry - No further details available.' ;
3231
+ errorMessage = response . data . message || 'Error! Sorry - No further details available.' ;
3225
3232
}
3226
3233
$scope . showError ( errorMessage ) ;
3227
3234
}
3228
3235
else {
3229
- $scope . showError ( status + ' ' + JSON . stringify ( data ) ) ;
3236
+ $scope . showError ( response . status + ' ' + JSON . stringify ( response . data ) ) ;
3230
3237
}
3231
3238
} ;
3232
3239
}
3233
3240
return {
3234
3241
readRecord : function readRecord ( $scope , ctrlState ) {
3235
3242
// TODO Consider using $parse for this - http://bahmutov.calepin.co/angularjs-parse-hacks.html
3236
3243
SubmissionsService . readRecord ( $scope . modelName , $scope . id )
3237
- . success ( function ( data ) {
3244
+ . then ( function ( response ) {
3245
+ var data = response . data ;
3238
3246
if ( data . success === false ) {
3239
3247
$location . path ( '/404' ) ;
3240
3248
}
@@ -3244,7 +3252,7 @@ var fng;
3244
3252
$scope . dataEventFunctions . onAfterRead ( data ) ;
3245
3253
}
3246
3254
processServerData ( data , $scope , ctrlState ) ;
3247
- } ) . error ( $scope . handleHttpError ) ;
3255
+ } , $scope . handleHttpError ) ;
3248
3256
} ,
3249
3257
scrollTheList : function scrollTheList ( $scope ) {
3250
3258
var pagesLoaded = $scope . pagesLoaded ;
@@ -3255,7 +3263,8 @@ var fng;
3255
3263
skip : pagesLoaded * $scope . pageSize ,
3256
3264
order : $location . $$search . o
3257
3265
} )
3258
- . success ( function ( data ) {
3266
+ . then ( function ( response ) {
3267
+ var data = response . data ;
3259
3268
if ( angular . isArray ( data ) ) {
3260
3269
// I have seen an intermittent problem where a page is requested twice
3261
3270
if ( pagesLoaded === $scope . pagesLoaded ) {
@@ -3269,13 +3278,12 @@ var fng;
3269
3278
else {
3270
3279
$scope . showError ( data , 'Invalid query' ) ;
3271
3280
}
3272
- } )
3273
- . error ( $scope . handleHttpError ) ;
3281
+ } , $scope . handleHttpError ) ;
3274
3282
} ,
3275
3283
// TODO: Do we need model here? Can we not infer it from scope?
3276
3284
deleteRecord : function deleteRecord ( model , id , $scope , ctrlState ) {
3277
3285
SubmissionsService . deleteRecord ( model , id )
3278
- . success ( function ( ) {
3286
+ . then ( function ( ) {
3279
3287
if ( typeof $scope . dataEventFunctions . onAfterDelete === 'function' ) {
3280
3288
$scope . dataEventFunctions . onAfterDelete ( ctrlState . master ) ;
3281
3289
}
@@ -3285,7 +3293,8 @@ var fng;
3285
3293
updateDocument : function updateDocument ( dataToSave , options , $scope , ctrlState ) {
3286
3294
$scope . phase = 'updating' ;
3287
3295
SubmissionsService . updateRecord ( $scope . modelName , $scope . id , dataToSave )
3288
- . success ( function ( data ) {
3296
+ . then ( function ( response ) {
3297
+ var data = response . data ;
3289
3298
if ( data . success !== false ) {
3290
3299
if ( typeof $scope . dataEventFunctions . onAfterUpdate === 'function' ) {
3291
3300
$scope . dataEventFunctions . onAfterUpdate ( data , ctrlState . master ) ;
@@ -3304,12 +3313,12 @@ var fng;
3304
3313
else {
3305
3314
$scope . showError ( data ) ;
3306
3315
}
3307
- } )
3308
- . error ( $scope . handleHttpError ) ;
3316
+ } , $scope . handleHttpError ) ;
3309
3317
} ,
3310
3318
createNew : function createNew ( dataToSave , options , $scope ) {
3311
3319
SubmissionsService . createRecord ( $scope . modelName , dataToSave )
3312
- . success ( function ( data ) {
3320
+ . then ( function ( response ) {
3321
+ var data = response . data ;
3313
3322
if ( data . success !== false ) {
3314
3323
if ( typeof $scope . dataEventFunctions . onAfterCreate === 'function' ) {
3315
3324
$scope . dataEventFunctions . onAfterCreate ( data ) ;
@@ -3324,8 +3333,7 @@ var fng;
3324
3333
else {
3325
3334
$scope . showError ( data ) ;
3326
3335
}
3327
- } )
3328
- . error ( $scope . handleHttpError ) ;
3336
+ } , $scope . handleHttpError ) ;
3329
3337
} ,
3330
3338
getListData : getListData ,
3331
3339
suffixCleanId : suffixCleanId ,
@@ -3334,7 +3342,8 @@ var fng;
3334
3342
var optionsList = $scope [ schemaElement . options ] = [ ] ;
3335
3343
var idList = $scope [ schemaElement . ids ] = [ ] ;
3336
3344
SchemasService . getSchema ( lookupCollection )
3337
- . success ( function ( data ) {
3345
+ . then ( function ( response ) {
3346
+ var data = response . data ;
3338
3347
var listInstructions = [ ] ;
3339
3348
handleSchema ( 'Lookup ' + lookupCollection , data , null , listInstructions , '' , false , $scope , ctrlState ) ;
3340
3349
var dataRequest ;
@@ -3346,7 +3355,8 @@ var fng;
3346
3355
dataRequest = SubmissionsService . getAll ( lookupCollection ) ;
3347
3356
}
3348
3357
dataRequest
3349
- . success ( function ( data ) {
3358
+ . then ( function ( response ) {
3359
+ var data = response . data ;
3350
3360
if ( data ) {
3351
3361
for ( var i = 0 ; i < data . length ; i ++ ) {
3352
3362
var option = '' ;
@@ -3608,10 +3618,10 @@ var fng;
3608
3618
fillFormFromBackendCustomSchema : fillFormFromBackendCustomSchema ,
3609
3619
fillFormWithBackendSchema : function fillFormWithBackendSchema ( $scope , formGeneratorInstance , recordHandlerInstance , ctrlState ) {
3610
3620
SchemasService . getSchema ( $scope . modelName , $scope . formName )
3611
- . success ( function ( schema ) {
3621
+ . then ( function ( response ) {
3622
+ var schema = response . data ;
3612
3623
fillFormFromBackendCustomSchema ( schema , $scope , formGeneratorInstance , recordHandlerInstance , ctrlState ) ;
3613
- } )
3614
- . error ( $scope . handleHttpError ) ;
3624
+ } , $scope . handleHttpError ) ;
3615
3625
}
3616
3626
} ;
3617
3627
}
0 commit comments