@@ -415,106 +415,17 @@ function dtLoadingTemplate() {
415
415
'use strict' ;
416
416
417
417
angular . module ( 'datatables.instances' , [ 'datatables.util' ] )
418
- . factory ( 'DTInstances' , dtInstances )
419
418
. factory ( 'DTInstanceFactory' , dtInstanceFactory ) ;
420
419
421
- /* @ngInject */
422
- function dtInstances ( $q , failzQ , $timeout , $log ) {
423
- var TIME_BEFORE_CLEANING = 1000 ;
424
- var _instances = { } ;
425
- var _lastInstance = { } ;
426
- // Promise for fetching the last DT instance
427
- var _deferLastDTInstances = null ;
428
- var _lastDTInstance = null ;
429
- // Promise for fetching the list of DT instances
430
- var _deferDTInstances = null ;
431
- var _dtInstances = null ;
432
- return {
433
- register : register ,
434
- getLast : getLast ,
435
- getList : getList
436
- } ;
437
-
438
- function register ( dtInstance , result ) {
439
- dtInstance . id = result . id ;
440
- dtInstance . DataTable = result . DataTable ;
441
- dtInstance . dataTable = result . dataTable ;
442
-
443
- //_instances[dtInstance.id] = dtInstance;
444
- _instances [ dtInstance . id ] = dtInstance ;
445
- _cleanInstances ( ) ;
446
- _lastInstance = dtInstance ;
447
- if ( _deferLastDTInstances ) {
448
- _deferLastDTInstances . resolve ( _lastInstance ) ;
449
- }
450
- if ( _deferDTInstances ) {
451
- _deferDTInstances . resolve ( _instances ) ;
452
- }
453
- return dtInstance ;
454
- }
455
-
456
- function getLast ( ) {
457
- $log . warn ( '"DTInstances.getLast()" and "DTInstances.getList()" are deprecated! Use the "dt-instance" to provide the datatables instance. See https://l-lin.github.com/angular-datatables/#/dtInstances for more information.' ) ;
458
- var defer = $q . defer ( ) ;
459
- if ( ! _lastDTInstance ) {
460
- _deferLastDTInstances = $q . defer ( ) ;
461
- _lastDTInstance = _deferLastDTInstances . promise ;
462
- }
463
- failzQ ( _lastDTInstance ) . then ( function ( dtInstance ) {
464
- defer . resolve ( dtInstance ) ;
465
- // Reset the promise
466
- _deferLastDTInstances = null ;
467
- _lastDTInstance = null ;
468
- } , function ( ) {
469
- // In case we are trying to fetch the last instance again
470
- defer . resolve ( _lastInstance ) ;
471
- } ) ;
472
- return defer . promise ;
473
- }
474
-
475
- function getList ( ) {
476
- $log . warn ( '"DTInstances.getLast()" and "DTInstances.getList()" are deprecated! Use the "dt-instance" to provide the datatables instance. See https://l-lin.github.com/angular-datatables/#/dtInstances for more information.' ) ;
477
- var defer = $q . defer ( ) ;
478
- if ( ! _dtInstances ) {
479
- _deferDTInstances = $q . defer ( ) ;
480
- _dtInstances = _deferDTInstances . promise ;
481
- }
482
- failzQ ( _dtInstances ) . then ( function ( instances ) {
483
- defer . resolve ( instances ) ;
484
- // Reset the promise
485
- _deferDTInstances = null ;
486
- _dtInstances = null ;
487
- } , function ( ) {
488
- // In case we are trying to fetch the instances again
489
- defer . resolve ( _instances ) ;
490
- } ) ;
491
- return defer . promise ;
492
- }
493
-
494
- function _cleanInstances ( ) {
495
- $timeout ( function ( ) {
496
- var newInstances = { } ;
497
- for ( var attr in _instances ) {
498
- if ( _instances . hasOwnProperty ( attr ) ) {
499
- if ( $ . fn . DataTable . isDataTable ( _instances [ attr ] . id ) ) {
500
- newInstances [ attr ] = _instances [ attr ] ;
501
- }
502
- }
503
- }
504
- _instances = newInstances ;
505
- } , TIME_BEFORE_CLEANING ) ;
506
- }
507
- }
508
- dtInstances . $inject = [ '$q' , 'failzQ' , '$timeout' , '$log' ] ;
509
-
510
420
function dtInstanceFactory ( ) {
511
421
var DTInstance = {
512
422
reloadData : reloadData ,
513
423
changeData : changeData ,
514
424
rerender : rerender
515
425
} ;
516
426
return {
517
- newDTInstance : newDTInstance
427
+ newDTInstance : newDTInstance ,
428
+ copyDTProperties : copyDTProperties
518
429
} ;
519
430
520
431
function newDTInstance ( renderer ) {
@@ -523,6 +434,12 @@ function dtInstanceFactory() {
523
434
return dtInstance ;
524
435
}
525
436
437
+ function copyDTProperties ( result , dtInstance ) {
438
+ dtInstance . id = result . id ;
439
+ dtInstance . DataTable = result . DataTable ;
440
+ dtInstance . dataTable = result . dataTable ;
441
+ }
442
+
526
443
function reloadData ( callback , resetPaging ) {
527
444
/*jshint validthis:true */
528
445
this . _renderer . reloadData ( callback , resetPaging ) ;
@@ -836,7 +753,7 @@ function dtRenderer() {
836
753
}
837
754
838
755
/* @ngInject */
839
- function dtDefaultRenderer ( $q , DTRenderer , DTRendererService , DTInstanceFactory , DTInstances ) {
756
+ function dtDefaultRenderer ( $q , DTRenderer , DTRendererService , DTInstanceFactory ) {
840
757
return {
841
758
create : create
842
759
} ;
@@ -857,7 +774,8 @@ function dtDefaultRenderer($q, DTRenderer, DTRendererService, DTInstanceFactory,
857
774
var dtInstance = DTInstanceFactory . newDTInstance ( renderer ) ;
858
775
var result = DTRendererService . hideLoadingAndRenderDataTable ( $elem , renderer . options ) ;
859
776
_oTable = result . DataTable ;
860
- return $q . when ( DTInstances . register ( dtInstance , result ) ) ;
777
+ DTInstanceFactory . copyDTProperties ( result , dtInstance ) ;
778
+ return $q . when ( dtInstance ) ;
861
779
}
862
780
863
781
function reloadData ( ) {
@@ -876,10 +794,10 @@ function dtDefaultRenderer($q, DTRenderer, DTRendererService, DTInstanceFactory,
876
794
return renderer ;
877
795
}
878
796
}
879
- dtDefaultRenderer . $inject = [ '$q' , 'DTRenderer' , 'DTRendererService' , 'DTInstanceFactory' , 'DTInstances' ] ;
797
+ dtDefaultRenderer . $inject = [ '$q' , 'DTRenderer' , 'DTRendererService' , 'DTInstanceFactory' ] ;
880
798
881
799
/* @ngInject */
882
- function dtNGRenderer ( $log , $q , $compile , $timeout , DTRenderer , DTRendererService , DTInstances , DTInstanceFactory ) {
800
+ function dtNGRenderer ( $log , $q , $compile , $timeout , DTRenderer , DTRendererService , DTInstanceFactory ) {
883
801
/**
884
802
* Renderer for displaying the Angular way
885
803
* @param options
@@ -933,7 +851,8 @@ function dtNGRenderer($log, $q, $compile, $timeout, DTRenderer, DTRendererServic
933
851
_alreadyRendered = true ;
934
852
var result = DTRendererService . hideLoadingAndRenderDataTable ( _$elem , renderer . options ) ;
935
853
_oTable = result . DataTable ;
936
- defer . resolve ( DTInstances . register ( dtInstance , result ) ) ;
854
+ DTInstanceFactory . copyDTProperties ( result , dtInstance ) ;
855
+ defer . resolve ( dtInstance ) ;
937
856
} , 0 , false ) ;
938
857
} , true ) ;
939
858
return defer . promise ;
@@ -953,7 +872,7 @@ function dtNGRenderer($log, $q, $compile, $timeout, DTRenderer, DTRendererServic
953
872
$timeout ( function ( ) {
954
873
var result = DTRendererService . hideLoadingAndRenderDataTable ( _$elem , renderer . options ) ;
955
874
_oTable = result . DataTable ;
956
- dtInstance = DTInstances . register ( dtInstance , result ) ;
875
+ DTInstanceFactory . copyDTProperties ( result , dtInstance ) ;
957
876
} , 0 , false ) ;
958
877
}
959
878
@@ -969,10 +888,10 @@ function dtNGRenderer($log, $q, $compile, $timeout, DTRenderer, DTRendererServic
969
888
}
970
889
}
971
890
}
972
- dtNGRenderer . $inject = [ '$log' , '$q' , '$compile' , '$timeout' , 'DTRenderer' , 'DTRendererService' , 'DTInstances' , ' DTInstanceFactory'] ;
891
+ dtNGRenderer . $inject = [ '$log' , '$q' , '$compile' , '$timeout' , 'DTRenderer' , 'DTRendererService' , 'DTInstanceFactory' ] ;
973
892
974
893
/* @ngInject */
975
- function dtPromiseRenderer ( $q , $timeout , $log , DTRenderer , DTRendererService , DTInstances , DTInstanceFactory ) {
894
+ function dtPromiseRenderer ( $q , $timeout , $log , DTRenderer , DTRendererService , DTInstanceFactory ) {
976
895
/**
977
896
* Renderer for displaying with a promise
978
897
* @param options the options
@@ -1004,7 +923,8 @@ function dtPromiseRenderer($q, $timeout, $log, DTRenderer, DTRendererService, DT
1004
923
_$elem = $elem ;
1005
924
_resolve ( renderer . options . fnPromise , DTRendererService . renderDataTable ) . then ( function ( result ) {
1006
925
_oTable = result . DataTable ;
1007
- defer . resolve ( DTInstances . register ( dtInstance , result ) ) ;
926
+ DTInstanceFactory . copyDTProperties ( result , dtInstance ) ;
927
+ defer . resolve ( dtInstance ) ;
1008
928
} ) ;
1009
929
return defer . promise ;
1010
930
}
@@ -1104,10 +1024,10 @@ function dtPromiseRenderer($q, $timeout, $log, DTRenderer, DTRendererService, DT
1104
1024
}
1105
1025
}
1106
1026
}
1107
- dtPromiseRenderer . $inject = [ '$q' , '$timeout' , '$log' , 'DTRenderer' , 'DTRendererService' , 'DTInstances' , ' DTInstanceFactory'] ;
1027
+ dtPromiseRenderer . $inject = [ '$q' , '$timeout' , '$log' , 'DTRenderer' , 'DTRendererService' , 'DTInstanceFactory' ] ;
1108
1028
1109
1029
/* @ngInject */
1110
- function dtAjaxRenderer ( $q , $timeout , DTRenderer , DTRendererService , DT_DEFAULT_OPTIONS , DTInstances , DTInstanceFactory ) {
1030
+ function dtAjaxRenderer ( $q , $timeout , DTRenderer , DTRendererService , DT_DEFAULT_OPTIONS , DTInstanceFactory ) {
1111
1031
/**
1112
1032
* Renderer for displaying with Ajax
1113
1033
* @param options the options
@@ -1143,7 +1063,8 @@ function dtAjaxRenderer($q, $timeout, DTRenderer, DTRendererService, DT_DEFAULT_
1143
1063
}
1144
1064
_doRender ( renderer . options , $elem ) . then ( function ( result ) {
1145
1065
_oTable = result . DataTable ;
1146
- defer . resolve ( DTInstances . register ( dtInstance , result ) ) ;
1066
+ DTInstanceFactory . copyDTProperties ( result , dtInstance ) ;
1067
+ defer . resolve ( dtInstance ) ;
1147
1068
} ) ;
1148
1069
return defer . promise ;
1149
1070
}
@@ -1169,21 +1090,21 @@ function dtAjaxRenderer($q, $timeout, DTRenderer, DTRendererService, DT_DEFAULT_
1169
1090
}
1170
1091
1171
1092
function _doRender ( options , $elem ) {
1172
- var defer = $q . defer ( ) ;
1173
- // Set it to true in order to be able to redraw the dataTable
1174
- options . bDestroy = true ;
1175
- DTRendererService . hideLoading ( $elem ) ;
1176
- // Condition to refresh the dataTable
1177
- if ( _shouldDeferRender ( options ) ) {
1178
- $timeout ( function ( ) {
1179
- defer . resolve ( DTRendererService . renderDataTable ( $elem , options ) ) ;
1180
- } , 0 , false ) ;
1181
- } else {
1093
+ var defer = $q . defer ( ) ;
1094
+ // Set it to true in order to be able to redraw the dataTable
1095
+ options . bDestroy = true ;
1096
+ DTRendererService . hideLoading ( $elem ) ;
1097
+ // Condition to refresh the dataTable
1098
+ if ( _shouldDeferRender ( options ) ) {
1099
+ $timeout ( function ( ) {
1182
1100
defer . resolve ( DTRendererService . renderDataTable ( $elem , options ) ) ;
1183
- }
1184
- return defer . promise ;
1101
+ } , 0 , false ) ;
1102
+ } else {
1103
+ defer . resolve ( DTRendererService . renderDataTable ( $elem , options ) ) ;
1185
1104
}
1186
- // See https://github.com/l-lin/angular-datatables/issues/147
1105
+ return defer . promise ;
1106
+ }
1107
+ // See https://github.com/l-lin/angular-datatables/issues/147
1187
1108
function _shouldDeferRender ( options ) {
1188
1109
if ( angular . isDefined ( options ) && angular . isDefined ( options . dom ) ) {
1189
1110
// S for scroller plugin
@@ -1193,7 +1114,7 @@ function dtAjaxRenderer($q, $timeout, DTRenderer, DTRendererService, DT_DEFAULT_
1193
1114
}
1194
1115
}
1195
1116
}
1196
- dtAjaxRenderer . $inject = [ '$q' , '$timeout' , 'DTRenderer' , 'DTRendererService' , 'DT_DEFAULT_OPTIONS' , 'DTInstances' , ' DTInstanceFactory'] ;
1117
+ dtAjaxRenderer . $inject = [ '$q' , '$timeout' , 'DTRenderer' , 'DTRendererService' , 'DT_DEFAULT_OPTIONS' , 'DTInstanceFactory' ] ;
1197
1118
1198
1119
/* @ngInject */
1199
1120
function dtRendererFactory ( DTDefaultRenderer , DTNGRenderer , DTPromiseRenderer , DTAjaxRenderer ) {
@@ -1223,9 +1144,7 @@ dtRendererFactory.$inject = ['DTDefaultRenderer', 'DTNGRenderer', 'DTPromiseRend
1223
1144
'use strict' ;
1224
1145
1225
1146
angular . module ( 'datatables.util' , [ ] )
1226
- . factory ( 'DTPropertyUtil' , dtPropertyUtil )
1227
- // TODO: Remove this service when the DTInstances service is removed!
1228
- . service ( 'failzQ' , failzQ ) ;
1147
+ . factory ( 'DTPropertyUtil' , dtPropertyUtil ) ;
1229
1148
1230
1149
/* @ngInject */
1231
1150
function dtPropertyUtil ( $q ) {
@@ -1343,29 +1262,5 @@ function dtPropertyUtil($q) {
1343
1262
}
1344
1263
dtPropertyUtil . $inject = [ '$q' ] ;
1345
1264
1346
- /* @ngInject */
1347
- function failzQ ( $q , $timeout ) {
1348
- var DEFAULT_TIME = 1000 ;
1349
- /**
1350
- * failzQ wrap a promise and reject the promise if not resolved with a given time
1351
- */
1352
- return function ( promise , time ) {
1353
- var defer = $q . defer ( ) ;
1354
- var t = time || DEFAULT_TIME ;
1355
-
1356
- $timeout ( function ( ) {
1357
- defer . reject ( 'Not resolved within ' + t ) ;
1358
- } , t ) ;
1359
-
1360
- $q . when ( promise ) . then ( function ( result ) {
1361
- defer . resolve ( result ) ;
1362
- } , function ( failure ) {
1363
- defer . reject ( failure ) ;
1364
- } ) ;
1365
- return defer . promise ;
1366
- } ;
1367
- }
1368
- failzQ . $inject = [ '$q' , '$timeout' ] ;
1369
-
1370
1265
1371
1266
} ) ( window , document , jQuery , angular ) ;
0 commit comments