Skip to content
Snippets Groups Projects
Commit 216b5019 authored by Sander Mathijs van Veen's avatar Sander Mathijs van Veen
Browse files

Implemented frontend logic for 'step' and 'answer'.

parent feb84e0e
No related branches found
No related tags found
No related merge requests found
......@@ -108,13 +108,14 @@
})(math_lines, real_lines));
}
setInterval(function() {
window.update_math = function() {
if (trigger_update) {
trigger_update = false;
//update_math(input_box.getValue());
update_math(input_textarea.val());
}
}, 100);
};
setInterval(window.update_math, 100);
});
var loader = $('#loader');
......@@ -127,23 +128,96 @@
loader.hide();
};
window.append_hint = function(hint) {
$('#math div').last().filter('.hint').remove();
var elem = $('<div class=hint/>');
elem.text(hint);
$('#math').append(elem);
};
window.append_input = function(input) {
input_textarea.val(input_textarea.val() + '\n' + input);
};
window.answer_input = function() {
show_loader();
// TODO: disable input box and enable it when this ajax request is done
// (on failure and success).
$.post('/answer', {data: input_textarea.val()}, function(response) {
if (!response)
return;
if ('steps' in response) {
for(i = 0; i < response.steps.length; i++) {
cur = response.steps[i];
if ('step' in cur)
window.append_input(cur.step);
if('hint' in cur)
window.append_hint(cur.hint);
trigger_update = true;
window.update_math();
}
}
if('hint' in response)
window.append_hint(response.hint);
input_textarea.focus();
hide_loader();
}, 'json').error(function(e) {
console.log('error:', e);
hide_loader();
});
};
window.hint_input = function() {
show_loader();
// TODO: disable input box and enable it when this ajax request is done
// (on failure and success).
//$.post('/hint', {data: input_box.getValue()}, function(response) {
$.post('/hint', {data: input_textarea.val()}, function(response) {
if (!response)
return;
window.append_hint(response.hint);
input_textarea.focus();
hide_loader();
}, 'json').error(function(e) {
console.log('error:', e);
hide_loader();
});
};
window.step_input = function() {
show_loader();
// TODO: disable input box and enable it when this ajax request is done
// (on failure and success).
$.post('/step', {data: input_textarea.val()}, function(response) {
if (!response)
return;
console.log(response);
$('#math div').last().filter('.hint').remove();
if ('step' in response) {
window.append_input(response.step);
trigger_update = true;
}
if('hint' in response)
window.append_hint(response.hint);
var elem = $('<div class=hint/>');
elem.text(response.hint);
$('#math').append(elem);
input_textarea.focus();
hide_loader();
}, 'json').error(function(e) {
......@@ -158,7 +232,6 @@
// TODO: disable input box and enable it when this ajax request is done
// (on failure and success).
//$.post('/validate', {data: input_box.getValue()}, function(response) {
$.post('/validate', {data: input_textarea.val()}, function(response) {
if (!response)
return;
......@@ -166,8 +239,6 @@
var math_container = $('#math'),
math_lines = math_container.find('div.box');
console.log(response.validated);
var i = 0;
// Mark every line as correct (and remove previous class names).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment