diff --git a/BUGS.md b/BUGS.md index 50a1df9..9f8cb93 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,7 +1,12 @@ BUGS: -- generators not working: bcrypt (ver blog) - implementar xsrf. Ver [http://www.tornadoweb.org/en/stable/guide/security.html#cross-site-request-forgery-protection]() + +TODO: + +- gravar answers -> db +- como gerar uma sequencia de perguntas? +- generators not working: bcrypt (ver blog) - implementar navegacao radio/checkbox. cursor cima/baixo, espaco selecciona, enter submete. SOLVED: diff --git a/serve.py b/serve.py index 444abde..1204036 100755 --- a/serve.py +++ b/serve.py @@ -145,13 +145,13 @@ class QuestionHandler(BaseHandler): md=md, # function that renders markdown to html ) self.write({ - 'html': tornado.escape.to_unicode(html_out), - 'correct': True, + 'params': tornado.escape.to_unicode(html_out), + 'method': 'new_question', }) else: self.write({ - 'html': 'None', - 'correct': False + 'params': 'None', + 'method': 'shake' }) diff --git a/templates/learn.html b/templates/learn.html index 1769d57..4ae594b 100644 --- a/templates/learn.html +++ b/templates/learn.html @@ -17,14 +17,11 @@ - - - @@ -96,24 +93,11 @@ $.fn.extend({ } }); -// function getCookie(name) { -// var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); -// return r ? r[1] : undefined; -// } - -// jQuery.postJSON = function(url, args, callback) { -// args._xsrf = getCookie("_xsrf"); -// alert(args); -// $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST", -// success: function(response) { -// callback(eval("(" + response + ")")); -// }}); -// } - function updateQuestion(response){ - if (response["correct"]) { - $("#question_div").html(response["html"]); + switch (response["method"]) { + case "new_question": + $("#question_div").html(response["params"]); MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); $("input:text").keypress(function (e) { @@ -129,32 +113,14 @@ function updateQuestion(response){ } }); $('#question_div').animateCSS('pulse'); - } - else + break; + case "shake": $('#question_div').animateCSS('shake'); + break; + } } function getQuestion() { - // var data = $("#question_form").serialize(); - // $.postJSON('/question', data, function(response){ - // $("#question_div").html(response["html"]); - // MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question"]); - - // if (response["correct"]) { - // $('#question_div').animateCSS('pulse'); - // } - // else { - // $('#question_div').animateCSS('shake'); - // } - - // $("input:text").bind("keypress", function (e) { - // if (e.keyCode == 13) { - // e.preventDefault(); - // getQuestion(); - // } - // }); - // }); - $.ajax({ type: "POST", url: "/question", -- libgit2 0.21.2