| 1 |
// $Id: batch.js,v 1.9 2009/04/27 20:19:35 webchick Exp $
|
| 2 |
(function ($) {
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Attaches the batch behavior to progress bars.
|
| 6 |
*/
|
| 7 |
Drupal.behaviors.batch = {
|
| 8 |
attach: function (context, settings) {
|
| 9 |
$('#progress', context).once('batch', function () {
|
| 10 |
var holder = $(this);
|
| 11 |
|
| 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 |
|
| 20 |
var errorCallback = function (pb) {
|
| 21 |
holder.prepend($('<p class="error"></p>').html(settings.batch.errorMessage));
|
| 22 |
$('#wait').hide();
|
| 23 |
};
|
| 24 |
|
| 25 |
var progress = new Drupal.progressBar('updateprogress', updateCallback, 'POST', errorCallback);
|
| 26 |
progress.setProgress(-1, settings.batch.initMessage);
|
| 27 |
holder.append(progress.element);
|
| 28 |
progress.startMonitoring(settings.batch.uri + '&op=do', 10);
|
| 29 |
});
|
| 30 |
}
|
| 31 |
};
|
| 32 |
|
| 33 |
})(jQuery);
|