Commit e7a6c95c by Eugeny Kolpakov

Merge pull request #6 from open-craft/edx-release

Edx release
parents 66006d1f 4af6218b
...@@ -519,6 +519,13 @@ class PollBlock(PollBase): ...@@ -519,6 +519,13 @@ class PollBlock(PollBase):
return result 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 @staticmethod
def workbench_scenarios(): def workbench_scenarios():
""" """
...@@ -876,6 +883,13 @@ class SurveyBlock(PollBase): ...@@ -876,6 +883,13 @@ class SurveyBlock(PollBase):
return result 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 @staticmethod
def workbench_scenarios(): def workbench_scenarios():
""" """
......
...@@ -216,3 +216,7 @@ th.survey-answer { ...@@ -216,3 +216,7 @@ th.survey-answer {
text-align: right; text-align: right;
cursor: pointer; cursor: pointer;
} }
.poll-block-form-wrapper {
display: none;
}
{{ js_template|safe }} {{ js_template|safe }}
<div class="poll-block themed-xblock" data-private="{% if private_results %}1{% endif %}" data-can-vote="{% if can_vote %}1{% endif %}"> <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. #} <div class="poll-block-form-wrapper">
{% if private_results or not choice %}
<h3 class="poll-header">{{display_name}}</h3> <h3 class="poll-header">{{display_name}}</h3>
<form> <form>
<div class="poll-question-container"> <div class="poll-question-container">
...@@ -42,5 +41,5 @@ ...@@ -42,5 +41,5 @@
{% if can_view_private_results %} {% if can_view_private_results %}
<div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div> <div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div>
{% endif %} {% endif %}
{% endif %} </div>
</div> </div>
{{ js_template|safe }} {{ js_template|safe }}
<div class="poll-block themed-xblock" data-private="{% if private_results %}1{% endif %}" data-can-vote="{% if can_vote %}1{% endif %}"> <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. #} <div class="poll-block-form-wrapper">
{% if not choices or private_results %}
<h3 class="poll-header">{{block_name}}</h3> <h3 class="poll-header">{{block_name}}</h3>
<form> <form>
<table class="survey-table"> <table class="survey-table">
...@@ -54,5 +53,5 @@ ...@@ -54,5 +53,5 @@
{% if can_view_private_results %} {% if can_view_private_results %}
<div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div> <div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div>
{% endif %} {% endif %}
{% endif %} </div>
</div> </div>
...@@ -7,23 +7,14 @@ function PollUtil (runtime, element, pollType) { ...@@ -7,23 +7,14 @@ function PollUtil (runtime, element, pollType) {
// Initialization function used for both Poll Types // Initialization function used for both Poll Types
this.voteUrl = runtime.handlerUrl(element, 'vote'); this.voteUrl = runtime.handlerUrl(element, 'vote');
this.tallyURL = runtime.handlerUrl(element, 'get_results'); this.tallyURL = runtime.handlerUrl(element, 'get_results');
this.votedUrl = runtime.handlerUrl(element, 'student_voted');
this.submit = $('input[type=button]', element); this.submit = $('input[type=button]', element);
this.answers = $('input[type=radio]', element); this.answers = $('input[type=radio]', element);
this.resultsTemplate = Handlebars.compile($("#" + pollType + "-results-template", element).html()); this.resultsTemplate = Handlebars.compile($("#" + pollType + "-results-template", element).html());
this.viewResultsButton = $('.view-results-button', element); this.viewResultsButton = $('.view-results-button', element);
this.viewResultsButton.click(this.getResults); 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. return this.shouldDisplayResults();
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;
}; };
this.pollInit = function(){ this.pollInit = function(){
...@@ -83,6 +74,16 @@ function PollUtil (runtime, element, pollType) { ...@@ -83,6 +74,16 @@ function PollUtil (runtime, element, pollType) {
self.verifyAll(); 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 () { this.surveyChoices = function () {
// Grabs all selections for survey answers, and returns a mapping for them. // Grabs all selections for survey answers, and returns a mapping for them.
var choices = {}; var choices = {};
...@@ -186,12 +187,25 @@ function PollUtil (runtime, element, pollType) { ...@@ -186,12 +187,25 @@ function PollUtil (runtime, element, pollType) {
self.answers.unbind("change.enableSubmit"); self.answers.unbind("change.enableSubmit");
}; };
var run_init = this.init();
if (run_init) {
var init_map = {'poll': self.pollInit, 'survey': self.surveyInit}; var init_map = {'poll': self.pollInit, 'survey': self.surveyInit};
init_map[pollType]() 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) { function PollBlock(runtime, element) {
......
function PollEditUtil(runtime, element, pollType) { function PollEditUtil(runtime, element, pollType) {
var self = this; var self = this;
var notify; var notify;
...@@ -105,14 +104,15 @@ function PollEditUtil(runtime, element, pollType) { ...@@ -105,14 +104,15 @@ function PollEditUtil(runtime, element, pollType) {
this.empowerArrows = function(scope, topMarker, bottomMarker) { this.empowerArrows = function(scope, topMarker, bottomMarker) {
// Activates the arrows on rendered line items. // Activates the arrows on rendered line items.
$('.poll-move-up', scope).click(function () { $('.poll-move-up', scope).click(function (ev) {
var tag = $(this).parents('li'); var tag = $(this).parents('li');
if (tag.index() <= ($(topMarker).index() + 1)){ if (tag.index() <= ($(topMarker).index() + 1)){
return; return;
} }
tag.prev().before(tag); tag.prev().before(tag);
tag.fadeOut(0).fadeIn('slow', 'swing'); tag.fadeOut(0).fadeIn('slow', 'swing');
self.scrollTo(tag) self.scrollTo(tag);
ev.preventDefault();
}); });
$('.poll-move-down', scope).click(function () { $('.poll-move-down', scope).click(function () {
var tag = $(this).parents('li'); var tag = $(this).parents('li');
...@@ -121,7 +121,8 @@ function PollEditUtil(runtime, element, pollType) { ...@@ -121,7 +121,8 @@ function PollEditUtil(runtime, element, pollType) {
} }
tag.next().after(tag); tag.next().after(tag);
tag.fadeOut(0).fadeIn('slow', 'swing'); tag.fadeOut(0).fadeIn('slow', 'swing');
self.scrollTo(tag) self.scrollTo(tag);
ev.preventDefault();
}); });
}; };
......
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