155 lines
4.5 KiB
PHP
155 lines
4.5 KiB
PHP
|
<!-- $o = Product::class -->
|
||
|
<div class="row">
|
||
|
<div class="col-12">
|
||
|
<h3>Product Details</h3>
|
||
|
<hr>
|
||
|
@if(session()->has('success'))
|
||
|
<span class="ml-3 pt-0 pb-0 pr-1 pl-1 btn btn-outline-success"><small>{{ session()->get('success') }}</small></span>
|
||
|
@endif
|
||
|
|
||
|
<form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form">
|
||
|
@csrf
|
||
|
|
||
|
<div class="row">
|
||
|
<div class="col-4">
|
||
|
<div class="row">
|
||
|
<!-- Product Name -->
|
||
|
<div class="col-9">
|
||
|
<div class="form-group has-validation">
|
||
|
<label for="name">Product Name</label>
|
||
|
<input type="text" class="form-control form-control-border @error('description.name') is-invalid @enderror" id="name" name="description[name]" placeholder="Product Name" value="{{ old('description.name',$o->name) }}" required>
|
||
|
<span class="invalid-feedback" role="alert">
|
||
|
@error('description.name')
|
||
|
{{ $message }}
|
||
|
@else
|
||
|
Product Name required.
|
||
|
@enderror
|
||
|
</span>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<!-- Product Active -->
|
||
|
<div class="col-3">
|
||
|
<div class="form-group">
|
||
|
<div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
|
||
|
<input type="checkbox" class="custom-control-input" id="active" name="active" {{ old('active',$o->active) ? 'checked' : '' }}>
|
||
|
<label class="custom-control-label" for="active">Active</label>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="row">
|
||
|
<!-- Product Type -->
|
||
|
<div class="col-4">
|
||
|
<div class="form-group has-validation">
|
||
|
<label for="name">Product Type</label>
|
||
|
<select class="form-control form-control-border" id="model" name="model">
|
||
|
<option value=""></option>
|
||
|
@foreach($o->availableTypes() as $type)
|
||
|
<option value="{{ $type }}" @if($o->type && ($type == get_class($o->type)))selected @endif>{{ $type }}</option>
|
||
|
@endforeach
|
||
|
</select>
|
||
|
<span class="invalid-feedback" role="alert">
|
||
|
@error('model')
|
||
|
{{ $message }}
|
||
|
@else
|
||
|
Product Type required.
|
||
|
@enderror
|
||
|
</span>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="row">
|
||
|
<!-- Supplied Product -->
|
||
|
<div class="col-4" id="supplier_product">
|
||
|
<div class="form-group has-validation">
|
||
|
<label for="name">Supplied Product</label>
|
||
|
<select class="form-control form-control-border" id="model_id" name="model_id">
|
||
|
</select>
|
||
|
<span class="invalid-feedback" role="alert">
|
||
|
@error('model_id')
|
||
|
{{ $message }}
|
||
|
@else
|
||
|
Supplied Product required.
|
||
|
@enderror
|
||
|
</span>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="row">
|
||
|
<!-- Buttons -->
|
||
|
<div class="col-12">
|
||
|
<a href="{{ url('/home') }}" class="btn btn-danger">Cancel</a>
|
||
|
@can('wholesaler')
|
||
|
<button type="submit" name="submit" class="btn btn-success mr-0 float-right">@if ($o->exists)Save @else Add @endif</button>
|
||
|
@endcan
|
||
|
</div>
|
||
|
</div>
|
||
|
</form>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
@section('page-scripts')
|
||
|
@css(select2)
|
||
|
@js(select2,autofocus)
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
// Get a list of supplier items matching this type to populate model_id
|
||
|
function supplier_products(type,destination,selected) {
|
||
|
destination.prop('disabled',true);
|
||
|
|
||
|
$.ajax({
|
||
|
type: 'GET',
|
||
|
dataType: 'json',
|
||
|
data: {type: type},
|
||
|
cache: false,
|
||
|
url: '{{ url('api/a/supplier_products') }}',
|
||
|
timeout: 2000,
|
||
|
error: function(x) {
|
||
|
// @todo add a spinner
|
||
|
//spinner.toggleClass('d-none').toggleClass('fa-spin');
|
||
|
alert('Failed to submit');
|
||
|
},
|
||
|
success: function(data) {
|
||
|
destination
|
||
|
.empty()
|
||
|
.append($('<option>'))
|
||
|
.append(data.map(function(item,key) {
|
||
|
return new Option(item.name,item.id,selected && selected==item.id,selected && selected==item.id);
|
||
|
}))
|
||
|
.prop('disabled',false);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
$(document).ready(function() {
|
||
|
$('#model').select2()
|
||
|
.on('change',function(item) {
|
||
|
if ($(this).val()) {
|
||
|
$('#supplier_product').show();
|
||
|
|
||
|
|
||
|
|
||
|
supplier_products($(this).val(),$('#model_id'));
|
||
|
|
||
|
} else {
|
||
|
$('#supplier_product').hide();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
$('#model_id').select2();
|
||
|
|
||
|
// After we render the page, hide the supplier_product if this product has no model.
|
||
|
// We do this here, because adding d-none to the div results in the select2 input not presenting correctly
|
||
|
if (! $('#model').val())
|
||
|
$('#supplier_product').hide();
|
||
|
else
|
||
|
supplier_products($('#model').val(),$('#model_id'),{{ old('model_id',$o->model_id) }});
|
||
|
});
|
||
|
</script>
|
||
|
@endsection
|