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,7 +302,7 @@ class QuestionNumericInterval(Question): | ||
302 | try: # replace , by . and convert to float | 302 | try: # replace , by . and convert to float |
303 | answer = float(self['answer'].replace(',', '.', 1)) | 303 | answer = float(self['answer'].replace(',', '.', 1)) |
304 | except ValueError: | 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 | self['grade'] = 0.0 | 306 | self['grade'] = 0.0 |
307 | else: | 307 | else: |
308 | self['grade'] = 1.0 if lower <= answer <= upper else 0.0 | 308 | self['grade'] = 1.0 if lower <= answer <= upper else 0.0 |
static/js/topic.js
@@ -7,6 +7,24 @@ $.fn.extend({ | @@ -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 | // Get current question | 28 | // Get current question |
11 | function getQuestion() { | 29 | function getQuestion() { |
12 | $.ajax({ | 30 | $.ajax({ |
@@ -32,10 +50,9 @@ function updateQuestion(response) { | @@ -32,10 +50,9 @@ function updateQuestion(response) { | ||
32 | break; | 50 | break; |
33 | case "finished_topic": | 51 | case "finished_topic": |
34 | $('#submit, #comments, #solution').remove(); | 52 | $('#submit, #comments, #solution').remove(); |
35 | - $("#content").html(response["params"]["question"]); | 53 | + $("#content").html(response["params"]["question"]).animateCSS('tada'); |
36 | $('#topic_progress').css('width', '100%').attr('aria-valuenow', 100); | 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 | break; | 56 | break; |
40 | } | 57 | } |
41 | } | 58 | } |
@@ -43,22 +60,14 @@ function updateQuestion(response) { | @@ -43,22 +60,14 @@ function updateQuestion(response) { | ||
43 | 60 | ||
44 | function new_question(type, question, tries, progress) { | 61 | function new_question(type, question, tries, progress) { |
45 | window.scrollTo(0, 0); | 62 | window.scrollTo(0, 0); |
46 | - $("#question_div").html(question); | 63 | + $("#question_div").html(question).animateCSS('bounceInDown'); |
64 | + showTriesLeft(tries); | ||
47 | $("#comments, #solution").html(""); | 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 | $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); | 68 | $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); |
58 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); | 69 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); |
59 | 70 | ||
60 | - $('#question_div').animateCSS('bounceInDown'); | ||
61 | - | ||
62 | // enable shift+enter to submit | 71 | // enable shift+enter to submit |
63 | $("input:text, input:radio, input:checkbox").keydown(function (e) { | 72 | $("input:text, input:radio, input:checkbox").keydown(function (e) { |
64 | if (e.keyCode == 13) { | 73 | if (e.keyCode == 13) { |
@@ -104,21 +113,18 @@ function getFeedback(response) { | @@ -104,21 +113,18 @@ function getFeedback(response) { | ||
104 | $('#wrong').hide(); | 113 | $('#wrong').hide(); |
105 | $('#comments').html(params['comments']); | 114 | $('#comments').html(params['comments']); |
106 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); | 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 | $("#link_solution_on_right").click(function(){ | 117 | $("#link_solution_on_right").click(function(){ |
111 | $("#right").hide(); | 118 | $("#right").hide(); |
112 | - $('#solution').html(params['solution']); | 119 | + $('#solution').html(params['solution']).animateCSS('flipInX'); |
113 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]); | 120 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]); |
114 | - $('#solution').animateCSS('flipInX'); | ||
115 | }); | 121 | }); |
116 | break; | 122 | break; |
117 | 123 | ||
118 | case "try_again": | 124 | case "try_again": |
119 | $('#question_div').animateCSS('shake'); | 125 | $('#question_div').animateCSS('shake'); |
120 | $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); | 126 | $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); |
121 | - $("#tries").html(params["tries"]); | 127 | + showTriesLeft(params["tries"]); |
122 | $('#comments').html(params['comments']); | 128 | $('#comments').html(params['comments']); |
123 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"#comments"]); | 129 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"#comments"]); |
124 | break; | 130 | break; |
@@ -127,19 +133,16 @@ function getFeedback(response) { | @@ -127,19 +133,16 @@ function getFeedback(response) { | ||
127 | $('#right').hide(); | 133 | $('#right').hide(); |
128 | $('#wrong').show(); | 134 | $('#wrong').show(); |
129 | $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); | 135 | $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); |
130 | - $("#tries").html(params["tries"]); | 136 | + showTriesLeft(params["tries"]); |
131 | $('#comments').html(params['comments']); | 137 | $('#comments').html(params['comments']); |
132 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); | 138 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); |
133 | $("#link_solution_on_wrong").click(function () { | 139 | $("#link_solution_on_wrong").click(function () { |
134 | $("#wrong").hide(); | 140 | $("#wrong").hide(); |
135 | - $('#solution').html(params['solution']); | 141 | + $('#solution').html(params['solution']).animateCSS('flipInX'); |
136 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]); | 142 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]); |
137 | - $('#solution').animateCSS('flipInX'); | ||
138 | }); | 143 | }); |
139 | $("fieldset").attr("disabled", "disabled"); | 144 | $("fieldset").attr("disabled", "disabled"); |
140 | - $("#submit").html("Continuar"); | ||
141 | - $("#submit").off(); | ||
142 | - $("#submit").click(getQuestion); | 145 | + $("#submit").html("Continuar").off().click(getQuestion); |
143 | break; | 146 | break; |
144 | } | 147 | } |
145 | } | 148 | } |
templates/question.html