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,34 +494,54 @@ $(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: '',
if(killConfirm) { 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.',
$.ajax({ showCancelButton: true,
type: 'PUT', allowOutsideClick: true,
headers: { closeOnConfirm: true,
'X-Access-Token': '{{ $server->daemonSecret }}', confirmButtonText: 'Kill Server',
'X-Access-Server': '{{ $server->uuid }}' confirmButtonColor: '#d9534f'
}, }, function () {
contentType: 'application/json; charset=utf-8', setTimeout(function() {
data: JSON.stringify({ powerToggleServer('kill');
action: action }, 100);
}),
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power',
timeout: 10000
}).fail(function(jqXHR) {
var error = 'An unknown error occured processing this request.';
if (typeof jqXHR.responseJSON.error !== 'undefined') {
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();
}); });
} else {
powerToggleServer(action);
} }
}); });
function powerToggleServer(action) {
$.ajax({
type: 'PUT',
headers: {
'X-Access-Token': '{{ $server->daemonSecret }}',
'X-Access-Server': '{{ $server->uuid }}'
},
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
action: action
}),
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power',
timeout: 10000
}).fail(function(jqXHR) {
var error = 'An error occured while trying to process this request.';
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
error = jqXHR.responseJSON.error;
}
swal({
type: 'error',
title: 'Whoops!',
text: error
});
});
}
@endcan @endcan
}); });