Commit 96037111 by Alessandro Verdura

Improvements on error handling + misc

TNL-925
parent 8dd4f6ef
...@@ -5,6 +5,14 @@ define([ ...@@ -5,6 +5,14 @@ define([
'use strict'; 'use strict';
return function (feedbackUrl, library) { return function (feedbackUrl, library) {
var dbError;
if (library) {
dbError = gettext('There was an error while importing the new library to our database.');
} else {
dbError = gettext('There was an error while importing the new course to our database.');
}
var bar = $('.progress-bar'), var bar = $('.progress-bar'),
fill = $('.progress-fill'), fill = $('.progress-fill'),
submitBtn = $('.submit-button'), submitBtn = $('.submit-button'),
...@@ -15,8 +23,8 @@ define([ ...@@ -15,8 +23,8 @@ define([
gettext('There was an error while verifying the file you submitted.') + '\n', gettext('There was an error while verifying the file you submitted.') + '\n',
dbError + '\n' dbError + '\n'
], ],
unloading = false,
previousImport = Import.storedImport(), previousImport = Import.storedImport(),
dbError,
file; file;
var onComplete = function () { var onComplete = function () {
...@@ -26,11 +34,7 @@ define([ ...@@ -26,11 +34,7 @@ define([
.show(); .show();
} }
if (library) { $(window).on('beforeunload', function (event) { unloading = true; });
dbError = gettext('There was an error while importing the new library to our database.');
} else {
dbError = gettext('There was an error while importing the new course to our database.');
}
// Display the status of last file upload on page load // Display the status of last file upload on page load
if (previousImport) { if (previousImport) {
...@@ -77,9 +81,21 @@ define([ ...@@ -77,9 +81,21 @@ define([
} }
errMsg = serverMsg.hasOwnProperty('ErrMsg') ? serverMsg.ErrMsg : ''; errMsg = serverMsg.hasOwnProperty('ErrMsg') ? serverMsg.ErrMsg : '';
stage = Math.abs(serverMsg.Stage || 0);
Import.error(defaults[stage] + errMsg, stage); if (serverMsg.hasOwnProperty('Stage')) {
stage = Math.abs(serverMsg.Stage);
Import.error(defaults[stage] + errMsg, stage);
}
// It could be that the user is simply refreshing the page
// so we need to be sure this is an actual error from the server
else if (!unloading) {
$(window).off('beforeunload.import');
Import.reset();
onComplete();
alert(gettext('Your import has failed.') + '\n\n' + errMsg);
}
} }
}); });
}); });
......
...@@ -9,7 +9,7 @@ define( ...@@ -9,7 +9,7 @@ define(
/********** Private properties ****************************************/ /********** Private properties ****************************************/
var COOKIE_NAME = 'lastfileupload'; var COOKIE_NAME = 'lastimportupload';
var STAGE = { var STAGE = {
'UPLOADING': 0, 'UPLOADING': 0,
...@@ -44,7 +44,7 @@ define( ...@@ -44,7 +44,7 @@ define(
* *
*/ */
var destroyEventListeners = function () { var destroyEventListeners = function () {
window.onbeforeunload = null; $(window).off('beforeunload.import');
}; };
/** /**
...@@ -60,11 +60,11 @@ define( ...@@ -60,11 +60,11 @@ define(
* *
*/ */
var initEventListeners = function () { var initEventListeners = function () {
window.onbeforeunload = function () { $(window).on('beforeunload.import', function () {
if (current.stage <= STAGE.UNPACKING) { if (current.stage <= STAGE.UNPACKING) {
return gettext('Your import is in progress; navigating away will abort it.'); return gettext('Your import is in progress; navigating away will abort it.');
} }
} });
}; };
/** /**
...@@ -119,16 +119,13 @@ define( ...@@ -119,16 +119,13 @@ define(
} }
function errorStage(stage) { function errorStage(stage) {
var $stage = $(stage); if (!$(stage).hasClass('has-error')) {
var error = currStageMsg; $(stage)
if (!$stage.hasClass('has-error')) {
$stage
.removeClass('is-started') .removeClass('is-started')
.addClass('has-error') .addClass('has-error')
.find('p.copy') .find('p.copy')
.hide() .hide()
.after("<p class='copy error'>" + error + "</p>"); .after("<p class='copy error'>" + currStageMsg + "</p>");
} }
} }
...@@ -251,6 +248,7 @@ define( ...@@ -251,6 +248,7 @@ define(
current.stage = STAGE.UPLOADING; current.stage = STAGE.UPLOADING;
current.state = STATE.READY; current.state = STATE.READY;
clearTimeout(timeout.id);
updateFeedbackList(); updateFeedbackList();
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment