From 3f2b287d7c6ce2f9ea798406e2458421fb4b0371 Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Wed, 1 Mar 2006 22:19:24 +0000 Subject: - #49501: Improve error reporting in the update system --- misc/progress.js | 29 +++++++++++++++++++++++------ misc/update.js | 6 +++++- 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'misc') diff --git a/misc/progress.js b/misc/progress.js index 84979d68f..776e2b637 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); + } +} diff --git a/misc/update.js b/misc/update.js index 2586fbf50..e595e4cb2 100644 --- a/misc/update.js +++ b/misc/update.js @@ -12,7 +12,11 @@ if (isJsEnabled()) { } } - var progress = new progressBar('updateprogress', updateCallback, HTTPPost); + errorCallback = function (pb) { + window.location = window.location.href.split('op=')[0] +'op=error'; + } + + var progress = new progressBar('updateprogress', updateCallback, HTTPPost, errorCallback); progress.setProgress(-1, 'Starting updates'); $('progress').appendChild(progress.element); progress.startMonitoring('update.php?op=do_update', 0); -- cgit v1.2.3