Make AJAX calls alert on lost connection

This commit is contained in:
Disassembler 2018-11-07 14:37:03 +01:00
parent a4bf77a00a
commit bd066710f5
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499

View File

@ -24,6 +24,10 @@ $(function() {
} }
}); });
function lost_connection_alert() {
alert('Spojení se serverem bylo ztraceno');
}
function update_host() { function update_host() {
$('#host-submit').hide(); $('#host-submit').hide();
$('#host-message').hide(); $('#host-message').hide();
@ -36,7 +40,7 @@ function update_host() {
$('input').prop('disabled', true); $('input').prop('disabled', true);
$('.setup-box').slice(1).css('opacity', '0.5'); $('.setup-box').slice(1).css('opacity', '0.5');
} }
}); }).fail(lost_connection_alert);
return false; return false;
} }
@ -52,7 +56,7 @@ function verify_dns() {
} else { } else {
$('#dns-message').attr('class','info').html(data.ok).show(); $('#dns-message').attr('class','info').html(data.ok).show();
} }
}); }).fail(lost_connection_alert);
return false; return false;
} }
@ -68,7 +72,7 @@ function _verify_http(proto) {
} else { } else {
$('#'+proto+'-message').attr('class','info').html(data.ok).show(); $('#'+proto+'-message').attr('class','info').html(data.ok).show();
} }
}); }).fail(lost_connection_alert);
return false; return false;
} }
@ -100,7 +104,7 @@ function update_cert() {
} else { } else {
$('#cert-message').attr('class','info').html(data.ok).show(); $('#cert-message').attr('class','info').html(data.ok).show();
} }
}}); }}).fail(lost_connection_alert);
return false; return false;
} }
@ -113,7 +117,7 @@ function _update_app(item, ev) {
el.prop('checked', !value); el.prop('checked', !value);
alert(data.error); alert(data.error);
} }
}); }).fail(lost_connection_alert);
} }
function update_app_visibility(ev) { function update_app_visibility(ev) {
@ -137,9 +141,7 @@ function _do_app(url, ev) {
$('#app-manager tbody').html(data.ok); $('#app-manager tbody').html(data.ok);
} }
status_interval = setInterval(get_app_status, 1000); status_interval = setInterval(get_app_status, 1000);
}).fail(function() { }).fail(lost_connection_alert);
alert('Spojení se serverem bylo ztraceno');
});
return false; return false;
} }
@ -174,7 +176,7 @@ function get_app_status() {
}).fail(function() { }).fail(function() {
conn_fail_counter++; conn_fail_counter++;
if (conn_fail_counter == 10) { if (conn_fail_counter == 10) {
alert('Spojení se serverem bylo ztraceno'); lost_connection_alert();
clearInterval(status_interval); clearInterval(status_interval);
} }
}); });
@ -192,14 +194,14 @@ function update_password() {
} else { } else {
$('#password-message').attr('class','info').html(data.ok).show(); $('#password-message').attr('class','info').html(data.ok).show();
} }
}); }).fail(lost_connection_alert);
return false; return false;
} }
function _do_vm(action) { function _do_vm(action) {
$.get('/'+action+'-vm', function(data) { $.get('/'+action+'-vm', function(data) {
$('#vm-message').attr('class','info').html(data.ok).show(); $('#vm-message').attr('class','info').html(data.ok).show();
}); }).fail(lost_connection_alert);
} }
function reboot_vm() { function reboot_vm() {