Commit d3cf58ab by E. Kolpakov

Fix for TNL-3065: poll shows voting options if voted and subsection navigation is used

parent 7b892f3b
......@@ -519,6 +519,13 @@ class PollBlock(PollBase):
return result
@XBlock.json_handler
def student_voted(self, data, suffix=''):
return {
'voted': self.get_choice() is not None,
'private_results': self.private_results
}
@staticmethod
def workbench_scenarios():
"""
......@@ -876,6 +883,13 @@ class SurveyBlock(PollBase):
return result
@XBlock.json_handler
def student_voted(self, data, suffix=''):
return {
'voted': self.get_choices() is not None,
'private_results': self.private_results
}
@staticmethod
def workbench_scenarios():
"""
......
......@@ -216,3 +216,7 @@ th.survey-answer {
text-align: right;
cursor: pointer;
}
.poll-block-form-wrapper {
display: none;
}
{{ js_template|safe }}
<div class="poll-block themed-xblock" data-private="{% if private_results %}1{% endif %}" data-can-vote="{% if can_vote %}1{% endif %}">
{# If no form is present, the Javascript will load the results instead. #}
{% if private_results or not choice %}
<h3 class="poll-header">{{display_name}}</h3>
<form>
<div class="poll-question-container">
{{question|safe}}
</div>
<ul class="poll-answers">
{% for key, value in answers %}
<li class="poll-answer">
<input type="radio" name="choice" id="{{url_name}}-answer-{{key}}" value="{{key}}" {% if choice == key %}checked{% endif %}/>
{% if value.img %}
<div class="poll-image">
<label for="{{url_name}}-answer-{{key}}" class="poll-image-label">
<img src="{{value.img}}" alt="{{value.img_alt|default_if_none:''}}"/>
</label>
</div>
{% endif %}
<label class="poll-answer" for="{{url_name}}-answer-{{key}}">{{value.label|safe}}</label>
</li>
{% endfor %}
</ul>
<input class="input-main" type="button" name="poll-submit" value="{% if choice %}Resubmit{% else %}Submit{% endif %}" disabled />
</form>
<div class="poll-voting-thanks{% if not choice or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div>
<div class="poll-submissions-count poll-hidden">
You have used <span class="poll-current-count">{{ submissions_count }}</span>
out of <span class="poll-max-submissions">{{ max_submissions }}</span> submissions.
</div>
{% if feedback %}
<div class="poll-feedback-container{% if not choice %} poll-hidden{% endif %}">
<hr />
<h3 class="poll-header">Feedback</h3>
<div class="poll-feedback">
{{feedback|safe}}
</div>
</div>
{% endif %}
<div class="poll-block-form-wrapper">
<h3 class="poll-header">{{display_name}}</h3>
<form>
<div class="poll-question-container">
{{question|safe}}
</div>
<ul class="poll-answers">
{% for key, value in answers %}
<li class="poll-answer">
<input type="radio" name="choice" id="{{url_name}}-answer-{{key}}" value="{{key}}" {% if choice == key %}checked{% endif %}/>
{% if value.img %}
<div class="poll-image">
<label for="{{url_name}}-answer-{{key}}" class="poll-image-label">
<img src="{{value.img}}" alt="{{value.img_alt|default_if_none:''}}"/>
</label>
</div>
{% endif %}
<label class="poll-answer" for="{{url_name}}-answer-{{key}}">{{value.label|safe}}</label>
</li>
{% endfor %}
</ul>
<input class="input-main" type="button" name="poll-submit" value="{% if choice %}Resubmit{% else %}Submit{% endif %}" disabled />
</form>
<div class="poll-voting-thanks{% if not choice or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div>
<div class="poll-submissions-count poll-hidden">
You have used <span class="poll-current-count">{{ submissions_count }}</span>
out of <span class="poll-max-submissions">{{ max_submissions }}</span> submissions.
</div>
{% if feedback %}
<div class="poll-feedback-container{% if not choice %} poll-hidden{% endif %}">
<hr />
<h3 class="poll-header">Feedback</h3>
<div class="poll-feedback">
{{feedback|safe}}
</div>
</div>
{% endif %}
{% if can_view_private_results %}
<div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div>
{% endif %}
{% endif %}
{% if can_view_private_results %}
<div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div>
{% endif %}
</div>
</div>
{{ js_template|safe }}
<div class="poll-block themed-xblock" data-private="{% if private_results %}1{% endif %}" data-can-vote="{% if can_vote %}1{% endif %}">
{# If no form is present, the Javascript will load the results instead. #}
{% if not choices or private_results %}
<h3 class="poll-header">{{block_name}}</h3>
<form>
<table class="survey-table">
<thead>
<tr>
<th></th>
{% for answer, label in answers %}
<th class="survey-answer">{{label}}</th>
{% endfor %}
</tr>
</thead>
{% for key, question in questions %}
<tr class="survey-row">
<td class="survey-question">
{% if question.img %}
<div class="poll-image-td">
<img src="{{question.img}}" alt="{{question.img_alt|default_if_none:''}}"/>
</div>
{% endif %}
{{question.label|safe}}
</td>
{% for answer, label in answers %}
<td class="survey-option">
<label>
<input type="radio" name="{{key}}" value="{{answer}}"{% if question.choice == answer %} checked{% endif %}/>
<span class="sr">{{label}}</span>
</label>
</td>
<div class="poll-block-form-wrapper">
<h3 class="poll-header">{{block_name}}</h3>
<form>
<table class="survey-table">
<thead>
<tr>
<th></th>
{% for answer, label in answers %}
<th class="survey-answer">{{label}}</th>
{% endfor %}
</tr>
</thead>
{% for key, question in questions %}
<tr class="survey-row">
<td class="survey-question">
{% if question.img %}
<div class="poll-image-td">
<img src="{{question.img}}" alt="{{question.img_alt|default_if_none:''}}"/>
</div>
{% endif %}
{{question.label|safe}}
</td>
{% for answer, label in answers %}
<td class="survey-option">
<label>
<input type="radio" name="{{key}}" value="{{answer}}"{% if question.choice == answer %} checked{% endif %}/>
<span class="sr">{{label}}</span>
</label>
</td>
{% endfor %}
</tr>
{% endfor %}
</tr>
{% endfor %}
</table>
<input class="input-main" type="button" name="poll-submit" value="{% if choices and can_vote %}Resubmit{% else %}Submit{% endif %}" disabled />
</form>
<div class="poll-voting-thanks{% if not choices or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div>
<div class="poll-submissions-count poll-hidden">
You have used <span class="poll-current-count">{{ submissions_count }}</span>
out of <span class="poll-max-submissions">{{ max_submissions }}</span> submissions.
</div>
{% if feedback %}
<div class="poll-feedback-container{% if not choices %} poll-hidden{% endif %}">
<hr />
<h3 class="poll-header">Feedback</h3>
<div class="poll-feedback">
{{feedback|safe}}
</div>
</table>
<input class="input-main" type="button" name="poll-submit" value="{% if choices and can_vote %}Resubmit{% else %}Submit{% endif %}" disabled />
</form>
<div class="poll-voting-thanks{% if not choices or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div>
<div class="poll-submissions-count poll-hidden">
You have used <span class="poll-current-count">{{ submissions_count }}</span>
out of <span class="poll-max-submissions">{{ max_submissions }}</span> submissions.
</div>
{% endif %}
{% if feedback %}
<div class="poll-feedback-container{% if not choices %} poll-hidden{% endif %}">
<hr />
<h3 class="poll-header">Feedback</h3>
<div class="poll-feedback">
{{feedback|safe}}
</div>
</div>
{% endif %}
{% if can_view_private_results %}
<div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div>
{% endif %}
{% endif %}
{% if can_view_private_results %}
<div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div>
{% endif %}
</div>
</div>
......@@ -7,23 +7,14 @@ function PollUtil (runtime, element, pollType) {
// Initialization function used for both Poll Types
this.voteUrl = runtime.handlerUrl(element, 'vote');
this.tallyURL = runtime.handlerUrl(element, 'get_results');
this.votedUrl = runtime.handlerUrl(element, 'student_voted');
this.submit = $('input[type=button]', element);
this.answers = $('input[type=radio]', element);
this.resultsTemplate = Handlebars.compile($("#" + pollType + "-results-template", element).html());
this.viewResultsButton = $('.view-results-button', element);
this.viewResultsButton.click(this.getResults);
// If the submit button doesn't exist, the user has already
// selected a choice. Render results instead of initializing machinery.
if (! self.submit.length) {
self.onSubmit({'success': true});
return false;
}
var max_submissions = parseInt($('.poll-max-submissions', element).text());
var current_count = parseInt($('.poll-current-count', element).text());
if (max_submissions > 1 && current_count > 0) {
$('.poll-submissions-count', element).show();
}
return true;
return this.shouldDisplayResults();
};
this.pollInit = function(){
......@@ -83,6 +74,16 @@ function PollUtil (runtime, element, pollType) {
self.verifyAll();
};
this.shouldDisplayResults = function() {
return $.ajax({
// Semantically, this would be better as GET, but we can use helper
// functions with POST.
type: "POST",
url: self.votedUrl,
data: JSON.stringify({})
});
};
this.surveyChoices = function () {
// Grabs all selections for survey answers, and returns a mapping for them.
var choices = {};
......@@ -186,12 +187,25 @@ function PollUtil (runtime, element, pollType) {
self.answers.unbind("change.enableSubmit");
};
var run_init = this.init();
if (run_init) {
var init_map = {'poll': self.pollInit, 'survey': self.surveyInit};
init_map[pollType]()
}
var init_map = {'poll': self.pollInit, 'survey': self.surveyInit};
this.init().done(function(data) {
// If the submit button doesn't exist, the user has already
// selected a choice. Render results instead of initializing machinery.
if (data['voted'] && ! data['private_results']) {
self.onSubmit({'success': true});
$('.poll-block-form-wrapper', element).hide();
}
else {
$('.poll-block-form-wrapper', element).show();
var max_submissions = parseInt($('.poll-max-submissions', element).text());
var current_count = parseInt($('.poll-current-count', element).text());
if (max_submissions > 1 && current_count > 0) {
$('.poll-submissions-count', element).show();
}
}
}).always(function(){
init_map[pollType]();
});
}
function PollBlock(runtime, element) {
......
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