diff options
author | Steven Wittens <steven@10.no-reply.drupal.org> | 2006-03-01 22:19:24 +0000 |
---|---|---|
committer | Steven Wittens <steven@10.no-reply.drupal.org> | 2006-03-01 22:19:24 +0000 |
commit | 3f2b287d7c6ce2f9ea798406e2458421fb4b0371 (patch) | |
tree | 5e6ae137f781c325a84acf8811f7e71256ec6b4b /misc/progress.js | |
parent | 9a014043a467e9710d93c66580b33f374e2f4223 (diff) | |
download | drupal-3f2b287d7c6ce2f9ea798406e2458421fb4b0371.tar.gz drupal-3f2b287d7c6ce2f9ea798406e2458421fb4b0371.zip |
- #49501: Improve error reporting in the update system
Diffstat (limited to 'misc/progress.js')
-rw-r--r-- | misc/progress.js | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/misc/progress.js b/misc/progress.js index 84979d68fc06..776e2b637082 100644 --- a/misc/progress.js +++ b/misc/progress.js @@ -8,11 +8,12 @@ * e.g. pb = new progressBar('myProgressBar'); * some_element.appendChild(pb.element); */ -function progressBar(id, callback, method) { +function progressBar(id, updateCallback, method, errorCallback) { var pb = this; this.id = id; this.method = method ? method : HTTPGet; - this.callback = callback; + this.updateCallback = updateCallback; + this.errorCallback = errorCallback; this.element = document.createElement('div'); this.element.id = id; @@ -41,8 +42,8 @@ progressBar.prototype.setProgress = function (percentage, message) { divs[i].innerHTML = message; } } - if (this.callback) { - this.callback(percentage, message, this); + if (this.updateCallback) { + this.updateCallback(percentage, message, this); } } @@ -82,13 +83,13 @@ progressBar.prototype.sendPing = function () { */ progressBar.prototype.receivePing = function (string, xmlhttp, pb) { if (xmlhttp.status != 200) { - return alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ pb.uri); + return pb.displayError('An HTTP error '+ xmlhttp.status +' occured.\n'+ pb.uri); } // Parse response var progress = parseJson(string); // Display errors if (progress.status == 0) { - alert(progress.data); + pb.displayError(progress.data); return; } @@ -97,3 +98,19 @@ progressBar.prototype.receivePing = function (string, xmlhttp, pb) { // Schedule next timer pb.timer = setTimeout(function() { pb.sendPing(); }, pb.delay); } + +/** + * Display errors on the page. + */ +progressBar.prototype.displayError = function (string) { + var error = document.createElement('div'); + error.className = 'error'; + error.appendChild(document.createTextNode(string)); + + this.element.style.display = 'none'; + this.element.parentNode.insertBefore(error, this.element); + + if (this.errorCallback) { + this.errorCallback(this); + } +} |