|
43 | 43 | </div> |
44 | 44 | <div class="col-md-6" style="text-align:center;"> |
45 | 45 | <hr /> |
46 | | - @can('power', $server) |
47 | | - <button class="btn btn-success btn-sm disabled" data-attr="power" data-action="start">Start</button> |
48 | | - <button class="btn btn-primary btn-sm disabled" data-attr="power" data-action="restart">Restart</button> |
49 | | - <button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="stop">Stop</button> |
50 | | - <button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="kill"><i class="fa fa-ban" data-toggle="tooltip" data-placement="top" title="Kill Running Process"></i></button> |
51 | | - <button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#pauseConsole" id="pause_console"><small><i class="fa fa-pause fa-fw"></i></small></button> |
52 | | - <div id="pw_resp" style="display:none;margin-top: 15px;"></div> |
53 | | - @endcan |
| 46 | + @can('power-start', $server)<button class="btn btn-success btn-sm disabled" data-attr="power" data-action="start">Start</button>@endcan |
| 47 | + @can('power-restart', $server)<button class="btn btn-primary btn-sm disabled" data-attr="power" data-action="restart">Restart</button>@endcan |
| 48 | + @can('power-stop', $server)<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="stop">Stop</button>@endcan |
| 49 | + @can('power-kill', $server)<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="kill"><i class="fa fa-ban" data-toggle="tooltip" data-placement="top" title="Kill Running Process"></i></button>@endcan |
| 50 | + <button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#pauseConsole" id="pause_console"><small><i class="fa fa-pause fa-fw"></i></small></button> |
| 51 | + <div id="pw_resp" style="display:none;margin-top: 15px;"></div> |
54 | 52 | </div> |
55 | 53 | </div> |
56 | 54 | <div class="row"> |
@@ -462,87 +460,84 @@ function updatePlayerListVisibility(data) { |
462 | 460 | }); |
463 | 461 | }); |
464 | 462 | @endcan |
465 | | - @can('power', $server) |
466 | | - var can_run = true; |
467 | | - function updateServerPowerControls (data) { |
468 | | -
|
469 | | - // Reset Console Data |
470 | | - if (data === 2) { |
471 | | - $('#live_console').val($('#live_console').val() + '\n --+ Server Detected as Booting + --\n'); |
472 | | - $('#live_console').scrollTop($('#live_console')[0].scrollHeight); |
473 | | - } |
| 463 | + var can_run = true; |
| 464 | + function updateServerPowerControls (data) { |
474 | 465 |
|
475 | | - // Server is On or Starting |
476 | | - if(data == 1 || data == 2) { |
477 | | - $("#console_command").slideDown(); |
478 | | - $('[data-attr="power"][data-action="start"]').addClass('disabled'); |
479 | | - $('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').removeClass('disabled'); |
480 | | - } else { |
481 | | - $("#console_command").slideUp(); |
482 | | - $('[data-attr="power"][data-action="start"]').removeClass('disabled'); |
483 | | - $('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').addClass('disabled'); |
484 | | - } |
485 | | -
|
486 | | - if(data !== 0) { |
487 | | - $('[data-attr="power"][data-action="kill"]').removeClass('disabled'); |
488 | | - } else { |
489 | | - $('[data-attr="power"][data-action="kill"]').addClass('disabled'); |
490 | | - } |
| 466 | + // Reset Console Data |
| 467 | + if (data === 2) { |
| 468 | + $('#live_console').val($('#live_console').val() + '\n --+ Server Detected as Booting + --\n'); |
| 469 | + $('#live_console').scrollTop($('#live_console')[0].scrollHeight); |
| 470 | + } |
491 | 471 |
|
| 472 | + // Server is On or Starting |
| 473 | + if(data == 1 || data == 2) { |
| 474 | + $("#console_command").slideDown(); |
| 475 | + $('[data-attr="power"][data-action="start"]').addClass('disabled'); |
| 476 | + $('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').removeClass('disabled'); |
| 477 | + } else { |
| 478 | + $("#console_command").slideUp(); |
| 479 | + $('[data-attr="power"][data-action="start"]').removeClass('disabled'); |
| 480 | + $('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').addClass('disabled'); |
492 | 481 | } |
493 | 482 |
|
494 | | - $('[data-attr="power"]').click(function (event) { |
495 | | - event.preventDefault(); |
496 | | - var action = $(this).data('action'); |
497 | | - var killConfirm = false; |
498 | | - if (action === 'kill') { |
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); |
512 | | - }); |
513 | | - } else { |
514 | | - powerToggleServer(action); |
515 | | - } |
| 483 | + if(data !== 0) { |
| 484 | + $('[data-attr="power"][data-action="kill"]').removeClass('disabled'); |
| 485 | + } else { |
| 486 | + $('[data-attr="power"][data-action="kill"]').addClass('disabled'); |
| 487 | + } |
516 | 488 |
|
517 | | - }); |
| 489 | + } |
518 | 490 |
|
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 | | - }); |
| 491 | + $('[data-attr="power"]').click(function (event) { |
| 492 | + event.preventDefault(); |
| 493 | + var action = $(this).data('action'); |
| 494 | + var killConfirm = false; |
| 495 | + if (action === 'kill') { |
| 496 | + swal({ |
| 497 | + type: 'warning', |
| 498 | + title: '', |
| 499 | + 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.', |
| 500 | + showCancelButton: true, |
| 501 | + allowOutsideClick: true, |
| 502 | + closeOnConfirm: true, |
| 503 | + confirmButtonText: 'Kill Server', |
| 504 | + confirmButtonColor: '#d9534f' |
| 505 | + }, function () { |
| 506 | + setTimeout(function() { |
| 507 | + powerToggleServer('kill'); |
| 508 | + }, 100); |
542 | 509 | }); |
| 510 | + } else { |
| 511 | + powerToggleServer(action); |
543 | 512 | } |
544 | 513 |
|
545 | | - @endcan |
| 514 | + }); |
| 515 | +
|
| 516 | + function powerToggleServer(action) { |
| 517 | + $.ajax({ |
| 518 | + type: 'PUT', |
| 519 | + headers: { |
| 520 | + 'X-Access-Token': '{{ $server->daemonSecret }}', |
| 521 | + 'X-Access-Server': '{{ $server->uuid }}' |
| 522 | + }, |
| 523 | + contentType: 'application/json; charset=utf-8', |
| 524 | + data: JSON.stringify({ |
| 525 | + action: action |
| 526 | + }), |
| 527 | + url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power', |
| 528 | + timeout: 10000 |
| 529 | + }).fail(function(jqXHR) { |
| 530 | + var error = 'An error occured while trying to process this request.'; |
| 531 | + if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') { |
| 532 | + error = jqXHR.responseJSON.error; |
| 533 | + } |
| 534 | + swal({ |
| 535 | + type: 'error', |
| 536 | + title: 'Whoops!', |
| 537 | + text: error |
| 538 | + }); |
| 539 | + }); |
| 540 | + } |
546 | 541 | }); |
547 | 542 |
|
548 | 543 | $(document).ready(function () { |
|
0 commit comments