check.js 1.1 KB

1234567891011121314151617181920212223242526
  1. import $ from 'jquery';
  2. import { Instance as gpm } from '../utils/gpm';
  3. import { translations } from 'grav-config';
  4. import toastr from '../utils/toastr';
  5. // Check for updates trigger
  6. $('[data-gpm-checkupdates]').on('click', function() {
  7. let element = $(this);
  8. element.find('i').addClass('fa-spin');
  9. gpm.fetch((response) => {
  10. element.find('i').removeClass('fa-spin');
  11. let payload = response.payload;
  12. if (!payload) { return; }
  13. if (!payload.grav.isUpdatable && !payload.resources.total) {
  14. toastr.success(translations.PLUGIN_ADMIN.EVERYTHING_UP_TO_DATE);
  15. } else {
  16. var grav = payload.grav.isUpdatable ? 'Grav v' + payload.grav.available : '';
  17. var resources = payload.resources.total ? payload.resources.total + ' ' + translations.PLUGIN_ADMIN.UPDATES_ARE_AVAILABLE : '';
  18. if (!resources) { grav += ' ' + translations.PLUGIN_ADMIN.IS_AVAILABLE_FOR_UPDATE; }
  19. toastr.info(grav + (grav && resources ? ' ' + translations.PLUGIN_ADMIN.AND + ' ' : '') + resources);
  20. }
  21. }, true);
  22. });