Commit fbdc190a by Vik Paruchuri

Add in file upload ability

parent f367b7ac
......@@ -39,7 +39,7 @@ MAX_SCORE = 1
MAX_SCORE_ALLOWED = 3
IS_SCORED=False
UPLOAD_IMAGE = False
ACCEPT_FILE_UPLOAD = False
class CombinedOpenEndedModule(XModule):
"""
......@@ -142,7 +142,7 @@ class CombinedOpenEndedModule(XModule):
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.upload_image = (self.metadata.get('upload_image', UPLOAD_IMAGE)=="True")
self.accept_file_upload = (self.metadata.get('accept_file_upload', ACCEPT_FILE_UPLOAD)=="True")
log.debug(self.metadata.get('is_graded', IS_SCORED))
......@@ -176,7 +176,7 @@ class CombinedOpenEndedModule(XModule):
'prompt': definition['prompt'],
'rubric': definition['rubric'],
'display_name': self.display_name,
'accept_file_upload' : self.upload_image,
'accept_file_upload' : self.accept_file_upload,
}
self.task_xml = definition['task_xml']
......@@ -327,7 +327,8 @@ class CombinedOpenEndedModule(XModule):
'task_count': len(self.task_xml),
'task_number': self.current_task_number + 1,
'status': self.get_status(),
'display_name': self.display_name
'display_name': self.display_name ,
'accept_file_upload' : self.accept_file_upload,
}
return context
......
......@@ -12,6 +12,7 @@ class @CombinedOpenEnded
@state = @el.data('state')
@task_count = @el.data('task-count')
@task_number = @el.data('task-number')
@accept_file_upload = @el.data('accept-file-upload')
@allow_reset = @el.data('allow_reset')
@reset_button = @$('.reset-button')
......@@ -45,6 +46,7 @@ class @CombinedOpenEnded
@skip_button.click @skip_post_assessment
@file_upload_area = @$('.file-upload')
@can_upload_files = false
@open_ended_child= @$('.open-ended-child')
@find_assessment_elements()
......@@ -119,6 +121,7 @@ class @CombinedOpenEnded
@submit_button.show()
@reset_button.hide()
@next_problem_button.hide()
@hide_file_upload()
@hint_area.attr('disabled', false)
if @child_state == 'done'
@rubric_wrapper.hide()
......@@ -134,8 +137,10 @@ class @CombinedOpenEnded
@answer_area.attr("disabled", false)
@submit_button.prop('value', 'Submit')
@submit_button.click @save_answer
@setup_file_upload()
else if @child_state == 'assessing'
@answer_area.attr("disabled", true)
@hide_file_upload()
@submit_button.prop('value', 'Submit assessment')
@submit_button.click @save_assessment
if @child_type == "openended"
......@@ -301,4 +306,15 @@ class @CombinedOpenEnded
window.queuePollerID = window.setTimeout(@poll, 10000)
setup_file_upload: =>
@file_upload_area.html('<input type="file" class="file">')
\ No newline at end of file
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">')
@file_upload_area.show()
else
@gentle_alert 'File uploads are not supported in this browser. Try the newest version of google chrome'
hide_file_upload: =>
if @accept_file_upload == "True"
@file_upload_area.hide()
\ No newline at end of file
<section id="combined-open-ended" class="combined-open-ended" data-ajax-url="${ajax_url}" data-allow_reset="${allow_reset}" data-state="${state}" data-task-count="${task_count}" data-task-number="${task_number}">
<section id="combined-open-ended" class="combined-open-ended" data-ajax-url="${ajax_url}" data-allow_reset="${allow_reset}" data-state="${state}" data-task-count="${task_count}" data-task-number="${task_number}" data-accept-file-upload = "${accept_file_upload}">
<h2>${display_name}</h2>
<div class="status-container">
......
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