Commit 7c93b45d by Felix Sun

Added wizard / slideshow style hint collection script.

Still requires a little polishing, I think.
parent 64c91cf2
...@@ -36,8 +36,9 @@ class @Hinter ...@@ -36,8 +36,9 @@ class @Hinter
@$('input.vote').click @vote @$('input.vote').click @vote
@$('input.submit-hint').click @submit_hint @$('input.submit-hint').click @submit_hint
@$('.custom-hint').click @clear_default_text @$('.custom-hint').click @clear_default_text
@$('#answer-tabs').tabs({active: 0})
@$('.expand').click @expand @$('.expand').click @expand
@$('.wizard-link').click @wizard_link_handle
@$('.answer-choice').click @answer_choice_handle
expand: (eventObj) => expand: (eventObj) =>
target = @$('#' + @$(eventObj.currentTarget).data('target')) target = @$('#' + @$(eventObj.currentTarget).data('target'))
...@@ -55,11 +56,10 @@ class @Hinter ...@@ -55,11 +56,10 @@ class @Hinter
submit_hint: (eventObj) => submit_hint: (eventObj) =>
textarea = $('.custom-hint') textarea = $('.custom-hint')
answer = $('input:radio[name=answer-select]:checked').val() if @answer == ''
if answer == undefined # The user didn't choose an answer, somehow. Do nothing.
# The user didn't choose an answer. Do nothing.
return return
post_json = {'answer': answer, 'hint': textarea.val()} post_json = {'answer': @answer, 'hint': textarea.val()}
$.postWithPrefix "#{@url}/submit_hint",post_json, (response) => $.postWithPrefix "#{@url}/submit_hint",post_json, (response) =>
@render(response.contents) @render(response.contents)
...@@ -69,6 +69,15 @@ class @Hinter ...@@ -69,6 +69,15 @@ class @Hinter
target.val('') target.val('')
target.data('cleared', true) target.data('cleared', true)
wizard_link_handle: (eventObj) =>
target = @$(eventObj.currentTarget)
@go_to(target.attr('dest'))
answer_choice_handle: (eventObj) =>
@answer = @$(eventObj.target).attr('value')
@$('#blank-answer').html(@answer)
@go_to('p3')
render: (content) -> render: (content) ->
if content if content
# Trim leading and trailing whitespace # Trim leading and trailing whitespace
...@@ -82,3 +91,16 @@ class @Hinter ...@@ -82,3 +91,16 @@ class @Hinter
@$('#previous-answer-0').css('display', 'inline') @$('#previous-answer-0').css('display', 'inline')
else else
@el.hide() @el.hide()
# Initialize the answer choice - remembers which answer the user picked on
# p2 when he submits a hint on p3.
@answer = ''
# Make the correct wizard view show up.
hints_exist = @$('#hints-exist').html() == 'True'
if hints_exist
@go_to('p1')
else
@go_to('p2')
go_to: (view_id) ->
$('.wizard-view').css('display', 'none')
$('#' + view_id).css('display', 'block')
\ No newline at end of file
...@@ -34,50 +34,71 @@ ...@@ -34,50 +34,71 @@
for pk, hint_text in pk_dict.items(): for pk, hint_text in pk_dict.items():
pk_list.append([answer, pk]) pk_list.append([answer, pk])
json_pk_list = json.dumps(pk_list) json_pk_list = json.dumps(pk_list)
%> %>
% if hints_exist:
<p> <!-- Tells coffeescript whether there are hints to show. -->
<em> Optional. </em> Help us improve our hints! Which hint was most helpful to you? <span id="hints-exist" style="display:none">${hints_exist}</span>
</p>
<div class="wizard-view" id="p1">
<div id="pk-list" data-pk-list='${json_pk_list}' style="display:none"> </div> <p>
<em> Optional. </em> Help us improve our hints! Which hint was most helpful to you?
% for answer, pk_dict in answer_to_hints.items(): </p>
% for hint_pk, hint_text in pk_dict.items():
<p> <div id="pk-list" data-pk-list='${json_pk_list}' style="display:none"> </div>
<input class="vote" data-answer="${answer}" data-hintno="${hint_pk}" type="button" value="Vote">
${hint_text} % for answer, pk_dict in answer_to_hints.items():
</p> % for hint_pk, hint_text in pk_dict.items():
% endfor <p>
<input class="vote" data-answer="${answer}" data-hintno="${hint_pk}" type="button" value="Vote">
${hint_text}
</p>
% endfor % endfor
% endfor
<p> <p>
Don't like any of the hints above? Don't like any of the hints above?
<a class="expand" data-target="hint-submission-div" href="javascript:void(0);"> <a class="wizard-link" dest="p2" href="javascript: void(0);">
Write your own! Write your own!
</a></p> </a></p>
</div>
<div id="hint-submission-div" style="display:none"> <div class="wizard-view" id="p2">
% if hints_exist:
<p>
Choose the incorrect answer for which you want to write a hint:
</p>
% else: % else:
<p> <p>
<em> Optional. </em> Help us write hints for this problem! Think about how you would help <em>Optional.</em> Help other students by submitting a hint! Pick one of your previous
another student who made the same mistake that you did. answers for which you would like to write a hint:
</p> </p>
% endif
% for answer in user_submissions:
<a class="answer-choice" href="javascript: void(0)" value="${answer}">${answer}</a><br />
% endfor
% if hints_exist:
<br />
<p><a class="wizard-link" dest="p1" href="javascript: void(0);">
Back to voting.
</a></p>
% endif % endif
</div>
<div class="wizard-view" id="p3">
<p> <p>
Choose the incorrect answer for which you want to write a hint: Write a hint for other students who get the wrong answer of <span id="blank-answer"></span>.
<br /> <br />
% for answer in user_submissions: <a class="wizard-link" dest="p2" href="javascript: void(0);">
<input type="radio" name="answer-select" value="${answer}"> ${answer} </input><br /> Choose a different answer.
% endfor </a>
</p> </p>
<textarea cols="50" class="custom-hint" data-answer="${answer}" style="height: 200px"> <textarea cols="50" class="custom-hint" data-answer="${answer}" style="height: 200px">
Write your hint here. Please don't give away the correct answer. Write your hint here. Please don't give away the correct answer.
</textarea> </textarea>
<br/><br/> <br/><br/>
<input class="submit-hint" data-answer="${answer}" type="button" value="submit"> <input class="submit-hint" data-answer="${answer}" type="button" value="Submit">
<p>Read about <a class="expand" data-target="goodhint" href="javascript:void(0);">what makes a good hint</a>.</p> <p>Read about <a class="expand" data-target="goodhint" href="javascript:void(0);">what makes a good hint</a>.</p>
<div id="goodhint" style="display:none"> <div id="goodhint" style="display:none">
...@@ -109,12 +130,10 @@ Write your hint here. Please don't give away the correct answer. ...@@ -109,12 +130,10 @@ Write your hint here. Please don't give away the correct answer.
<p> <p>
<a href="http://www.apa.org/education/k12/misconceptions.aspx?item=2" target="_blank">Learn even more</a> <a href="http://www.apa.org/education/k12/misconceptions.aspx?item=2" target="_blank">Learn even more</a>
</p> </div> </p>
## Close out the text-hiding div. The text-hiding div only exists if there </div>
## were hints for the student to vote on. </div>
% if hints_exist:
</div>
% endif
</%def> </%def>
......
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