Commit e6b57fcd by Arjun Singh

Make show answer work for choicegroups + javascriptinputs

parent 8f4b599a
<form class="choicegroup"> <form class="choicegroup capa_inputtype" id="inputtype_${id}">
% for choice_id, choice_description in choices: % 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}" <label for="input_${id}_${choice_id}"> <input type="${input_type}" name="input_${id}${name_array_suffix}" id="input_${id}_${choice_id}" value="${choice_id}"
......
<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"/> <input type="hidden" name="input_${id}" id="input_${id}" class="javascriptinput_input"/>
<div class="javascriptinput_data" data-display_class="${display_class}" <div class="javascriptinput_data" data-display_class="${display_class}"
data-problem_state="${problem_state}" data-params="${params}" data-problem_state="${problem_state}" data-params="${params}"
......
...@@ -32,6 +32,12 @@ section.problem { ...@@ -32,6 +32,12 @@ section.problem {
display: inline; display: inline;
} }
.choicegroup {
label.choicegroup_correct:after {
content: url('../images/correct-icon.png');
}
}
div { div {
p { p {
......
...@@ -84,11 +84,14 @@ class @Problem ...@@ -84,11 +84,14 @@ class @Problem
# stuff if a div w a class is found # stuff if a div w a class is found
setupInputTypes: => setupInputTypes: =>
@inputtypeDisplays = {}
@el.find(".capa_inputtype").each (index, inputtype) => @el.find(".capa_inputtype").each (index, inputtype) =>
classes = $(inputtype).attr('class').split(' ') classes = $(inputtype).attr('class').split(' ')
id = $(inputtype).attr('id')
for cls in classes for cls in classes
setupMethod = @inputtypeSetupMethods[cls] setupMethod = @inputtypeSetupMethods[cls]
setupMethod(inputtype) if setupMethod? if setupMethod?
@inputtypeDisplays[id] = setupMethod(inputtype)
executeProblemScripts: (callback=null) -> executeProblemScripts: (callback=null) ->
...@@ -248,6 +251,17 @@ class @Problem ...@@ -248,6 +251,17 @@ class @Problem
@$("label[for='input_#{key}_#{choice}']").attr correct_answer: 'true' @$("label[for='input_#{key}_#{choice}']").attr correct_answer: 'true'
else else
@$("#answer_#{key}, #solution_#{key}").html(value) @$("#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] MathJax.Hub.Queue ["Typeset", MathJax.Hub]
@$('.show').val 'Hide Answer' @$('.show').val 'Hide Answer'
@el.addClass 'showed' @el.addClass 'showed'
...@@ -258,6 +272,13 @@ class @Problem ...@@ -258,6 +272,13 @@ class @Problem
@el.removeClass 'showed' @el.removeClass 'showed'
@$('.show').val 'Show Answer' @$('.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) => gentle_alert: (msg) =>
if @el.find('.capa_alert').length if @el.find('.capa_alert').length
@el.find('.capa_alert').remove() @el.find('.capa_alert').remove()
...@@ -314,3 +335,27 @@ class @Problem ...@@ -314,3 +335,27 @@ class @Problem
display = new displayClass(problemState, submission, evaluation, container, submissionField, params) display = new displayClass(problemState, submission, evaluation, container, submissionField, params)
display.render() 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()
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