Commit b788a2e5 by attiyaishaque

Do not try to upload/submit when uploaded file is moved or deleted.

parent 9b6f447a
......@@ -702,4 +702,20 @@ describe("OpenAssessment.ResponseView", function() {
expect(view.files).toEqual(null);
expect($(view.element).find('.file__upload').first().is(':disabled')).toEqual(true);
});
});
it("prevents user from uploading files when file is moved or deleted", function() {
spyOn(view.baseView, 'toggleActionError').and.callThrough();
view.fileUploadResponse = 'optional';
var file = [{type: 'image/jpeg', size: 0, name: 'picture.jpg', data: ''}];
view.prepareUpload(file, 'image', ['test1']);
view.uploadFiles();
expect(view.hasAllUploadFiles()).toEqual(false);
expect(view.baseView.toggleActionError).toHaveBeenCalledWith('upload',
"Your file " + file[0].name + " has been deleted or path has been changed.");
});
});
\ No newline at end of file
......@@ -125,13 +125,15 @@ OpenAssessment.ResponseView.prototype = {
eventObject.preventDefault();
var previouslyUploadedFiles = sel.find('.submission__answer__file').length ? true : false;
$('.submission__answer__display__file', view.element).removeClass('is--hidden');
if (previouslyUploadedFiles) {
var msg = gettext('After you upload new files all your previously uploaded files will be overwritten. Continue?'); // jscs:ignore maximumLineLength
if (confirm(msg)) {
if (view.hasAllUploadFiles()) {
if (previouslyUploadedFiles) {
var msg = gettext('After you upload new files all your previously uploaded files will be overwritten. Continue?'); // jscs:ignore maximumLineLength
if (confirm(msg)) {
view.uploadFiles();
}
} else {
view.uploadFiles();
}
} else {
view.uploadFiles();
}
}
);
......@@ -267,7 +269,24 @@ OpenAssessment.ResponseView.prototype = {
hasPendingUploadFiles: function() {
return this.files !== null && !this.filesUploaded;
},
/**
Check if there is a selected file moved or deleted before uploading
Returns:
boolean: if we have deleted/moved files or not.
**/
hasAllUploadFiles: function() {
for (var i = 0; i < this.files.length; i++) {
var file = this.files[i];
if (file.size === 0) {
this.baseView.toggleActionError(
'upload',
gettext("Your file " + file.name + " has been deleted or path has been changed."));
this.submitEnabled(true);
return false;
}
}
return true;
},
/**
Set the save status message.
Retrieve the save status message.
......@@ -431,16 +450,18 @@ OpenAssessment.ResponseView.prototype = {
var fileDefer = $.Deferred();
if (view.hasPendingUploadFiles()) {
var msg = gettext('Do you want to upload your file before submitting?');
if (confirm(msg)) {
fileDefer = view.uploadFiles();
if (fileDefer === false) {
return;
}
} else {
view.submitEnabled(true);
if (!view.hasAllUploadFiles()) {
return;
}
else {
var msg = gettext('Do you want to upload your file before submitting?');
if (confirm(msg)) {
fileDefer = view.uploadFiles();
if (fileDefer === false) {
return;
}
}
}
} else {
fileDefer.resolve();
}
......
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