annotate core/misc/batch.es6.js @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author |
Chris Cannam |
date |
Thu, 28 Feb 2019 13:21:36 +0000 |
parents |
4c8ae668cc8c |
children |
|
rev |
line source |
Chris@0
|
1 /**
|
Chris@0
|
2 * @file
|
Chris@0
|
3 * Drupal's batch API.
|
Chris@0
|
4 */
|
Chris@0
|
5
|
Chris@17
|
6 (function($, Drupal) {
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Attaches the batch behavior to progress bars.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @type {Drupal~behavior}
|
Chris@0
|
11 */
|
Chris@0
|
12 Drupal.behaviors.batch = {
|
Chris@0
|
13 attach(context, settings) {
|
Chris@0
|
14 const batch = settings.batch;
|
Chris@0
|
15 const $progress = $('[data-drupal-progress]').once('batch');
|
Chris@0
|
16 let progressBar;
|
Chris@0
|
17
|
Chris@0
|
18 // Success: redirect to the summary.
|
Chris@0
|
19 function updateCallback(progress, status, pb) {
|
Chris@0
|
20 if (progress === '100') {
|
Chris@0
|
21 pb.stopMonitoring();
|
Chris@0
|
22 window.location = `${batch.uri}&op=finished`;
|
Chris@0
|
23 }
|
Chris@0
|
24 }
|
Chris@0
|
25
|
Chris@0
|
26 function errorCallback(pb) {
|
Chris@0
|
27 $progress.prepend($('<p class="error"></p>').html(batch.errorMessage));
|
Chris@0
|
28 $('#wait').hide();
|
Chris@0
|
29 }
|
Chris@0
|
30
|
Chris@0
|
31 if ($progress.length) {
|
Chris@17
|
32 progressBar = new Drupal.ProgressBar(
|
Chris@17
|
33 'updateprogress',
|
Chris@17
|
34 updateCallback,
|
Chris@17
|
35 'POST',
|
Chris@17
|
36 errorCallback,
|
Chris@17
|
37 );
|
Chris@0
|
38 progressBar.setProgress(-1, batch.initMessage);
|
Chris@0
|
39 progressBar.startMonitoring(`${batch.uri}&op=do`, 10);
|
Chris@0
|
40 // Remove HTML from no-js progress bar.
|
Chris@0
|
41 $progress.empty();
|
Chris@0
|
42 // Append the JS progressbar element.
|
Chris@0
|
43 $progress.append(progressBar.element);
|
Chris@0
|
44 }
|
Chris@0
|
45 },
|
Chris@0
|
46 };
|
Chris@17
|
47 })(jQuery, Drupal);
|