From 7c93b45d0c0a7c2a0bc1d131593fe11258c028d2 Mon Sep 17 00:00:00 2001 From: Felix Sun Date: Wed, 31 Jul 2013 17:13:32 -0400 Subject: [PATCH] Added wizard / slideshow style hint collection script. Still requires a little polishing, I think. --- .../js/src/crowdsource_hinter/display.coffee | 32 +++++- common/templates/hinter_display.html | 101 +++++++++++------- 2 files changed, 87 insertions(+), 46 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/crowdsource_hinter/display.coffee b/common/lib/xmodule/xmodule/js/src/crowdsource_hinter/display.coffee index a1dc35a604..34956603c6 100644 --- a/common/lib/xmodule/xmodule/js/src/crowdsource_hinter/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/crowdsource_hinter/display.coffee @@ -36,8 +36,9 @@ class @Hinter @$('input.vote').click @vote @$('input.submit-hint').click @submit_hint @$('.custom-hint').click @clear_default_text - @$('#answer-tabs').tabs({active: 0}) @$('.expand').click @expand + @$('.wizard-link').click @wizard_link_handle + @$('.answer-choice').click @answer_choice_handle expand: (eventObj) => target = @$('#' + @$(eventObj.currentTarget).data('target')) @@ -55,11 +56,10 @@ class @Hinter submit_hint: (eventObj) => textarea = $('.custom-hint') - answer = $('input:radio[name=answer-select]:checked').val() - if answer == undefined - # The user didn't choose an answer. Do nothing. + if @answer == '' + # The user didn't choose an answer, somehow. Do nothing. return - post_json = {'answer': answer, 'hint': textarea.val()} + post_json = {'answer': @answer, 'hint': textarea.val()} $.postWithPrefix "#{@url}/submit_hint",post_json, (response) => @render(response.contents) @@ -69,6 +69,15 @@ class @Hinter target.val('') 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) -> if content # Trim leading and trailing whitespace @@ -82,3 +91,16 @@ class @Hinter @$('#previous-answer-0').css('display', 'inline') else @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 diff --git a/common/templates/hinter_display.html b/common/templates/hinter_display.html index 8fd219e847..0f350083de 100644 --- a/common/templates/hinter_display.html +++ b/common/templates/hinter_display.html @@ -34,50 +34,71 @@ for pk, hint_text in pk_dict.items(): pk_list.append([answer, pk]) json_pk_list = json.dumps(pk_list) - %> - % if hints_exist: -

- Optional. Help us improve our hints! Which hint was most helpful to you? -

+ %> - - - % for answer, pk_dict in answer_to_hints.items(): - % for hint_pk, hint_text in pk_dict.items(): -

- - ${hint_text} -

- % endfor - % endfor - -

- Don't like any of the hints above? - - Write your own! -

- - + +