clrghouz/resources/views/system/widget/form-echoarea.blade.php

149 lines
4.1 KiB
PHP
Raw Permalink Normal View History

2024-12-06 00:16:38 +00:00
<form class="needs-validation" method="post" action="{{ url('system/echoarea',$o->id) }}" autocomplete="off" novalidate>
@csrf
2021-08-25 12:13:49 +00:00
<div class="row pt-0">
<div class="col-12">
<div class="greyframe titledbox shadow0xb0">
<div class="row">
<!-- Select Domain -->
<div class="col-3">
<x-form.select id="echoarea_domain_id" name="domain_id" icon="bi-hash" label="Network" :options="$o->sessions->map(fn($item)=>['id'=>$item->domain_id,'value'=>sprintf('%s (%s)',$item->zone_id,$item->domain->name)])"/>
</div>
2021-08-25 12:13:49 +00:00
<!-- Select Address -->
<div class="col-3">
<div class="d-none" id="echoarea_address-select">
<x-form.select id="echoarea_address_id" name="address_id" icon="bi-hash" label="Address"/>
2021-08-25 12:13:49 +00:00
</div>
</div>
2021-08-25 12:13:49 +00:00
<!-- Summary of Addresses -->
<div class="offset-3 col-3" id="echoarea-summary">
<table class="table monotable">
<thead>
<tr>
<th>Network</th>
<th class="text-end">Areas</th>
</tr>
</thead>
<tbody>
@foreach ($o->echoareas()->with(['domain'])->get()->groupBy('domain_id') as $oo)
2021-08-25 12:13:49 +00:00
<tr>
<td>{{ $oo->first()->domain->name }}</td>
<td class="text-end">{{ $oo->count() }}</td>
2021-08-25 12:13:49 +00:00
</tr>
@endforeach
</tbody>
</table>
2021-08-25 12:13:49 +00:00
</div>
</div>
2021-08-25 12:13:49 +00:00
@if($errors->count())
2021-08-25 12:13:49 +00:00
<div class="row">
<span class="btn btn-sm btn-danger" role="alert" style="text-align: left;">
There were errors with the submission.
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</span>
2021-08-25 12:13:49 +00:00
</div>
@endif
<div class="row">
<div class="col-12 d-none" id="echoarea-select"></div>
2021-08-25 12:13:49 +00:00
</div>
</div>
</div>
</div>
</form>
2021-08-25 12:13:49 +00:00
@section('page-scripts')
<script type="text/javascript" src="{{ asset('plugin/checkboxes/jquery.checkboxes-1.2.2.min.js') }}"></script>
<script type="text/javascript">
$(document).ready(function() {
2022-11-01 11:24:36 +00:00
$('#echoarea_domain_id').on('change',function() {
if (! $('#echoarea-select').hasClass('d-none'))
$('#echoarea-select').addClass('d-none');
if (! $(this).val()) {
$('#echoarea-summary').removeClass('d-none');
2022-11-01 11:24:36 +00:00
$('#echoarea_address-select').addClass('d-none');
return;
} else {
2022-11-01 11:24:36 +00:00
$('#echoarea_address-select').removeClass('d-none');
}
var item = this;
icon = $(item).parent().find('i');
$.ajax({
type: 'POST',
data: {domain_id: $(item).val()},
beforeSend: function() {
icon.addClass('spinner-grow spinner-grow-sm');
},
success: function(data) {
icon.removeClass('spinner-grow spinner-grow-sm');
2022-11-01 11:24:36 +00:00
$('#echoarea_address_id')
.empty()
.append($('<option>'))
.append(data.map(function(item) {
return $('<option>').val(item.id).text(item.value);
}));
},
error: function(e) {
icon.removeClass('spinner-grow spinner-grow-sm');
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('system/api/address',[$o->id]) }}',
cache: false
})
});
2022-11-01 11:24:36 +00:00
$('#echoarea_address_id').on('change',function() {
2021-08-25 12:13:49 +00:00
if (! $(this).val()) {
$('#echoarea-summary').removeClass('d-none');
$('#echoarea-select').addClass('d-none');
return;
}
if ($('#echoarea-select').hasClass('d-none')) {
$('#echoarea-select').removeClass('d-none');
$('#echoarea-summary').addClass('d-none');
}
var item = this;
icon = $(item).parent().find('i');
$.ajax({
type: 'GET',
data: {address_id: $(item).val()},
2021-08-25 12:13:49 +00:00
beforeSend: function() {
icon.addClass('spinner-grow spinner-grow-sm');
},
success: function(data) {
icon.removeClass('spinner-grow spinner-grow-sm');
$('#echoarea-select').empty().append(data);
$('#echoareas').checkboxes('range',true);
},
error: function(e) {
icon.removeClass('spinner-grow spinner-grow-sm');
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('system/echoarea',[$o->id]) }}',
2021-08-25 12:13:49 +00:00
cache: false
})
});
});
2021-08-25 12:13:49 +00:00
</script>
@append