Commit 0622dc99 by Vik Paruchuri

Javascript to handle file uploads

parent fbdc190a
...@@ -39,7 +39,7 @@ MAX_SCORE = 1 ...@@ -39,7 +39,7 @@ MAX_SCORE = 1
MAX_SCORE_ALLOWED = 3 MAX_SCORE_ALLOWED = 3
IS_SCORED=False IS_SCORED=False
ACCEPT_FILE_UPLOAD = False ACCEPT_FILE_UPLOAD = True
class CombinedOpenEndedModule(XModule): class CombinedOpenEndedModule(XModule):
""" """
...@@ -141,8 +141,8 @@ 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 #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.allow_reset = instance_state.get('ready_to_reset', False)
self.max_attempts = int(self.metadata.get('attempts', MAX_ATTEMPTS)) self.max_attempts = int(self.metadata.get('attempts', MAX_ATTEMPTS))
self.is_scored = (self.metadata.get('is_graded', IS_SCORED)=="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)=="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)) log.debug(self.metadata.get('is_graded', IS_SCORED))
......
...@@ -179,7 +179,11 @@ class @CombinedOpenEnded ...@@ -179,7 +179,11 @@ class @CombinedOpenEnded
save_answer: (event) => save_answer: (event) =>
event.preventDefault() event.preventDefault()
if @child_state == 'initial' 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) => $.postWithPrefix "#{@ajax_url}/save_answer", data, (response) =>
if response.success if response.success
@rubric_wrapper.html(response.rubric_html) @rubric_wrapper.html(response.rubric_html)
...@@ -307,7 +311,6 @@ class @CombinedOpenEnded ...@@ -307,7 +311,6 @@ class @CombinedOpenEnded
setup_file_upload: => setup_file_upload: =>
if window.File and window.FileReader and window.FileList and window.Blob if window.File and window.FileReader and window.FileList and window.Blob
alert('File API supported.')
if @accept_file_upload == "True" if @accept_file_upload == "True"
@can_upload_files = true @can_upload_files = true
@file_upload_area.html('<input type="file" class="file-upload-box">') @file_upload_area.html('<input type="file" class="file-upload-box">')
......
...@@ -107,6 +107,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild): ...@@ -107,6 +107,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
if dispatch not in handlers: if dispatch not in handlers:
return 'Error' return 'Error'
log.debug(get)
before = self.get_progress() before = self.get_progress()
d = handlers[dispatch](get, system) d = handlers[dispatch](get, system)
after = self.get_progress() 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