Commit 8c599f3e by Awais Jibran

Do not try to upload when popup is cancled during file upload

parent 7bee621d
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -679,4 +679,27 @@ describe("OpenAssessment.ResponseView", function() { ...@@ -679,4 +679,27 @@ describe("OpenAssessment.ResponseView", function() {
view.uploadFiles(); view.uploadFiles();
expect($(view.element).find('.file__description').length).toEqual(0); expect($(view.element).find('.file__description').length).toEqual(0);
}); });
it("prevents user from submitting response when files selection is cancelled", function() {
// Set fileupload to be required.
view.fileUploadResponse = 'required';
// Change the response text
view.response(['Lorem ipsum 1', 'Lorem ipsum 2']);
view.handleResponseChanged();
// Expect the unsaved warning to be enabled and save progress button is enabled.
expect(view.saveEnabled()).toBe(true);
expect(view.saveStatus()).toContain('This response has not been saved.');
// Assume user has selected no files (cancelled the file select pop-up) the event will
// trigger with no files selected. Expect Submit response button is disabled.
view.prepareUpload([], 'image', []);
expect(view.submitEnabled()).toBe(false);
// Expect there are no pending upload files & file upload button is disabled.
expect(view.hasPendingUploadFiles()).toEqual(false);
expect(view.files).toEqual(null);
expect($(view.element).find('.file__upload').first().is(':disabled')).toEqual(true);
});
}); });
...@@ -259,6 +259,14 @@ OpenAssessment.ResponseView.prototype = { ...@@ -259,6 +259,14 @@ OpenAssessment.ResponseView.prototype = {
previewEnabled: function(enabled) { previewEnabled: function(enabled) {
return this.baseView.buttonEnabled('.submission__preview', enabled); return this.baseView.buttonEnabled('.submission__preview', enabled);
}, },
/**
Check if there is a file selected but not uploaded yet
Returns:
boolean: if we have pending files or not.
**/
hasPendingUploadFiles: function() {
return this.files !== null && !this.filesUploaded;
},
/** /**
Set the save status message. Set the save status message.
...@@ -422,8 +430,7 @@ OpenAssessment.ResponseView.prototype = { ...@@ -422,8 +430,7 @@ OpenAssessment.ResponseView.prototype = {
var baseView = this.baseView; var baseView = this.baseView;
var fileDefer = $.Deferred(); var fileDefer = $.Deferred();
// check if there is a file selected but not uploaded yet if (view.hasPendingUploadFiles()) {
if (view.files !== null && !view.filesUploaded) {
var msg = gettext('Do you want to upload your file before submitting?'); var msg = gettext('Do you want to upload your file before submitting?');
if (confirm(msg)) { if (confirm(msg)) {
fileDefer = view.uploadFiles(); fileDefer = view.uploadFiles();
...@@ -533,7 +540,6 @@ OpenAssessment.ResponseView.prototype = { ...@@ -533,7 +540,6 @@ OpenAssessment.ResponseView.prototype = {
var fileType = null; var fileType = null;
var fileName = ''; var fileName = '';
var errorCheckerTriggered = false; var errorCheckerTriggered = false;
var sel = $('.step--response', this.element);
for (var i = 0; i < files.length; i++) { for (var i = 0; i < files.length; i++) {
totalSize += files[i].size; totalSize += files[i].size;
...@@ -582,12 +588,14 @@ OpenAssessment.ResponseView.prototype = { ...@@ -582,12 +588,14 @@ OpenAssessment.ResponseView.prototype = {
if (!errorCheckerTriggered) { if (!errorCheckerTriggered) {
this.baseView.toggleActionError('upload', null); this.baseView.toggleActionError('upload', null);
this.files = files; if (files.length > 0) {
this.files = files;
}
this.updateFilesDescriptionsFields(files, descriptions, uploadType); this.updateFilesDescriptionsFields(files, descriptions, uploadType);
} }
if (this.files === null) { if (this.files === null) {
sel.find('.file__upload').prop('disabled', true); $(this.element).find('.file__upload').prop('disabled', true);
} }
}, },
......
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