@@ -41,14 +41,38 @@ define([
41
41
*/
42
42
setDefaultSelections : function ( ) {
43
43
var positionCacheValid = registry . get ( 'position_cache_valid' ) ,
44
+ selectedFromCache = registry . get ( 'selected_cache' ) ,
44
45
key ,
45
46
i ;
46
47
47
- registry . set ( 'position_cache_valid' , true ) ;
48
+ if ( positionCacheValid && this . selected ( ) . length === 0 ) {
49
+ // Check selected data
50
+ selectedFromCache = JSON . parse ( selectedFromCache ) ;
51
+
52
+ for ( i = 0 ; i < selectedFromCache . length ; i ++ ) {
53
+ this . selected . push ( selectedFromCache [ i ] ) ;
54
+ }
55
+
56
+ registry . set ( 'position_cache_valid' , true ) ;
57
+ registry . set ( 'selected_cache' , JSON . stringify ( this . selected ( ) ) ) ;
48
58
49
- if ( this . selectedData . length === 0 || positionCacheValid ) {
50
59
return ;
51
60
}
61
+
62
+ if ( positionCacheValid && this . selected ( ) . length > 0 ) {
63
+ registry . set ( 'position_cache_valid' , true ) ;
64
+ registry . set ( 'selected_cache' , JSON . stringify ( this . selected ( ) ) ) ;
65
+
66
+ return ;
67
+ }
68
+
69
+ if ( this . selectedData . length === 0 ) {
70
+ registry . set ( 'position_cache_valid' , true ) ;
71
+ registry . set ( 'selected_cache' , JSON . stringify ( [ ] ) ) ;
72
+
73
+ return ;
74
+ }
75
+
52
76
// Check selected data
53
77
for ( key in this . selectedData ) {
54
78
if ( this . selectedData . hasOwnProperty ( key ) && this . selected ( ) . indexOf ( key ) === - 1 ) {
@@ -61,6 +85,8 @@ define([
61
85
this . selectedData . hasOwnProperty ( key ) || this . selected . splice ( this . selected ( ) . indexOf ( key ) , 1 ) ;
62
86
this . selectedData . hasOwnProperty ( key ) || i -- ;
63
87
}
88
+ registry . set ( 'position_cache_valid' , true ) ;
89
+ registry . set ( 'selected_cache' , JSON . stringify ( this . selected ( ) ) ) ;
64
90
} ,
65
91
66
92
/**
@@ -91,12 +117,18 @@ define([
91
117
* @returns {Object } Chainable.
92
118
*/
93
119
updateState : function ( ) {
94
- var totalRecords = this . totalRecords ( ) ,
120
+ var positionCacheValid = registry . get ( 'position_cache_valid' ) ,
121
+ totalRecords = this . totalRecords ( ) ,
95
122
selected = this . selected ( ) . length ,
96
123
excluded = this . excluded ( ) . length ,
97
124
totalSelected = this . totalSelected ( ) ,
98
125
allSelected ;
99
126
127
+ if ( positionCacheValid && this . selected ( ) . length > 0 ) {
128
+ registry . set ( 'position_cache_valid' , true ) ;
129
+ registry . set ( 'selected_cache' , JSON . stringify ( this . selected ( ) ) ) ;
130
+ }
131
+
100
132
// When filters are enabled then totalRecords is unknown
101
133
if ( this . getFiltering ( ) ) {
102
134
if ( this . getFiltering ( ) . search !== '' ) {
0 commit comments