Commit 0622dc99 by Vik Paruchuri

Javascript to handle file uploads

parent fbdc190a
......@@ -39,7 +39,7 @@ MAX_SCORE = 1
MAX_SCORE_ALLOWED = 3
IS_SCORED=False
ACCEPT_FILE_UPLOAD = False
ACCEPT_FILE_UPLOAD = True
class CombinedOpenEndedModule(XModule):
"""
......@@ -141,8 +141,8 @@ class CombinedOpenEndedModule(XModule):
#Allow reset is true if student has failed the criteria to move to the next child task
self.allow_reset = instance_state.get('ready_to_reset', False)
self.max_attempts = int(self.metadata.get('attempts', MAX_ATTEMPTS))
self.is_scored = (self.metadata.get('is_graded', IS_SCORED)=="True")
self.accept_file_upload = (self.metadata.get('accept_file_upload', ACCEPT_FILE_UPLOAD)=="True")
self.is_scored = (self.metadata.get('is_graded', IS_SCORED) in [True, "True"])
self.accept_file_upload = (self.metadata.get('accept_file_upload', ACCEPT_FILE_UPLOAD) in [True, "True"])
log.debug(self.metadata.get('is_graded', IS_SCORED))
......
......@@ -140,15 +140,15 @@ class @Problem
allowed_files = $(element).data("allowed_files")
for file in element.files
if allowed_files.length != 0 and file.name not in allowed_files
unallowed_file_submitted = true
errors.push "You submitted #{file.name}; only #{allowed_files} are allowed."
unallowed_file_submitted = true
errors.push "You submitted #{file.name}; only #{allowed_files} are allowed."
if file.name in required_files
required_files.splice(required_files.indexOf(file.name), 1)
required_files.splice(required_files.indexOf(file.name), 1)
if file.size > max_filesize
file_too_large = true
errors.push 'Your file "' + file.name '" is too large (max size: ' + max_filesize/(1000*1000) + ' MB)'
fd.append(element.id, file)
if element.files.length == 0
if element.files.length == 0
file_not_selected = true
fd.append(element.id, '') # In case we want to allow submissions with no file
if required_files.length != 0
......@@ -157,7 +157,7 @@ class @Problem
else
fd.append(element.id, element.value)
if file_not_selected
errors.push 'You did not select any files to submit'
......
......@@ -179,7 +179,11 @@ class @CombinedOpenEnded
save_answer: (event) =>
event.preventDefault()
if @child_state == 'initial'
data = {'student_answer' : @answer_area.val()}
file_data = ""
if @can_upload_files == true
files = $('.file-upload-box')[0].files[0]
file_data = files
data = {'student_answer' : @answer_area.val(), 'file_data' : file_data}
$.postWithPrefix "#{@ajax_url}/save_answer", data, (response) =>
if response.success
@rubric_wrapper.html(response.rubric_html)
......@@ -307,7 +311,6 @@ class @CombinedOpenEnded
setup_file_upload: =>
if window.File and window.FileReader and window.FileList and window.Blob
alert('File API supported.')
if @accept_file_upload == "True"
@can_upload_files = true
@file_upload_area.html('<input type="file" class="file-upload-box">')
......
......@@ -107,6 +107,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
if dispatch not in handlers:
return 'Error'
log.debug(get)
before = self.get_progress()
d = handlers[dispatch](get, system)
after = self.get_progress()
......
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