Path: blob/1.0-develop/resources/views/admin/nodes/view/allocation.blade.php
7461 views
@extends('layouts.admin')12@section('title')3{{ $node->name }}: Allocations4@endsection56@section('content-header')7<h1>{{ $node->name }}<small>Control allocations available for servers on this node.</small></h1>8<ol class="breadcrumb">9<li><a href="{{ route('admin.index') }}">Admin</a></li>10<li><a href="{{ route('admin.nodes') }}">Nodes</a></li>11<li><a href="{{ route('admin.nodes.view', $node->id) }}">{{ $node->name }}</a></li>12<li class="active">Allocations</li>13</ol>14@endsection1516@section('content')17<div class="row">18<div class="col-xs-12">19<div class="nav-tabs-custom nav-tabs-floating">20<ul class="nav nav-tabs">21<li><a href="{{ route('admin.nodes.view', $node->id) }}">About</a></li>22<li><a href="{{ route('admin.nodes.view.settings', $node->id) }}">Settings</a></li>23<li><a href="{{ route('admin.nodes.view.configuration', $node->id) }}">Configuration</a></li>24<li class="active"><a href="{{ route('admin.nodes.view.allocation', $node->id) }}">Allocation</a></li>25<li><a href="{{ route('admin.nodes.view.servers', $node->id) }}">Servers</a></li>26</ul>27</div>28</div>29</div>30<div class="row">31<div class="col-sm-8">32<div class="box box-primary">33<div class="box-header with-border">34<h3 class="box-title">Existing Allocations</h3>35</div>36<div class="box-body table-responsive no-padding" style="overflow-x: visible">37<table class="table table-hover" style="margin-bottom:0;">38<tr>39<th>40<input type="checkbox" class="select-all-files hidden-xs" data-action="selectAll">41</th>42<th>IP Address <i class="fa fa-fw fa-minus-square" style="font-weight:normal;color:#d9534f;cursor:pointer;" data-toggle="modal" data-target="#allocationModal"></i></th>43<th>IP Alias</th>44<th>Port</th>45<th>Assigned To</th>46<th>47<div class="btn-group hidden-xs">48<button type="button" id="mass_actions" class="btn btn-sm btn-default dropdown-toggle disabled"49data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Mass Actions <span class="caret"></span>50</button>51<ul class="dropdown-menu dropdown-massactions">52<li><a href="#" id="selective-deletion" data-action="selective-deletion">Delete <i class="fa fa-fw fa-trash-o"></i></a></li>53</ul>54</div>55</th>56</tr>57@foreach($node->allocations as $allocation)58<tr>59<td class="middle min-size" data-identifier="type">60@if(is_null($allocation->server_id))61<input type="checkbox" class="select-file hidden-xs" data-action="addSelection">62@else63<input disabled="disabled" type="checkbox" class="select-file hidden-xs" data-action="addSelection">64@endif65</td>66<td class="col-sm-3 middle" data-identifier="ip">{{ $allocation->ip }}</td>67<td class="col-sm-3 middle">68<input class="form-control input-sm" type="text" value="{{ $allocation->ip_alias }}" data-action="set-alias" data-id="{{ $allocation->id }}" placeholder="none" />69<span class="input-loader"><i class="fa fa-refresh fa-spin fa-fw"></i></span>70</td>71<td class="col-sm-2 middle" data-identifier="port">{{ $allocation->port }}</td>72<td class="col-sm-3 middle">73@if(! is_null($allocation->server))74<a href="{{ route('admin.servers.view', $allocation->server_id) }}">{{ $allocation->server->name }}</a>75@endif76</td>77<td class="col-sm-1 middle">78@if(is_null($allocation->server_id))79<button data-action="deallocate" data-id="{{ $allocation->id }}" class="btn btn-sm btn-danger"><i class="fa fa-trash-o"></i></button>80@endif81</td>82</tr>83@endforeach84</table>85</div>86@if($node->allocations->hasPages())87<div class="box-footer text-center">88{{ $node->allocations->render() }}89</div>90@endif91</div>92</div>93<div class="col-sm-4">94<form action="{{ route('admin.nodes.view.allocation', $node->id) }}" method="POST">95<div class="box box-success">96<div class="box-header with-border">97<h3 class="box-title">Assign New Allocations</h3>98</div>99<div class="box-body">100<div class="form-group">101<label for="pAllocationIP" class="control-label">IP Address</label>102<div>103<select class="form-control" name="allocation_ip" id="pAllocationIP" multiple>104@foreach($allocations as $allocation)105<option value="{{ $allocation->ip }}">{{ $allocation->ip }}</option>106@endforeach107</select>108<p class="text-muted small">Enter an IP address to assign ports to here.</p>109</div>110</div>111<div class="form-group">112<label for="pAllocationIP" class="control-label">IP Alias</label>113<div>114<input type="text" id="pAllocationAlias" class="form-control" name="allocation_alias" placeholder="alias" />115<p class="text-muted small">If you would like to assign a default alias to these allocations enter it here.</p>116</div>117</div>118<div class="form-group">119<label for="pAllocationPorts" class="control-label">Ports</label>120<div>121<select class="form-control" name="allocation_ports[]" id="pAllocationPorts" multiple></select>122<p class="text-muted small">Enter individual ports or port ranges here separated by commas or spaces.</p>123</div>124</div>125</div>126<div class="box-footer">127{!! csrf_field() !!}128<button type="submit" class="btn btn-success btn-sm pull-right">Submit</button>129</div>130</div>131</form>132</div>133</div>134<div class="modal fade" id="allocationModal" tabindex="-1" role="dialog">135<div class="modal-dialog" role="document">136<div class="modal-content">137<div class="modal-header">138<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>139<h4 class="modal-title">Delete Allocations for IP Block</h4>140</div>141<form action="{{ route('admin.nodes.view.allocation.removeBlock', $node->id) }}" method="POST">142<div class="modal-body">143<div class="row">144<div class="col-md-12">145<select class="form-control" name="ip">146@foreach($allocations as $allocation)147<option value="{{ $allocation->ip }}">{{ $allocation->ip }}</option>148@endforeach149</select>150</div>151</div>152</div>153<div class="modal-footer">154{{{ csrf_field() }}}155<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>156<button type="submit" class="btn btn-danger">Delete Allocations</button>157</div>158</form>159</div>160</div>161</div>162@endsection163164@section('footer-scripts')165@parent166<script>167$('[data-action="addSelection"]').on('click', function () {168updateMassActions();169});170171$('[data-action="selectAll"]').on('click', function () {172$('input.select-file').not(':disabled').prop('checked', function (i, val) {173return !val;174});175176updateMassActions();177});178179$('[data-action="selective-deletion"]').on('mousedown', function () {180deleteSelected();181});182183$('#pAllocationIP').select2({184tags: true,185maximumSelectionLength: 1,186selectOnClose: true,187tokenSeparators: [',', ' '],188});189190$('#pAllocationPorts').select2({191tags: true,192selectOnClose: true,193tokenSeparators: [',', ' '],194});195196$('button[data-action="deallocate"]').click(function (event) {197event.preventDefault();198var element = $(this);199var allocation = $(this).data('id');200swal({201title: '',202text: 'Are you sure you want to delete this allocation?',203type: 'warning',204showCancelButton: true,205allowOutsideClick: true,206closeOnConfirm: false,207confirmButtonText: 'Delete',208confirmButtonColor: '#d9534f',209showLoaderOnConfirm: true210}, function () {211$.ajax({212method: 'DELETE',213url: '/admin/nodes/view/' + {{ $node->id }} + '/allocation/remove/' + allocation,214headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') },215}).done(function (data) {216element.parent().parent().addClass('warning').delay(100).fadeOut();217swal({ type: 'success', title: 'Port Deleted!' });218}).fail(function (jqXHR) {219console.error(jqXHR);220swal({221title: 'Whoops!',222text: jqXHR.responseJSON.error,223type: 'error'224});225});226});227});228229var typingTimer;230$('input[data-action="set-alias"]').keyup(function () {231clearTimeout(typingTimer);232$(this).parent().removeClass('has-error has-success');233typingTimer = setTimeout(sendAlias, 250, $(this));234});235236var fadeTimers = [];237function sendAlias(element) {238element.parent().find('.input-loader').show();239clearTimeout(fadeTimers[element.data('id')]);240$.ajax({241method: 'POST',242url: '/admin/nodes/view/' + {{ $node->id }} + '/allocation/alias',243headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') },244data: {245alias: element.val(),246allocation_id: element.data('id'),247}248}).done(function () {249element.parent().addClass('has-success');250}).fail(function (jqXHR) {251console.error(jqXHR);252element.parent().addClass('has-error');253}).always(function () {254element.parent().find('.input-loader').hide();255fadeTimers[element.data('id')] = setTimeout(clearHighlight, 2500, element);256});257}258259function clearHighlight(element) {260element.parent().removeClass('has-error has-success');261}262263function updateMassActions() {264if ($('input.select-file:checked').length > 0) {265$('#mass_actions').removeClass('disabled');266} else {267$('#mass_actions').addClass('disabled');268}269}270271function deleteSelected() {272var selectedIds = [];273var selectedItems = [];274var selectedItemsElements = [];275276$('input.select-file:checked').each(function () {277var $parent = $($(this).closest('tr'));278var id = $parent.find('[data-action="deallocate"]').data('id');279var $ip = $parent.find('td[data-identifier="ip"]');280var $port = $parent.find('td[data-identifier="port"]');281var block = `${$ip.text()}:${$port.text()}`;282283selectedIds.push({284id: id285});286selectedItems.push(block);287selectedItemsElements.push($parent);288});289290if (selectedItems.length !== 0) {291var formattedItems = "";292var i = 0;293$.each(selectedItems, function (key, value) {294formattedItems += ("<code>" + value + "</code>, ");295i++;296return i < 5;297});298299formattedItems = formattedItems.slice(0, -2);300if (selectedItems.length > 5) {301formattedItems += ', and ' + (selectedItems.length - 5) + ' other(s)';302}303304swal({305type: 'warning',306title: '',307text: 'Are you sure you want to delete the following allocations: ' + formattedItems + '?',308html: true,309showCancelButton: true,310showConfirmButton: true,311closeOnConfirm: false,312showLoaderOnConfirm: true313}, function () {314$.ajax({315method: 'DELETE',316url: '/admin/nodes/view/' + {{ $node->id }} + '/allocations',317headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},318data: JSON.stringify({319allocations: selectedIds320}),321contentType: 'application/json',322processData: false323}).done(function () {324$('#file_listing input:checked').each(function () {325$(this).prop('checked', false);326});327328$.each(selectedItemsElements, function () {329$(this).addClass('warning').delay(200).fadeOut();330});331332swal({333type: 'success',334title: 'Allocations Deleted'335});336}).fail(function (jqXHR) {337console.error(jqXHR);338swal({339type: 'error',340title: 'Whoops!',341html: true,342text: 'An error occurred while attempting to delete these allocations. Please try again.',343});344});345});346} else {347swal({348type: 'warning',349title: '',350text: 'Please select allocation(s) to delete.',351});352}353}354</script>355@endsection356357358