Skip to content

Commit aaf9768

Browse files
committed
Improved alerts on server console and power controls
1 parent 80bef5b commit aaf9768

File tree

1 file changed

+50
-24
lines changed

1 file changed

+50
-24
lines changed

resources/views/server/index.blade.php

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,16 @@ function updatePlayerListVisibility(data) {
449449
timeout: 10000,
450450
data: JSON.stringify({ command: ccmd })
451451
}).fail(function (jqXHR) {
452-
$('#sc_resp').html('Unable to process your request. Please try again.').fadeIn().delay(5000).fadeOut();
452+
console.error(jqXHR);
453+
swal({
454+
type: 'error',
455+
title: 'Whoops!',
456+
text: 'There was an error while attempting to process your request. Please try again.'
457+
});
458+
}).done(function () {
459+
$('#ccmd').val('');
453460
}).always(function () {
454461
$('#sending_command').html('→').removeClass('disabled');
455-
$('#ccmd').val('');
456462
});
457463
});
458464
@endcan
@@ -488,34 +494,54 @@ function updateServerPowerControls (data) {
488494
$('[data-attr="power"]').click(function (event) {
489495
event.preventDefault();
490496
var action = $(this).data('action');
497+
var killConfirm = false;
491498
if (action === 'kill') {
492-
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.');
493-
} else { var killConfirm = true; }
494-
495-
if(killConfirm) {
496-
$.ajax({
497-
type: 'PUT',
498-
headers: {
499-
'X-Access-Token': '{{ $server->daemonSecret }}',
500-
'X-Access-Server': '{{ $server->uuid }}'
501-
},
502-
contentType: 'application/json; charset=utf-8',
503-
data: JSON.stringify({
504-
action: action
505-
}),
506-
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power',
507-
timeout: 10000
508-
}).fail(function(jqXHR) {
509-
var error = 'An unknown error occured processing this request.';
510-
if (typeof jqXHR.responseJSON.error !== 'undefined') {
511-
error = jqXHR.responseJSON.error;
512-
}
513-
$('#pw_resp').attr('class', 'alert alert-danger').html('Unable to process your request. Please try again. (' + error + ')').fadeIn().delay(5000).fadeOut();
499+
swal({
500+
type: 'warning',
501+
title: '',
502+
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.',
503+
showCancelButton: true,
504+
allowOutsideClick: true,
505+
closeOnConfirm: true,
506+
confirmButtonText: 'Kill Server',
507+
confirmButtonColor: '#d9534f'
508+
}, function () {
509+
setTimeout(function() {
510+
powerToggleServer('kill');
511+
}, 100);
514512
});
513+
} else {
514+
powerToggleServer(action);
515515
}
516516
517517
});
518518
519+
function powerToggleServer(action) {
520+
$.ajax({
521+
type: 'PUT',
522+
headers: {
523+
'X-Access-Token': '{{ $server->daemonSecret }}',
524+
'X-Access-Server': '{{ $server->uuid }}'
525+
},
526+
contentType: 'application/json; charset=utf-8',
527+
data: JSON.stringify({
528+
action: action
529+
}),
530+
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power',
531+
timeout: 10000
532+
}).fail(function(jqXHR) {
533+
var error = 'An error occured while trying to process this request.';
534+
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
535+
error = jqXHR.responseJSON.error;
536+
}
537+
swal({
538+
type: 'error',
539+
title: 'Whoops!',
540+
text: error
541+
});
542+
});
543+
}
544+
519545
@endcan
520546
});
521547

0 commit comments

Comments
 (0)