2015-06-08 14:04:39 +00:00
|
|
|
/**
|
2017-05-19 22:12:53 +00:00
|
|
|
* DO NOT EDIT THIS FILE.
|
|
|
|
* See the following change record for more information,
|
2017-05-23 14:30:14 +00:00
|
|
|
* https://www.drupal.org/node/2815083
|
2017-05-19 22:12:53 +00:00
|
|
|
* @preserve
|
|
|
|
**/
|
2015-06-08 14:04:39 +00:00
|
|
|
|
2015-04-16 13:48:54 +00:00
|
|
|
(function ($, Drupal) {
|
|
|
|
Drupal.theme.progressBar = function (id) {
|
2020-01-30 09:08:38 +00:00
|
|
|
return "<div id=\"".concat(id, "\" class=\"progress\" aria-live=\"polite\">") + '<div class="progress__label"> </div>' + '<div class="progress__track"><div class="progress__bar"></div></div>' + '<div class="progress__percentage"></div>' + '<div class="progress__description"> </div>' + '</div>';
|
2015-04-16 13:48:54 +00:00
|
|
|
};
|
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.ProgressBar = function (id, updateCallback, method, errorCallback) {
|
|
|
|
this.id = id;
|
|
|
|
this.method = method || 'GET';
|
|
|
|
this.updateCallback = updateCallback;
|
|
|
|
this.errorCallback = errorCallback;
|
2015-04-16 21:46:15 +00:00
|
|
|
this.element = $(Drupal.theme('progressBar', id));
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
|
2017-05-19 22:12:53 +00:00
|
|
|
$.extend(Drupal.ProgressBar.prototype, {
|
|
|
|
setProgress: function setProgress(percentage, message, label) {
|
2014-01-27 21:41:32 +00:00
|
|
|
if (percentage >= 0 && percentage <= 100) {
|
2020-01-30 09:08:38 +00:00
|
|
|
$(this.element).find('div.progress__bar').css('width', "".concat(percentage, "%"));
|
|
|
|
$(this.element).find('div.progress__percentage').html("".concat(percentage, "%"));
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
$('div.progress__description', this.element).html(message);
|
|
|
|
$('div.progress__label', this.element).html(label);
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
if (this.updateCallback) {
|
|
|
|
this.updateCallback(percentage, message, this);
|
|
|
|
}
|
|
|
|
},
|
2017-05-19 22:12:53 +00:00
|
|
|
startMonitoring: function startMonitoring(uri, delay) {
|
2014-01-27 21:41:32 +00:00
|
|
|
this.delay = delay;
|
|
|
|
this.uri = uri;
|
|
|
|
this.sendPing();
|
|
|
|
},
|
2017-05-19 22:12:53 +00:00
|
|
|
stopMonitoring: function stopMonitoring() {
|
2012-08-19 11:53:28 +00:00
|
|
|
clearTimeout(this.timer);
|
2014-01-27 21:41:32 +00:00
|
|
|
this.uri = null;
|
|
|
|
},
|
2017-05-19 22:12:53 +00:00
|
|
|
sendPing: function sendPing() {
|
2014-01-27 21:41:32 +00:00
|
|
|
if (this.timer) {
|
|
|
|
clearTimeout(this.timer);
|
|
|
|
}
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
if (this.uri) {
|
|
|
|
var pb = this;
|
2020-01-28 13:12:54 +00:00
|
|
|
var uri = this.uri;
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2015-06-08 10:11:09 +00:00
|
|
|
if (uri.indexOf('?') === -1) {
|
|
|
|
uri += '?';
|
2017-05-19 22:12:53 +00:00
|
|
|
} else {
|
2015-06-08 10:11:09 +00:00
|
|
|
uri += '&';
|
|
|
|
}
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2015-06-08 10:11:09 +00:00
|
|
|
uri += '_format=json';
|
2014-01-27 21:41:32 +00:00
|
|
|
$.ajax({
|
|
|
|
type: this.method,
|
2015-06-08 10:11:09 +00:00
|
|
|
url: uri,
|
2014-01-27 21:41:32 +00:00
|
|
|
data: '',
|
2015-11-12 12:54:14 +00:00
|
|
|
dataType: 'json',
|
2017-05-19 22:12:53 +00:00
|
|
|
success: function success(progress) {
|
2014-01-27 21:41:32 +00:00
|
|
|
if (progress.status === 0) {
|
|
|
|
pb.displayError(progress.data);
|
|
|
|
return;
|
|
|
|
}
|
2017-05-19 22:12:53 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
pb.setProgress(progress.percentage, progress.message, progress.label);
|
2017-05-19 22:12:53 +00:00
|
|
|
pb.timer = setTimeout(function () {
|
|
|
|
pb.sendPing();
|
|
|
|
}, pb.delay);
|
2014-01-27 21:41:32 +00:00
|
|
|
},
|
2017-05-19 22:12:53 +00:00
|
|
|
error: function error(xmlhttp) {
|
2014-01-27 21:41:32 +00:00
|
|
|
var e = new Drupal.AjaxError(xmlhttp, pb.uri);
|
2020-01-30 09:08:38 +00:00
|
|
|
pb.displayError("<pre>".concat(e.message, "</pre>"));
|
2012-08-19 11:53:28 +00:00
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2017-05-19 22:12:53 +00:00
|
|
|
displayError: function displayError(string) {
|
2014-01-27 21:41:32 +00:00
|
|
|
var error = $('<div class="messages messages--error"></div>').html(string);
|
|
|
|
$(this.element).before(error).hide();
|
2006-03-01 22:19:24 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
if (this.errorCallback) {
|
|
|
|
this.errorCallback(this);
|
|
|
|
}
|
2012-08-19 11:53:28 +00:00
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
});
|
2017-05-19 22:12:53 +00:00
|
|
|
})(jQuery, Drupal);
|