Commit 45cffaba177e6dad78e27054cc22dabfe3a0a4cc
1 parent
fbc63692
Exists in
master
and in
1 other branch
- fixed tries left
- code simplification in topics.js - clarified comments on question numeric-interval
Showing
3 changed files
with
32 additions
and
29 deletions
Show diff stats
questions.py
... | ... | @@ -302,7 +302,7 @@ class QuestionNumericInterval(Question): |
302 | 302 | try: # replace , by . and convert to float |
303 | 303 | answer = float(self['answer'].replace(',', '.', 1)) |
304 | 304 | except ValueError: |
305 | - self['comments'] = 'A resposta não é numérica.' | |
305 | + self['comments'] = 'A resposta tem de ser numérica, por exemplo 12.345.' | |
306 | 306 | self['grade'] = 0.0 |
307 | 307 | else: |
308 | 308 | self['grade'] = 1.0 if lower <= answer <= upper else 0.0 | ... | ... |
static/js/topic.js
... | ... | @@ -7,6 +7,24 @@ $.fn.extend({ |
7 | 7 | } |
8 | 8 | }); |
9 | 9 | |
10 | +function showTriesLeft(tries) { | |
11 | + var tries_msg; | |
12 | + | |
13 | + switch (tries) { | |
14 | + case 0: | |
15 | + tries_msg = ""; | |
16 | + break; | |
17 | + case 1: | |
18 | + tries_msg = "(1 tentativa)"; | |
19 | + break; | |
20 | + default: | |
21 | + tries_msg = "(" + tries + " tentativas)"; | |
22 | + } | |
23 | + | |
24 | + $("#tries").html(tries_msg); | |
25 | +} | |
26 | + | |
27 | + | |
10 | 28 | // Get current question |
11 | 29 | function getQuestion() { |
12 | 30 | $.ajax({ |
... | ... | @@ -32,10 +50,9 @@ function updateQuestion(response) { |
32 | 50 | break; |
33 | 51 | case "finished_topic": |
34 | 52 | $('#submit, #comments, #solution').remove(); |
35 | - $("#content").html(response["params"]["question"]); | |
53 | + $("#content").html(response["params"]["question"]).animateCSS('tada'); | |
36 | 54 | $('#topic_progress').css('width', '100%').attr('aria-valuenow', 100); |
37 | - $("#content").animateCSS('tada'); | |
38 | - setTimeout(function(){ window.location.replace('/'); }, 2000); | |
55 | + setTimeout(function(){window.location.replace('/');}, 2000); | |
39 | 56 | break; |
40 | 57 | } |
41 | 58 | } |
... | ... | @@ -43,22 +60,14 @@ function updateQuestion(response) { |
43 | 60 | |
44 | 61 | function new_question(type, question, tries, progress) { |
45 | 62 | window.scrollTo(0, 0); |
46 | - $("#question_div").html(question); | |
63 | + $("#question_div").html(question).animateCSS('bounceInDown'); | |
64 | + showTriesLeft(tries); | |
47 | 65 | $("#comments, #solution").html(""); |
48 | - if (type == "info") { | |
49 | - $("#submit").html("Continuar"); | |
50 | - } | |
51 | - else { | |
52 | - $("#submit").html("Responder"); | |
53 | - } | |
54 | - $("#submit").off(); | |
55 | - $("#submit").click(postAnswer); | |
56 | - $("#tries").html(tries); | |
66 | + var btn_text = (type == "info") ? "Continuar" : "Responder"; | |
67 | + $("#submit").html(btn_text).off().click(postAnswer); | |
57 | 68 | $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); |
58 | 69 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); |
59 | 70 | |
60 | - $('#question_div').animateCSS('bounceInDown'); | |
61 | - | |
62 | 71 | // enable shift+enter to submit |
63 | 72 | $("input:text, input:radio, input:checkbox").keydown(function (e) { |
64 | 73 | if (e.keyCode == 13) { |
... | ... | @@ -104,21 +113,18 @@ function getFeedback(response) { |
104 | 113 | $('#wrong').hide(); |
105 | 114 | $('#comments').html(params['comments']); |
106 | 115 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); |
107 | - $("#submit").html("Continuar"); | |
108 | - $("#submit").off(); | |
109 | - $("#submit").click(getQuestion); | |
116 | + $("#submit").html("Continuar").off().click(getQuestion); | |
110 | 117 | $("#link_solution_on_right").click(function(){ |
111 | 118 | $("#right").hide(); |
112 | - $('#solution').html(params['solution']); | |
119 | + $('#solution').html(params['solution']).animateCSS('flipInX'); | |
113 | 120 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]); |
114 | - $('#solution').animateCSS('flipInX'); | |
115 | 121 | }); |
116 | 122 | break; |
117 | 123 | |
118 | 124 | case "try_again": |
119 | 125 | $('#question_div').animateCSS('shake'); |
120 | 126 | $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); |
121 | - $("#tries").html(params["tries"]); | |
127 | + showTriesLeft(params["tries"]); | |
122 | 128 | $('#comments').html(params['comments']); |
123 | 129 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"#comments"]); |
124 | 130 | break; |
... | ... | @@ -127,19 +133,16 @@ function getFeedback(response) { |
127 | 133 | $('#right').hide(); |
128 | 134 | $('#wrong').show(); |
129 | 135 | $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); |
130 | - $("#tries").html(params["tries"]); | |
136 | + showTriesLeft(params["tries"]); | |
131 | 137 | $('#comments').html(params['comments']); |
132 | 138 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); |
133 | 139 | $("#link_solution_on_wrong").click(function () { |
134 | 140 | $("#wrong").hide(); |
135 | - $('#solution').html(params['solution']); | |
141 | + $('#solution').html(params['solution']).animateCSS('flipInX'); | |
136 | 142 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]); |
137 | - $('#solution').animateCSS('flipInX'); | |
138 | 143 | }); |
139 | 144 | $("fieldset").attr("disabled", "disabled"); |
140 | - $("#submit").html("Continuar"); | |
141 | - $("#submit").off(); | |
142 | - $("#submit").click(getQuestion); | |
145 | + $("#submit").html("Continuar").off().click(getQuestion); | |
143 | 146 | break; |
144 | 147 | } |
145 | 148 | } | ... | ... |
templates/question.html