83 lines
4.1 KiB
PHP
83 lines
4.1 KiB
PHP
{{-- MINI CRUD EDIT --}}
|
|
<div id="minicrud">
|
|
@foreach($model->data as $k => $input)
|
|
@if(!$loop->first)
|
|
<hr class="w-25">
|
|
@endif
|
|
@php
|
|
$input = json_decode(json_encode($input), true);
|
|
@endphp
|
|
@switch($input['inputType']['value'])
|
|
@case(InputType::url()->value)
|
|
@case(InputType::string()->value)
|
|
<div class="form-group">
|
|
<label for="{{ $k }}"><small>{{ $input['label'] }}*</small></label>
|
|
<input id="{{ $k }}" type="text" class="form-control" name="data[{{$k}}][value]" placeholder="{{ $input['label'] }}" value="{{ old("data.$k.value") ?? $input['value'] ?? '' }}" required>
|
|
</div>
|
|
@break
|
|
@case(InputType::number()->value)
|
|
<div class="form-group">
|
|
<label for="{{ $k }}"><small>{{ $input['label'] }}*</small></label>
|
|
<input id="{{ $k }}" type="number" step="0.01" class="form-control" name="data[{{$k}}][value]" placeholder="{{ $input['label'] }}" value="{{ old("data.$k.value") ?? $input['value'] ?? '' }}" required>
|
|
</div>
|
|
@break
|
|
@case(InputType::text()->value)
|
|
<div class="form-group vueComponent">
|
|
<label class="col-form-label">{{ $input['label'] }}*</label>
|
|
<custom-ckeditor name="data[{{$k}}][text]" dbtext="{{ old("data.$k.text") ?? $input['text'] ?? '' }}"></custom-ckeditor>
|
|
</div>
|
|
@break
|
|
@case(InputType::boolean()->value)
|
|
<div class="form-group">
|
|
<label class="user-select-none">
|
|
<input type="checkbox" name="data[{{$k}}][value]" value="1" @if (( old("data.$k.value") ?? $input['value'] ?? 0 ))checked @endif>
|
|
{{ $input['label'] }}*
|
|
</label>
|
|
</div>
|
|
@break
|
|
@case(InputType::image()->value)
|
|
<div class="form-group">
|
|
@if(isset($input['label']))
|
|
<h3>{{ $input['label'] }}</h3>
|
|
@endif
|
|
<span id="{{ $k }}imgLABEL">{{ __('Visuel * de type JPEG/PNG/SVG - 2Mo max.')}} - {{ isset($input['dimensions']) ? __('Dimensions :dimensions', ['dimensions' => $input['dimensions']]) : __('Dimensions Maximales :max', ['max' => $input['dimensionsMax']]) }} px</span>
|
|
<div class="input-group mb-3">
|
|
<div class="custom-file">
|
|
<input id="{{ $k }}img" type="file" class="custom-file-input" name="data[{{$k}}][value]" accept="image/png,image/jpeg,.svg" aria-describedby="{{ $k }}imgLABEL">
|
|
<label class="custom-file-label" for="{{ $k }}img">{{ __('Choisir un fichier') }}</label>
|
|
</div>
|
|
</div>
|
|
<br>
|
|
<label for="{{ $k }}alt"><small>{{ $input['label'] }} - {{ __('Texte alternatif') }}</small></label>
|
|
<input id="{{ $k }}alt" type="text" class="form-control" name="data[{{$k}}][alt]" placeholder="{{ __('Texte alternatif à l\'image') }}" value="{{ old("data.$k.alt") ?? $input['alt'] ?? '' }}">
|
|
<br>
|
|
@if(isset($input['value']) and strlen($input['value']))
|
|
<img src="{{ $input['value'] }}" alt="image" style="max-height:200px;max-width:100%;object-fit:contain;margin:0 auto;display:block;">
|
|
@endif
|
|
</div>
|
|
@break
|
|
@case(InputType::imageArray()->value)
|
|
@case(InputType::labelArray()->value)
|
|
@default
|
|
@php throw new Exception('Input type not handled'); @endphp
|
|
@endswitch
|
|
@endforeach
|
|
</div>
|
|
|
|
@push('scripts')
|
|
<script nonce="{{ $nonce }}">
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
let minicrud = document.getElementById('minicrud').closest('form');
|
|
if(minicrud) {
|
|
minicrud.addEventListener('submit', function(e) {
|
|
document.querySelectorAll('input[type="file"]').forEach(function(input) {
|
|
if (input.dataset['old-value'] && !input.value) {
|
|
input.setAttribute('type', 'text');
|
|
input.value = input.getAttribute('old-value');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
@endpush
|