Merge pull request #619 from MITx/feature/arjun/generalize_show
Make show answer work for choiceresponse + javascriptinputs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<form class="choicegroup">
|
||||
<form class="choicegroup capa_inputtype" id="inputtype_${id}">
|
||||
|
||||
% for choice_id, choice_description in choices:
|
||||
<label for="input_${id}_${choice_id}"> <input type="${input_type}" name="input_${id}${name_array_suffix}" id="input_${id}_${choice_id}" value="${choice_id}"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<form class="javascriptinput capa_inputtype">
|
||||
<form class="javascriptinput capa_inputtype" id="inputtype_${id}">
|
||||
<input type="hidden" name="input_${id}" id="input_${id}" class="javascriptinput_input"/>
|
||||
<div class="javascriptinput_data" data-display_class="${display_class}"
|
||||
data-problem_state="${problem_state}" data-params="${params}"
|
||||
|
||||
@@ -32,6 +32,12 @@ section.problem {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.choicegroup {
|
||||
label.choicegroup_correct:after {
|
||||
content: url('../images/correct-icon.png');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
div {
|
||||
p {
|
||||
|
||||
@@ -84,11 +84,14 @@ class @Problem
|
||||
# stuff if a div w a class is found
|
||||
|
||||
setupInputTypes: =>
|
||||
@inputtypeDisplays = {}
|
||||
@el.find(".capa_inputtype").each (index, inputtype) =>
|
||||
classes = $(inputtype).attr('class').split(' ')
|
||||
id = $(inputtype).attr('id')
|
||||
for cls in classes
|
||||
setupMethod = @inputtypeSetupMethods[cls]
|
||||
setupMethod(inputtype) if setupMethod?
|
||||
if setupMethod?
|
||||
@inputtypeDisplays[id] = setupMethod(inputtype)
|
||||
|
||||
executeProblemScripts: (callback=null) ->
|
||||
|
||||
@@ -248,6 +251,17 @@ class @Problem
|
||||
@$("label[for='input_#{key}_#{choice}']").attr correct_answer: 'true'
|
||||
else
|
||||
@$("#answer_#{key}, #solution_#{key}").html(value)
|
||||
|
||||
# TODO remove the above once everything is extracted into its own
|
||||
# inputtype functions.
|
||||
|
||||
@el.find(".capa_inputtype").each (index, inputtype) =>
|
||||
classes = $(inputtype).attr('class').split(' ')
|
||||
for cls in classes
|
||||
display = @inputtypeDisplays[$(inputtype).attr('id')]
|
||||
showMethod = @inputtypeShowAnswerMethods[cls]
|
||||
showMethod(inputtype, display, answers) if showMethod?
|
||||
|
||||
MathJax.Hub.Queue ["Typeset", MathJax.Hub]
|
||||
@$('.show').val 'Hide Answer'
|
||||
@el.addClass 'showed'
|
||||
@@ -258,6 +272,13 @@ class @Problem
|
||||
@el.removeClass 'showed'
|
||||
@$('.show').val 'Show Answer'
|
||||
|
||||
@el.find(".capa_inputtype").each (index, inputtype) =>
|
||||
display = @inputtypeDisplays[$(inputtype).attr('id')]
|
||||
classes = $(inputtype).attr('class').split(' ')
|
||||
for cls in classes
|
||||
hideMethod = @inputtypeHideAnswerMethods[cls]
|
||||
hideMethod(inputtype, display) if hideMethod?
|
||||
|
||||
gentle_alert: (msg) =>
|
||||
if @el.find('.capa_alert').length
|
||||
@el.find('.capa_alert').remove()
|
||||
@@ -314,3 +335,27 @@ class @Problem
|
||||
|
||||
display = new displayClass(problemState, submission, evaluation, container, submissionField, params)
|
||||
display.render()
|
||||
|
||||
return display
|
||||
|
||||
inputtypeShowAnswerMethods:
|
||||
choicegroup: (element, display, answers) =>
|
||||
element = $(element)
|
||||
for key, value of answers
|
||||
element.find('input').attr('disabled', 'disabled')
|
||||
for choice in value
|
||||
element.find("label[for='input_#{key}_#{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()
|
||||
|
||||
Reference in New Issue
Block a user