[IMP] Score for each question
bzr revid: rim@openerp.com-20140416151320-1zsxsss60zi9w11y
This commit is contained in:
parent
598d23a4a5
commit
4aed9ce7e7
|
@ -214,6 +214,24 @@ class WebsiteSurvey(http.Controller):
|
|||
_logger.warning("[survey] No answer has been found for question %s marked as non skipped" % answer_tag)
|
||||
return json.dumps(ret)
|
||||
|
||||
# AJAX scores loading for quiz correction mode
|
||||
@http.route(['/survey/scores/<model("survey.survey"):survey>/<string:token>'],
|
||||
type='http', auth='public', multilang=True, website=True)
|
||||
def get_scores(self, survey, token, page=None, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
user_input_line_obj = request.registry['survey.user_input_line']
|
||||
ret = {}
|
||||
|
||||
# Fetch answers
|
||||
ids = user_input_line_obj.search(cr, uid, [('user_input_id.token', '=', token)], context=context)
|
||||
previous_answers = user_input_line_obj.browse(cr, uid, ids, context=context)
|
||||
|
||||
# Compute score for each question
|
||||
for answer in previous_answers:
|
||||
tmp_score = ret.get(answer.question_id.id, 0.0)
|
||||
ret.update({answer.question_id.id: tmp_score + answer.quizz_mark})
|
||||
return json.dumps(ret)
|
||||
|
||||
# AJAX submission of a page
|
||||
@http.route(['/survey/submit/<model("survey.survey"):survey>'],
|
||||
type='http', auth='public', multilang=True, website=True)
|
||||
|
|
|
@ -30,7 +30,9 @@ $(document).ready(function () {
|
|||
var prefill_controller = the_form.attr("data-prefill");
|
||||
var validate_controller = the_form.attr("data-validate");
|
||||
var submit_controller = the_form.attr("data-submit");
|
||||
var scores_controller = the_form.attr("data-scores");
|
||||
var print_mode = false;
|
||||
var quiz_correction_mode = false;
|
||||
|
||||
// Printing mode: will disable all the controls in the form
|
||||
if (_.isUndefined(submit_controller)) {
|
||||
|
@ -38,6 +40,11 @@ $(document).ready(function () {
|
|||
print_mode = true;
|
||||
}
|
||||
|
||||
// Quizz correction mode
|
||||
if (! _.isUndefined(scores_controller)) {
|
||||
quiz_correction_mode = true;
|
||||
}
|
||||
|
||||
// Custom code for right behavior of radio buttons with comments box
|
||||
$('.js_comments>input[type="text"]').focusin(function(){
|
||||
$(this).prev().find('>input').attr("checked","checked");
|
||||
|
@ -88,6 +95,20 @@ $(document).ready(function () {
|
|||
return prefill_def;
|
||||
}
|
||||
|
||||
// Display score if quiz correction mode
|
||||
function display_scores(){
|
||||
var score_def = $.ajax(scores_controller, {dataType: "json"})
|
||||
.done(function(json_data){
|
||||
_.each(json_data, function(value, key){
|
||||
the_form.find("span[data-score-question=" + key + "]").text("Your score: " + value);
|
||||
});
|
||||
})
|
||||
.fail(function(){
|
||||
console.warn("[survey] Unable to load score data");
|
||||
});
|
||||
return score_def;
|
||||
}
|
||||
|
||||
// Parameters for form submission
|
||||
$('.js_surveyform').ajaxForm({
|
||||
url: submit_controller,
|
||||
|
@ -126,6 +147,9 @@ $(document).ready(function () {
|
|||
|
||||
// Launch prefilling
|
||||
prefill();
|
||||
if(quiz_correction_mode === true){
|
||||
display_scores();
|
||||
}
|
||||
|
||||
console.debug("[survey] Custom JS for survey loaded!");
|
||||
});
|
||||
|
|
|
@ -256,7 +256,7 @@
|
|||
<h1><span t-field='survey.title'/></h1>
|
||||
<t t-if="survey.description"><div t-field='survey.description'/></t>
|
||||
</div>
|
||||
<form role="form" method="post" class="js_surveyform" t-att-name="'%s' % (survey.id)" t-att-data-prefill="'/survey/prefill/%s/%s' % (slug(survey), token)">
|
||||
<form role="form" method="post" class="js_surveyform" t-att-name="'%s' % (survey.id)" t-att-data-prefill="'/survey/prefill/%s/%s' % (slug(survey), token)" t-att-data-scores="'/survey/scores/%s/%s' % (slug(survey), token) if quizz_correction else ''">
|
||||
<t t-foreach="survey.page_ids" t-as="page">
|
||||
<div class="page-header">
|
||||
<h1 t-field='page.title' />
|
||||
|
@ -268,7 +268,7 @@
|
|||
<h2>
|
||||
<span t-field='question.question' />
|
||||
<span t-if="question.constr_mandatory" class="text-danger">*</span>
|
||||
<span t-if="quizz_correction" class="badge" t-att-name="question.id"></span>
|
||||
<span t-if="quizz_correction" class="badge" t-att-data-score-question="question.id"></span>
|
||||
</h2>
|
||||
<t t-if="question.description"><div class="text-muted" t-field='question.description' /></t>
|
||||
<t t-if="question.type == 'free_text'"><t t-call="survey.free_text"/></t>
|
||||
|
|
Loading…
Reference in New Issue