summaryrefslogtreecommitdiff
path: root/js/looking-glass.js
diff options
context:
space:
mode:
authorGuillaume Mazoyer <respawneral@gmail.com>2014-06-11 09:56:00 +0200
committerGuillaume Mazoyer <respawneral@gmail.com>2014-06-11 09:56:00 +0200
commitc28a69e2eb758b70f8631b2cf5c63d12093a1fc5 (patch)
tree2b8f9c3376fcc072865da7216eb139589071fa67 /js/looking-glass.js
parent9189da16073a0c2fab560df7fdbe5edb331d8c47 (diff)
Handle error more properly.
Exception are forwarded up to be able to inform the user about it.
Diffstat (limited to 'js/looking-glass.js')
-rw-r--r--js/looking-glass.js30
1 files changed, 24 insertions, 6 deletions
diff --git a/js/looking-glass.js b/js/looking-glass.js
index b837e82..3a72f23 100644
--- a/js/looking-glass.js
+++ b/js/looking-glass.js
@@ -2,10 +2,12 @@ $(document).ready(function() {
// hide the optional parameters field
$('.result').hide();
$('.loading').hide();
+ $('.alert').hide();
// show and hide loading bar
$(document).ajaxStart(function() {
$('#command_properties').attr('disabled', '');
+ $('.alert').hide();
$('.loading').show();
});
$(document).ajaxStop(function() {
@@ -13,6 +15,14 @@ $(document).ready(function() {
$('.loading').hide();
});
+ // close the alert bar
+ $('.close').click(function() {
+ $('.alert').slideUp();
+ });
+ $('#clear').click(function() {
+ $('.alert').slideUp();
+ });
+
// reset the view to the default one
$('#backhome').click(function() {
$('.content').slideDown();
@@ -27,12 +37,20 @@ $(document).ready(function() {
type: 'post',
url: 'execute.php',
data: $('form').serialize()
- }).done(function(response, state, xhr) {
- $('#output').text(response);
- $('.content').slideUp();
- $('.result').slideDown();
- }).fail(function(xhr, state, error) {
- alert('The following error occured: ' + state, error);
+ }).done(function(response) {
+ var response = $.parseJSON(response);
+
+ if (response.error) {
+ $('#error-text').text(response.error);
+ $('.alert').slideDown();
+ } else {
+ $('#output').text(response.result);
+ $('.content').slideUp();
+ $('.result').slideDown();
+ }
+ }).fail(function(xhr) {
+ $('#error-text').text(xhr.responseText);
+ $('.alert').slideDown();
});
});
});