Chris@0: /** Chris@0: * @file Chris@0: * Drupal's batch API. Chris@0: */ Chris@0: Chris@17: (function($, Drupal) { Chris@0: /** Chris@0: * Attaches the batch behavior to progress bars. Chris@0: * Chris@0: * @type {Drupal~behavior} Chris@0: */ Chris@0: Drupal.behaviors.batch = { Chris@0: attach(context, settings) { Chris@0: const batch = settings.batch; Chris@0: const $progress = $('[data-drupal-progress]').once('batch'); Chris@0: let progressBar; Chris@0: Chris@0: // Success: redirect to the summary. Chris@0: function updateCallback(progress, status, pb) { Chris@0: if (progress === '100') { Chris@0: pb.stopMonitoring(); Chris@0: window.location = `${batch.uri}&op=finished`; Chris@0: } Chris@0: } Chris@0: Chris@0: function errorCallback(pb) { Chris@0: $progress.prepend($('

').html(batch.errorMessage)); Chris@0: $('#wait').hide(); Chris@0: } Chris@0: Chris@0: if ($progress.length) { Chris@17: progressBar = new Drupal.ProgressBar( Chris@17: 'updateprogress', Chris@17: updateCallback, Chris@17: 'POST', Chris@17: errorCallback, Chris@17: ); Chris@0: progressBar.setProgress(-1, batch.initMessage); Chris@0: progressBar.startMonitoring(`${batch.uri}&op=do`, 10); Chris@0: // Remove HTML from no-js progress bar. Chris@0: $progress.empty(); Chris@0: // Append the JS progressbar element. Chris@0: $progress.append(progressBar.element); Chris@0: } Chris@0: }, Chris@0: }; Chris@17: })(jQuery, Drupal);