ldc-loue/resources/views/back/modules/minicrud-form-inputs.blade.php
2022-09-19 09:10:04 +00:00

153 lines
7.5 KiB
PHP

<div id="minicrud">
@foreach ($model->data as $k => $input)
<hr class="w-25 mx-auto">
@php
$input = json_decode(json_encode($input), true);
@endphp
@switch($input['inputType']['value'])
@case(App\Enums\InputType::url()->value)
@case(App\Enums\InputType::string()->value)
<div class="form-group">
<label for="{{$k}}"><b>{{ $input['label'] }}*</b></label>
<div class="word-counter" data-json='@json(['id' => $k])'></div>
<input id="{{$k}}" type="text" class="form-control" name="data[{{$k}}][value]"
placeholder="{{ $input['label'] }}" value="{{ old("data.$k.value") ?? ($input['value'] ?? '') }}" required>
@include('back.modules.input-error', [
'inputName' => 'data[{{$k}}][value]',
'helperId' => '{{$k}}StringHelp',
'helper' => $input['helper'],
])
</div>
@break
@case(App\Enums\InputType::number()->value)
<div class="form-group">
<label for="{{$k}}"><b>{{ $input['label'] }}*</b></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>
@include('back.modules.input-error', [
'inputName' => 'data[{{$k}}][value]',
'helperId' => '{{$k}}NumberHelp',
'helper' => $input['helper'],
])
</div>
@break
@case(App\Enums\InputType::text()->value)
<div class="form-group vueComponent">
<label class="col-form-label"><b>{{ $input['label'] }}*</b></label>
@php
$editor = [
'csrf' => csrf_token(),
'name' => "data[$k][text]",
'text' => old("data.$k.text") ?? ($input['text'] ?? ''),
];
@endphp
<div class="ck-editor-bo" data-json='@json($editor)'></div>
@include('back.modules.input-error', [
'inputName' => 'data[{{$k}}][text]',
'helperId' => '{{$k}}TextHelp',
'helper' => $input['helper'],
])
</div>
@break
@case(App\Enums\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'] }}*
@include('back.modules.input-error', [
'inputName' => 'data[{{$k}}][value]',
'helperId' => '{{$k}}BooleanHelp',
'helper' => $input['helper'],
])
</label>
</div>
@break
@case(App\Enums\InputType::image()->value)
<div class="row mb-3">
<div class="col-12 col-md-6 form-group">
<label for="{{$k}}alt" class="col-form-label">
<b>{{ __('Texte alternatif de l\'image') }}</b>
</label>
<div class="word-counter" data-json='@json(['id' => $k.'alt'])'></div>
<input name="data[{{$k}}][alt]" type="text"
value="{{ old("data.$k.alt") ?? $input['alt'] ?? '' }}"
class="form-control" id="{{$k}}alt"
aria-describedby="{{$k}}altHelp"
placeholder="{{ __('Texte alternatif à l\'image') }}" required>
@include('back.modules.input-error', [
'inputName' => 'data[{{$k}}][alt]',
'helperId' => '{{$k}}altHelp',
'helper' => __(
'Doit décrire votre image pour les moteurs de recherches et les non voyants (5 à 6 mots)'
),
])
</div>
<div class="col-12 col-md-6 form-group">
<label for="{{$k}}title" class="col-form-label">
<b>{{ __('Titre de l\'image') }}</b>
</label>
<div class="word-counter" data-json='@json(['id' => $k.'title'])'></div>
<input name="data[{{$k}}][title]" type="text"
value="{{ old("data.$k.title") ?? $input['title'] ?? '' }}"
class="form-control" id="{{$k}}title"
aria-describedby="{{$k}}titleHelp"
placeholder="{{ __('Titre de l\'image') }}" required>
@include('back.modules.input-error', [
'inputName' => 'data[{{$k}}][title]',
'helperId' => '{{$k}}titleHelp',
'helper' => __(
'Utile pour les utilisateurs, s\'affiche en passant la souris sur l\'image'
),
])
</div>
</div>
<div class="row">
<div class="col-12">
@php
$data = [
'id' => $k . 'picture',
'name' => 'data[' . $k . '][value]',
'helper' => __('L\'image qui va servir de vignette à l\'article, doit être de ') . $input['dimensions'],
'value' => $input['value'] ?? '',
];
@endphp
@include('back.modules.input-error', ['inputName' => 'data[' . $k . '][value]'])
<div class="image-input" data-json='@json($data)'></div>
</div>
</div>
@break
@case(App\Enums\InputType::imageArray()->value)
@case(App\Enums\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