annotate core/misc/batch.es6.js @ 0:4c8ae668cc8c
Initial import (non-working)
author |
Chris Cannam |
date |
Wed, 29 Nov 2017 16:09:58 +0000 |
parents |
|
children |
129ea1e6d783 |
rev |
line source |
Chris@0
|
1 /**
|
Chris@0
|
2 * @file
|
Chris@0
|
3 * Drupal's batch API.
|
Chris@0
|
4 */
|
Chris@0
|
5
|
Chris@0
|
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@0
|
32 progressBar = new Drupal.ProgressBar('updateprogress', updateCallback, 'POST', errorCallback);
|
Chris@0
|
33 progressBar.setProgress(-1, batch.initMessage);
|
Chris@0
|
34 progressBar.startMonitoring(`${batch.uri}&op=do`, 10);
|
Chris@0
|
35 // Remove HTML from no-js progress bar.
|
Chris@0
|
36 $progress.empty();
|
Chris@0
|
37 // Append the JS progressbar element.
|
Chris@0
|
38 $progress.append(progressBar.element);
|
Chris@0
|
39 }
|
Chris@0
|
40 },
|
Chris@0
|
41 };
|
Chris@0
|
42 }(jQuery, Drupal));
|