Files
verifikator/resources/views/verifikasi/berita-acara/index.blade.php
T

287 lines
12 KiB
PHP

@extends('layouts.main')
@section('breadcrumb')
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript:void(0);">Verifikasi</a></li>
<li class="breadcrumb-item active" aria-current="page">{{ $title }}</li>
</ol>
@endsection
@section('content')
<div class="card border">
<div class="card-body">
@include('components.datatable-header', [
'title' => 'Daftar Berita Acara',
'description' => 'Berikut adalah daftar Berita Acara dari setiap Unit Kerja',
])
<div class="table-responsive">
<table class="table table-bordered w-100 dt-styled" id="berita-acara-table">
<thead>
<tr>
<th>File BA</th>
<th>Periode</th>
<th>NIP Penandatangan</th>
<th>Nama Penandatangan</th>
<th>Unit Kerja</th>
<th width="180">Aksi</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<!-- Modal Preview File BA -->
<div class="modal fade" id="previewModal" tabindex="-1" aria-labelledby="previewModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="previewModalLabel">Preview Berita Acara - <span id="unitKerjaNama"></span>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" style="height: 80vh;">
<iframe id="pdfViewer" style="width: 100%; height: 100%; border: none;"></iframe>
</div>
<div class="modal-footer">
<a id="downloadBtn" href="#" target="_blank" class="btn btn-success" download>
<i class="uil-file-download-alt"></i> Download
</a>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
</div>
</div>
</div>
</div>
<!-- Modal Upload File BA -->
<div class="modal fade" id="uploadModal" tabindex="-1" aria-labelledby="uploadModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form id="uploadForm" enctype="multipart/form-data">
@csrf
<div class="modal-header">
<h5 class="modal-title" id="uploadModalLabel">Upload Berita Acara - <span
id="uploadUnitKerjaNama"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<input type="hidden" id="beritaAcaraId" name="berita_acara_id">
<input type="hidden" id="unitId" name="unit_id">
<input type="hidden" id="periode" name="periode">
<div class="alert alert-info">
<strong>Informasi:</strong><br>
File akan disimpan dengan nama: <strong><span id="uploadNip"></span>.pdf</strong><br>
Format file: PDF (max 10MB)
</div>
<div class="mb-3">
<label for="filePdf" class="form-label">Pilih File PDF <span
class="text-danger">*</span></label>
<input type="file" class="form-control" id="filePdf" name="file_pdf" accept=".pdf"
required>
<div class="invalid-feedback">
Pilih file PDF yang akan diupload
</div>
</div>
<div id="uploadProgress" class="progress d-none mb-3" style="height: 25px;">
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar"
style="width: 0%">0%</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" id="btnUpload">
<i class="uil-upload"></i> Upload
</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
</div>
</form>
</div>
</div>
</div>
@endsection
@section('js')
<script>
$(document).ready(function() {
$('#berita-acara-table').DataTable({
processing: true,
serverSide: true,
ajax: "{{ route('berita-acara.data') }}",
columns: [{
data: 'file_ba',
name: 'file_cap',
orderable: false,
searchable: false,
className: 'text-center'
},
{
data: 'periode',
name: 'periode',
className: 'text-center'
},
{
data: 'nip_penandatangan',
name: 'team.pegawai.nip',
className: 'text-center'
},
{
data: 'nama_penandatangan',
name: 'team.pegawai.nama_lengkap'
},
{
data: 'unit_kerja',
name: 'unitKerja.nama'
},
{
data: 'aksi',
name: 'aksi',
orderable: false,
searchable: false,
className: 'text-center'
}
],
order: [
[1, 'asc']
],
language: {
processing: "<div class='spinner'></div>&nbsp; Sedang Memuat...",
},
});
// Event handler untuk tombol preview
$(document).on('click', '.preview-btn', function() {
const fileUrl = $(this).data('file');
const unitNama = $(this).data('unit');
// Set judul modal
$('#unitKerjaNama').text(unitNama);
// Set iframe src untuk preview PDF
$('#pdfViewer').attr('src', fileUrl);
// Set download button
$('#downloadBtn').attr('href', fileUrl);
// Tampilkan modal
$('#previewModal').modal('show');
});
// Clear iframe saat modal ditutup untuk menghemat resource
$('#previewModal').on('hidden.bs.modal', function() {
$('#pdfViewer').attr('src', '');
});
// Event handler untuk tombol upload
$(document).on('click', '.upload-btn', function() {
const baId = $(this).data('ba-id');
const unitId = $(this).data('unit-id');
const unitNama = $(this).data('unit');
const periode = $(this).data('periode');
const nip = $(this).data('nip');
// Reset form dulu sebelum set data
$('#uploadForm')[0].reset();
$('#uploadProgress').addClass('d-none');
$('#uploadProgress .progress-bar').css('width', '0%').text('0%');
// Set data modal setelah reset
$('#beritaAcaraId').val(baId);
$('#unitId').val(unitId);
$('#periode').val(periode);
$('#uploadUnitKerjaNama').text(unitNama);
$('#uploadNip').text(nip);
// Tampilkan modal
$('#uploadModal').modal('show');
});
// Handle form upload
$('#uploadForm').on('submit', function(e) {
e.preventDefault();
const form = this;
const formData = new FormData(form);
const $btnUpload = $('#btnUpload');
const $progress = $('#uploadProgress');
const $progressBar = $progress.find('.progress-bar');
// Validasi file
const fileInput = $('#filePdf')[0];
if (!fileInput.files.length) {
fileInput.classList.add('is-invalid');
return;
}
fileInput.classList.remove('is-invalid');
// Disable button dan tampilkan progress
$btnUpload.prop('disabled', true);
$progress.removeClass('d-none');
$.ajax({
url: "{{ route('berita-acara.upload') }}",
type: 'POST',
data: formData,
contentType: false,
processData: false,
xhr: function() {
const xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener('progress', function(e) {
if (e.lengthComputable) {
const percentComplete = Math.round((e.loaded / e.total) * 100);
$progressBar.css('width', percentComplete + '%')
.text(percentComplete + '%');
}
}, false);
return xhr;
},
success: function(response) {
if (response.success) {
Swal.fire({
icon: 'success',
title: 'Berhasil',
text: response.message,
timer: 2000,
showConfirmButton: false
});
// Tutup modal dan reload table
$('#uploadModal').modal('hide');
$('#berita-acara-table').DataTable().ajax.reload();
}
},
error: function(xhr) {
let errorMsg = 'Terjadi kesalahan saat upload file';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMsg = xhr.responseJSON.message;
} else if (xhr.responseJSON && xhr.responseJSON.errors) {
const errors = xhr.responseJSON.errors;
errorMsg = Object.values(errors).flat().join('<br>');
}
Swal.fire({
icon: 'error',
title: 'Gagal',
html: errorMsg
});
},
complete: function() {
$btnUpload.prop('disabled', false);
$progress.addClass('d-none');
$progressBar.css('width', '0%').text('0%');
}
});
});
// Reset validation saat file dipilih
$('#filePdf').on('change', function() {
this.classList.remove('is-invalid');
});
});
</script>
@endsection