backup.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import $ from 'jquery';
  2. import { translations } from 'grav-config';
  3. import request from '../utils/request';
  4. import { Instances as Charts } from './chart';
  5. $('[data-backup][data-ajax*="backup/"]').on('click', function() {
  6. let element = $(this);
  7. let url = element.data('ajax');
  8. const inDropdown = element.closest('.dropdown-menu');
  9. (inDropdown.length ? inDropdown : element)
  10. .closest('.button-group').find('> button:first')
  11. .attr('disabled', 'disabled')
  12. .find('> .fa').removeClass('fa-life-ring').addClass('fa-spin fa-refresh');
  13. request(url, (/* response */) => {
  14. if (Charts && Charts.backups) {
  15. Charts.backups.updateData({ series: [0, 100] });
  16. Charts.backups.element.find('.numeric').html(`0 <em>${translations.PLUGIN_ADMIN.DAYS.toLowerCase()}</em>`);
  17. }
  18. (inDropdown.length ? inDropdown : element)
  19. .closest('.button-group').find('> button:first')
  20. .removeAttr('disabled')
  21. .find('> .fa').removeClass('fa-spin fa-refresh').addClass('fa-life-ring');
  22. });
  23. });
  24. $('[data-backup][data-ajax*="backupDelete"]').on('click', function() {
  25. let element = $(this);
  26. let url = element.data('ajax');
  27. const tr = element.closest('tr');
  28. tr.addClass('deleting');
  29. request(url, (response) => {
  30. if (response.status === 'success') {
  31. tr.remove();
  32. } else {
  33. tr.removeClass('deleting');
  34. }
  35. });
  36. });