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"> {{question|safe}}
{{question|safe}} </div>
</div> <ul class="poll-answers">
<ul class="poll-answers"> {% for key, value in answers %}
{% for key, value in answers %} <li class="poll-answer">
<li class="poll-answer"> <input type="radio" name="choice" id="{{url_name}}-answer-{{key}}" value="{{key}}" {% if choice == key %}checked{% endif %}/>
<input type="radio" name="choice" id="{{url_name}}-answer-{{key}}" value="{{key}}" {% if choice == key %}checked{% endif %}/> {% if value.img %}
{% if value.img %} <div class="poll-image">
<div class="poll-image"> <label for="{{url_name}}-answer-{{key}}" class="poll-image-label">
<label for="{{url_name}}-answer-{{key}}" class="poll-image-label"> <img src="{{value.img}}" alt="{{value.img_alt|default_if_none:''}}"/>
<img src="{{value.img}}" alt="{{value.img_alt|default_if_none:''}}"/> </label>
</label> </div>
</div> {% endif %}
{% endif %} <label class="poll-answer" for="{{url_name}}-answer-{{key}}">{{value.label|safe}}</label>
<label class="poll-answer" for="{{url_name}}-answer-{{key}}">{{value.label|safe}}</label> </li>
</li> {% endfor %}
{% endfor %} </ul>
</ul> <input class="input-main" type="button" name="poll-submit" value="{% if choice %}Resubmit{% else %}Submit{% endif %}" disabled />
<input class="input-main" type="button" name="poll-submit" value="{% if choice %}Resubmit{% else %}Submit{% endif %}" disabled /> </form>
</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-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">
<div class="poll-submissions-count poll-hidden"> You have used <span class="poll-current-count">{{ submissions_count }}</span>
You have used <span class="poll-current-count">{{ submissions_count }}</span> out of <span class="poll-max-submissions">{{ max_submissions }}</span> submissions.
out of <span class="poll-max-submissions">{{ max_submissions }}</span> submissions. </div>
</div> {% if feedback %}
{% if feedback %} <div class="poll-feedback-container{% if not choice %} poll-hidden{% endif %}">
<div class="poll-feedback-container{% if not choice %} poll-hidden{% endif %}"> <hr />
<hr /> <h3 class="poll-header">Feedback</h3>
<h3 class="poll-header">Feedback</h3> <div class="poll-feedback">
<div class="poll-feedback"> {{feedback|safe}}
{{feedback|safe}} </div>
</div> </div>
</div> {% endif %}
{% endif %}
{% 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"> <thead>
<thead> <tr>
<tr> <th></th>
<th></th> {% for answer, label in answers %}
{% for answer, label in answers %} <th class="survey-answer">{{label}}</th>
<th class="survey-answer">{{label}}</th> {% endfor %}
{% endfor %} </tr>
</tr> </thead>
</thead> {% for key, question in questions %}
{% for key, question in questions %} <tr class="survey-row">
<tr class="survey-row"> <td class="survey-question">
<td class="survey-question"> {% if question.img %}
{% if question.img %} <div class="poll-image-td">
<div class="poll-image-td"> <img src="{{question.img}}" alt="{{question.img_alt|default_if_none:''}}"/>
<img src="{{question.img}}" alt="{{question.img_alt|default_if_none:''}}"/> </div>
</div> {% endif %}
{% endif %} {{question.label|safe}}
{{question.label|safe}} </td>
</td> {% for answer, label in answers %}
{% for answer, label in answers %} <td class="survey-option">
<td class="survey-option"> <label>
<label> <input type="radio" name="{{key}}" value="{{answer}}"{% if question.choice == answer %} checked{% endif %}/>
<input type="radio" name="{{key}}" value="{{answer}}"{% if question.choice == answer %} checked{% endif %}/> <span class="sr">{{label}}</span>
<span class="sr">{{label}}</span> </label>
</label> </td>
</td> {% endfor %}
</tr>
{% endfor %} {% endfor %}
</tr> </table>
{% endfor %} <input class="input-main" type="button" name="poll-submit" value="{% if choices and can_vote %}Resubmit{% else %}Submit{% endif %}" disabled />
</table> </form>
<input class="input-main" type="button" name="poll-submit" value="{% if choices and can_vote %}Resubmit{% else %}Submit{% endif %}" disabled /> <div class="poll-voting-thanks{% if not choices or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div>
</form> <div class="poll-submissions-count poll-hidden">
<div class="poll-voting-thanks{% if not choices or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div> You have used <span class="poll-current-count">{{ submissions_count }}</span>
<div class="poll-submissions-count poll-hidden"> out of <span class="poll-max-submissions">{{ max_submissions }}</span> submissions.
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>
</div> </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 %} {% 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(); var init_map = {'poll': self.pollInit, 'survey': self.surveyInit};
if (run_init) { this.init().done(function(data) {
var init_map = {'poll': self.pollInit, 'survey': self.surveyInit}; // If the submit button doesn't exist, the user has already
init_map[pollType]() // 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