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