@@ -21,11 +21,9 @@ define([
21
21
totalDisabledProducts : 0 ,
22
22
totalNotVisibleProducts : 0 ,
23
23
totalOutOfStockProducts : 0 ,
24
- category_ids : '' ,
25
24
listens : {
26
25
conditionOption : 'updateProductTotals' ,
27
26
conditionValue : 'updateProductTotals' ,
28
- category_ids : 'updateProductTotals'
29
27
} ,
30
28
imports : {
31
29
formData : '${ $.provider }:data'
@@ -39,7 +37,21 @@ define([
39
37
notVisiblePlaceholder : $t ( '%1 not visible' ) ,
40
38
outOfStockPlaceholder : $t ( '%1 out of stock' ) ,
41
39
showSpinner : true ,
42
- loading : false
40
+ loading : false ,
41
+ jqXHR : null
42
+ } ,
43
+
44
+ initialize : function ( ) {
45
+ $ ( '.cms-page-edit .modals-wrapper' ) . on ( 'modalclosed' , function ( ) {
46
+ this . abortRunningRequest ( ) ;
47
+ } . bind ( this ) ) ;
48
+ return this . _super ( ) ;
49
+ } ,
50
+
51
+ abortRunningRequest : function ( ) {
52
+ if ( this . jqXHR && this . jqXHR . readyState !== 4 ) {
53
+ this . jqXHR . abort ( ) ;
54
+ }
43
55
} ,
44
56
45
57
/** @inheritdoc */
@@ -49,9 +61,13 @@ define([
49
61
'totalOutOfStockProducts loading' ) ;
50
62
} ,
51
63
64
+ callSuperError : function ( jqXHR ) {
65
+ var superError = $ . ajaxSettings . error . bind ( window , jqXHR ) ;
66
+ superError ( ) ;
67
+ } ,
68
+
52
69
/**
53
70
* Update product count.
54
- *
55
71
*/
56
72
updateProductTotals : _ . debounce ( function ( ) {
57
73
var totalText ,
@@ -61,20 +77,26 @@ define([
61
77
return ;
62
78
}
63
79
64
- if ( this . conditionOption === 'category_ids' && typeof this . formData [ 'category_ids' ] != 'string' ) {
80
+ if ( this . conditionOption === 'category_ids' && typeof this . formData [ 'category_ids' ] !== 'string' ) {
65
81
this . formData [ 'category_ids' ] = '' ;
66
82
}
67
83
68
84
_ . extend ( this . formData , this . conditionValue ) ;
69
85
conditionsDataProcessor ( this . formData , this . conditionOption + '_source' ) ;
70
86
71
87
this . loading ( true ) ;
72
- $ . ajax ( {
88
+ this . abortRunningRequest ( ) ;
89
+ this . jqXHR = $ . ajax ( {
73
90
url : this . url ,
74
91
method : 'POST' ,
75
92
data : {
76
93
conditionValue : this . formData [ 'conditions_encoded' ]
77
- }
94
+ } ,
95
+ error : function ( jqXHR ) {
96
+ if ( jqXHR . statusText !== 'abort' ) {
97
+ this . callSuperError ( jqXHR )
98
+ }
99
+ } . bind ( this )
78
100
} ) . done ( function ( response ) {
79
101
this . totalProductCount ( parseInt ( response . total , 10 ) ) ;
80
102
this . totalDisabledProducts ( parseInt ( response . disabled , 10 ) ) ;
@@ -102,7 +124,9 @@ define([
102
124
this . value ( totalText ) ;
103
125
this . loading ( false ) ;
104
126
} . bind ( this ) ) . fail ( function ( ) {
105
- this . value ( $t ( 'An unknown error occurred. Please try again.' ) ) ;
127
+ if ( this . jqXHR . statusText !== 'abort' ) {
128
+ this . value ( $t ( 'An unknown error occurred. Please try again.' ) ) ;
129
+ }
106
130
this . loading ( false ) ;
107
131
} . bind ( this ) ) ;
108
132
} , 10 )
0 commit comments