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
|
|
|
/**
|
2015-06-08 14:04:39 +00:00
|
|
|
* @file
|
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
|
|
|
* Drupal's batch API.
|
|
|
|
*/
|
2015-06-08 14:04:39 +00:00
|
|
|
|
2012-08-22 22:13:51 +00:00
|
|
|
(function ($, Drupal) {
|
2007-05-04 09:41:37 +00:00
|
|
|
|
2015-10-13 22:37:56 +00:00
|
|
|
'use strict';
|
2012-05-08 02:57:33 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
/**
|
|
|
|
* Attaches the batch behavior to progress bars.
|
2015-06-08 14:04:39 +00:00
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
2014-01-27 21:41:32 +00:00
|
|
|
*/
|
|
|
|
Drupal.behaviors.batch = {
|
|
|
|
attach: function (context, settings) {
|
|
|
|
var batch = settings.batch;
|
2014-02-25 14:05:43 +00:00
|
|
|
var $progress = $('[data-drupal-progress]').once('batch');
|
2014-01-27 21:41:32 +00:00
|
|
|
var progressBar;
|
2007-05-04 09:41:37 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
// Success: redirect to the summary.
|
|
|
|
function updateCallback(progress, status, pb) {
|
|
|
|
if (progress === '100') {
|
|
|
|
pb.stopMonitoring();
|
|
|
|
window.location = batch.uri + '&op=finished';
|
|
|
|
}
|
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) {
|
|
|
|
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);
|
|
|
|
}
|
2012-08-22 22:13:51 +00:00
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
2009-02-18 13:46:55 +00:00
|
|
|
|
2012-08-22 22:13:51 +00:00
|
|
|
})(jQuery, Drupal);
|