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):
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 %}
<div class="poll-block-form-wrapper">
<h3 class="poll-header">{{display_name}}</h3>
<form>
<div class="poll-question-container">
......@@ -42,5 +41,5 @@
{% if can_view_private_results %}
<div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div>
{% endif %}
{% 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 %}
<div class="poll-block-form-wrapper">
<h3 class="poll-header">{{block_name}}</h3>
<form>
<table class="survey-table">
......@@ -54,5 +53,5 @@
{% if can_view_private_results %}
<div class="view-results-button-wrapper"><button class="view-results-button">View results</button></div>
{% endif %}
{% 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]()
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 PollEditUtil(runtime, element, pollType) {
var self = this;
var notify;
......@@ -105,14 +104,15 @@ function PollEditUtil(runtime, element, pollType) {
this.empowerArrows = function(scope, topMarker, bottomMarker) {
// 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');
if (tag.index() <= ($(topMarker).index() + 1)){
return;
}
tag.prev().before(tag);
tag.fadeOut(0).fadeIn('slow', 'swing');
self.scrollTo(tag)
self.scrollTo(tag);
ev.preventDefault();
});
$('.poll-move-down', scope).click(function () {
var tag = $(this).parents('li');
......@@ -121,7 +121,8 @@ function PollEditUtil(runtime, element, pollType) {
}
tag.next().after(tag);
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