Display error in GUI when something goes wrong

parent 47794dc0
...@@ -116,12 +116,28 @@ ...@@ -116,12 +116,28 @@
var loader = $('#loader'); 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() { window.show_loader = function() {
loader.show().css('display', 'inline-block'); loader.show().css('display', 'inline-block');
}; };
window.hide_loader = function() { window.hide_loader = function() {
loader.hide(); loader.hide();
clear_error();
}; };
window.append_hint = function(hint) { window.append_hint = function(hint) {
...@@ -146,6 +162,9 @@ ...@@ -146,6 +162,9 @@
if (!response) if (!response)
return; return;
if ('error' in response)
return report_error(response);
if ('steps' in response) { if ('steps' in response) {
for(i = 0; i < response.steps.length; i++) { for(i = 0; i < response.steps.length; i++) {
cur = response.steps[i]; cur = response.steps[i];
...@@ -167,11 +186,7 @@ ...@@ -167,11 +186,7 @@
input_textarea.focus(); input_textarea.focus();
hide_loader(); hide_loader();
}, 'json').error(function(e) { }, 'json').error(report_error);
console.log('error:', e);
hide_loader();
});
}; };
window.hint_input = function() { window.hint_input = function() {
...@@ -183,16 +198,15 @@ ...@@ -183,16 +198,15 @@
if (!response) if (!response)
return; return;
if ('error' in response)
return report_error(response);
window.append_hint(response.hint); window.append_hint(response.hint);
input_textarea.focus(); input_textarea.focus();
hide_loader(); hide_loader();
}, 'json').error(function(e) { }, 'json').error(report_error);
console.log('error:', e);
hide_loader();
});
}; };
window.step_input = function() { window.step_input = function() {
...@@ -204,6 +218,9 @@ ...@@ -204,6 +218,9 @@
if (!response) if (!response)
return; return;
if ('error' in response)
return report_error(response);
if ('step' in response) { if ('step' in response) {
window.append_input(response.step); window.append_input(response.step);
trigger_update = true; trigger_update = true;
...@@ -215,11 +232,7 @@ ...@@ -215,11 +232,7 @@
input_textarea.focus(); input_textarea.focus();
hide_loader(); hide_loader();
}, 'json').error(function(e) { }, 'json').error(report_error);
console.log('error:', e);
hide_loader();
});
}; };
window.validate_input = function() { window.validate_input = function() {
...@@ -231,6 +244,9 @@ ...@@ -231,6 +244,9 @@
if (!response) if (!response)
return; return;
if ('error' in response)
return report_error(response);
var math_container = $('#math'), var math_container = $('#math'),
math_lines = math_container.find('div.box'); math_lines = math_container.find('div.box');
...@@ -251,17 +267,14 @@ ...@@ -251,17 +267,14 @@
} }
hide_loader(); hide_loader();
}, 'json').error(function(e) { }, 'json').error(report_error);
console.log('error:', e);
hide_loader();
});
}; };
window.clear_input = function() { window.clear_input = function() {
input_textarea.val(''); input_textarea.val('');
$('#math .box,#math .hint').remove(); $('#math .box,#math .hint').remove();
trigger_update = true; trigger_update = true;
clear_error();
hide_loader(); hide_loader();
}; };
})(jQuery); })(jQuery);
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
<body> <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="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 id="input" class="panel">
<div class="label">Input view</div> <div class="label">Input view</div>
<div class="box"> <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