6 (function ($, Drupal) {
8 * Attaches the batch behavior to progress bars.
10 * @type {Drupal~behavior}
12 Drupal.behaviors.batch = {
13 attach(context, settings) {
14 const batch = settings.batch;
15 const $progress = $('[data-drupal-progress]').once('batch');
18 // Success: redirect to the summary.
19 function updateCallback(progress, status, pb) {
20 if (progress === '100') {
22 window.location = `${batch.uri}&op=finished`;
26 function errorCallback(pb) {
27 $progress.prepend($('<p class="error"></p>').html(batch.errorMessage));
31 if ($progress.length) {
32 progressBar = new Drupal.ProgressBar('updateprogress', updateCallback, 'POST', errorCallback);
33 progressBar.setProgress(-1, batch.initMessage);
34 progressBar.startMonitoring(`${batch.uri}&op=do`, 10);
35 // Remove HTML from no-js progress bar.
37 // Append the JS progressbar element.
38 $progress.append(progressBar.element);