From aaf9768a9247971d9120cde89e9ba8e36d2d55c7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 8 Jan 2016 22:54:30 -0500 Subject: [PATCH] Improved alerts on server console and power controls --- resources/views/server/index.blade.php | 74 +++++++++++++++++--------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/resources/views/server/index.blade.php b/resources/views/server/index.blade.php index feeadf576..e452230bd 100644 --- a/resources/views/server/index.blade.php +++ b/resources/views/server/index.blade.php @@ -449,10 +449,16 @@ $(window).load(function () { timeout: 10000, data: JSON.stringify({ command: ccmd }) }).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 () { $('#sending_command').html('→').removeClass('disabled'); - $('#ccmd').val(''); }); }); @endcan @@ -488,34 +494,54 @@ $(window).load(function () { $('[data-attr="power"]').click(function (event) { event.preventDefault(); var action = $(this).data('action'); + var killConfirm = false; 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.'); - } else { var killConfirm = true; } - - if(killConfirm) { - $.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 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(); + swal({ + 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); } }); + 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 });