Multiple file submissions

This commit is contained in:
kimth
2012-08-19 09:26:03 -04:00
parent d920e718d0
commit d2cb645834
5 changed files with 54 additions and 33 deletions

View File

@@ -151,28 +151,33 @@ class @Problem
return
if not window.FormData
alert "Sorry, your browser does not support file uploads. Your submit request could not be fulfilled. If you can, please use Chrome or Safari which have been verified to support file uploads."
alert "Submission aborted! Sorry, your browser does not support file uploads. If you can, please use Chrome or Safari which have been verified to support file uploads."
return
fd = new FormData()
# Sanity check of file size
abort_submission = false
# Sanity checks on submission
max_filesize = 4*1000*1000 # 4 MB
file_too_large = false
file_not_selected = false
@inputs.each (index, element) ->
if element.type is 'file'
for file in element.files
if file.size > max_filesize
abort_submission = true
file_too_large = true
alert 'Submission aborted! Your file "' + file.name '" is too large (max size: ' + max_filesize/(1000*1000) + ' MB)'
fd.append(element.id, file)
if element.files.length == 0
abort_submission = true
alert 'Submission aborted! You did not select any files to submit'
fd.append(element.id, '')
file_not_selected = true
fd.append(element.id, '') # In case we want to allow submissions with no file
else
fd.append(element.id, element.value)
if file_not_selected
alert 'Submission aborted! You did not select any files to submit'
abort_submission = file_too_large or file_not_selected
settings =
type: "POST"
@@ -186,7 +191,7 @@ class @Problem
@updateProgress response
else
alert(response.success)
if not abort_submission
$.ajaxWithPrefix("#{@url}/problem_check", settings)