1
+ let requestWPApi ;
1
2
jQuery ( document ) . ready ( function ( $ ) {
2
3
const $document = $ ( document ) ; // Cache document lookup
3
4
@@ -20,7 +21,7 @@ jQuery(document).ready(function ($) {
20
21
* @param function callback
21
22
* @param string method (default: 'GET')
22
23
*/
23
- function requestWPApi ( route , data , callback , method = 'GET' , error_callback = null ) {
24
+ requestWPApi = function requestWPApi ( route , data , callback , method = 'GET' , error_callback = null ) {
24
25
const $trigger = $ ( document . activeElement ) ;
25
26
const $overlayTemplate = $ ( '#backwpup-loading-overlay-template' ) . children ( ) . first ( ) ;
26
27
const $jobCard = $trigger . closest ( '.backwpup-job-card' ) ;
@@ -1129,7 +1130,7 @@ jQuery(document).ready(function ($) {
1129
1130
job_id = null ;
1130
1131
}
1131
1132
if ( $ ( "#s3bucketerror" ) . html ( ) != "" ) {
1132
- refresh_storage_destinations ( 'S3' , false ) ;
1133
+ refresh_storage_destinations ( job_id , 'S3' , false ) ;
1133
1134
alert ( 'Error in Bucket Configurations' ) ;
1134
1135
return ;
1135
1136
}
@@ -1183,7 +1184,7 @@ jQuery(document).ready(function ($) {
1183
1184
job_id = null ;
1184
1185
}
1185
1186
if ( $ ( "#glacierbucketerror" ) . html ( ) != "" ) {
1186
- refresh_storage_destinations ( 'GLACIER' , false ) ;
1187
+ refresh_storage_destinations ( job_id , 'GLACIER' , false ) ;
1187
1188
alert ( 'Error in Bucket Configurations' ) ;
1188
1189
return ;
1189
1190
}
@@ -1301,13 +1302,13 @@ jQuery(document).ready(function ($) {
1301
1302
backwpupApi . cloudsaveandtest ,
1302
1303
data ,
1303
1304
function ( response ) {
1304
- refresh_storage_destinations ( 'GDRIVE' , response . connected ) ;
1305
+ refresh_storage_destinations ( job_id , 'GDRIVE' , response . connected ) ;
1305
1306
backwpupDisplaySettingsToast ( 'success' , response . message ) ;
1306
1307
closeSidebar ( ) ;
1307
1308
} ,
1308
1309
"POST" ,
1309
1310
function ( request , error ) {
1310
- refresh_storage_destinations ( 'GDRIVE' , false ) ;
1311
+ refresh_storage_destinations ( job_id , 'GDRIVE' , false ) ;
1311
1312
const errorMessage = request . responseJSON && request . responseJSON . error
1312
1313
? request . responseJSON . error
1313
1314
: ( request . responseText || 'Unknown error occurred' ) ;
@@ -1606,6 +1607,7 @@ jQuery(document).ready(function ($) {
1606
1607
openSidebar ( content ) ;
1607
1608
} ) ;
1608
1609
1610
+
1609
1611
$ ( '.js-backwpup-refresh-authentification' ) . on ( 'click' , function ( ) {
1610
1612
let trigger = $ ( this ) . data ( 'trigger' ) ;
1611
1613
if ( typeof window [ trigger ] === 'function' ) {
@@ -2032,6 +2034,7 @@ jQuery(document).ready(function ($) {
2032
2034
$ ( document ) . on ( 'backup-complete' , function ( ) {
2033
2035
enableBackupButton ( true ) ;
2034
2036
enableDeleteJob ( true ) ;
2037
+ loadBackupsListingAndPagination ( getUrlParameter ( 'page_num' , 1 ) ) ;
2035
2038
} ) ;
2036
2039
2037
2040
@@ -2269,4 +2272,40 @@ jQuery(document).ready(function ($) {
2269
2272
this . trigger ( 'hide' ) ; // Trigger 'hide' event
2270
2273
return originalHide . apply ( this , arguments ) ;
2271
2274
} ;
2272
- } ) ( jQuery ) ;
2275
+ } ) ( jQuery ) ;
2276
+
2277
+ /**
2278
+ * Unselects a storage option by sending a request to the WordPress API.
2279
+ *
2280
+ */
2281
+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
2282
+ document . addEventListener ( "click" , function ( event ) {
2283
+ const group_buttons = document . querySelectorAll ( '.js-backwpup-unselect-storage' ) ,
2284
+ storage_button = event . target . closest ( '.js-backwpup-unselect-storage' ) ;
2285
+
2286
+ if ( group_buttons . length > 1 && storage_button ) {
2287
+ const data = {
2288
+ 'job_id' : storage_button . dataset . jobId ,
2289
+ 'name' : storage_button . dataset . storage ,
2290
+ } ;
2291
+
2292
+ const storage_checkbox = storage_button . querySelector ( 'input[type="checkbox"]' ) ,
2293
+ is_currently_checked = storage_checkbox . checked
2294
+
2295
+ if ( typeof requestWPApi === 'function' ) {
2296
+ requestWPApi ( backwpupApi . storages , data , function ( response ) {
2297
+ if ( response . status === 200 ) {
2298
+ storage_button . classList . toggle ( 'js-backwpup-unselect-storage' )
2299
+ storage_checkbox . checked = ! is_currently_checked
2300
+ }
2301
+ } ,
2302
+ 'POST' ,
2303
+ function ( request , error ) {
2304
+ console . log ( request ) ;
2305
+ console . log ( error ) ;
2306
+ alert ( request . responseJSON . error ) ;
2307
+ } ) ;
2308
+ }
2309
+ }
2310
+ } )
2311
+ } ) ;
0 commit comments