Backup Perbaikan

This commit is contained in:
Ariyutta
2026-09-27 13:53:17 +07:00
parent 977e8d7de8
commit 870aeaf2db
10 changed files with 651 additions and 314 deletions
@@ -8,6 +8,14 @@
@endsection
@section('css')
<style>
#atasan-table tbody tr {
cursor: pointer;
}
#atasan-table tbody tr:hover td {
background-color: #e3f2fd;
}
</style>
@endsection
@section('content')
@@ -19,23 +27,35 @@
<div class="col-12">
<div class="card border">
<div class="card-body">
<h5 class="card-title mb-3">Pilih Pegawai Atasan</h5>
<form action="{{ route('tri-dharma.bawahan.index') }}" method="get" id="form-pilih-atasan">
<div class="row">
<div class="col-md-12 mb-3">
<label for="select_atasan" class="form-label">Pilih Atasan</label>
<select name="nip_atasan" id="select_atasan" class="form-control select2" required>
<option value="">-- Pilih Pegawai Atasan --</option>
@foreach ($allPegawais as $peg)
<option value="{{ $peg->nip }}"
{{ isset($nipAtasan) && $nipAtasan == $peg->nip ? 'selected' : '' }}>
{{ $peg->nama }} ({{ $peg->nip }})
</option>
@endforeach
</select>
</div>
</div>
</form>
@include('components.datatable-header', [
'title' => 'Daftar Atasan (Ketua Jurusan)',
'description' => 'Klik salah satu baris untuk melihat dan mengelola daftar bawahannya.',
])
<div class="table-responsive">
<table id="atasan-table" class="table table-striped table-bordered w-100">
<thead>
<tr>
<th width="60">No</th>
<th>Nama</th>
<th>NIP</th>
</tr>
</thead>
<tbody>
@forelse ($allPegawais as $index => $peg)
<tr class="atasan-row" data-nip="{{ $peg->nip }}" data-nama="{{ $peg->nama }}">
<td>{{ $index + 1 }}</td>
<td>{{ $peg->nama }}</td>
<td>{{ $peg->nip }}</td>
</tr>
@empty
<tr>
<td colspan="3" class="text-center text-muted py-3">Tidak ada data atasan</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</div>
</div>
@@ -46,13 +66,8 @@
<div class="card border">
<div class="card-body">
@include('components.datatable-header', [
'title' =>
isset($isAdmin) && $isAdmin
? 'Daftar Bawahan - ' . $pegawai->nama
: 'Daftar Bawahan',
'description' =>
'Berikut adalah daftar bawahan dari Jabatan Tugas Tambahan' .
(isset($isAdmin) && $isAdmin ? ' pegawai ' . $pegawai->nama : ''),
'title' => 'Daftar Bawahan',
'description' => 'Berikut adalah daftar bawahan dari Jabatan Tugas Tambahan',
])
<!-- Form Tambah Bawahan -->
@@ -104,6 +119,57 @@
</div>
@endif
</div>
@if (isset($isAdmin) && $isAdmin)
<!-- Modal Detail & Kelola Bawahan -->
<div class="modal fade" id="modalBawahan" tabindex="-1" aria-hidden="true" data-bs-backdrop="static">
<div class="modal-dialog modal-lg modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title mb-0">Daftar Bawahan - <span id="modalAtasanNama"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row mb-3 g-2">
<div class="col-md-9">
<select id="modal_select_tambah_bawahan" class="form-control" style="width: 100%">
<option value=""></option>
</select>
</div>
<div class="col-md-3 d-flex align-items-stretch">
<button type="button" id="modal-btn-tambah-bawahan" class="btn {{ ($beritaAcaraUploaded ?? false) ? 'btn-secondary' : 'btn-success' }} w-100">
<i class="uil-plus"></i> Tambah
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-sm table-striped table-bordered w-100 mb-0">
<thead>
<tr>
<th width="40">No</th>
<th>NIP</th>
<th>Nama</th>
<th width="90">Aksi</th>
</tr>
</thead>
<tbody id="modalBawahanBody">
<tr>
<td colspan="4" class="text-center text-muted py-3">Memuat data...</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
<button type="button" id="modal-btn-simpan" class="btn btn-primary">
<i class="uil-save"></i> Simpan Semua Perubahan
</button>
</div>
</div>
</div>
</div>
@endif
@endsection
@section('js')
@@ -115,7 +181,7 @@
if (beritaAcaraUploaded) {
document.addEventListener('click', function(e) {
var $matched = $(e.target).closest('#btn-tambah-bawahan, .btn-hapus');
var $matched = $(e.target).closest('#btn-tambah-bawahan, .btn-hapus, #modal-btn-tambah-bawahan, .btn-hapus-modal');
if ($matched.length) {
e.preventDefault();
e.stopPropagation();
@@ -127,9 +193,9 @@
});
</script>
<script>
$(document).ready(function() {
@if (isset($nipAtasan) && $nipAtasan)
@if (isset($nipAtasan) && $nipAtasan)
<script>
$(document).ready(function() {
// Store added/removed items temporarily
let addedBawahan = [];
let removedBawahan = [];
@@ -386,24 +452,176 @@
}
});
});
@endif
});
</script>
@endif
@if (isset($isAdmin) && $isAdmin)
// Initialize Select2 for atasan selection
$('select#select_atasan').select2({
'width': '100%',
'placeholder': 'Pilih Pegawai Atasan',
'allowClear': true
});
@if (isset($isAdmin) && $isAdmin)
<script>
$(document).ready(function() {
let currentNipAtasan = null;
let currentBawahan = []; // {nip, nama}
let availablePegawais = []; // {nip, nama}
let modalSelect2Initialized = false;
// Auto-submit form when atasan is selected
$('select#select_atasan').on('change', function() {
const selectedValue = $(this).val();
if (selectedValue) {
$('#form-pilih-atasan').submit();
const modalEl = document.getElementById('modalBawahan');
const modalBawahan = new bootstrap.Modal(modalEl);
function renderModalTable() {
const $body = $('#modalBawahanBody').empty();
if (currentBawahan.length === 0) {
$body.append('<tr><td colspan="4" class="text-center text-muted py-3">Belum ada bawahan yang ditugaskan</td></tr>');
return;
}
currentBawahan.forEach(function(b, idx) {
$body.append(
'<tr>' +
'<td class="text-center">' + (idx + 1) + '</td>' +
'<td>' + b.nip + '</td>' +
'<td>' + b.nama + '</td>' +
'<td class="text-center"><button type="button" class="btn btn-sm btn-danger btn-hapus-modal" data-nip="' + b.nip + '" data-nama="' + b.nama + '"><i class="uil-trash-alt"></i></button></td>' +
'</tr>'
);
});
}
function renderModalSelectOptions() {
const $select = $('#modal_select_tambah_bawahan');
$select.empty().append('<option value=""></option>');
availablePegawais.forEach(function(p) {
$select.append('<option value="' + p.nip + '" data-nama="' + p.nama + '">' + p.nama + ' (' + p.nip + ')</option>');
});
if (modalSelect2Initialized) {
$select.trigger('change.select2');
} else {
$select.select2({
width: '100%',
placeholder: 'Pilih Pegawai untuk Ditambahkan',
allowClear: true,
dropdownParent: $('#modalBawahan')
});
modalSelect2Initialized = true;
}
}
function loadModalData(nip, nama) {
currentNipAtasan = nip;
$('#modalAtasanNama').text(nama);
$('#modalBawahanBody').html('<tr><td colspan="4" class="text-center text-muted py-3">Memuat data...</td></tr>');
currentBawahan = [];
availablePegawais = [];
$.ajax({
url: "{{ route('tri-dharma.bawahan.modal-data') }}",
type: 'GET',
data: {
nip_atasan: nip
},
success: function(response) {
currentBawahan = (response.bawahan || []).map(b => ({
nip: b.nip,
nama: b.nama
}));
availablePegawais = response.available || [];
renderModalTable();
renderModalSelectOptions();
},
error: function() {
$('#modalBawahanBody').html('<tr><td colspan="4" class="text-center text-danger py-3">Gagal memuat data</td></tr>');
}
});
}
$(document).on('click', '.atasan-row', function() {
const nip = $(this).data('nip');
const nama = $(this).data('nama');
loadModalData(nip, nama);
modalBawahan.show();
});
@endif
});
</script>
$('#modal-btn-tambah-bawahan').on('click', function() {
const select = $('#modal_select_tambah_bawahan');
const selectedOption = select.find(':selected');
const nip = select.val();
const nama = selectedOption.data('nama');
if (!nip) {
showError('Peringatan', 'Pilih pegawai terlebih dahulu!');
return;
}
currentBawahan.push({
nip: nip,
nama: nama
});
availablePegawais = availablePegawais.filter(p => p.nip !== nip);
renderModalTable();
renderModalSelectOptions();
});
$(document).on('click', '.btn-hapus-modal', function() {
const nip = $(this).data('nip');
const nama = $(this).data('nama');
if (!confirm(`Apakah Anda yakin ingin menghapus ${nama} dari daftar bawahan?`)) {
return;
}
currentBawahan = currentBawahan.filter(b => b.nip !== nip);
availablePegawais.push({
nip: nip,
nama: nama
});
availablePegawais.sort((a, b) => a.nama.localeCompare(b.nama));
renderModalTable();
renderModalSelectOptions();
});
$('#modal-btn-simpan').on('click', function() {
if (!currentNipAtasan) {
return;
}
const nipList = currentBawahan.map(b => b.nip);
const confirmMessage = nipList.length === 0 ?
'Simpan dengan daftar bawahan kosong? Semua bawahan akan dihapus.' :
`Simpan ${nipList.length} bawahan?`;
if (!confirm(confirmMessage)) {
return;
}
const btnSimpan = $('#modal-btn-simpan');
btnSimpan.prop('disabled', true).html('<i class="uil-hourglass"></i> Menyimpan...');
$.ajax({
url: '{{ route('tri-dharma.bawahan.update') }}',
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
nip_atasan: currentNipAtasan,
bawahan: nipList
},
success: function() {
showSuccess('Berhasil', 'Data bawahan berhasil disimpan!');
btnSimpan.prop('disabled', false).html('<i class="uil-save"></i> Simpan Semua Perubahan');
loadModalData(currentNipAtasan, $('#modalAtasanNama').text());
},
error: function(xhr) {
let errorMsg = 'Gagal menyimpan data bawahan';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMsg = xhr.responseJSON.message;
}
showError('Error', errorMsg);
btnSimpan.prop('disabled', false).html('<i class="uil-save"></i> Simpan Semua Perubahan');
}
});
});
});
</script>
@endif
@endsection