Commit 96037111 by Alessandro Verdura

Improvements on error handling + misc

TNL-925
parent 8dd4f6ef
......@@ -5,6 +5,14 @@ define([
'use strict';
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'),
fill = $('.progress-fill'),
submitBtn = $('.submit-button'),
......@@ -15,8 +23,8 @@ define([
gettext('There was an error while verifying the file you submitted.') + '\n',
dbError + '\n'
],
unloading = false,
previousImport = Import.storedImport(),
dbError,
file;
var onComplete = function () {
......@@ -26,11 +34,7 @@ define([
.show();
}
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.');
}
$(window).on('beforeunload', function (event) { unloading = true; });
// Display the status of last file upload on page load
if (previousImport) {
......@@ -77,9 +81,21 @@ define([
}
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(
/********** Private properties ****************************************/
var COOKIE_NAME = 'lastfileupload';
var COOKIE_NAME = 'lastimportupload';
var STAGE = {
'UPLOADING': 0,
......@@ -44,7 +44,7 @@ define(
*
*/
var destroyEventListeners = function () {
window.onbeforeunload = null;
$(window).off('beforeunload.import');
};
/**
......@@ -60,11 +60,11 @@ define(
*
*/
var initEventListeners = function () {
window.onbeforeunload = function () {
$(window).on('beforeunload.import', function () {
if (current.stage <= STAGE.UNPACKING) {
return gettext('Your import is in progress; navigating away will abort it.');
}
}
});
};
/**
......@@ -119,16 +119,13 @@ define(
}
function errorStage(stage) {
var $stage = $(stage);
var error = currStageMsg;
if (!$stage.hasClass('has-error')) {
$stage
if (!$(stage).hasClass('has-error')) {
$(stage)
.removeClass('is-started')
.addClass('has-error')
.find('p.copy')
.hide()
.after("<p class='copy error'>" + error + "</p>");
.after("<p class='copy error'>" + currStageMsg + "</p>");
}
}
......@@ -251,6 +248,7 @@ define(
current.stage = STAGE.UPLOADING;
current.state = STATE.READY;
clearTimeout(timeout.id);
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