batch.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. (function ($) {
  2. /**
  3. * Attaches the batch behavior to progress bars.
  4. */
  5. Drupal.behaviors.batch = {
  6. attach: function (context, settings) {
  7. $('#progress', context).once('batch', function () {
  8. var holder = $(this);
  9. // Remove HTML from no-js progress bar. The JS progress bar is created
  10. // later on.
  11. holder.empty();
  12. // Success: redirect to the summary.
  13. var updateCallback = function (progress, status, pb) {
  14. if (progress == 100) {
  15. pb.stopMonitoring();
  16. window.location = settings.batch.uri + '&op=finished';
  17. }
  18. };
  19. var errorCallback = function (pb) {
  20. holder.prepend($('<p class="error"></p>').html(settings.batch.errorMessage));
  21. $('#wait').hide();
  22. };
  23. var progress = new Drupal.progressBar('updateprogress', updateCallback, 'POST', errorCallback);
  24. progress.setProgress(-1, settings.batch.initMessage);
  25. holder.append(progress.element);
  26. progress.startMonitoring(settings.batch.uri + '&op=do', 10);
  27. });
  28. }
  29. };
  30. })(jQuery);