Commit d920e718 by kimth

AJAX permits multiple file upload

parent 588444c4
...@@ -157,17 +157,19 @@ class @Problem ...@@ -157,17 +157,19 @@ class @Problem
fd = new FormData() fd = new FormData()
# Sanity check of file size # Sanity check of file size
file_too_large = false abort_submission = false
max_filesize = 4*1000*1000 # 4 MB max_filesize = 4*1000*1000 # 4 MB
@inputs.each (index, element) -> @inputs.each (index, element) ->
if element.type is 'file' if element.type is 'file'
if element.files[0] instanceof File for file in element.files
if element.files[0].size > max_filesize if file.size > max_filesize
file_too_large = true abort_submission = true
alert 'Submission aborted! Your file "' + element.files[0].name + '" is too large (max size: ' + max_filesize/(1000*1000) + ' MB)' alert 'Submission aborted! Your file "' + file.name '" is too large (max size: ' + max_filesize/(1000*1000) + ' MB)'
fd.append(element.id, element.files[0]) fd.append(element.id, file)
else if element.files.length == 0
abort_submission = true
alert 'Submission aborted! You did not select any files to submit'
fd.append(element.id, '') fd.append(element.id, '')
else else
fd.append(element.id, element.value) fd.append(element.id, element.value)
...@@ -185,7 +187,7 @@ class @Problem ...@@ -185,7 +187,7 @@ class @Problem
else else
alert(response.success) alert(response.success)
if not file_too_large if not abort_submission
$.ajaxWithPrefix("#{@url}/problem_check", settings) $.ajaxWithPrefix("#{@url}/problem_check", settings)
check: => check: =>
......
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