Improved alerts on server console and power controls

This commit is contained in:
Dane Everitt 2016-01-08 22:54:30 -05:00
parent 80bef5bd93
commit aaf9768a92

View file

@ -449,10 +449,16 @@ $(window).load(function () {
timeout: 10000, timeout: 10000,
data: JSON.stringify({ command: ccmd }) data: JSON.stringify({ command: ccmd })
}).fail(function (jqXHR) { }).fail(function (jqXHR) {
$('#sc_resp').html('Unable to process your request. Please try again.').fadeIn().delay(5000).fadeOut(); console.error(jqXHR);
swal({
type: 'error',
title: 'Whoops!',
text: 'There was an error while attempting to process your request. Please try again.'
});
}).done(function () {
$('#ccmd').val('');
}).always(function () { }).always(function () {
$('#sending_command').html('→').removeClass('disabled'); $('#sending_command').html('→').removeClass('disabled');
$('#ccmd').val('');
}); });
}); });
@endcan @endcan
@ -488,11 +494,29 @@ $(window).load(function () {
$('[data-attr="power"]').click(function (event) { $('[data-attr="power"]').click(function (event) {
event.preventDefault(); event.preventDefault();
var action = $(this).data('action'); var action = $(this).data('action');
var killConfirm = false;
if (action === 'kill') { if (action === 'kill') {
var killConfirm = confirm('WARNING: This operation will not save your server data gracefully. You should only use this if your server is failing to respond to normal stop commands.'); swal({
} else { var killConfirm = true; } type: 'warning',
title: '',
text: 'This operation will not save your server data gracefully. You should only use this if your server is failing to respond to normal stop commands.',
showCancelButton: true,
allowOutsideClick: true,
closeOnConfirm: true,
confirmButtonText: 'Kill Server',
confirmButtonColor: '#d9534f'
}, function () {
setTimeout(function() {
powerToggleServer('kill');
}, 100);
});
} else {
powerToggleServer(action);
}
if(killConfirm) { });
function powerToggleServer(action) {
$.ajax({ $.ajax({
type: 'PUT', type: 'PUT',
headers: { headers: {
@ -506,16 +530,18 @@ $(window).load(function () {
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power', url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power',
timeout: 10000 timeout: 10000
}).fail(function(jqXHR) { }).fail(function(jqXHR) {
var error = 'An unknown error occured processing this request.'; var error = 'An error occured while trying to process this request.';
if (typeof jqXHR.responseJSON.error !== 'undefined') { if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
error = jqXHR.responseJSON.error; error = jqXHR.responseJSON.error;
} }
$('#pw_resp').attr('class', 'alert alert-danger').html('Unable to process your request. Please try again. (' + error + ')').fadeIn().delay(5000).fadeOut(); swal({
type: 'error',
title: 'Whoops!',
text: error
});
}); });
} }
});
@endcan @endcan
}); });