2007-07-01 15:37:10 +00:00
|
|
|
// $Id$
|
2009-04-27 20:19:38 +00:00
|
|
|
(function ($) {
|
2007-05-04 09:41:37 +00:00
|
|
|
|
2007-07-01 15:37:10 +00:00
|
|
|
/**
|
2007-10-21 18:59:02 +00:00
|
|
|
* Attaches the batch behavior to progress bars.
|
2007-07-01 15:37:10 +00:00
|
|
|
*/
|
2008-10-29 10:01:28 +00:00
|
|
|
Drupal.behaviors.batch = {
|
2009-04-27 20:19:38 +00:00
|
|
|
attach: function (context, settings) {
|
2009-08-31 05:51:08 +00:00
|
|
|
$('#progress', context).once('batch', function () {
|
2009-04-26 19:18:46 +00:00
|
|
|
var holder = $(this);
|
2007-05-04 09:41:37 +00:00
|
|
|
|
2008-10-29 10:01:28 +00:00
|
|
|
// Success: redirect to the summary.
|
2009-04-27 20:19:38 +00:00
|
|
|
var updateCallback = function (progress, status, pb) {
|
2008-10-29 10:01:28 +00:00
|
|
|
if (progress == 100) {
|
|
|
|
pb.stopMonitoring();
|
2009-04-26 19:18:46 +00:00
|
|
|
window.location = settings.batch.uri + '&op=finished';
|
2008-10-29 10:01:28 +00:00
|
|
|
}
|
|
|
|
};
|
2007-05-04 09:41:37 +00:00
|
|
|
|
2009-04-27 20:19:38 +00:00
|
|
|
var errorCallback = function (pb) {
|
2009-04-26 19:18:46 +00:00
|
|
|
holder.prepend($('<p class="error"></p>').html(settings.batch.errorMessage));
|
2008-10-29 10:01:28 +00:00
|
|
|
$('#wait').hide();
|
|
|
|
};
|
2007-07-01 15:37:10 +00:00
|
|
|
|
2009-04-26 19:18:46 +00:00
|
|
|
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);
|
2008-10-29 10:01:28 +00:00
|
|
|
});
|
|
|
|
}
|
2007-07-01 15:37:10 +00:00
|
|
|
};
|
2009-02-18 13:46:55 +00:00
|
|
|
|
|
|
|
})(jQuery);
|