diff --git a/questions.py b/questions.py index ad2c80b..ad0e9bb 100644 --- a/questions.py +++ b/questions.py @@ -302,7 +302,7 @@ class QuestionNumericInterval(Question): try: # replace , by . and convert to float answer = float(self['answer'].replace(',', '.', 1)) except ValueError: - self['comments'] = 'A resposta não é numérica.' + self['comments'] = 'A resposta tem de ser numérica, por exemplo 12.345.' self['grade'] = 0.0 else: self['grade'] = 1.0 if lower <= answer <= upper else 0.0 diff --git a/static/js/topic.js b/static/js/topic.js index 3b5e01f..e25f272 100644 --- a/static/js/topic.js +++ b/static/js/topic.js @@ -7,6 +7,24 @@ $.fn.extend({ } }); +function showTriesLeft(tries) { + var tries_msg; + + switch (tries) { + case 0: + tries_msg = ""; + break; + case 1: + tries_msg = "(1 tentativa)"; + break; + default: + tries_msg = "(" + tries + " tentativas)"; + } + + $("#tries").html(tries_msg); +} + + // Get current question function getQuestion() { $.ajax({ @@ -32,10 +50,9 @@ function updateQuestion(response) { break; case "finished_topic": $('#submit, #comments, #solution').remove(); - $("#content").html(response["params"]["question"]); + $("#content").html(response["params"]["question"]).animateCSS('tada'); $('#topic_progress').css('width', '100%').attr('aria-valuenow', 100); - $("#content").animateCSS('tada'); - setTimeout(function(){ window.location.replace('/'); }, 2000); + setTimeout(function(){window.location.replace('/');}, 2000); break; } } @@ -43,22 +60,14 @@ function updateQuestion(response) { function new_question(type, question, tries, progress) { window.scrollTo(0, 0); - $("#question_div").html(question); + $("#question_div").html(question).animateCSS('bounceInDown'); + showTriesLeft(tries); $("#comments, #solution").html(""); - if (type == "info") { - $("#submit").html("Continuar"); - } - else { - $("#submit").html("Responder"); - } - $("#submit").off(); - $("#submit").click(postAnswer); - $("#tries").html(tries); + var btn_text = (type == "info") ? "Continuar" : "Responder"; + $("#submit").html(btn_text).off().click(postAnswer); $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); - $('#question_div').animateCSS('bounceInDown'); - // enable shift+enter to submit $("input:text, input:radio, input:checkbox").keydown(function (e) { if (e.keyCode == 13) { @@ -104,21 +113,18 @@ function getFeedback(response) { $('#wrong').hide(); $('#comments').html(params['comments']); MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); - $("#submit").html("Continuar"); - $("#submit").off(); - $("#submit").click(getQuestion); + $("#submit").html("Continuar").off().click(getQuestion); $("#link_solution_on_right").click(function(){ $("#right").hide(); - $('#solution').html(params['solution']); + $('#solution').html(params['solution']).animateCSS('flipInX'); MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]); - $('#solution').animateCSS('flipInX'); }); break; case "try_again": $('#question_div').animateCSS('shake'); $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); - $("#tries").html(params["tries"]); + showTriesLeft(params["tries"]); $('#comments').html(params['comments']); MathJax.Hub.Queue(["Typeset",MathJax.Hub,"#comments"]); break; @@ -127,19 +133,16 @@ function getFeedback(response) { $('#right').hide(); $('#wrong').show(); $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); - $("#tries").html(params["tries"]); + showTriesLeft(params["tries"]); $('#comments').html(params['comments']); MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); $("#link_solution_on_wrong").click(function () { $("#wrong").hide(); - $('#solution').html(params['solution']); + $('#solution').html(params['solution']).animateCSS('flipInX'); MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]); - $('#solution').animateCSS('flipInX'); }); $("fieldset").attr("disabled", "disabled"); - $("#submit").html("Continuar"); - $("#submit").off(); - $("#submit").click(getQuestion); + $("#submit").html("Continuar").off().click(getQuestion); break; } } diff --git a/templates/question.html b/templates/question.html index 595749b..434a349 100644 --- a/templates/question.html +++ b/templates/question.html @@ -8,4 +8,4 @@ {% block answer %}{% end %} -

( tentativas)

+

-- libgit2 0.21.2