comparison misc/batch.js @ 1:c1f4ac30525a 6.0

Drupal 6.0
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:28:28 +0100
parents
children
comparison
equal deleted inserted replaced
0:5a113a1c4740 1:c1f4ac30525a
1 // $Id: batch.js,v 1.4 2007/10/21 18:59:01 goba Exp $
2
3 /**
4 * Attaches the batch behavior to progress bars.
5 */
6 Drupal.behaviors.batch = function (context) {
7 // This behavior attaches by ID, so is only valid once on a page.
8 if ($('#progress.batch-processed').size()) {
9 return;
10 }
11 $('#progress', context).addClass('batch-processed').each(function () {
12 var holder = this;
13 var uri = Drupal.settings.batch.uri;
14 var initMessage = Drupal.settings.batch.initMessage;
15 var errorMessage = Drupal.settings.batch.errorMessage;
16
17 // Success: redirect to the summary.
18 var updateCallback = function (progress, status, pb) {
19 if (progress == 100) {
20 pb.stopMonitoring();
21 window.location = uri+'&op=finished';
22 }
23 };
24
25 var errorCallback = function (pb) {
26 var div = document.createElement('p');
27 div.className = 'error';
28 $(div).html(errorMessage);
29 $(holder).prepend(div);
30 $('#wait').hide();
31 };
32
33 var progress = new Drupal.progressBar('updateprogress', updateCallback, "POST", errorCallback);
34 progress.setProgress(-1, initMessage);
35 $(holder).append(progress.element);
36 progress.startMonitoring(uri+'&op=do', 10);
37 });
38 };