learn.js 2.4 KB
// function newquestion(q) {
//     $('#title').html(q["title"]);
//     $('#text').html(q["text"]);
//     switch (q["type"]) {
//         case "information":
//         case "warning":
//         case "alert":
//             $('#answer').html("");
//             break;

//         case "text":
//         case "text_regex":
//             $('#answer').html(`
//                 <fieldset data-role="controlgroup">
//                 <input type="text" name="FIXME" class="form-control">
//                 </fieldset>
//             `);
//             // <input type="text" name="${i}" class="form-control" value="${q['answer'] if q['answer'] is not None else ''}">
//             break;

//         case "radio":
//         case "checkbox":
//             // $('#answer').html(nunjucks.renderString('<h1>{{title}}</h1><strong>{{type}}</strong>', data)); // FIXME should not be public
//             // $('#answer').html(render('question-radio.html', data));
//             $('#answer').html(nunjucks.renderString(`
//                 <fieldset data-role="controlgroup">
//                 <div class="list-group">
//                 {% for opt in options %}
//                         <a class="list-group-item">
//                             <input type="{{ type }}" name="a" id="b" value="c">
//                             {{ opt }}
//                         </a>
//                 {% else %}
//                     No options????? FIXME
//                 {% endfor %}
//                 </div>
//                 </fieldset>
//                 <button class="btn btn-primary" id="submit">
//                     Submeter resposta
//                 </button>
//                 `, q));
//             $("submit").click(function (e) {

//                 e.preventDefault();
//             });
//             break;

//         default:
//             $('#answer').html("Tipo de pergunta desconhecido: " + data["type"]);
//     }
//     $("#actions").html(`
//     `);
// }

// function get_question() {

// }



// $(document).ready(function() {
//     // nunjucks.configure("/static/tmpl", {"autoescape": false}); // FIXME
//     // get question
//     $.ajax({
//         url: "/question",
//         context: document.body;

//         // dataType: "json",
//         success: function(response){
//             $("#question").html(response);
//         },
//         error: function() {alert("Servidor não responde.");}
//     });
// });