batch.js 939 B

1234567891011121314151617181920212223242526272829303132
  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. // Success: redirect to the summary.
  10. var updateCallback = function (progress, status, pb) {
  11. if (progress == 100) {
  12. pb.stopMonitoring();
  13. window.location = settings.batch.uri + '&op=finished';
  14. }
  15. };
  16. var errorCallback = function (pb) {
  17. holder.prepend($('<p class="error"></p>').html(settings.batch.errorMessage));
  18. $('#wait').hide();
  19. };
  20. var progress = new Drupal.progressBar('updateprogress', updateCallback, 'POST', errorCallback);
  21. progress.setProgress(-1, settings.batch.initMessage);
  22. holder.append(progress.element);
  23. progress.startMonitoring(settings.batch.uri + '&op=do', 10);
  24. });
  25. }
  26. };
  27. })(jQuery);