From bd066710f5d02728b6b7f44c0fdf7e136d84e03d Mon Sep 17 00:00:00 2001 From: Disassembler Date: Wed, 7 Nov 2018 14:37:03 +0100 Subject: [PATCH] Make AJAX calls alert on lost connection --- usr/share/vmmgr/static/js/admin.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/usr/share/vmmgr/static/js/admin.js b/usr/share/vmmgr/static/js/admin.js index c20d5f6..e7b4c76 100644 --- a/usr/share/vmmgr/static/js/admin.js +++ b/usr/share/vmmgr/static/js/admin.js @@ -24,6 +24,10 @@ $(function() { } }); +function lost_connection_alert() { + alert('Spojení se serverem bylo ztraceno'); +} + function update_host() { $('#host-submit').hide(); $('#host-message').hide(); @@ -36,7 +40,7 @@ function update_host() { $('input').prop('disabled', true); $('.setup-box').slice(1).css('opacity', '0.5'); } - }); + }).fail(lost_connection_alert); return false; } @@ -52,7 +56,7 @@ function verify_dns() { } else { $('#dns-message').attr('class','info').html(data.ok).show(); } - }); + }).fail(lost_connection_alert); return false; } @@ -68,7 +72,7 @@ function _verify_http(proto) { } else { $('#'+proto+'-message').attr('class','info').html(data.ok).show(); } - }); + }).fail(lost_connection_alert); return false; } @@ -100,7 +104,7 @@ function update_cert() { } else { $('#cert-message').attr('class','info').html(data.ok).show(); } - }}); + }}).fail(lost_connection_alert); return false; } @@ -113,7 +117,7 @@ function _update_app(item, ev) { el.prop('checked', !value); alert(data.error); } - }); + }).fail(lost_connection_alert); } function update_app_visibility(ev) { @@ -137,9 +141,7 @@ function _do_app(url, ev) { $('#app-manager tbody').html(data.ok); } status_interval = setInterval(get_app_status, 1000); - }).fail(function() { - alert('Spojení se serverem bylo ztraceno'); - }); + }).fail(lost_connection_alert); return false; } @@ -174,7 +176,7 @@ function get_app_status() { }).fail(function() { conn_fail_counter++; if (conn_fail_counter == 10) { - alert('Spojení se serverem bylo ztraceno'); + lost_connection_alert(); clearInterval(status_interval); } }); @@ -192,14 +194,14 @@ function update_password() { } else { $('#password-message').attr('class','info').html(data.ok).show(); } - }); + }).fail(lost_connection_alert); return false; } function _do_vm(action) { $.get('/'+action+'-vm', function(data) { $('#vm-message').attr('class','info').html(data.ok).show(); - }); + }).fail(lost_connection_alert); } function reboot_vm() {