PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
mainwp / modules / api-backups / assets / js / module-api-backups-manager.js

module-api-backups-manager.js in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.2.2, at modules/api-backups/assets/js/module-api-backups-manager.js

2,349 lines 74.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * MainWP 3rd-party API Manager JS.
3 *
4 * JS actions for the MainWP 3rd-party API Manager.
5 *
6 * @file This files handles all js actions for the MainWP 3rd-party API Manager.
7 * @author MainWP.
8 * @since 4.2.7.1
9 */
10
11 /* eslint complexity: ["error", 100] */
12
13 jQuery(function(){
14
15 /********************************************************
16 * Ajax Event Hooks.
17 */
18
19 /**
20 * CloudWays Ajax Hooks
21 */
22
23 // Trigger action_backup.
24 jQuery('.mainwp_3rd_party_api_cloudways_action_backup').on('click', function () {
25 cloudways_action_backup(this);
26 });
27
28 // Trigger action_backup.
29 jQuery('#mainwp_3rd_party_api_cloudways_action_individual_create_backup').on('click', function () {
30 cloudways_action_backup(this);
31 });
32
33 // Trigger action_update_ids.
34 jQuery('.mainwp_3rd_party_api_cloudways_action_update_ids').on('click', function () {
35 cloudways_action_update_ids(this);
36 });
37
38 //Trigger action_refresh_available_backups.
39 jQuery('#mainwp_3rd_party_api_cloudways_action_refresh_available_backups').on('click', function () {
40 cloudways_action_refresh_available_backups(this);
41 });
42
43 // Trigger action_restore_backup.
44 jQuery(document).on('click', '.mainwp_3rd_party_api_cloudways_action_restore_backup', function () {
45 cloudways_action_restore_backup(this);
46 });
47
48 // Trigger action_delete_backup. This will delete the 24hr restore point allowing for a new restoration to be created.
49 jQuery('#mainwp_3rd_party_api_cloudways_action_delete_backup').on('click', function () {
50 cloudways_action_delete_backup(this);
51 });
52
53 /**
54 * Vultr Ajax Hooks
55 */
56
57 // Trigger action_backup.
58 jQuery('.mainwp_3rd_party_api_vultr_action_backup').on('click', function () {
59 vultr_action_create_snapshot(this);
60 });
61
62 // Trigger action_backup.
63 jQuery('#mainwp_3rd_party_api_vultr_action_individual_create_backup').on('click', function () {
64 vultr_action_create_snapshot(this);
65 });
66
67 // Trigger action_update_ids.
68 jQuery('.mainwp_3rd_party_api_vultr_action_update_ids').on('click', function () {
69 vultr_action_update_ids(this);
70 });
71
72 //Trigger action_refresh_available_backups.
73 jQuery('#mainwp_3rd_party_api_vultr_action_refresh_available_backups').on('click', function () {
74 vultr_action_refresh_available_backups(this);
75 });
76
77 // Trigger action_restore_backup.
78 jQuery(document).on('click', '.mainwp_3rd_party_api_vultr_action_restore_backup', function () {
79 vultr_action_restore_backup(this);
80 });
81
82 // Trigger action_delete_backup.
83 jQuery(document).on('click', '.mainwp_3rd_party_api_vultr_action_delete_backup', function () {
84 vultr_action_delete_backup(this);
85 });
86
87 /**
88 * GridPane Ajax Hooks
89 */
90
91 // Trigger action_backup.
92 jQuery('.mainwp_3rd_party_api_gridpane_action_backup').on('click', function () {
93 gridpane_action_create_backup(this);
94 });
95
96 // Trigger action_backup.
97 jQuery('#mainwp_3rd_party_api_gridpane_action_individual_create_backup').on('click', function () {
98 gridpane_action_create_backup(this);
99 });
100
101 // Trigger action_update_ids.
102 jQuery('.mainwp_3rd_party_api_gridpane_action_update_ids').on('click', function () {
103 gridpane_action_update_ids(this);
104 });
105
106 // Trigger action_refresh_available_backups.
107 jQuery('#mainwp_3rd_party_api_gridpane_action_refresh_available_backups').on('click', function () {
108 gridpane_action_refresh_available_backups(this);
109 });
110
111 // Trigger action_restore_backup.
112 jQuery(document).on('click', '.mainwp_3rd_party_api_gridpane_action_restore_backup', function () {
113 gridpane_action_restore_backup(this);
114 });
115
116 // Trigger action_delete_backup.
117 jQuery(document).on('click', '.mainwp_3rd_party_api_gridpane_action_delete_backup', function () {
118 gridpane_action_delete_backup(this);
119 });
120
121 /**
122 * Linode Ajax Hooks
123 */
124
125 // Trigger action_backup.
126 jQuery('.mainwp_3rd_party_api_linode_action_backup').on('click', function () {
127 linode_action_create_backup(this);
128 });
129
130 // Trigger action_backup.
131 jQuery('#mainwp_3rd_party_api_linode_action_individual_create_backup').on('click', function () {
132 linode_action_create_backup(this);
133 });
134
135 //Trigger action_update_ids.
136 jQuery('.mainwp_3rd_party_api_linode_action_update_ids').on('click', function () {
137 linode_action_update_ids(this);
138 });
139
140 // Trigger action_refresh_available_backups.
141 jQuery('#mainwp_3rd_party_api_linode_action_refresh_available_backups').on('click', function () {
142 linode_action_refresh_available_backups(this);
143 });
144
145 // Trigger action_restore_backup.
146 jQuery(document).on('click', '.mainwp_3rd_party_api_linode_action_restore_backup', function () {
147 linode_action_restore_backup(this);
148 });
149
150 // Trigger action_delete_backup.
151 jQuery('#mainwp_3rd_party_api_linode_action_cancel_backups').on('click', function () {
152 let confirmMsg = MainWP.I18n.t('Are you sure you want to Disable and Delete all existing backups from this Linode?');
153 mainwp_confirm(confirmMsg, function () {
154 linode_action_cancel_backups(this);
155 });
156 });
157
158 /**
159 * digitalocean Ajax Hooks
160 */
161
162 //Trigger action_update_ids.
163 jQuery('.mainwp_3rd_party_api_digitalocean_action_update_ids').on('click', function () {
164 digitalocean_action_update_ids(this);
165 });
166
167 // Trigger action_create_backup.
168 jQuery('.mainwp_3rd_party_api_digitalocean_action_backup').on('click', function () {
169 digitalocean_action_create_backup(this);
170 });
171
172 // Trigger action_individual_create_backup.
173 jQuery('#mainwp_3rd_party_api_digitalocean_action_individual_create_backup').on('click', function () {
174 digitalocean_action_create_backup(this);
175 });
176
177 // Trigger action_refresh_available_backups.
178 jQuery('#mainwp_3rd_party_api_digitalocean_action_refresh_available_backups').on('click', function () {
179 digitalocean_action_refresh_available_backups(this);
180 });
181
182 // Trigger action_delete_backup.
183 jQuery(document).on('click', '.mainwp_3rd_party_api_digitalocean_action_delete_backup', function () {
184 digitalocean_action_delete_backup(this);
185 });
186
187 // Trigger action_restore_backup.
188 jQuery(document).on('click', '.mainwp_3rd_party_api_digitalocean_action_restore_backup', function () {
189 digitalocean_action_restore_backup(this);
190 });
191
192 /**
193 * CPanel Ajax Hooks
194 */
195
196 // Trigger action_refresh_available_backups.
197 jQuery('#mainwp_3rd_party_api_cpanel_action_refresh_available_backups').on('click', function () {
198 cpanel_action_refresh_available_backups(this);
199 });
200
201 // Trigger action_restore_backup.
202 jQuery(document).on('click', '.mainwp_3rd_party_api_cpanel_action_restore_backup', function () {
203 let confirmMsg = MainWP.I18n.t('Are you sure you want to Restore this backup?');
204 mainwp_confirm(confirmMsg, function () {
205 cPanel_action_restore_backup(this);
206 });
207 });
208
209 // Trigger action_restore_database_backup.
210 jQuery(document).on('click', '.mainwp_3rd_party_api_cpanel_action_restore_database_backup', function () {
211 let confirmMsg = MainWP.I18n.t('Are you sure you want to Restore this backup?');
212 mainwp_confirm(confirmMsg, () => {
213 cpanel_action_restore_database_backup(this);
214 });
215 });
216
217 // Trigger action_restore_manual_backup.
218 jQuery(document).on('click', '.mainwp_3rd_party_api_cpanel_action_restore_manual_backup', function () {
219 let confirmMsg = MainWP.I18n.t('Are you sure you want to Restore this backup?');
220 mainwp_confirm(confirmMsg, function () {
221 cpanel_action_restore_manual_backup();
222 });
223 });
224
225 // Trigger action_backup.
226 jQuery('#mainwp_3rd_party_api_cpanel_action_individual_create_backup').on('click', function () {
227 cpanel_action_create_backup(this);
228 });
229
230 // Trigger action_create_wptk_backup.
231 jQuery('#mainwp_3rd_party_api_cpanel_action_create_wptk_backup').on('click', function () {
232 cpanel_action_create_wptk_backup(this);
233 });
234
235 // Trigger action_backup for bulk backups.
236 jQuery('.mainwp_3rd_party_api_cpanel_action_full_backup').on('click', function () {
237 cpanel_action_create_full_backup(this);
238 });
239
240 // Trigger action_database_backup.
241 jQuery('#mainwp_3rd_party_api_cpanel_action_create_database_backup').on('click', function () {
242 cpanel_action_create_database_backup(this);
243 });
244
245 // Trigger action_backup for full backups. Database & Files.
246 jQuery('#mainwp_3rd_party_api_cpanel_action_create_full_backup').on('click', function () {
247 cpanel_action_create_full_backup(this);
248 });
249
250 // Trigger action_restore_wptk_backup.
251 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_wptk_backup').on('click', function () {
252 let confirmMsg = MainWP.I18n.t('Are you sure you want to Restore this backup?');
253 mainwp_confirm(confirmMsg, function () {
254 cpanel_action_restore_wptk_backup(this);
255 });
256 });
257
258 // Trigger action_delete_wptk_backup.
259 jQuery('.mainwp_3rd_party_api_cpanel_action_delete_wptk_backup').on('click', function () {
260 let confirmMsg = MainWP.I18n.t('Are you sure you want to Delete this backup?');
261 mainwp_confirm(confirmMsg, function () {
262 cpanel_action_delete_wptk_backup(this);
263 });
264 });
265
266 // Trigger action_download_wptk_backup
267 jQuery('.mainwp_3rd_party_api_cpanel_action_download_wptk_backup').on('click', function () {
268 cpanel_action_download_wptk_backup();
269 });
270
271 /**
272 * Plesk Ajax Hooks
273 */
274
275 // Trigger action_refresh_available_backups.
276 jQuery('#mainwp_3rd_party_api_plesk_action_refresh_available_backups').on('click', function () {
277 plesk_action_refresh_available_backups(this);
278 });
279
280 //Trigger action_backup.
281 jQuery('#mainwp_3rd_party_api_plesk_action_individual_create_backup').on('click', function () {
282 plesk_action_create_backup(this);
283 });
284
285 // Trigger action_backup. ( bulk )
286 jQuery('.mainwp_3rd_party_api_plesk_action_backup ').on('click', function () {
287 plesk_action_create_backup(this);
288 });
289
290 // Trigger action_restore_backup.
291 jQuery(document).on('click', '.mainwp_3rd_party_api_plesk_action_restore_backup', function () {
292 let confirmMsg = MainWP.I18n.t('Are you sure you want to Restore this backup?');
293 mainwp_confirm(confirmMsg, function () {
294 plesk_action_restore_backup();
295 });
296 });
297
298 // Trigger action_delete_backup.
299 jQuery(document).on('click', '.mainwp_3rd_party_api_plesk_action_delete_backup', function () {
300 let confirmMsg = MainWP.I18n.t('Are you sure you want to Delete this backup?');
301 mainwp_confirm(confirmMsg, function () {
302 plesk_action_delete_backup();
303 });
304 });
305
306 /**
307 * Kinsta Ajax Hooks
308 */
309 // Trigger action_refresh_available_backups.
310 jQuery('#mainwp_3rd_party_api_kinsta_action_refresh_available_backups').on('click', function () {
311 kinsta_action_refresh_available_backups(this);
312 });
313
314 //Trigger action_backup.
315 jQuery('#mainwp_3rd_party_api_kinsta_action_individual_create_backup').on('click', function () {
316 kinsta_action_create_backup(this);
317 });
318
319 // Trigger Bulk action_create_backup.
320 jQuery('.mainwp_3rd_party_api_kinsta_action_backup').on('click', function () {
321 kinsta_action_create_backup(this);
322 });
323
324 // Trigger action_delete_backup.
325 jQuery('.mainwp_3rd_party_api_kinsta_action_delete_backup').on('click', function () {
326 let confirmMsg = MainWP.I18n.t('Are you sure you want to Delete this backup?');
327 let backupId = jQuery(this).attr('backup_id');
328 mainwp_confirm(confirmMsg, function () {
329 kinsta_action_delete_backup(this, backupId);
330 });
331 });
332
333 // Trigger action_restore_backup.
334 jQuery('.mainwp_3rd_party_api_kinsta_action_restore_backup').on('click', function () {
335 let confirmMsg = MainWP.I18n.t('Are you sure you want to Restore this backup?');
336 let backupId = jQuery(this).attr('backup_id');
337 mainwp_confirm(confirmMsg, function () {
338 kinsta_action_restore_backup(this, backupId);
339 });
340 });
341
342 /**
343 * Global Bulk Action: backup selected sites.
344 */
345
346 // Trigger action_backup_selected_sites.
347 jQuery('#action_backup_selected_sites').on('click', function () {
348 action_backup_selected_sites(this);
349 });
350
351 /********************************************************
352 * Fomantic-ui Tabs Event Hooks.
353 */
354
355 /**
356 * Activate Fomantic-ui tabs for the 3rd-party API Manager Settings page,
357 * Settings > 3rd-Party API Manager.
358 *
359 * @url https://fomantic-ui.com/modules/tab.html#/usage
360 */
361 jQuery('#3rd-party-api-manager .menu .item').tab();
362
363 /**
364 * Activate Fomantic-ui tabs for the Individual cPanel Backups page,
365 * ChildSite Overview > API Backups
366 *
367 * @url https://fomantic-ui.com/modules/tab.html#/usage
368 */
369 jQuery('#mainwp_api_cpanel_backup_tabs .item').tab();
370
371 // Trigger action_check_tab. Handle the click event on the TAB Buttons.
372 jQuery('#mainwp_api_cpanel_backup_tabs .item').on('click', function () {
373 action_check_tab();
374 });
375
376 /**
377 * Handle switching TAB Buttons.
378 * Check if cPanel or Plesk is selected TAB when page loads & display the correct content.
379 */
380 let ref_this = jQuery('#mainwp_api_cpanel_backup_tabs div.active');
381 if (ref_this.data('tab') === 'cpanel-native') {
382 jQuery('#mainwp_3rd_party_api_cpanel_action_create_full_backup').show();
383 jQuery('#mainwp_3rd_party_api_cpanel_action_create_wptk_backup').hide();
384 } else if (ref_this.data('tab') === 'cpanel-wp-toolkit') {
385 jQuery('#mainwp_3rd_party_api_cpanel_action_create_full_backup').hide();
386 jQuery('#mainwp_3rd_party_api_cpanel_action_create_wptk_backup').show();
387 }
388 });
389 /********************************************************
390 * Invocable Functions.
391 */
392
393 /**
394 * Extension Overview Page: #action_backup_selected_sites.
395 *
396 * This function is called when the "Backup Selected Sites" button is clicked.
397 * mainwp_api_backups_do_backups() is defined in assets/js/mainwp-api-backups.js.
398 */
399 let action_backup_selected_sites = function (pObj) {
400 mainwp_api_backups_do_backups(pObj);
401 }
402
403 /**
404 * Handle switching TAB Action Buttons on Individual Cpanel Backups page.
405 * Check if cPanel or Plesk is selected TAB when TAB is clicked & display the correct content.
406 */
407 let action_check_tab = function () {
408
409 let ref_this = jQuery('#mainwp_api_cpanel_backup_tabs div.active');
410 if (ref_this.data('tab') === 'cpanel-native') {
411 jQuery('#mainwp_3rd_party_api_cpanel_action_create_full_backup').show();
412 jQuery('#mainwp_3rd_party_api_cpanel_action_create_wptk_backup').hide();
413 } else if (ref_this.data('tab') === 'cpanel-wp-toolkit') {
414 jQuery('#mainwp_3rd_party_api_cpanel_action_create_full_backup').hide();
415 jQuery('#mainwp_3rd_party_api_cpanel_action_create_wptk_backup').show();
416 }
417 }
418
419 let module_api_backups_prepare_working_status = function(button){
420 jQuery(button).html('<i class="notched circle loading icon"></i>');
421 }
422
423 /********************************************************
424 * Cloudways Functions.
425 */
426
427 // Create Backup.
428 let cloudways_action_backup = function (pObj) {
429
430 jQuery(pObj).attr('disabled', 'true');
431 let button = jQuery(pObj).closest('td');
432 let lastBackup = jQuery(pObj).closest('td').prev();
433 let websiteId = jQuery(pObj).attr('website_id');
434
435 let data = mainwp_secure_data({
436 action: 'cloudways_action_backup',
437 website_id: websiteId,
438 backup_api: 'cloudways'
439 });
440
441 module_api_backups_prepare_working_status(button);
442 jQuery(lastBackup).html('Requesting Backup...');
443
444 jQuery.post(ajaxurl, data, function (response) {
445 response = jQuery.trim(response);
446
447 if (response === 'true') {
448
449 // Show message.
450 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
451 jQuery('#mainwp-api-backups-message-zone .content .message')
452 .html( 'A backup has been requested. Please allow some time for the backup to complete, then Refresh Available Backups.')
453 ;
454
455 setTimeout(function () {
456 mainwp_forceReload();
457 }, 5000);
458
459 } else {
460
461 // Show message.
462 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
463 jQuery('#mainwp-api-backups-message-zone .content .message')
464 .html('There was an issue while requesting your backup. Please check that your ID and API Key are correct.')
465 ;
466
467 setTimeout(function () {
468 mainwp_forceReload();
469 }, 5000);
470
471 }
472 });
473
474 };
475
476 // Assign Apps to Child Sites.
477 let cloudways_action_update_ids = function (pObj) {
478
479 jQuery(pObj).attr('disabled', 'true');
480 let button = jQuery(pObj).closest('td');
481
482 let data = mainwp_secure_data({
483 action: 'cloudways_action_update_ids'
484 });
485
486 module_api_backups_prepare_working_status(button);
487
488 jQuery.post(ajaxurl, data, function (response) {
489 response = jQuery.trim(response);
490
491 if (response === 'true') {
492 window.location.search += '&update=true';
493 } else {
494 window.location.search += '&update=false';
495 }
496
497 });
498 };
499
500
501 // Refresh Available Backup.
502 let cloudways_action_refresh_available_backups = function (pObj) {
503
504 let websiteId = jQuery(pObj).attr('website_id');
505
506 // Start button animation.
507 jQuery(pObj).addClass('disabled loading');
508
509 // Prepare the data to send.
510 // The "action" is the name of the action hook to trigger.
511 // Anything else is data that we want to pass to the PHP function.
512 let data = mainwp_secure_data({
513 action: 'cloudways_action_refresh_available_backups',
514 website_id: websiteId,
515 backup_api: 'cloudways'
516 });
517
518 // Send a POST request to the ajaxurl (WordPress variable), using the data
519 // we prepared above, and running the below function when we receive the
520 // response. The last parameter tells jQuery to expect a JSON response
521
522 jQuery.post(ajaxurl, data, function (response) {
523 response = jQuery.trim(response);
524
525 if (response === 'true') {
526
527 // Show message.
528 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
529 jQuery('#mainwp-api-backups-message-zone .content .message')
530 .html( 'Available backups have been refreshed.' )
531 ;
532
533 // Stop button animation.
534 jQuery(pObj).removeClass('disabled loading');
535
536 setInterval('location.reload()', 7000); // Using .reload() method.
537
538 } else {
539
540 // Show message.
541 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
542 jQuery('#mainwp-api-backups-message-zone .content .message')
543 .html( 'There was an issue while refreshing available backups.' )
544 ;
545
546 // Stop button animation.
547 jQuery(pObj).removeClass('disabled loading');
548
549 }
550 }, 'json');
551 };
552
553 // Restore backups.
554 let cloudways_action_restore_backup = function (pObj) {
555 let button = jQuery(pObj);
556 let websiteId = jQuery(pObj).attr('website_id');
557 let backupDate = jQuery(pObj).attr('backup_date');
558
559 let data = mainwp_secure_data({
560 action: 'cloudways_action_restore_backup',
561 website_id: websiteId,
562 backup_date: backupDate,
563 backup_api: 'cloudways'
564 });
565
566 // Start button animation.
567 module_api_backups_prepare_working_status(button);
568
569 jQuery.post(ajaxurl, data, function (response) {
570 response = jQuery.trim(response);
571
572 if (response === 'true') {
573
574 // Show message.
575 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
576 jQuery('#mainwp-api-backups-message-zone .content .message')
577 .html( 'Your application is in the process of restoring. This will take a few minuets...' )
578 ;
579
580 // Stop button animation.
581 jQuery(button).html('<i class="undo icon"></i>');
582
583 } else {
584
585 // Show message.
586 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
587 jQuery('#mainwp-api-backups-message-zone .content .message')
588 .html( 'There was an issue while attempting to restore your application...' )
589 ;
590
591 // Stop button animation.
592 jQuery(button).html('<i class="undo icon"></i>');
593
594 }
595 });
596 };
597
598 // Delete backups.
599 let cloudways_action_delete_backup = function (pObj) {
600
601 jQuery(pObj).attr('disabled', 'true');
602 let button = jQuery(pObj).closest('td');
603
604 let websiteId = jQuery(pObj).attr('website_id');
605
606 let data = mainwp_secure_data({
607 action: 'cloudways_action_delete_backup',
608 website_id: websiteId,
609 backup_api: 'cloudways'
610 });
611
612 // Start button animation.
613 jQuery(button).find('i.loading').css({ 'display': 'block' });
614 jQuery(button).find('div').addClass('hidden');
615
616 jQuery.post(ajaxurl, data, function (response) {
617 response = jQuery.trim(response);
618
619 if (response === 'true') {
620
621 // Show message.
622 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
623 jQuery('#mainwp-api-backups-message-zone .content .message')
624 .html( 'The local backups done before last restore have been deleted.' )
625 ;
626
627 // Stop button animation.
628 jQuery(button).find('i.loading').css({ 'display': 'none' });
629 jQuery(button).find('div').removeClass('hidden');
630
631 } else {
632
633 // Show message.
634 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
635 jQuery('#mainwp-api-backups-message-zone .content .message')
636 .html( 'There was an issue while deleting your backups.' )
637 ;
638
639 // Stop button animation.
640 jQuery(button).find('i.loading').css({ 'display': 'none' });
641 jQuery(button).find('div').removeClass('hidden');
642
643 }
644 });
645 };
646
647 /********************************************************
648 * Vultr Functions.
649 */
650
651 // Assign Instances to Child Sites.
652 let vultr_action_update_ids = function (pObj) {
653 jQuery(pObj).attr('disabled', 'true');
654 let button = jQuery(pObj).closest('td');
655
656 let data = mainwp_secure_data({
657 action: 'vultr_action_update_ids'
658 });
659
660 // Start button animation.
661 jQuery(button).find('i.loading').css({ 'display': 'block' });
662 jQuery(button).find('div').addClass('hidden');
663
664 jQuery.post(ajaxurl, data, function (response) {
665 response = jQuery.trim(response);
666
667 if (response === 'true') {
668
669 // Show message.
670 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
671 jQuery('#mainwp-api-backups-message-zone .content .message')
672 .html('Backup Stats have been refreshed.')
673 ;
674
675 // Stop button animation.
676 jQuery(button).find('i.loading').css({ 'display': 'none' });
677 jQuery(button).find('div').removeClass('hidden');
678
679 } else {
680
681 // Show message.
682 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
683 jQuery('#mainwp-api-backups-message-zone .content .message')
684 .html( 'There was an issue refreshing the Backup Stats.' )
685 ;
686
687 // Stop button animation.
688 jQuery(button).find('i.loading').css({ 'display': 'none' });
689 jQuery(button).find('div').removeClass('hidden');
690
691 }
692 });
693 };
694
695 // Create Backup.
696 let vultr_action_create_snapshot = function (pObj) {
697
698 jQuery(pObj).attr('disabled', 'true');
699 let button = jQuery(pObj).closest('td');
700 let lastBackup = jQuery(pObj).closest('td').prev();
701 let websiteId = jQuery(pObj).attr('website_id');
702
703 let data = mainwp_secure_data({
704 action: 'vultr_action_create_snapshot',
705 website_id: websiteId,
706 backup_api: 'vultr'
707 });
708
709 module_api_backups_prepare_working_status(button);
710 jQuery(lastBackup).html('Requesting Backup...');
711
712 jQuery.post(ajaxurl, data, function (response) {
713 response = jQuery.trim(response);
714 if (response === 'true') {
715
716 // Show message.
717 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
718 jQuery('#mainwp-api-backups-message-zone .content .message')
719 .html('A backup has been requested.');
720 setTimeout(function () {
721 mainwp_forceReload();
722 }, 5000);
723
724 } else {
725 let err_message = '' !== response ? response : 'There was an issue while requesting your backup. Please check that your ID and API Key are correct.';
726
727 // Show message.
728 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
729 jQuery('#mainwp-api-backups-message-zone .content .message')
730 .html( err_message );
731 setTimeout(function () {
732 mainwp_forceReload();
733 }, 5000);
734
735 }
736 });
737 };
738
739 // Refresh Available Backup.
740 let vultr_action_refresh_available_backups = function (pObj) {
741
742 let websiteId = jQuery(pObj).attr('website_id');
743
744 let data = mainwp_secure_data({
745 action: 'vultr_action_refresh_available_backups',
746 website_id: websiteId,
747 backup_api: 'vultr'
748 });
749
750 // Start button animation.
751 jQuery(pObj).addClass('disabled loading');
752
753 jQuery.post(ajaxurl, data, function (response) {
754 response = jQuery.trim(response);
755
756 if (response === 'true') {
757
758 // Show message.
759 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
760 jQuery('#mainwp-api-backups-message-zone .content .message')
761 .html('Available backups have been refreshed.')
762 ;
763
764 // Stop button animation.
765 jQuery(pObj).removeClass('disabled loading');
766
767 setInterval('location.reload()', 7000); // Using .reload() method.
768
769 } else {
770
771 // Show message.
772 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
773 jQuery('#mainwp-api-backups-message-zone .content .message')
774 .html('There was an issue while refreshing available backups.' )
775 ;
776
777 // Stop button animation.
778 jQuery(pObj).removeClass('disabled loading');
779
780 }
781 });
782 };
783 // Restore Backup.
784 let vultr_action_restore_backup = function (pObj) {
785
786 let button = jQuery(pObj);
787 let websiteId = jQuery(pObj).attr('website_id');
788 let snapshotID = jQuery(pObj).attr('snapshot_id');
789
790 let data = mainwp_secure_data({
791 action: 'vultr_action_restore_backup',
792 website_id: websiteId,
793 backup_api: 'vultr',
794 snapshot_id: snapshotID
795 });
796
797 // Start button animation.
798 module_api_backups_prepare_working_status(button);
799
800 jQuery.post(ajaxurl, data, function (response) {
801 response = jQuery.trim(response);
802
803 if (response === 'true') {
804
805 // Show message.
806 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
807 jQuery('#mainwp-api-backups-message-zone .content .message')
808 .html('Backup restoration process has begun. Please wait a few moments and then check the site.')
809 ;
810
811 // Stop button animation.
812 jQuery(button).html('<i class="undo icon"></i>');
813
814 } else {
815
816 // Show message.
817 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
818 jQuery('#mainwp-api-backups-message-zone .content .message')
819 .html('There was an issue while restoring your backup.')
820 ;
821
822 // Stop button animation.
823 jQuery(button).html('<i class="undo icon"></i>');
824
825 }
826 });
827 };
828
829
830 // Delete Backup.
831 let vultr_action_delete_backup = function (pObj) {
832
833 let button = jQuery(pObj);
834 let websiteId = jQuery(pObj).attr('website_id');
835 let snapshotID = jQuery(pObj).attr('snapshot_id');
836
837 let data = mainwp_secure_data({
838 action: 'vultr_action_delete_backup',
839 website_id: websiteId,
840 backup_api: 'vultr',
841 snapshot_id: snapshotID
842 });
843
844 // Start button animation.
845 module_api_backups_prepare_working_status(button);
846
847 jQuery.post(ajaxurl, data, function (response) {
848 response = jQuery.trim(response);
849
850 if (response === 'true') {
851
852 // Show message.
853 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
854 jQuery('#mainwp-api-backups-message-zone .content .message')
855 .html('The selected backup has been deleted.')
856 ;
857
858 // Stop button animation.
859 jQuery(button).html('<i class="undo icon"></i>');
860
861 } else {
862
863 // Show message.
864 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
865 jQuery('#mainwp-api-backups-message-zone .content .message')
866 .html('There was an issue while deleting the selected backup.')
867 ;
868
869 // Stop button animation.
870 jQuery(button).html('<i class="undo icon"></i>');
871
872 }
873 });
874 };
875
876
877 /********************************************************
878 * Gridpane Functions.
879 */
880
881 // Assign Site ID's to Child Sites.
882 let gridpane_action_update_ids = function (pObj) {
883 jQuery(pObj).attr('disabled', 'true');
884 let button = jQuery(pObj).closest('td');
885
886 let data = mainwp_secure_data({
887 action: 'gridpane_action_update_ids'
888 });
889
890 module_api_backups_prepare_working_status(button);
891
892 jQuery.post(ajaxurl, data, function (response) {
893 response = jQuery.trim(response);
894
895 if (response === 'true') {
896 window.location.search += '&update=true';
897 } else {
898 window.location.search += '&update=false';
899 }
900
901 });
902 };
903
904 // Create Backup.
905 let gridpane_action_create_backup = function (pObj) {
906
907 jQuery(pObj).attr('disabled', 'true');
908 let button = jQuery(pObj).closest('td');
909 let lastBackup = jQuery(pObj).closest('td').prev();
910 let websiteId = jQuery(pObj).attr('website_id');
911
912 let data = mainwp_secure_data({
913 action: 'gridpane_action_create_backup',
914 website_id: websiteId,
915 backup_api: 'gridpane'
916 });
917
918 module_api_backups_prepare_working_status(button);
919
920 jQuery(lastBackup).html('Requesting Backup...');
921
922 jQuery.post(ajaxurl, data, function (response) {
923 response = jQuery.trim(response);
924
925 if (response === 'true') {
926
927 // Show message.
928 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
929 jQuery('#mainwp-api-backups-message-zone .content .message')
930 .html('A backup has been requested.')
931 ;
932
933 setTimeout(function () {
934 mainwp_forceReload();
935 }, 5000);
936
937 } else {
938
939 // Show message.
940 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
941 jQuery('#mainwp-api-backups-message-zone .content .message')
942 .html('There was an issue while requesting your backup. Please check that your ID and API Key are correct.' )
943 ;
944
945 setTimeout(function () {
946 mainwp_forceReload();
947 }, 5000);
948
949 }
950 });
951 };
952
953 // Refresh Available Backup.
954 let gridpane_action_refresh_available_backups = function (pObj) {
955
956 let websiteId = jQuery(pObj).attr('website_id');
957
958 let data = mainwp_secure_data({
959 action: 'gridpane_action_refresh_available_backups',
960 website_id: websiteId,
961 backup_api: 'gridpane'
962 });
963
964 // Start button animation.
965 jQuery(pObj).addClass('disabled loading');
966
967 jQuery.post(ajaxurl, data, function (response) {
968 response = jQuery.trim(response);
969
970 if (response === 'true') {
971
972 // Show message.
973 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
974 jQuery('#mainwp-api-backups-message-zone .content .message')
975 .html('Available backups have been refreshed.')
976 ;
977
978 // Stop button animation.
979 jQuery(pObj).removeClass('disabled loading');
980
981 setInterval('location.reload()', 7000); // Using .reload() method.
982
983 } else {
984
985 // Show message.
986 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
987 jQuery('#mainwp-api-backups-message-zone .content .message')
988 .html('There was an issue while refreshing available backups.' )
989 ;
990
991 // Stop button animation.
992 jQuery(pObj).removeClass('disabled loading');
993
994 }
995 });
996 };
997
998 // Restore Backup.
999 let gridpane_action_restore_backup = function (pObj) {
1000
1001 let button = jQuery(pObj);
1002 let websiteId = jQuery(pObj).attr('website_id');
1003 let backupType = jQuery(pObj).attr('backup_type');
1004 let backupName = jQuery(pObj).attr('backup_name');
1005
1006 let data = mainwp_secure_data({
1007 action: 'gridpane_action_restore_backup',
1008 website_id: websiteId,
1009 backup_api: 'gridpane',
1010 backup_type: backupType,
1011 backup_name: backupName
1012 });
1013
1014 // Start button animation.
1015 module_api_backups_prepare_working_status(button);
1016
1017 jQuery.post(ajaxurl, data, function (response) {
1018 response = jQuery.trim(response);
1019
1020 if (response === 'true') {
1021
1022 // Show message.
1023 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1024 jQuery('#mainwp-api-backups-message-zone .content .message')
1025 .html('Backup restoration has begun. Please wait a few moments and then check the site.')
1026 ;
1027
1028 // Stop button animation.
1029 jQuery(button).html('<i class="undo icon"></i>');
1030
1031 } else {
1032
1033 // Show message.
1034 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1035 jQuery('#mainwp-api-backups-message-zone .content .message')
1036 .html('There was an issue while restoring your backup.' )
1037 ;
1038
1039 // Stop button animation.
1040 jQuery(button).html('<i class="undo icon"></i>');
1041
1042 }
1043 });
1044 };
1045
1046 // Delete Backup.
1047 let gridpane_action_delete_backup = function (pObj) {
1048
1049 let button = jQuery(pObj);
1050
1051 let websiteId = jQuery(pObj).attr('website_id');
1052 let backupType = jQuery(pObj).attr('backup_type');
1053 let backupName = jQuery(pObj).attr('backup_name');
1054
1055 let data = mainwp_secure_data({
1056 action: 'gridpane_action_delete_backup',
1057 website_id: websiteId,
1058 backup_api: 'gridpane',
1059 backup_type: backupType,
1060 backup_name: backupName
1061 });
1062
1063 // Start button animation.
1064 module_api_backups_prepare_working_status(button);
1065
1066 jQuery.post(ajaxurl, data, function (response) {
1067 response = jQuery.trim(response);
1068
1069 if (response === 'true') {
1070
1071 // Show message.
1072 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1073 jQuery('#mainwp-api-backups-message-zone .content .message')
1074 .html('The selected backup has been deleted.')
1075 ;
1076
1077 // Stop button animation.
1078 jQuery(button).html('<i class="trash icon"></i>');
1079
1080 } else {
1081
1082 // Show message.
1083 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1084 jQuery('#mainwp-api-backups-message-zone .content .message')
1085 .html('There was an issue while deleting the selected backup.')
1086 ;
1087
1088 // Stop button animation.
1089 jQuery(button).html('<i class="trash icon"></i>');
1090
1091 }
1092 });
1093 };
1094
1095 /********************************************************
1096 * Linode Functions.
1097 */
1098
1099 // Assign Site ID's to Child Sites.
1100 let linode_action_update_ids = function (pObj) {
1101 jQuery(pObj).attr('disabled', 'true');
1102 let button = jQuery(pObj).closest('td');
1103
1104 let data = mainwp_secure_data({
1105 action: 'linode_action_update_ids'
1106 });
1107
1108 module_api_backups_prepare_working_status(button);
1109
1110 jQuery.post(ajaxurl, data, function (response) {
1111 response = jQuery.trim(response);
1112
1113 if (response === 'true') {
1114 window.location.search += '&update=true';
1115 } else {
1116 window.location.search += '&update=false';
1117 }
1118 });
1119 };
1120
1121 // Create Backup.
1122 let linode_action_create_backup = function (pObj) {
1123
1124 jQuery(pObj).attr('disabled', 'true');
1125 let button = jQuery(pObj).closest('td');
1126 let lastBackup = jQuery(pObj).closest('td').prev();
1127 let websiteId = jQuery(pObj).attr('website_id');
1128
1129 let data = mainwp_secure_data({
1130 action: 'linode_action_create_backup',
1131 website_id: websiteId,
1132 backup_api: 'linode'
1133 });
1134
1135 module_api_backups_prepare_working_status(button);
1136
1137 jQuery(lastBackup).html('Requesting Backup...');
1138
1139 jQuery.post(ajaxurl, data, function (response) {
1140 response = jQuery.trim(response);
1141
1142 if (response === 'true') {
1143
1144 // Show message.
1145 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1146 jQuery('#mainwp-api-backups-message-zone .content .message')
1147 .html('A backup has been requested.')
1148 ;
1149
1150 setTimeout(function () {
1151 mainwp_forceReload();
1152 }, 5000);
1153
1154 } else {
1155
1156 // Show message.
1157 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1158 jQuery('#mainwp-api-backups-message-zone .content .message')
1159 .html('There was an issue while requesting your backup. Please check that your backups are enabled & ID\'s are correct.')
1160 ;
1161
1162 setTimeout(function () {
1163 mainwp_forceReload();
1164 }, 5000);
1165 }
1166 });
1167 };
1168
1169 // Refresh Available Backup.
1170 let linode_action_refresh_available_backups = function (pObj) {
1171
1172 let websiteId = jQuery(pObj).attr('website_id');
1173
1174 let data = mainwp_secure_data({
1175 action: 'linode_action_refresh_available_backups',
1176 website_id: websiteId,
1177 backup_api: 'linode'
1178 });
1179
1180 // Start button animation.
1181 jQuery(pObj).addClass('disabled loading');
1182
1183 jQuery.post(ajaxurl, data, function (response) {
1184 response = jQuery.trim(response);
1185
1186 if (response === 'true') {
1187
1188 // Show message.
1189 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1190 jQuery('#mainwp-api-backups-message-zone .content .message')
1191 .html('Available backups have been refreshed.')
1192 ;
1193
1194 // Stop button animation.
1195 jQuery(pObj).removeClass('disabled loading');
1196
1197 setInterval('location.reload()', 7000); // Using .reload() method.
1198
1199 } else {
1200
1201 // Show message.
1202 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1203 jQuery('#mainwp-api-backups-message-zone .content .message')
1204 .html('There was an issue while refreshing available backups.')
1205 ;
1206
1207 // Stop button animation.
1208 jQuery(pObj).removeClass('disabled loading');
1209
1210 }
1211 });
1212 };
1213
1214 // restore Backup.
1215 let linode_action_restore_backup = function (pObj) {
1216
1217 jQuery(pObj).attr('disabled', 'true');
1218 let button = jQuery(pObj).closest('td');
1219 let backupStatus = jQuery(pObj).closest('td').prev();
1220 let websiteId = jQuery(pObj).attr('website_id');
1221 let backupId = jQuery(pObj).attr('backup_id');
1222
1223 let data = mainwp_secure_data({
1224 action: 'linode_action_restore_backup',
1225 website_id: websiteId,
1226 backup_api: 'linode',
1227 backup_id: backupId
1228 });
1229
1230 // Start button animation.
1231 module_api_backups_prepare_working_status(button);
1232 jQuery(backupStatus).html('Restoring Backup...');
1233
1234 jQuery.post(ajaxurl, data, function (response) {
1235 response = jQuery.trim(response);
1236
1237 if (response === 'true') {
1238
1239 // Show message.
1240 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1241 jQuery('#mainwp-api-backups-message-zone .content .message')
1242 .html('The backup restoration was successful. Please check your Linode Server Status...')
1243 ;
1244
1245 jQuery(backupStatus).html('Rebooting Server...');
1246 setInterval('location.reload()', 7000);// Using .reload() method.
1247
1248 } else {
1249
1250 // Show message.
1251 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1252 jQuery('#mainwp-api-backups-message-zone .content .message')
1253 .html('There was an issue while restoring your backup.')
1254 ;
1255
1256 // Stop button animation.
1257 setInterval('location.reload()', 7000); // Using .reload() method.
1258
1259 }
1260 });
1261 };
1262
1263 // Cancel Backup.
1264 let linode_action_cancel_backups = function (pObj) {
1265
1266 let websiteId = jQuery(pObj).attr('website_id');
1267
1268 let data = mainwp_secure_data({
1269 action: 'linode_action_cancel_backups',
1270 website_id: websiteId,
1271 backup_api: 'linode'
1272 });
1273
1274 // Start button animation.
1275 jQuery(pObj).addClass('disabled loading');
1276
1277 jQuery.post(ajaxurl, data, function (response) {
1278 response = jQuery.trim(response);
1279
1280 if (response === 'true') {
1281
1282 // Show message.
1283 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1284 jQuery('#mainwp-api-backups-message-zone .content .message')
1285 .html('The backups associated with this Linode have been removed.')
1286 ;
1287
1288 // Stop button animation.
1289 jQuery(pObj).removeClass('disabled loading');
1290
1291 } else {
1292
1293 // Show message.
1294 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1295 jQuery('#mainwp-api-backups-message-zone .content .message')
1296 .html('There was an issue while canceling your backup.')
1297 ;
1298
1299 // Stop button animation.
1300 jQuery(pObj).removeClass('disabled loading');
1301
1302 }
1303 });
1304 };
1305
1306 /********************************************************
1307 * Digital Ocean Functions.
1308 */
1309
1310 // Assign Site ID's to Child Sites.
1311 let digitalocean_action_update_ids = function (pObj) {
1312 jQuery(pObj).attr('disabled', 'true');
1313 let button = jQuery(pObj).closest('td');
1314
1315 let data = mainwp_secure_data({
1316 action: 'digitalocean_action_update_ids'
1317 });
1318
1319 module_api_backups_prepare_working_status(button);
1320
1321 jQuery.post(ajaxurl, data, function (response) {
1322 response = jQuery.trim(response);
1323
1324 if (response === 'true') {
1325 window.location.search += '&update=true';
1326 } else {
1327 window.location.search += '&update=false';
1328 }
1329
1330 });
1331 };
1332
1333 // Create Backup.
1334 let digitalocean_action_create_backup = function (pObj) {
1335 jQuery(pObj).attr('disabled', 'true');
1336 let button = jQuery(pObj).closest('td');
1337 let lastBackup = jQuery(pObj).closest('td').prev();
1338 let websiteId = jQuery(pObj).attr('website_id');
1339
1340 let data = mainwp_secure_data({
1341 action: 'digitalocean_action_create_backup',
1342 website_id: websiteId,
1343 backup_api: 'digitalocean'
1344 });
1345
1346 module_api_backups_prepare_working_status(button);
1347
1348 jQuery(lastBackup).html('Requesting Backup...');
1349
1350 jQuery.post(ajaxurl, data, function (response) {
1351 response = jQuery.trim(response);
1352
1353 if (response === 'true') {
1354
1355 // Show message.
1356 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1357 jQuery('#mainwp-api-backups-message-zone .content .message')
1358 .html('A backup has been requested.')
1359 ;
1360
1361 setTimeout(function () {
1362 mainwp_forceReload();
1363 }, 5000);
1364 } else {
1365
1366 // Show message.
1367 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1368 jQuery('#mainwp-api-backups-message-zone .content .message')
1369 .html('There was an issue while requesting your backup. Please check that your ID and API Key are correct.')
1370 ;
1371
1372 setTimeout(function () {
1373 mainwp_forceReload();
1374 }, 5000);
1375 }
1376 });
1377 };
1378
1379 // Refresh Available Backups.
1380 let digitalocean_action_refresh_available_backups = function (pObj) {
1381
1382 let websiteId = jQuery(pObj).attr('website_id');
1383
1384 let data = mainwp_secure_data({
1385 action: 'digitalocean_action_refresh_available_backups',
1386 website_id: websiteId,
1387 backup_api: 'digitalocean'
1388 });
1389
1390 // Start button animation.
1391 jQuery(pObj).addClass('disabled loading');
1392
1393 jQuery.post(ajaxurl, data, function (response) {
1394 response = jQuery.trim(response);
1395
1396 if (response === 'true') {
1397
1398 // Show message.
1399 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1400 jQuery('#mainwp-api-backups-message-zone .content .message')
1401 .html('Available backups have been refreshed.')
1402 ;
1403
1404 // Stop button animation.
1405 jQuery(pObj).removeClass('disabled loading');
1406
1407 setInterval('location.reload()', 7000);// Using .reload() method.
1408
1409 } else {
1410
1411 // Show message.
1412 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1413 jQuery('#mainwp-api-backups-message-zone .content .message')
1414 .html('There was an issue while refreshing available backups.')
1415 ;
1416
1417 // Stop button animation.
1418 jQuery(pObj).removeClass('disabled loading');
1419
1420 }
1421 });
1422 };
1423
1424 // restore Backup.
1425 let digitalocean_action_restore_backup = function (pObj) {
1426
1427 let button = jQuery(pObj);
1428 let lastBackup = jQuery(pObj).closest('td').prev();
1429 let websiteId = jQuery(pObj).attr('website_id');
1430 let snapshotId = jQuery(pObj).attr('snapshot_id');
1431
1432 let data = mainwp_secure_data({
1433 action: 'digitalocean_action_restore_backup',
1434 website_id: websiteId,
1435 backup_api: 'digitalocean',
1436 snapshot_id: snapshotId
1437 });
1438
1439 // Start button animation.
1440 module_api_backups_prepare_working_status(button);
1441
1442 jQuery.post(ajaxurl, data, function (response) {
1443 response = jQuery.trim(response);
1444
1445 jQuery(lastBackup).html('');
1446
1447 if (response === 'true') {
1448
1449 // Show message.
1450 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1451 jQuery('#mainwp-api-backups-message-zone .content .message')
1452 .html('Backup restoration has begun. Please wait a few moments and then check the site.')
1453 ;
1454
1455 // Stop button animation.
1456 jQuery(button).html('<i class="undo icon"></i>');
1457
1458 } else {
1459
1460 // Show message.
1461 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1462 jQuery('#mainwp-api-backups-message-zone .content .message')
1463 .html('There was an issue while restoring your backup.')
1464 ;
1465
1466 // Stop button animation.
1467 jQuery(button).html('<i class="undo icon"></i>');
1468 }
1469
1470 });
1471 };
1472
1473 // Delete Backup.
1474 let digitalocean_action_delete_backup = function (pObj) {
1475
1476 let button = jQuery(pObj);
1477
1478 let snapshotId = jQuery(pObj).attr('snapshot_id');
1479
1480 let data = mainwp_secure_data({
1481 action: 'digitalocean_action_delete_backup',
1482 snapshot_id: snapshotId
1483 });
1484
1485 // Start button animation.
1486 module_api_backups_prepare_working_status(button);
1487
1488 jQuery.post(ajaxurl, data, function (response) {
1489 response = jQuery.trim(response);
1490
1491 if (response === 'true') {
1492
1493 // Show message.
1494 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1495 jQuery('#mainwp-api-backups-message-zone .content .message')
1496 .html('The selected backup has been deleted.')
1497 ;
1498
1499 // Stop button animation.
1500 jQuery(button).html('<i class="trash icon"></i>');
1501
1502 } else {
1503
1504 // Show message.
1505 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1506 jQuery('#mainwp-api-backups-message-zone .content .message')
1507 .html('There was an issue while deleting the selected backup.')
1508 ;
1509
1510 // Stop button animation.
1511 jQuery(button).html('<i class="trash icon"></i>');
1512
1513 }
1514 });
1515 };
1516
1517 /********************************************************
1518 * Cpanel Functions.
1519 */
1520
1521 let cpanel_action_create_wptk_backup = function (pObj) {
1522
1523 let websiteId = jQuery(pObj).attr('website_id');
1524
1525 let data = mainwp_secure_data({
1526 action: 'cpanel_action_create_wptk_backup',
1527 website_id: websiteId,
1528 backup_api: 'cpanel',
1529 backup: 'true'
1530 });
1531
1532 // Start button animation.
1533 jQuery(pObj).addClass('disabled loading');
1534
1535 jQuery.post(ajaxurl, data, function (response) {
1536 response = jQuery.trim(response);
1537
1538 if (response === 'true') {
1539
1540 // Show message.
1541 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1542 jQuery('#mainwp-api-backups-message-zone .content .message')
1543 .html( 'A backup has been requested. Please allow some time for the backup to complete, then Refresh Available Backups.');
1544
1545 // Stop button animation.
1546 jQuery(pObj).removeClass('disabled loading');
1547
1548 } else {
1549
1550 // Show message.
1551 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1552 jQuery('#mainwp-api-backups-message-zone .content .message')
1553 .html( response )
1554 ;
1555
1556 // Stop button animation.
1557 jQuery(pObj).removeClass('disabled loading');
1558
1559 }
1560 });
1561 };
1562
1563 // restore Backup.
1564
1565 let cpanel_action_restore_wptk_backup = function (pObj) {
1566
1567 // Disable link.
1568 jQuery(pObj).attr('disabled', 'true');
1569
1570 let backupName = jQuery('.mainwp_3rd_party_api_cpanel_action_restore_wptk_backup').attr('backup_name');
1571 let websiteId = jQuery('.mainwp_3rd_party_api_cpanel_action_restore_wptk_backup').attr('website_id');
1572
1573 let data = mainwp_secure_data({
1574 action: 'cpanel_action_restore_wptk_backup',
1575 website_id: websiteId,
1576 backup_api: 'cpanel',
1577 backup_name: backupName,
1578 });
1579
1580 // Start button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1581 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_wptk_backup').addClass('disabled loading');
1582
1583 jQuery.post(ajaxurl, data, function (response) {
1584 response = jQuery.trim(response);
1585
1586 if (response === 'true') {
1587
1588 // Show message.
1589 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1590 jQuery('#mainwp-api-backups-message-zone .content .message')
1591 .html('The backup restoration process has finished. Please wait a few moments and then check the site.')
1592 ;
1593
1594 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1595 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_wptk_backup').removeClass('disabled loading');
1596
1597 } else {
1598
1599 // Show message.
1600 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1601 jQuery('#mainwp-api-backups-message-zone .content .message')
1602 .html('There was an issue while restoring your backup.')
1603 ;
1604
1605 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1606 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_wptk_backup').removeClass('disabled loading');
1607
1608 }
1609 });
1610 };
1611
1612 // Delete Backup.
1613 let cpanel_action_delete_wptk_backup = function (pObj) {
1614
1615 // Disable link.
1616 jQuery(pObj).attr('disabled', 'true');
1617
1618 let backupName = jQuery('.mainwp_3rd_party_api_cpanel_action_delete_wptk_backup').attr('backup_name');
1619 let websiteId = jQuery('.mainwp_3rd_party_api_cpanel_action_delete_wptk_backup').attr('website_id');
1620
1621 let data = mainwp_secure_data({
1622 action: 'cpanel_action_delete_wptk_backup',
1623 website_id: websiteId,
1624 backup_api: 'cpanel',
1625 backup_name: backupName,
1626 });
1627
1628 // Start button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1629 jQuery('.mainwp_3rd_party_api_cpanel_action_delete_wptk_backup').addClass('disabled loading');
1630
1631 jQuery.post(ajaxurl, data, function (response) {
1632 response = jQuery.trim(response);
1633
1634 if (response === 'true') {
1635
1636 // Show message.
1637 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1638 jQuery('#mainwp-api-backups-message-zone .content .message')
1639 .html('The selected backup has been deleted.')
1640 ;
1641
1642 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1643 jQuery('.mainwp_3rd_party_api_cpanel_action_delete_wptk_backup').removeClass('disabled loading');
1644
1645 } else {
1646
1647 // Show message.
1648 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1649 jQuery('#mainwp-api-backups-message-zone .content .message')
1650 .html('There was an issue while deleting your backup.')
1651 ;
1652
1653 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1654 jQuery('.mainwp_3rd_party_api_cpanel_action_delete_wptk_backup').removeClass('disabled loading');
1655
1656 }
1657 });
1658 };
1659
1660 // Download Backup.
1661 let cpanel_action_download_wptk_backup = function () {
1662
1663 let href = jQuery('.mainwp_3rd_party_api_cpanel_action_download_wptk_backup').attr('href');
1664 window.open(href, '_blank');
1665
1666 };
1667
1668 let cpanel_action_create_backup = function (pObj) {
1669
1670 let websiteId = jQuery(pObj).attr('website_id');
1671
1672 let data = mainwp_secure_data({
1673 action: 'cpanel_action_create_manual_backup',
1674 website_id: websiteId,
1675 backup_api: 'cpanel'
1676 });
1677
1678 // Start button animation.
1679 jQuery(pObj).addClass('disabled loading');
1680
1681 jQuery.post(ajaxurl, data, function (response) {
1682 response = jQuery.trim(response);
1683
1684 if (response === 'true') {
1685
1686 // Show message.
1687 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1688 jQuery('#mainwp-api-backups-message-zone .content .message')
1689 .html('A backup has been requested.')
1690 ;
1691
1692 // Stop button animation.
1693 jQuery(pObj).removeClass('disabled loading');
1694
1695 } else {
1696
1697 // Show message.
1698 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1699 jQuery('#mainwp-api-backups-message-zone .content .message')
1700 .html( response )
1701 ;
1702
1703 // Stop button animation.
1704 jQuery(pObj).removeClass('disabled loading');
1705
1706 }
1707 });
1708 };
1709
1710 // Refresh Available Backups.
1711 let cpanel_action_refresh_available_backups = function (pObj) {
1712
1713 let websiteId = jQuery(pObj).attr('website_id');
1714
1715 let data = mainwp_secure_data({
1716 action: 'cpanel_action_refresh_available_backups',
1717 website_id: websiteId,
1718 backup_api: 'cPanel'
1719 });
1720
1721 // Start button animation.
1722 jQuery(pObj).addClass('disabled loading');
1723
1724 jQuery.post(ajaxurl, data, function (response) {
1725 response = jQuery.trim(response);
1726
1727 if (response === 'true') {
1728
1729 // Show message.
1730 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1731 jQuery('#mainwp-api-backups-message-zone .content .message')
1732 .html('Available backups have been refreshed.')
1733 ;
1734
1735 // Stop button animation.
1736 jQuery(pObj).removeClass('disabled loading');
1737
1738 setInterval('location.reload()', 7000); // Using .reload() method.
1739
1740 } else {
1741
1742 // Show message.
1743 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1744 jQuery('#mainwp-api-backups-message-zone .content .message')
1745 .html('There was an issue while refreshing available backups.')
1746 ;
1747
1748 // Stop button animation.
1749 jQuery(pObj).removeClass('disabled loading');
1750
1751 }
1752 });
1753 };
1754
1755 // restore Backup.
1756 let cPanel_action_restore_backup = function (pObj) {
1757
1758 // Disable link.
1759 jQuery(pObj).attr('disabled', 'true');
1760
1761 let websiteId = jQuery('#cpanel_automatic_backup_button').attr('website_id');
1762 let backupID = jQuery('#cpanel_automatic_backup_button').attr('backup_name');
1763 let backupPath = jQuery('#cpanel_automatic_backup_button').attr('backup_path');
1764
1765 let data = mainwp_secure_data({
1766 action: 'cpanel_action_restore_backup',
1767 website_id: websiteId,
1768 backup_api: 'cpanel',
1769 backup_id: backupID,
1770 backup_path: backupPath
1771 });
1772
1773 // Start button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1774 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_backup button').addClass('disabled loading');
1775
1776 jQuery.post(ajaxurl, data, function (response) {
1777 response = jQuery.trim(response);
1778
1779 if (response === 'true') {
1780
1781 // Show message.
1782 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1783 jQuery('#mainwp-api-backups-message-zone .content .message')
1784 .html('The backup restoration process has finished. Please wait a few moments and then check the site.')
1785 ;
1786
1787 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1788 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_backup button').removeClass('disabled loading');
1789
1790 } else {
1791
1792 // Show message.
1793 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1794 jQuery('#mainwp-api-backups-message-zone .content .message')
1795 .html('There was an issue while restoring your backup.')
1796 ;
1797
1798 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1799 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_backup button').removeClass('disabled loading');
1800
1801 }
1802 });
1803 };
1804
1805 // restore Backup.
1806 let cpanel_action_restore_database_backup = function (btObj) {
1807
1808 let websiteId = jQuery(btObj).attr('website_id');
1809 let backupID = jQuery(btObj).attr('backup_name');
1810 let backupPath = jQuery(btObj).attr('backup_path');
1811
1812 let data = mainwp_secure_data({
1813 action: 'cpanel_action_restore_database_backup',
1814 website_id: websiteId,
1815 backup_api: 'cpanel',
1816 backup_id: backupID,
1817 backup_path: backupPath
1818 });
1819
1820 // Start button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1821 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_database_backup button').addClass('disabled loading');
1822
1823 jQuery.post(ajaxurl, data, function (response) {
1824 response = jQuery.trim(response);
1825
1826 if (response === 'true') {
1827
1828 // Show message.
1829 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1830 jQuery('#mainwp-api-backups-message-zone .content .message')
1831 .html('The backup restoration process has finished. Please wait a few moments and then check the site.')
1832 ;
1833
1834 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1835 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_database_backup button').removeClass('disabled loading');
1836
1837 } else {
1838
1839 // Show message.
1840 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1841 jQuery('#mainwp-api-backups-message-zone .content .message')
1842 .html('There was an issue while restoring your backup.')
1843 ;
1844
1845 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1846 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_database_backup button').removeClass('disabled loading');
1847
1848 }
1849 });
1850 };
1851
1852 // restore Backup.
1853 let cpanel_action_restore_manual_backup = function () {
1854
1855 let websiteId = jQuery('#cpanel_automatic_backup_button').attr('website_id');
1856 let backupID = jQuery('#database_backup_button').attr('backup_name');
1857 let backupPath = jQuery('#database_backup_button').attr('backup_path');
1858
1859 let data = mainwp_secure_data({
1860 action: 'cpanel_action_restore_manual_backup',
1861 website_id: websiteId,
1862 backup_api: 'cpanel',
1863 backup_id: backupID,
1864 backup_path: backupPath
1865 });
1866
1867 // Start button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1868 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_manual_backup button').addClass('disabled loading');
1869
1870 jQuery.post(ajaxurl, data, function (response) {
1871 response = jQuery.trim(response);
1872
1873 if (response === 'true') {
1874
1875 // Show message.
1876 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1877 jQuery('#mainwp-api-backups-message-zone .content .message')
1878 .html('The backup restoration process has finished. Please wait a few moments and then check the site.')
1879 ;
1880
1881 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1882 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_manual_backup button').removeClass('disabled loading');
1883
1884 } else {
1885
1886 // Show message.
1887 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1888 jQuery('#mainwp-api-backups-message-zone .content .message')
1889 .html('There was an issue while restoring your backup.')
1890 ;
1891
1892 // Stop button animation. ( Using class so ALL buttons are animated not just the one clicked ).
1893 jQuery('.mainwp_3rd_party_api_cpanel_action_restore_database_backup button').removeClass('disabled loading');
1894
1895 }
1896 });
1897 };
1898
1899 let cpanel_action_create_database_backup = function (pObj) {
1900
1901 // Grab the website ID.
1902 let websiteId = jQuery(pObj).attr('website_id');
1903
1904 // Build the data object.
1905 let data = mainwp_secure_data({
1906 action: 'cpanel_action_create_database_backup',
1907 website_id: websiteId,
1908 });
1909
1910 // Start button animation.
1911 jQuery(pObj).addClass('disabled loading');
1912
1913 // Send the data to the server.
1914 jQuery.post(ajaxurl, data, function (response) {
1915 response = jQuery.trim(response);
1916
1917 // Check & return the response.
1918 if (response === 'true') {
1919
1920 // Show message.
1921 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1922 jQuery('#mainwp-api-backups-message-zone .content .message')
1923 .html('The current database backup has finished. Please wait a few moments and then Refresh Available Backups.')
1924 ;
1925
1926 // Start button animation.
1927 jQuery(pObj).removeClass('disabled loading');
1928
1929 } else {
1930
1931 // Show message.
1932 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1933 jQuery('#mainwp-api-backups-message-zone .content .message')
1934 .html('There was an issue while creating your backup.')
1935 ;
1936
1937 // Start button animation.
1938 jQuery(pObj).removeClass('disabled loading');
1939
1940 }
1941 });
1942 }
1943
1944 let cpanel_action_create_full_backup = function (pObj) {
1945
1946 // Grab the website ID.
1947 let websiteId = jQuery(pObj).attr('website_id');
1948
1949 // Build the data object.
1950 let data = mainwp_secure_data({
1951 action: 'cpanel_action_create_full_backup',
1952 website_id: websiteId,
1953 backup_api: 'cpanel',
1954 backup: 'true'
1955 });
1956
1957
1958 // Start button animation.
1959 jQuery(pObj).addClass('disabled loading');
1960
1961 // Send the data to the server.
1962 jQuery.post(ajaxurl, data, function (response) {
1963 response = jQuery.trim(response);
1964
1965 // Check & return the response.
1966 if (response === 'true') {
1967
1968 // Show message.
1969 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
1970 jQuery('#mainwp-api-backups-message-zone .content .message')
1971 .html('The current File & Database backup has finished. Please wait a few moments and then Refresh Available Backups.')
1972 ;
1973
1974 // Start button animation.
1975 jQuery(pObj).removeClass('disabled loading');
1976
1977 } else {
1978
1979 // Show message.
1980 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
1981 jQuery('#mainwp-api-backups-message-zone .content .message')
1982 .html('There was an issue while creating your backups.')
1983 ;
1984
1985 // Start button animation.
1986 jQuery(pObj).removeClass('disabled loading');
1987
1988 }
1989 });
1990 }
1991
1992 /********************************************************
1993 * Plesk Functions.
1994 */
1995
1996 // Refresh Available Backups.
1997 let plesk_action_refresh_available_backups = function (pObj) {
1998
1999 let websiteId = jQuery(pObj).attr('website_id');
2000
2001 let data = mainwp_secure_data({
2002 action: 'plesk_action_refresh_available_backups',
2003 website_id: websiteId,
2004 backup_api: 'Plesk'
2005 });
2006
2007 // Start button animation.
2008 jQuery(pObj).addClass('disabled loading');
2009
2010 jQuery.post(ajaxurl, data, function (response) {
2011 response = jQuery.trim(response);
2012
2013 if (response === 'true') {
2014
2015 // Show message.
2016 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
2017 jQuery('#mainwp-api-backups-message-zone .content .message')
2018 .html('Available backups have been refreshed.')
2019 ;
2020
2021 // Stop button animation.
2022 jQuery(pObj).removeClass('disabled loading');
2023
2024 setInterval('location.reload()', 7000);// Using .reload() method.
2025
2026 } else {
2027
2028 // Show message.
2029 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
2030 jQuery('#mainwp-api-backups-message-zone .content .message')
2031 .html('There was an issue while refreshing available backups.')
2032 ;
2033
2034 // Stop button animation.
2035 jQuery(pObj).removeClass('disabled loading');
2036
2037 }
2038 });
2039 };
2040
2041 let plesk_action_create_backup = function (pObj) {
2042
2043 let websiteId = jQuery(pObj).attr('website_id');
2044
2045 let data = mainwp_secure_data({
2046 action: 'plesk_action_create_backup',
2047 website_id: websiteId,
2048 backup_api: 'plesk'
2049 });
2050
2051 // Start button animation.
2052 jQuery(pObj).addClass('disabled loading');
2053
2054 jQuery.post(ajaxurl, data, function (response) {
2055 response = jQuery.trim(response);
2056
2057 if (response === 'true') {
2058
2059 // Show message.
2060 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
2061 jQuery('#mainwp-api-backups-message-zone .content .message')
2062 .html('A backup has been requested.')
2063 ;
2064
2065 // Stop button animation.
2066 jQuery(pObj).removeClass('disabled loading');
2067
2068 } else {
2069
2070 // Show message.
2071 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
2072 jQuery('#mainwp-api-backups-message-zone .content .message')
2073 .html( response )
2074 ;
2075
2076 // Stop button animation.
2077 jQuery(pObj).removeClass('disabled loading');
2078
2079 }
2080 });
2081 };
2082
2083 // Restore backups.
2084 let plesk_action_restore_backup = function () {
2085 let button = jQuery('.mainwp_3rd_party_api_plesk_action_restore_backup').closest('td');
2086 let installationId = jQuery('.mainwp_3rd_party_api_plesk_action_restore_backup').attr('installation_id');
2087 let backupName = jQuery('.mainwp_3rd_party_api_plesk_action_restore_backup').attr('backup_name');
2088 let websiteId = jQuery('.mainwp_3rd_party_api_plesk_action_restore_backup').attr('website_id');
2089
2090 let data = mainwp_secure_data({
2091 action: 'plesk_action_restore_backup',
2092 installation_id: installationId,
2093 backup_name: backupName,
2094 website_id: websiteId,
2095 backup_api: 'plesk'
2096 });
2097
2098 // Start button animation.
2099 jQuery(button).addClass('disabled loading');
2100
2101 jQuery.post(ajaxurl, data, function (response) {
2102 response = jQuery.trim(response);
2103
2104 if (response === 'true') {
2105
2106 // Show message.
2107 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
2108 jQuery('#mainwp-api-backups-message-zone .content .message')
2109 .html('Your application is in the process of restoring. This will take a few minuets...')
2110 ;
2111
2112 // Stop button animation.
2113 jQuery(button).removeClass('disabled loading');
2114
2115 } else {
2116
2117 // Show message.
2118 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
2119 jQuery('#mainwp-api-backups-message-zone .content .message')
2120 .html('There was an issue while attempting to restore your application...')
2121 ;
2122
2123 // Stop button animation.
2124 jQuery(button).removeClass('disabled loading');
2125 }
2126 });
2127 };
2128
2129 // Delete backups.
2130 let plesk_action_delete_backup = function () {
2131 jQuery('.mainwp_3rd_party_api_plesk_action_delete_backup').attr('disabled', 'true');
2132 let button = jQuery('.mainwp_3rd_party_api_plesk_action_delete_backup').closest('td');
2133
2134 let installationId = jQuery('.mainwp_3rd_party_api_plesk_action_delete_backup').attr('installation_id');
2135 let backupName = jQuery('.mainwp_3rd_party_api_plesk_action_delete_backup').attr('backup_name');
2136 let websiteId = jQuery('.mainwp_3rd_party_api_plesk_action_delete_backup').attr('website_id');
2137
2138 let data = mainwp_secure_data({
2139 action: 'plesk_action_delete_backup',
2140 installation_id: installationId,
2141 backup_name: backupName,
2142 website_id: websiteId,
2143 backup_api: 'plesk'
2144 });
2145
2146 // Start button animation.
2147 jQuery(button).find('i.loading').css({ 'display': 'block' });
2148 jQuery(button).find('div').addClass('hidden');
2149
2150 jQuery.post(ajaxurl, data, function (response) {
2151 response = jQuery.trim(response);
2152
2153 if (response === 'true') {
2154
2155 // Show message.
2156 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
2157 jQuery('#mainwp-api-backups-message-zone .content .message')
2158 .html('The selected backup has been deleted.')
2159 ;
2160
2161 setInterval('location.reload()', 5000); // Using .reload() method.
2162
2163 } else {
2164
2165 // Show message.
2166 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
2167 jQuery('#mainwp-api-backups-message-zone .content .message')
2168 .html('There was an issue while deleting your backup.')
2169 ;
2170
2171 setInterval('location.reload()', 5000); // Using .reload() method.
2172
2173 }
2174 });
2175 };
2176
2177 /********************************************************
2178 * Kinsta Functions.
2179 */
2180
2181 // Refresh Available Backups.
2182 let kinsta_action_refresh_available_backups = function (pObj) {
2183
2184 let websiteId = jQuery(pObj).attr('website_id');
2185
2186 let data = mainwp_secure_data({
2187 action: 'kinsta_action_refresh_available_backups',
2188 website_id: websiteId,
2189 backup_api: 'Kinsta'
2190 });
2191
2192 // Start button animation.
2193 jQuery(pObj).addClass('disabled loading');
2194
2195 jQuery.post(ajaxurl, data, function (response) {
2196 response = jQuery.trim(response);
2197
2198 if (response === 'true') {
2199
2200 // Show message.
2201 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
2202 jQuery('#mainwp-api-backups-message-zone .content .message')
2203 .html('Available backups have been refreshed.')
2204 ;
2205
2206 // Stop button animation.
2207 jQuery(pObj).removeClass('disabled loading');
2208
2209 setInterval('location.reload()', 7000);// Using .reload() method.
2210
2211 } else {
2212
2213 // Show message.
2214 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
2215 jQuery('#mainwp-api-backups-message-zone .content .message')
2216 .html('There was an issue while refreshing available backups.')
2217 ;
2218
2219 // Stop button animation.
2220 jQuery(pObj).removeClass('disabled loading');
2221
2222 }
2223 });
2224 };
2225
2226 // Create Manual Backup.
2227 let kinsta_action_create_backup = function (pObj) {
2228
2229 let websiteId = jQuery(pObj).attr('website_id');
2230
2231 let data = mainwp_secure_data({
2232 action: 'kinsta_action_create_backup',
2233 website_id: websiteId,
2234 backup_api: 'kinsta'
2235 });
2236
2237 // Start button animation.
2238 jQuery(pObj).addClass('disabled loading');
2239
2240 jQuery.post(ajaxurl, data, function (response) {
2241 response = jQuery.trim(response);
2242
2243 if (response === 'true') {
2244
2245 // Show message.
2246 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
2247 jQuery('#mainwp-api-backups-message-zone .content .message')
2248 .html('A backup has been requested.')
2249 ;
2250
2251 // Stop button animation.
2252 jQuery(pObj).removeClass('disabled loading');
2253
2254 } else {
2255
2256 // Show message.
2257 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
2258 jQuery('#mainwp-api-backups-message-zone .content .message')
2259 .html( response )
2260 ;
2261
2262 // Stop button animation.
2263 jQuery(pObj).removeClass('disabled loading');
2264
2265 }
2266 });
2267 };
2268
2269 // Delete Manual Backup.
2270 let kinsta_action_delete_backup = function (pObj, backupId) {
2271 let websiteId = jQuery('.mainwp_3rd_party_api_kinsta_action_delete_backup ').attr('website_id');
2272 let data = mainwp_secure_data({
2273 action: 'kinsta_action_delete_backup',
2274 backup_id: backupId,
2275 website_id: websiteId,
2276 backup_api: 'kinsta'
2277 });
2278
2279 // Start button animation.
2280 jQuery(pObj).addClass('disabled loading');
2281
2282 jQuery.post(ajaxurl, data, function (response) {
2283 response = jQuery.trim(response);
2284 if (response === 'true') {
2285
2286 // Show message.
2287 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
2288 jQuery('#mainwp-api-backups-message-zone .content .message')
2289 .html('The selected backup has been deleted.')
2290 ;
2291
2292 setInterval('location.reload()', 5000); // Using .reload() method.
2293
2294 } else {
2295
2296 // Show message.
2297 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
2298 jQuery('#mainwp-api-backups-message-zone .content .message')
2299 .html('There was an issue while deleting your backup.')
2300 ;
2301
2302 setInterval('location.reload()', 5000); // Using .reload() method.
2303
2304 }
2305 });
2306 };
2307
2308 // Delete Manual Backup.
2309 let kinsta_action_restore_backup = function (pObj, backupId) {
2310
2311 let websiteId = jQuery('.mainwp_3rd_party_api_kinsta_action_restore_backup').attr('website_id');
2312
2313 let data = mainwp_secure_data({
2314 action: 'kinsta_action_restore_backup',
2315 backup_id: backupId,
2316 backup_api: 'kinsta',
2317 website_id: websiteId
2318 });
2319
2320 // Start button animation.
2321 jQuery(pObj).addClass('disabled loading');
2322
2323 jQuery.post(ajaxurl, data, function (response) {
2324 response = jQuery.trim(response);
2325 if (response === 'true') {
2326
2327 // Show message.
2328 jQuery('#mainwp-api-backups-message-zone').addClass('green').show();
2329 jQuery('#mainwp-api-backups-message-zone .content .message')
2330 .html('Your application is in the process of restoring. This will take a few minuets...')
2331 ;
2332
2333 // Stop button animation.
2334 jQuery(button).removeClass('disabled loading');
2335
2336 } else {
2337
2338 // Show message.
2339 jQuery('#mainwp-api-backups-message-zone').addClass('red').show();
2340 jQuery('#mainwp-api-backups-message-zone .content .message')
2341 .html('There was an issue while attempting to restore your application...')
2342 ;
2343
2344 // Stop button animation.
2345 jQuery(button).removeClass('disabled loading');
2346 }
2347 });
2348 };
2349