feat: add submission-completed event to reset file input and preview after assignment submission and update UI labels
This commit is contained in:
parent
6721ceffcc
commit
68ec1d3700
@ -230,6 +230,8 @@ public function submit(): void
|
|||||||
|
|
||||||
$this->file = null;
|
$this->file = null;
|
||||||
unset($this->existingSubmission, $this->isResubmit);
|
unset($this->existingSubmission, $this->isResubmit);
|
||||||
|
|
||||||
|
$this->dispatch('submission-completed');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class="prose prose-sm dark:prose-invert max-w-none text-gray-600 dark:text-gray-
|
|||||||
|
|
||||||
@if ($this->record->hasMedia('assignments'))
|
@if ($this->record->hasMedia('assignments'))
|
||||||
<div class="mt-4 pt-4 border-t border-gray-100 dark:border-gray-700">
|
<div class="mt-4 pt-4 border-t border-gray-100 dark:border-gray-700">
|
||||||
<p class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">Lampiran Tugas (PDF)</p>
|
<p class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">Lampiran Tugas</p>
|
||||||
<div
|
<div
|
||||||
class="rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900">
|
class="rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900">
|
||||||
<iframe src="{{ $this->record->getFirstMediaUrl('assignments') }}" width="100%" height="500"
|
<iframe src="{{ $this->record->getFirstMediaUrl('assignments') }}" width="100%" height="500"
|
||||||
@ -115,7 +115,7 @@ class="block border-0"></iframe>
|
|||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5">
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5">
|
||||||
{{ $this->isResubmit ? 'Ganti File PDF (opsional)' : 'File Tugas (PDF)' }}
|
{{ $this->isResubmit ? 'Ganti File PDF (opsional)' : 'File Tugas' }}
|
||||||
@if (!$this->isResubmit)
|
@if (!$this->isResubmit)
|
||||||
<span class="text-danger-500">*</span>
|
<span class="text-danger-500">*</span>
|
||||||
@endif
|
@endif
|
||||||
@ -164,19 +164,36 @@ class="block border-0"></iframe>
|
|||||||
@push('scripts')
|
@push('scripts')
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// Function to reset preview
|
||||||
|
function resetPreview() {
|
||||||
|
var preview = document.getElementById('pdf-submission-preview');
|
||||||
|
var frame = document.getElementById('pdf-submission-frame');
|
||||||
|
if (preview) preview.classList.add('hidden');
|
||||||
|
if (frame) frame.src = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delegation for change event
|
||||||
document.addEventListener('change', function(e) {
|
document.addEventListener('change', function(e) {
|
||||||
if (e.target && e.target.id === 'assignment-file') {
|
if (e.target && e.target.id === 'assignment-file') {
|
||||||
var file = e.target.files[0];
|
var file = e.target.files[0];
|
||||||
var preview = document.getElementById('pdf-submission-preview');
|
var preview = document.getElementById('pdf-submission-preview');
|
||||||
var frame = document.getElementById('pdf-submission-frame');
|
var frame = document.getElementById('pdf-submission-frame');
|
||||||
|
|
||||||
if (file && preview && frame) {
|
if (file && preview && frame) {
|
||||||
frame.src = URL.createObjectURL(file);
|
frame.src = URL.createObjectURL(file);
|
||||||
preview.classList.remove('hidden');
|
preview.classList.remove('hidden');
|
||||||
} else if (preview) {
|
} else {
|
||||||
preview.classList.add('hidden');
|
resetPreview();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Listen for the Livewire event after submission
|
||||||
|
window.addEventListener('submission-completed', function() {
|
||||||
|
var input = document.getElementById('assignment-file');
|
||||||
|
if (input) input.value = '';
|
||||||
|
resetPreview();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user