Upgraded drupal core with security updates
[yaffs-website] / web / core / misc / batch.js
1 /**
2  * @file
3  * Drupal's batch API.
4  */
5
6 (function ($, Drupal) {
7
8   'use strict';
9
10   /**
11    * Attaches the batch behavior to progress bars.
12    *
13    * @type {Drupal~behavior}
14    */
15   Drupal.behaviors.batch = {
16     attach: function (context, settings) {
17       var batch = settings.batch;
18       var $progress = $('[data-drupal-progress]').once('batch');
19       var progressBar;
20
21       // Success: redirect to the summary.
22       function updateCallback(progress, status, pb) {
23         if (progress === '100') {
24           pb.stopMonitoring();
25           window.location = batch.uri + '&op=finished';
26         }
27       }
28
29       function errorCallback(pb) {
30         $progress.prepend($('<p class="error"></p>').html(batch.errorMessage));
31         $('#wait').hide();
32       }
33
34       if ($progress.length) {
35         progressBar = new Drupal.ProgressBar('updateprogress', updateCallback, 'POST', errorCallback);
36         progressBar.setProgress(-1, batch.initMessage);
37         progressBar.startMonitoring(batch.uri + '&op=do', 10);
38         // Remove HTML from no-js progress bar.
39         $progress.empty();
40         // Append the JS progressbar element.
41         $progress.append(progressBar.element);
42       }
43     }
44   };
45
46 })(jQuery, Drupal);