Mercurial > hg > cmmr2012-drupal-site
comparison core/misc/batch.es6.js @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 /** | |
2 * @file | |
3 * Drupal's batch API. | |
4 */ | |
5 | |
6 (function ($, Drupal) { | |
7 /** | |
8 * Attaches the batch behavior to progress bars. | |
9 * | |
10 * @type {Drupal~behavior} | |
11 */ | |
12 Drupal.behaviors.batch = { | |
13 attach(context, settings) { | |
14 const batch = settings.batch; | |
15 const $progress = $('[data-drupal-progress]').once('batch'); | |
16 let progressBar; | |
17 | |
18 // Success: redirect to the summary. | |
19 function updateCallback(progress, status, pb) { | |
20 if (progress === '100') { | |
21 pb.stopMonitoring(); | |
22 window.location = `${batch.uri}&op=finished`; | |
23 } | |
24 } | |
25 | |
26 function errorCallback(pb) { | |
27 $progress.prepend($('<p class="error"></p>').html(batch.errorMessage)); | |
28 $('#wait').hide(); | |
29 } | |
30 | |
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. | |
36 $progress.empty(); | |
37 // Append the JS progressbar element. | |
38 $progress.append(progressBar.element); | |
39 } | |
40 }, | |
41 }; | |
42 }(jQuery, Drupal)); |