Issue #1996238 by sun, nod_, damiankloip, Wim Leers, longwave, alexpott, Xano, mdrummond, Mark Carver, Jeff Burnz, highrockmedia, joelpittet, et al: Replace hook_library_info() by *.libraries.yml file.
2014-02-23 04:56:51 +00:00
|
|
|
/**
|
2022-09-09 06:26:42 +00:00
|
|
|
* @file
|
|
|
|
* Drupal's batch API.
|
|
|
|
*/
|
2015-06-08 14:04:39 +00:00
|
|
|
|
2012-08-22 22:13:51 +00:00
|
|
|
(function ($, Drupal) {
|
2022-09-09 06:26:42 +00:00
|
|
|
/**
|
|
|
|
* Attaches the batch behavior to progress bars.
|
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
|
|
|
*/
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.behaviors.batch = {
|
2021-12-18 06:12:16 +00:00
|
|
|
attach(context, settings) {
|
|
|
|
const batch = settings.batch;
|
|
|
|
const $progress = $(once('batch', '[data-drupal-progress]'));
|
|
|
|
let progressBar;
|
2007-05-04 09:41:37 +00:00
|
|
|
|
2022-09-09 06:26:42 +00:00
|
|
|
// Success: redirect to the summary.
|
2014-01-27 21:41:32 +00:00
|
|
|
function updateCallback(progress, status, pb) {
|
|
|
|
if (progress === '100') {
|
|
|
|
pb.stopMonitoring();
|
2021-12-18 06:12:16 +00:00
|
|
|
window.location = `${batch.uri}&op=finished`;
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
2012-08-22 22:13:51 +00:00
|
|
|
}
|
2007-05-04 09:41:37 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
function errorCallback(pb) {
|
|
|
|
$progress.prepend($('<p class="error"></p>').html(batch.errorMessage));
|
|
|
|
$('#wait').hide();
|
|
|
|
}
|
2007-07-01 15:37:10 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
if ($progress.length) {
|
2022-09-09 06:26:42 +00:00
|
|
|
progressBar = new Drupal.ProgressBar(
|
|
|
|
'updateprogress',
|
|
|
|
updateCallback,
|
|
|
|
'POST',
|
|
|
|
errorCallback,
|
|
|
|
);
|
2014-01-27 21:41:32 +00:00
|
|
|
progressBar.setProgress(-1, batch.initMessage);
|
2021-12-18 06:12:16 +00:00
|
|
|
progressBar.startMonitoring(`${batch.uri}&op=do`, 10);
|
2022-09-09 06:26:42 +00:00
|
|
|
// Remove HTML from no-js progress bar.
|
2014-01-27 21:41:32 +00:00
|
|
|
$progress.empty();
|
2022-09-09 06:26:42 +00:00
|
|
|
// Append the JS progressbar element.
|
2014-01-27 21:41:32 +00:00
|
|
|
$progress.append(progressBar.element);
|
|
|
|
}
|
2022-09-09 06:26:42 +00:00
|
|
|
},
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
2022-09-09 06:26:42 +00:00
|
|
|
})(jQuery, Drupal);
|