Commit 8f6abbfd by Alessandro Verdura

Add cancel() on object interface

TNL-925
parent 96037111
...@@ -84,7 +84,7 @@ define([ ...@@ -84,7 +84,7 @@ define([
if (serverMsg.hasOwnProperty('Stage')) { if (serverMsg.hasOwnProperty('Stage')) {
stage = Math.abs(serverMsg.Stage); stage = Math.abs(serverMsg.Stage);
Import.error(defaults[stage] + errMsg, stage); Import.cancel(defaults[stage] + errMsg, stage);
} }
// It could be that the user is simply refreshing the page // 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 // so we need to be sure this is an actual error from the server
......
...@@ -56,6 +56,27 @@ define( ...@@ -56,6 +56,27 @@ define(
}; };
/** /**
* Sets the Import in the "error" status.
*
* Immediately stops any further polling from the server.
* Displays the error message at the list element that corresponds
* to the stage where the error occurred.
*
* @param {string} msg Error message to display.
* @param {int} [stage=current.stage] Stage of import process at which error occurred.
*/
var error = function (msg, stage) {
current.stage = Math.abs(stage || current.stage); // Could be negative
current.state = STATE.ERROR;
destroyEventListeners();
clearTimeout(timeout.id);
updateFeedbackList(msg);
deferred.resolve();
};
/**
* Initializes the event listeners * Initializes the event listeners
* *
*/ */
...@@ -190,24 +211,13 @@ define( ...@@ -190,24 +211,13 @@ define(
var CourseImport = { var CourseImport = {
/** /**
* Sets the Import in the "error" status. * Cancels the import and sets the Object to the error state
*
* Immediately stops any further polling from the server.
* Displays the error message at the list element that corresponds
* to the stage where the error occurred.
* *
* @param {string} msg Error message to display. * @param {string} msg Error message to display.
* @param {int} [stage=current.stage] Stage of import process at which error occurred. * @param {int} stage Stage of import process at which error occurred.
*/ */
error: function (msg, stage) { cancel: function (msg, stage) {
current.stage = Math.abs(stage || current.stage); // Could be negative error(msg, stage);
current.state = STATE.ERROR;
destroyEventListeners();
clearTimeout(timeout.id);
updateFeedbackList(msg);
deferred.resolve();
}, },
/** /**
...@@ -228,7 +238,7 @@ define( ...@@ -228,7 +238,7 @@ define(
if (current.stage === STAGE.SUCCESS) { if (current.stage === STAGE.SUCCESS) {
success(); success();
} else if (current.stage < STAGE.UPLOADING) { // Failed } else if (current.stage < STAGE.UPLOADING) { // Failed
this.error(gettext("Error importing course")); error(gettext("Error importing course"));
} else { // In progress } else { // In progress
updateFeedbackList(); updateFeedbackList();
...@@ -273,7 +283,7 @@ define( ...@@ -273,7 +283,7 @@ define(
this.pollStatus(current.stage); this.pollStatus(current.stage);
} else { } else {
// An import in the upload stage cannot be resumed // An import in the upload stage cannot be resumed
this.error(gettext("There was an error with the upload")); error(gettext("There was an error with the upload"));
} }
}.bind(this)); }.bind(this));
......
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