ldc-legaulois/resources/views/bo/modules/minicrud-form-inputs.blade.php
Jérémy Munsch c0d8fdb73f
Fixes #11
CSP ISSUES Add missing nonces everywhere + add strict dynamic
2023-03-23 16:02:56 +01:00

74 lines
4 KiB
PHP

{{-- MINI CRUD EDIT --}}
<div id="minicrud">
@foreach($model->data as $k => $input)
@if(!$loop->first)
<hr class="w-25">
@endif
@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::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>
<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
@if(isset($input['text']))
<div class="form-group vueComponent">
<label class="col-form-label">{{ $input['label_text'] }}*</label>
<custom-ckeditor name="data[{{$k}}][text]" dbtext="{{ old("data.$k.text") ?? $input['text'] ?? '' }}"></custom-ckeditor>
</div>
@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 }}">
$('#minicrud').parents('form').on('submit', function(e) {
$('input[type="file"]').each(function(i, img) {
if ($(img).data('old-value') && !$(img).val()) {
$(img).attr('type', 'text').val($(img).data('old-value'));
}
});
});
</script>
@endpush