diff options
Diffstat (limited to 'core/misc/batch.js')
-rw-r--r-- | core/misc/batch.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/core/misc/batch.js b/core/misc/batch.js new file mode 100644 index 00000000000..fee71a52fd1 --- /dev/null +++ b/core/misc/batch.js @@ -0,0 +1,32 @@ +(function ($) { + +/** + * Attaches the batch behavior to progress bars. + */ +Drupal.behaviors.batch = { + attach: function (context, settings) { + $('#progress', context).once('batch', function () { + var holder = $(this); + + // Success: redirect to the summary. + var updateCallback = function (progress, status, pb) { + if (progress == 100) { + pb.stopMonitoring(); + window.location = settings.batch.uri + '&op=finished'; + } + }; + + var errorCallback = function (pb) { + holder.prepend($('<p class="error"></p>').html(settings.batch.errorMessage)); + $('#wait').hide(); + }; + + var progress = new Drupal.progressBar('updateprogress', updateCallback, 'POST', errorCallback); + progress.setProgress(-1, settings.batch.initMessage); + holder.append(progress.element); + progress.startMonitoring(settings.batch.uri + '&op=do', 10); + }); + } +}; + +})(jQuery); |