Commit a91a571f by Vik Paruchuri

update javascript

parent 947e6e6e
......@@ -580,7 +580,7 @@ class CapaModule(XModule):
'contents': html,
}
def save_problem(self, get):
def save_problem(self, get):
'''
Save the passed in answers.
Returns a dict { 'success' : bool, ['error' : error-msg]},
......@@ -614,7 +614,7 @@ def save_problem(self, get):
self.system.track_function('save_problem_fail', event_info)
return {'success': True}
def reset_problem(self, get):
def reset_problem(self, get):
''' Changes problem state to unfinished -- removes student answers,
and causes problem to rerender itself.
......
class @Problem
constructor: (element) ->
@el = $(element).find('.problems-wrapper')
@id = @el.data('problem-id')
@element_id = @el.attr('id')
@url = @el.data('url')
@render()
$: (selector) ->
$(selector, @el)
bind: =>
problem_prefix = @element_id.replace(/sa_/,'')
@inputs = @$("[id^=input_#{problem_prefix}_]")
@$('section.action input.show').click @show
@$('section.action input.save').click @save
render: (content) ->
if content
@el.html(content)
JavascriptLoader.executeModuleScripts @el, () =>
@setupInputTypes()
@bind()
else
$.postWithPrefix "#{@url}/sa_get", (response) =>
@el.html(response.html)
JavascriptLoader.executeModuleScripts @el, () =>
@setupInputTypes()
@bind()
# TODO add hooks for problem types here by inspecting response.html and doing
# stuff if a div w a class is found
show: =>
show: =>
Logger.log 'sa_show', problem: @id
$.postWithPrefix "#{@url}/sa_show", (response) =>
answers = response.answers
......@@ -50,35 +14,8 @@ class @Problem
@$('.show').val 'Hide Answer'
@el.addClass 'showed'
save: =>
Logger.log 'problem_save', @answers
$.postWithPrefix "#{@url}/problem_save", @answers, (response) =>
save: =>
Logger.log 'sa_save', @answers
$.postWithPrefix "#{@url}/sa_save", @answers, (response) =>
if response.success
saveMessage = "Your answers have been saved but not graded. Hit 'Check' to grade them."
@gentle_alert saveMessage
@updateProgress response
inputtypeShowAnswerMethods:
choicegroup: (element, display, answers) =>
element = $(element)
element.find('input').attr('disabled', 'disabled')
input_id = element.attr('id').replace(/inputtype_/,'')
answer = answers[input_id]
for choice in answer
element.find("label[for='input_#{input_id}_#{choice}']").addClass 'choicegroup_correct'
javascriptinput: (element, display, answers) =>
answer_id = $(element).attr('id').split("_")[1...].join("_")
answer = JSON.parse(answers[answer_id])
display.showAnswer(answer)
inputtypeHideAnswerMethods:
choicegroup: (element, display) =>
element = $(element)
element.find('input').attr('disabled', null)
element.find('label').removeClass('choicegroup_correct')
javascriptinput: (element, display) =>
display.hideAnswer()
@$('p.rubric').replace(response.rubric)
......@@ -19,12 +19,12 @@ from xmodule.contentstore.content import XASSET_SRCREF_PREFIX, StaticContent
log = logging.getLogger("mitx.courseware")
problem_form=('<form action="show()"><input type="text" name="answer" '
'id="answer"/><br/><input type="submit" value="Check"/></form>')
problem_form=('<form action="save()"><input type="text" name="answer" '
'id="answer"/><br/><input type="submit" value="Check" id ="save"/></form><p id="rubric"></p>')
rubric_form=('<form action="save()"><input type="radio" name="assessment" value="correct"/>Correct<br/>'
rubric_form=('<form action="show()"><input type="radio" name="assessment" value="correct"/>Correct<br/>'
'<input type="radio" name="assessment" value="incorrect">'
'Incorrect<input type="submit" value="Submit"/></form>')
'Incorrect<input type="submit" value="Submit" id="show"/></form>')
def only_one(lst, default="", process=lambda x: x):
"""
......@@ -46,7 +46,7 @@ class SelfAssessmentModule(XModule):
resource_string(__name__, 'js/src/selfassessment/display.coffee')
]
}
js_module_name = "SelfAssessmentModule"
js_module_name = "SelfAssessment"
def get_html(self):
# cdodge: perform link substitutions for any references to course static content (e.g. images)
......@@ -80,8 +80,9 @@ class SelfAssessmentModule(XModule):
'progress' : 'none'/'in_progress'/'done',
<other request-specific values here > }
'''
handlers = {
'sa_get' : self.show_problem
'sa_get' : self.show_problem,
'sa_show': self.show_rubric,
'sa_save': self.save_problem,
}
......@@ -98,6 +99,19 @@ class SelfAssessmentModule(XModule):
})
return json.dumps(d, cls=ComplexEncoder)
def save_problem(self, get):
'''
Save the passed in answers.
Returns a dict { 'success' : bool, ['error' : error-msg]},
with the error key only present if success is False.
'''
event_info = dict()
event_info['state'] = self.lcp.get_state()
event_info['problem_id'] = self.location.url()
return {'success': True, 'rubric' : self.rubric}
......
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