291 lines
16 KiB
PHP
291 lines
16 KiB
PHP
<div id="minicrud">
|
|
@foreach ($model->data as $k => $input)
|
|
@php
|
|
$input = json_decode(json_encode($input), true);
|
|
@endphp
|
|
@switch($input['inputType']['value'])
|
|
@case(App\Enums\InputType::password()->value)
|
|
@php $isPassword = true; @endphp
|
|
@case(App\Enums\InputType::url()->value)
|
|
@case(App\Enums\InputType::string()->value)
|
|
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="border p-3 mb-3">
|
|
<div class="d-flex flex-row justify-content-start align-items-center mb-2">
|
|
<legend class="w-auto m-0">
|
|
<label for="string{{$k}}" class="col-form-label">
|
|
<b>{{ $input['label'] }}</b>
|
|
</label>
|
|
</legend>
|
|
@if(!empty($input['tooltip']))
|
|
<span class="ms-1" data-bs-toggle="tooltip" data-bs-html="true" title="{{ $input['tooltip'] }}">
|
|
<i class="fa fa-question-circle"></i>
|
|
</span>
|
|
@endif
|
|
</div>
|
|
<div class="row mb-3">
|
|
<div class="form-group">
|
|
@if(empty($isPassword))
|
|
<div class="word-counter" data-json='@json(['id' => "string{$k}"])'></div>
|
|
@endif
|
|
<input id="string{{$k}}" @if(empty($isPassword))type="text"@else type="password" @endif class="form-control" name="data[{{$k}}][value]"
|
|
aria-describedby="StringHelp{{$k}}"
|
|
placeholder="{{ $input['label'] }}" value="{{ old("data.{$k}.value") ?? ($input['value'] ?? '') }}" required>
|
|
@include('back::modules.input-error', [
|
|
'inputName' => "data.{$k}.value",
|
|
'helperId' => "StringHelp{$k}",
|
|
'helper' => $input['helper'] ?? '',
|
|
])
|
|
</div>
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
@break
|
|
@case(App\Enums\InputType::number()->value)
|
|
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="border p-3 mb-3">
|
|
<div class="d-flex flex-row justify-content-start align-items-center mb-2">
|
|
<legend class="w-auto m-0">
|
|
<label for="number{{$k}}" class="col-form-label">
|
|
<b>{{ $input['label'] }}</b>
|
|
</label>
|
|
</legend>
|
|
@if(!empty($input['tooltip']))
|
|
<span class="ms-1" data-bs-toggle="tooltip" data-bs-html="true" title="{{ $input['tooltip'] }}">
|
|
<i class="fa fa-question-circle"></i>
|
|
</span>
|
|
@endif
|
|
</div>
|
|
<div class="row mb-3">
|
|
<div class="form-group">
|
|
<input id="number{{$k}}" type="number" step="0.01" class="form-control"
|
|
aria-describedby="NumberHelp{{$k}}"
|
|
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' => "NumberHelp{$k}",
|
|
'helper' => $input['helper'] ?? '',
|
|
])
|
|
</div>
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
@break
|
|
@case(App\Enums\InputType::text()->value)
|
|
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="border p-3 mb-3">
|
|
<div class="d-flex flex-row justify-content-start align-items-center mb-2">
|
|
<legend class="w-auto m-0">
|
|
<label for="text{{$k}}" class="col-form-label">
|
|
<b>{{ $input['label'] }}</b>
|
|
</label>
|
|
</legend>
|
|
@if(!empty($input['tooltip']))
|
|
<span class="ms-1" data-bs-toggle="tooltip" data-bs-html="true" title="{{ $input['tooltip'] }}">
|
|
<i class="fa fa-question-circle"></i>
|
|
</span>
|
|
@endif
|
|
</div>
|
|
<div class="row mb-3">
|
|
<div class="form-group">
|
|
@include('back::modules.input-error', [
|
|
'inputName' => "data.{$k}.text",
|
|
'helperId' => "{$k}TextHelp",
|
|
'helper' => $input['helper'] ?? '',
|
|
])
|
|
@php
|
|
$editor = [
|
|
'id' => "text{$k}",
|
|
'csrf' => csrf_token(),
|
|
'name' => "data[$k][text]",
|
|
'text' => old("data.{$k}.text") ?? ($input['text'] ?? ''),
|
|
];
|
|
@endphp
|
|
<div class="ck-editor" data-json='@json($editor)'></div>
|
|
</div>
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
@break
|
|
@case(App\Enums\InputType::boolean()->value)
|
|
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="border p-3 mb-3">
|
|
<div class="d-flex flex-row justify-content-start align-items-center mb-2">
|
|
<legend class="w-auto m-0">
|
|
<label for="boolean{{$k}}" class="col-form-label">
|
|
<b>{{ $input['label'] }}</b>
|
|
</label>
|
|
</legend>
|
|
@if(!empty($input['tooltip']))
|
|
<span class="ms-1" data-bs-toggle="tooltip" data-bs-html="true" title="{{ $input['tooltip'] }}">
|
|
<i class="fa fa-question-circle"></i>
|
|
</span>
|
|
@endif
|
|
</div>
|
|
<div class="row mb-3">
|
|
<div class="form-group">
|
|
<label class="user-select-none">
|
|
<input type="checkbox" name="data[{{$k}}][value]" value="1"
|
|
id="boolean{{$k}}"
|
|
aria-describedby="BooleanHelp{{$k}}"
|
|
@if (old("data.{$k}.value", (old('_token') ? false : ($input['value'] ?? false)))) checked @endif>
|
|
{{ $input['label'] }}*
|
|
@include('back::modules.input-error', [
|
|
'inputName' => "data.{$k}.value",
|
|
'helperId' => "BooleanHelp{$k}",
|
|
'helper' => $input['helper'] ?? '',
|
|
])
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
@break
|
|
@case(App\Enums\InputType::image()->value)
|
|
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="border p-3 mb-3">
|
|
<div class="d-flex flex-row justify-content-start align-items-center mb-2">
|
|
<legend class="w-auto m-0">
|
|
<label for="picture{{$k}}" class="col-form-label">
|
|
<b>{{ $input['label'] }}</b>
|
|
</label>
|
|
</legend>
|
|
@if(!empty($input['tooltip']))
|
|
<span class="ms-1" data-bs-toggle="tooltip" data-bs-html="true" title="{{ $input['tooltip'] }}">
|
|
<i class="fa fa-question-circle"></i>
|
|
</span>
|
|
@endif
|
|
</div>
|
|
@if(isset($input['alt']) || isset($input['title']))
|
|
<div class="row mb-3">
|
|
@if(isset($input['alt']))
|
|
<div class="col-12 col-md-6 form-group">
|
|
<label for="alt{{$k}}" class="col-form-label">
|
|
<b>{{ __('Texte alternatif de l\'image') }}</b>
|
|
</label>
|
|
<div class="word-counter" data-json='@json(['id' => "alt{$k}"])'></div>
|
|
<input name="data[{{$k}}][alt]" type="text"
|
|
id="alt{{$k}}"
|
|
value="{{ old("data.{$k}.alt") ?? $input['alt'] ?? '' }}"
|
|
class="form-control" id="alt{{$k}}"
|
|
aria-describedby="altHelp{{$k}}"
|
|
placeholder="{{ __('Texte alternatif à l\'image') }}" required>
|
|
@include('back::modules.input-error', [
|
|
'inputName' => "data.{$k}.alt",
|
|
'helperId' => "altHelp{$k}",
|
|
'helper' => __(
|
|
'Doit décrire votre image pour les moteurs de recherches et les non voyants (5 à 6 mots)'
|
|
),
|
|
])
|
|
</div>
|
|
@endif
|
|
@if(isset($input['title']))
|
|
<div class="col-12 col-md-6 form-group">
|
|
<label for="title{{$k}}" class="col-form-label">
|
|
<b>{{ __('Titre de l\'image') }}</b>
|
|
</label>
|
|
<div class="word-counter" data-json='@json(['id' => "title{$k}"])'></div>
|
|
<input name="data[{{$k}}][title]" type="text"
|
|
id="title{{$k}}"
|
|
value="{{ old("data.{$k}.title") ?? $input['title'] ?? '' }}"
|
|
class="form-control" id="title{{$k}}"
|
|
aria-describedby="titleHelp{{$k}}"
|
|
placeholder="{{ __('Titre de l\'image') }}" required>
|
|
@include('back::modules.input-error', [
|
|
'inputName' => "data.{$k}.title",
|
|
'helperId' => "titleHelp{$k}",
|
|
'helper' => __(
|
|
'Utile pour les utilisateurs, s\'affiche en passant la souris sur l\'image'
|
|
),
|
|
])
|
|
</div>
|
|
@endif
|
|
</div>
|
|
@endif
|
|
<div class="row">
|
|
<div class="col-12">
|
|
@php
|
|
$data = [
|
|
'id' => "picture{$k}",
|
|
'name' => "data[{$k}][value]",
|
|
'helper' => __(":helper, doit être de " .
|
|
$input['dimensions']['largeur'] . "px (largeur) et " .
|
|
$input['dimensions']['hauteur'] . "px (hauteur).", ['helper' => $input['helper'] ?? 'Image']),
|
|
'value' => $input['value'] ?? '',
|
|
'width' => $input['dimensions']['largeur'],
|
|
'height' => $input['dimensions']['hauteur'],
|
|
'browseEvent' => false
|
|
];
|
|
@endphp
|
|
<div class="image-input" data-json='@json($data)'></div>
|
|
@include('back::modules.input-error', ['inputName' => 'data[' . $k . '][value]'])
|
|
</div>
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
@break
|
|
@case(App\Enums\InputType::email()->value)
|
|
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="border p-3 mb-3">
|
|
<div class="d-flex flex-row justify-content-start align-items-center mb-2">
|
|
<legend class="w-auto m-0">
|
|
<label for="title{{$k}}" class="col-form-label">
|
|
<b>{{ $input['label'] }}</b>
|
|
</label>
|
|
</legend>
|
|
@if(!empty($input['tooltip']))
|
|
<span class="ms-1" data-bs-toggle="tooltip" data-bs-html="true" title="{{ $input['tooltip'] }}">
|
|
<i class="fa fa-question-circle"></i>
|
|
</span>
|
|
@endif
|
|
</div>
|
|
<div class="row mb-3">
|
|
<div class="form-group">
|
|
<input id="title{{$k}}" type="email" 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>
|
|
</div>
|
|
</fieldset>
|
|
</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
|