Display error in GUI when something goes wrong

parent 47794dc0
......@@ -116,12 +116,28 @@
var loader = $('#loader');
window.report_error = function(e) {
$('.panel').css({top: 74});
$('#error').text('error: ' + e.error).show();
if (console && console.log)
console.log('error:', e);
loader.hide();
};
window.clear_error = function() {
$('#error').hide();
$('.panel').css({top: 58});
};
window.show_loader = function() {
loader.show().css('display', 'inline-block');
};
window.hide_loader = function() {
loader.hide();
clear_error();
};
window.append_hint = function(hint) {
......@@ -146,6 +162,9 @@
if (!response)
return;
if ('error' in response)
return report_error(response);
if ('steps' in response) {
for(i = 0; i < response.steps.length; i++) {
cur = response.steps[i];
......@@ -167,11 +186,7 @@
input_textarea.focus();
hide_loader();
}, 'json').error(function(e) {
console.log('error:', e);
hide_loader();
});
}, 'json').error(report_error);
};
window.hint_input = function() {
......@@ -183,16 +198,15 @@
if (!response)
return;
if ('error' in response)
return report_error(response);
window.append_hint(response.hint);
input_textarea.focus();
hide_loader();
}, 'json').error(function(e) {
console.log('error:', e);
hide_loader();
});
}, 'json').error(report_error);
};
window.step_input = function() {
......@@ -204,6 +218,9 @@
if (!response)
return;
if ('error' in response)
return report_error(response);
if ('step' in response) {
window.append_input(response.step);
trigger_update = true;
......@@ -215,11 +232,7 @@
input_textarea.focus();
hide_loader();
}, 'json').error(function(e) {
console.log('error:', e);
hide_loader();
});
}, 'json').error(report_error);
};
window.validate_input = function() {
......@@ -231,6 +244,9 @@
if (!response)
return;
if ('error' in response)
return report_error(response);
var math_container = $('#math'),
math_lines = math_container.find('div.box');
......@@ -251,17 +267,14 @@
}
hide_loader();
}, 'json').error(function(e) {
console.log('error:', e);
hide_loader();
});
}, 'json').error(report_error);
};
window.clear_input = function() {
input_textarea.val('');
$('#math .box,#math .hint').remove();
trigger_update = true;
clear_error();
hide_loader();
};
})(jQuery);
......@@ -11,6 +11,8 @@
<body>
<div id="control-buttons"><button onclick=window.clear_input()>clear</button><div class="separator"></div><button onclick=window.validate_input()>validate</button><button onclick=window.hint_input()>hint</button><button onclick=window.step_input()>step</button><button onclick=window.answer_input()>answer</button><div id="loader"></div></div>
<div id="error"></div>
<div id="input" class="panel">
<div class="label">Input view</div>
<div class="box">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment