Newer
Older
Angie Byron
committed
(function ($) {
Dries Buytaert
committed
/**
Gábor Hojtsy
committed
* Attaches the batch behavior to progress bars.
Dries Buytaert
committed
*/
Drupal.behaviors.batch = {
Angie Byron
committed
attach: function (context, settings) {
Dries Buytaert
committed
$('#progress', context).once('batch', function () {
Angie Byron
committed
var holder = $(this);
// Success: redirect to the summary.
Angie Byron
committed
var updateCallback = function (progress, status, pb) {
if (progress == 100) {
pb.stopMonitoring();
Angie Byron
committed
window.location = settings.batch.uri + '&op=finished';
}
};
Angie Byron
committed
var errorCallback = function (pb) {
Angie Byron
committed
holder.prepend($('<p class="error"></p>').html(settings.batch.errorMessage));
$('#wait').hide();
};
Dries Buytaert
committed
Angie Byron
committed
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);
});
}
Dries Buytaert
committed
};
})(jQuery);