summaryrefslogtreecommitdiffstatshomepage
path: root/core/misc/batch.es6.js
diff options
context:
space:
mode:
authorAlex Pott <alex.a.pott@googlemail.com>2017-05-19 23:12:53 +0100
committerAlex Pott <alex.a.pott@googlemail.com>2017-05-19 23:12:53 +0100
commit8287017e034bc323dec1d86b3f37a804aa082d2d (patch)
treeebd8ff908859b0e1cc4319392da94e8f68033321 /core/misc/batch.es6.js
parent9a0e9a649ac8078ce6e5f6089749a1115bdda06b (diff)
downloaddrupal-8287017e034bc323dec1d86b3f37a804aa082d2d.tar.gz
drupal-8287017e034bc323dec1d86b3f37a804aa082d2d.zip
Issue #2818825 by drpal, nod_, droplet, cilefen: Rename all JS files to *.es6.js and compile them
Diffstat (limited to 'core/misc/batch.es6.js')
-rw-r--r--core/misc/batch.es6.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/core/misc/batch.es6.js b/core/misc/batch.es6.js
new file mode 100644
index 000000000000..411badba4272
--- /dev/null
+++ b/core/misc/batch.es6.js
@@ -0,0 +1,46 @@
+/**
+ * @file
+ * Drupal's batch API.
+ */
+
+(function ($, Drupal) {
+
+ 'use strict';
+
+ /**
+ * Attaches the batch behavior to progress bars.
+ *
+ * @type {Drupal~behavior}
+ */
+ Drupal.behaviors.batch = {
+ attach: function (context, settings) {
+ var batch = settings.batch;
+ var $progress = $('[data-drupal-progress]').once('batch');
+ var progressBar;
+
+ // Success: redirect to the summary.
+ function updateCallback(progress, status, pb) {
+ if (progress === '100') {
+ pb.stopMonitoring();
+ window.location = batch.uri + '&op=finished';
+ }
+ }
+
+ function errorCallback(pb) {
+ $progress.prepend($('<p class="error"></p>').html(batch.errorMessage));
+ $('#wait').hide();
+ }
+
+ if ($progress.length) {
+ progressBar = new Drupal.ProgressBar('updateprogress', updateCallback, 'POST', errorCallback);
+ progressBar.setProgress(-1, batch.initMessage);
+ progressBar.startMonitoring(batch.uri + '&op=do', 10);
+ // Remove HTML from no-js progress bar.
+ $progress.empty();
+ // Append the JS progressbar element.
+ $progress.append(progressBar.element);
+ }
+ }
+ };
+
+})(jQuery, Drupal);