ldc-supportweb/resources/views/ticket/form-inputs.blade.php
2023-04-19 17:35:57 +02:00

120 lines
5.4 KiB
PHP

@php
$userPr = Auth::user()->sites ?? collect([]);
@endphp
<div class="form-row">
<div class="form-group col">
<label for="site" class="col-form-label">{{ __('Site') }}</label>
<select class="form-select" name="site_id" id="site">
@foreach($sites as $site)
@if (Auth::user()->isAdmin())
<option value="{{ $site->id }}" @if ($site->id == old('site_id') or (isset($ticket) and $ticket->site->id == $site->id))selected @endif>{{ $site->name }}</option>
@elseif ($userPr->filter(function($pr) use($site) { return $pr->id === $site->id; })->count())
<option value="{{ $site->id }}" selected>{{ $site->name }}</option>
@endif
@endforeach
</select>
</div>
<div class="form-group col">
<label for="type" class="col-form-label">{{ __('Type') }}</label>
<select class="form-select" name="type" id="type">
@foreach(\App\Enums\TicketTypeEnum::toArray() as $ticketType)
<option value="{{ $ticketType->value }}" @if($ticketType->value == old('type') or (isset($ticket) and $ticketType->equals($ticket->type)))selected @endif>{{ $ticketType->label }}</option>
@endforeach
</select>
</div>
@can('changeStatus', App\Model\Ticket::class)
<div class="form-group col">
<label for="status" class="col-form-label">{{ __('Status') }}</label>
<select class="form-select" name="status" id="status">
@foreach(TicketStatus::toArray() as $ticketStatus)
<option value="{{ $ticketStatus->value }}" @if($ticketType->value == old('status') or (isset($ticket) and $ticketStatus->equals($ticket->status)))selected @endif>{{ $ticketStatus->label }}</option>
@endforeach
</select>
</div>
@push('scripts')
<script nonce="{{ $nonce ?? null }}">
document.addEventListener('DOMContentLoaded', function () {
const typeSwitch = document.getElementById('type');
const textArea = document.getElementById('text');
const templates = {
@foreach(\App\Models\Ticket\TicketType::query()->get() as $ticketTypeModel)
@php $value = str_replace(["\r\n", "\n", "\r"], '\n', str_replace("<br />", '\n', strip_tags(nl2br($ticketTypeModel->template), '<br />'))); @endphp
"{{ $ticketTypeModel->type->value }}" : "{!! $value !!}",
@endforeach
};
const changeTextValue = () => {
switch(typeSwitch.value) {
@foreach(\App\Models\Ticket\TicketType::query()->get() as $ticketTypeModel)
case "{{ $ticketTypeModel->type->value }}":
// * Ignore if template already changed.
if(textArea.value !== (templates[textArea.template] ?? null) && textArea.value.length) {
return;
}
// Save actual template
textArea.template = typeSwitch.value;
// apply template
textArea.value = templates[typeSwitch.value];
break;
@endforeach
default:
console.error(`Unkown value ${typeSwitch.value}`);
}
};
typeSwitch.addEventListener('change', changeTextValue);
changeTextValue();
});
</script>
@endpush
@else
<input type="hidden" name="status" value="{{ \App\Enums\TicketStatus::new() }}" required>
@endcan
@can('assignLabels', App\Model\Ticket::class)
<div class="form-group col">
<label for="labels" class="col-form-label">{{ __('Étiquettes') }}</label>
@php
$dataVue = [
'name' => 'labels',
'value' => optional($ticket ?? null)->labels,
'labels' => \App\Models\Label::all()
];
@endphp
<div
id="label-select"
class="sticky-top"
data-json='@json($dataVue)'></div>
</div>
@endcan
</div>
<div class="form-group mb-5">
<label for="text" class="col-form-label text-md-right">{{ __('Description') }}</label>
<textarea rows="15" class="form-control" name="text" id="text" placeholder="{{ __('Description du ticket') }} *">{{ old('text') ?? $ticket->text ?? ''}}</textarea>
</div>
<h4>Fichier joint 1</h4>
<div class="form-group mb-3">
<input type="file" name="file_ticket" accept="image/png, image/jpeg, image/jpg, .pdf">
@if (isset($ticket) and $ticket->file !== null)
<hr>
<div class="text-center">
<img class="img-fluid" src="{{ asset($ticket->file) }}">
</div>
@endif
</div>
<h4>Fichier joint 2</h4>
<div class="form-group">
<input type="file" name="file_ticket2" accept="image/png, image/jpeg, image/jpg, .pdf">
@if (isset($ticket) and $ticket->file2 !== null)
<hr>
<div class="text-center">
<img class="img-fluid" src="{{ asset($ticket->file2) }}">
</div>
@endif
</div>
@can('changeInternalStatus', App\Model\Ticket::class)
<div class="form-group text-center">
<input type="checkbox" name="is_internal" id="is_internal" @if(old('is_internal', isset($ticket) and $ticket->is_internal)) checked @endif>
<label for="is_internal" class="col-form-label">Ticket interne</label>
</div>
@endcan