947 lines
30 KiB
HTML
947 lines
30 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
|
<title>Aplikasi Penelitian Dosen - Halaman Penelitian Dosen</title>
|
|
|
|
<script>
|
|
(async function checkAuth() {
|
|
const dosenId = localStorage.getItem('dosen_id');
|
|
const dosenName = localStorage.getItem('dosen_name');
|
|
|
|
if (!dosenId || !dosenName) {
|
|
localStorage.clear();
|
|
window.location.href = 'index.html';
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(`/api/dosen/verify?dosen_id=${encodeURIComponent(dosenId)}&dosen_name=${encodeURIComponent(dosenName)}`);
|
|
const data = await response.json();
|
|
|
|
if (response.ok && data.valid) {
|
|
document.body.style.display = 'block';
|
|
} else {
|
|
localStorage.clear();
|
|
window.location.href = 'index.html';
|
|
}
|
|
} catch (error) {
|
|
console.error("Auth check failed:", error);
|
|
localStorage.clear();
|
|
window.location.href = 'index.html';
|
|
}
|
|
})();
|
|
</script>
|
|
|
|
<link rel="stylesheet" href="assets/styles/style.min.css">
|
|
<link rel="stylesheet" href="assets/plugin/mCustomScrollbar/jquery.mCustomScrollbar.min.css">
|
|
<link rel="stylesheet" href="assets/plugin/waves/waves.min.css">
|
|
<link rel="stylesheet" href="assets/plugin/sweet-alert/sweetalert.css">
|
|
<link rel="stylesheet" href="assets/color-switcher/color-switcher.min.css">
|
|
<link rel="stylesheet" href="assets/plugin/datatables/media/css/dataTables.bootstrap.min.css">
|
|
<link rel="stylesheet" href="assets/plugin/datatables/extensions/Responsive/css/responsive.bootstrap.min.css">
|
|
<style>
|
|
body {
|
|
display: none;
|
|
}
|
|
|
|
.modal-body .form-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
/* Hide default DataTables search */
|
|
.dataTables_filter {
|
|
display: none;
|
|
}
|
|
|
|
.file-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 5px;
|
|
padding: 8px;
|
|
background: #f9f9f9;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
gap: 10px;
|
|
}
|
|
|
|
.file-item a {
|
|
color: #333;
|
|
text-decoration: none;
|
|
font-weight: 500;
|
|
word-break: break-all;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
flex: 1;
|
|
}
|
|
|
|
.file-item a:hover {
|
|
color: #007bff;
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.file-item button {
|
|
padding: 2px 8px;
|
|
font-size: 12px;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
/* Styles for History Panel */
|
|
.history-panel {
|
|
margin-bottom: 15px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.history-header {
|
|
background-color: #f5f5f5;
|
|
padding: 10px 15px;
|
|
border-bottom: 1px solid #ddd;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.history-body {
|
|
padding: 15px;
|
|
}
|
|
|
|
#modalHistory .modal-body {
|
|
max-height: calc(100vh - 210px);
|
|
/* Adjust 210px based on header/footer height */
|
|
overflow-y: auto;
|
|
}
|
|
|
|
/* Fix for the top-left profile image to be a perfect circle */
|
|
.header .avatar {
|
|
width: 65px;
|
|
height: 65px;
|
|
display: inline-block;
|
|
overflow: hidden;
|
|
border-radius: 50%;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.header .avatar img {
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
/* This ensures the image fills the circle without stretching */
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="main-menu">
|
|
<header class="header">
|
|
<a href="dosen_index.html" class="logo">UHM</a>
|
|
<button type="button" class="button-close fa fa-times js__menu_close"></button>
|
|
<div class="user">
|
|
<a href="#" class="avatar"><img src="assets/images/person.png" id="foto_dosen" alt=""><span
|
|
class="status online"></span></a>
|
|
<h5 class="name"><a href="#" id="dosenName">Dosen</a></h5>
|
|
<h5 class="position">Dosen</h5>
|
|
</div>
|
|
</header>
|
|
<div class="content">
|
|
<div class="navigation">
|
|
<h5 class="title">Navigasi</h5>
|
|
<ul class="menu js__accordion">
|
|
<li><a class="waves-effect" href="dosen_index.html"><i
|
|
class="menu-icon fa fa-home"></i><span>Halaman
|
|
Utama</span></a></li>
|
|
<li class="current"><a class="waves-effect" href="dosen.html"><i
|
|
class="menu-icon fa fa-list"></i><span>Managemen
|
|
Penelitian</span></a></li>
|
|
<li><a class="waves-effect" href="dosen_profil.html"><i
|
|
class="menu-icon fa fa-user"></i><span>Profil</span></a></li>
|
|
<li><a class="waves-effect" href="#" onclick="logout()"><i
|
|
class="menu-icon fa fa-sign-out"></i><span>Logout</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="fixed-navbar">
|
|
<div class="pull-left">
|
|
<button type="button"
|
|
class="menu-mobile-button glyphicon glyphicon-menu-hamburger js__menu_mobile"></button>
|
|
<h1 class="page-title">Manajemen Penelitian</h1>
|
|
</div>
|
|
<div class="pull-right">
|
|
<div class="ico-item fa fa-arrows-alt js__full_screen"></div>
|
|
<a href="#" class="ico-item fa fa-sign-out" onclick="logout()"></a>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="wrapper">
|
|
<div class="main-content">
|
|
|
|
<!-- DASHBOARD STATISTICS -->
|
|
<div class="row small-spacing">
|
|
<div class="col-lg-3 col-md-6 col-xs-12">
|
|
<div class="box-content">
|
|
<div class="statistics-box with-icon">
|
|
<i class="ico fa fa-wpforms text-inverse"></i>
|
|
<h2 class="counter text-inverse" id="h_jumlah_penelitian">...</h2>
|
|
<p class="text">Jumlah Penelitian</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-3 col-md-6 col-xs-12">
|
|
<div class="box-content">
|
|
<div class="statistics-box with-icon">
|
|
<i class="ico fa fa-check text-success"></i>
|
|
<h2 class="counter text-success" id="h_penelitian_selesai">...</h2>
|
|
<p class="text">Penelitian Selesai</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-3 col-md-6 col-xs-12">
|
|
<div class="box-content">
|
|
<div class="statistics-box with-icon">
|
|
<i class="ico fa fa-clock-o text-primary"></i>
|
|
<h2 class="counter text-primary" id="h_penelitian_berjalan">...</h2>
|
|
<p class="text">Penelitian Berjalan</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-3 col-md-6 col-xs-12">
|
|
<div class="box-content">
|
|
<div class="statistics-box with-icon">
|
|
<i class="ico fa fa-area-chart text-info"></i>
|
|
<h2 class="counter text-info" id="h_terakhir_update"
|
|
style="font-size: 20px; margin-top: 25px;">...</h2>
|
|
<p class="text">Terakhir Update</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- TABLE SECTION -->
|
|
<div class="row small-spacing">
|
|
<div class="col-md-12">
|
|
<div class="box-content">
|
|
|
|
<!-- UPDATED HEADER WITH CUSTOM SEARCH -->
|
|
<header class="panel-heading"
|
|
style="display: flex; flex-direction: column; gap: 15px; overflow: hidden;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center;">
|
|
<h4 class="box-title" style="margin: 0;">Daftar Penelitian</h4>
|
|
<button class="btn btn-primary btn-xs" onclick="openAddModal()"><i
|
|
class="fa fa-plus"></i> Tambah Penelitian</button>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<label>Judul Penelitian</label>
|
|
<input type="text" id="searchJudul" class="form-control"
|
|
placeholder="Cari judul...">
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label>Tahun Dari</label>
|
|
<select id="searchTahunFrom" class="form-control">
|
|
<option value="">-- Pilih --</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label>Tahun Sampai</label>
|
|
<select id="searchTahunTo" class="form-control">
|
|
<option value="">-- Pilih --</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2"
|
|
style="display: flex; align-items: flex-end; gap: 5px; margin-top: 24px;">
|
|
<button class="btn btn-info" onclick="applyCustomFilter()" style="flex: 1;"><i
|
|
class="fa fa-search"></i> Cari</button>
|
|
<button class="btn btn-default" onclick="resetCustomFilter()"><i
|
|
class="fa fa-refresh"></i></button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="panel-body" style="overflow-x: auto;">
|
|
<table id="tablePenelitian" class="table table-striped table-bordered dt-responsive nowrap"
|
|
style="width:100%">
|
|
<thead>
|
|
<tr>
|
|
<th>No</th>
|
|
<th>Judul Penelitian</th>
|
|
<th>Tahun</th>
|
|
<th>Status</th>
|
|
<th>Terakhir Update</th>
|
|
<th>Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="tbodyPenelitian"></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="footer">
|
|
<ul class="list-inline">
|
|
<li>2026 © Sistem Penelitian Dosen | Universitas Handayani Makassar.</li>
|
|
</ul>
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal Penelitian (Add/Edit/View) -->
|
|
<div class="modal fade" id="modalPenelitian" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
|
|
aria-hidden="true">×</span></button>
|
|
<h4 class="modal-title" id="modalLabel">Tambah Penelitian</h4>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="formPenelitian">
|
|
<input type="hidden" id="penelitianId">
|
|
<input type="hidden" id="dosenId" value="">
|
|
|
|
<div class="form-group">
|
|
<label for="judul_penelitian">Judul Penelitian</label>
|
|
<input type="text" class="form-control" id="judul_penelitian" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="tahun_penelitian">Tahun Penelitian</label>
|
|
<select class="form-control" id="tahun_penelitian" required>
|
|
<option value="">-- Pilih Tahun --</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="status_penelitian">Status Penelitian</label>
|
|
<select class="form-control" id="status_penelitian" required>
|
|
<option value="">-- Pilih Status --</option>
|
|
<option value="Berjalan">Berjalan</option>
|
|
<option value="Selesai">Selesai</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="keterangan">Keterangan / Info Penelitian</label>
|
|
<textarea class="form-control" id="keterangan" rows="3"
|
|
placeholder="Jelaskan secara singkat progres atau hasil penelitian..."></textarea>
|
|
</div>
|
|
|
|
<div class="form-group" id="uploadSection">
|
|
<label for="files">Upload Hasil Publikasi Baru (PDF, Max 1MB, Max 3 File)</label>
|
|
<input type="file" class="form-control" id="files" accept="application/pdf" multiple>
|
|
<small class="text-muted">Biarkan kosong jika tidak ingin menambah file baru.</small>
|
|
</div>
|
|
|
|
<div class="form-group" id="fileListSection" style="display: none;">
|
|
<label>Daftar File Publikasi:</label>
|
|
<div id="existingFilesContainer" class="mt-2"></div>
|
|
</div>
|
|
|
|
<div id="timestampInfo"
|
|
style="display: none; margin-top: 15px; border-top: 1px solid #eee; padding-top: 10px;">
|
|
<p class="text-muted" style="margin: 0; font-size: 12px;">
|
|
<strong>Dibuat:</strong> <span id="lblCreated"></span><br>
|
|
<strong>Terakhir Diubah:</strong> <span id="lblUpdated"></span>
|
|
</p>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-info pull-left" id="btnHistory" style="display: none;"
|
|
onclick="viewHistory()"><i class="fa fa-history"></i> Riwayat Laporan</button>
|
|
<button type="button" class="btn btn-default" data-dismiss="modal">Tutup</button>
|
|
<button type="button" class="btn btn-primary" id="btnSave"
|
|
onclick="savePenelitian()">Simpan</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal History / Laporan -->
|
|
<div class="modal fade" id="modalHistory" tabindex="-1" role="dialog">
|
|
<div class="modal-dialog modal-lg" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal"><span>×</span></button>
|
|
<h4 class="modal-title">Riwayat Perubahan Penelitian</h4>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div id="historyContainer"></div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-primary pull-left" onclick="printLaporan()"><i
|
|
class="fa fa-print"></i> Cetak Laporan PDF</button>
|
|
<button type="button" class="btn btn-default" data-dismiss="modal">Tutup</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Scripts -->
|
|
<script src="assets/scripts/jquery.min.js"></script>
|
|
<script src="assets/scripts/modernizr.min.js"></script>
|
|
<script src="assets/plugin/bootstrap/js/bootstrap.min.js"></script>
|
|
<script src="assets/plugin/mCustomScrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
|
|
<script src="assets/plugin/nprogress/nprogress.js"></script>
|
|
<script src="assets/plugin/sweet-alert/sweetalert.min.js"></script>
|
|
<script src="assets/plugin/waves/waves.min.js"></script>
|
|
<script src="assets/plugin/fullscreen/jquery.fullscreen-min.js"></script>
|
|
|
|
<!-- Data Tables -->
|
|
<script src="assets/plugin/datatables/media/js/jquery.dataTables.min.js"></script>
|
|
<script src="assets/plugin/datatables/media/js/dataTables.bootstrap.min.js"></script>
|
|
<script src="assets/plugin/datatables/extensions/Responsive/js/dataTables.responsive.min.js"></script>
|
|
<script src="assets/plugin/datatables/extensions/Responsive/js/responsive.bootstrap.min.js"></script>
|
|
<script src="assets/block/jquery.blockUI.js"></script>
|
|
<script src="assets/scripts/main.min.js"></script>
|
|
<script src="assets/color-switcher/color-switcher.min.js"></script>
|
|
<script src="assets/block.js"></script>
|
|
|
|
<script>
|
|
$(document).ready(function () {
|
|
const dosenId = localStorage.getItem('dosen_id');
|
|
const dosenName = localStorage.getItem('dosen_name');
|
|
if (dosenName) document.getElementById('dosenName').textContent = dosenName;
|
|
|
|
// Fetch current profile image
|
|
$.get(`/api/dosen`, function (data) {
|
|
const dosen = data.find(d => d.dosen_id === dosenId);
|
|
if (dosen && dosen.dosen_image) {
|
|
const imgUrl = `/api/images/dosen/${dosen.dosen_image}`;
|
|
|
|
$('#profileImagePreview').attr('src', imgUrl);
|
|
$('#foto_dosen').attr('src', imgUrl);
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
let dataTable;
|
|
let currentEditFiles = [];
|
|
let isViewMode = false;
|
|
let currentViewId = null;
|
|
|
|
// --- DATE FORMATTER (ISO String to "DD Mon YYYY, HH.mm") ---
|
|
function formatDateOnly(dateString) {
|
|
if (!dateString) return '-';
|
|
|
|
// If it's already in "YYYY-MM-DD HH:mm:ss" format, just format it
|
|
if (!dateString.includes('T')) {
|
|
// Replace T with space, then remove the seconds
|
|
let cleanStr = dateString.replace('T', ' ');
|
|
return cleanStr.substring(0, 16).replace(/-/g, ' ').replace(':', '.');
|
|
}
|
|
|
|
const date = new Date(dateString);
|
|
|
|
// Use UTC getters because the DB stores WIB as "UTC" in the ISO string
|
|
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des'];
|
|
|
|
const day = String(date.getUTCDate()).padStart(2, '0');
|
|
const month = months[date.getUTCMonth()];
|
|
const year = date.getUTCFullYear();
|
|
const hours = String(date.getUTCHours()).padStart(2, '0');
|
|
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
|
|
|
|
return `${day} ${month} ${year}, ${hours}.${minutes}`;
|
|
}
|
|
|
|
// Custom Search Logic
|
|
$.fn.dataTable.ext.search.push(
|
|
function (settings, data, dataIndex) {
|
|
const judul = data[1].toLowerCase();
|
|
const tahun = parseInt(data[2]);
|
|
|
|
const searchJudul = $('#searchJudul').val().toLowerCase();
|
|
const searchFrom = $('#searchTahunFrom').val();
|
|
const searchTo = $('#searchTahunTo').val();
|
|
|
|
if (searchJudul && !judul.includes(searchJudul)) {
|
|
return false;
|
|
}
|
|
if (searchFrom && tahun < parseInt(searchFrom)) {
|
|
return false;
|
|
}
|
|
if (searchTo && tahun > parseInt(searchTo)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
);
|
|
|
|
function applyCustomFilter() {
|
|
dataTable.draw();
|
|
}
|
|
|
|
function resetCustomFilter() {
|
|
$('#searchJudul').val('');
|
|
$('#searchTahunFrom').val('');
|
|
$('#searchTahunTo').val('');
|
|
dataTable.draw();
|
|
}
|
|
|
|
// Auth & Init
|
|
$(document).ready(function () {
|
|
const dosenName = localStorage.getItem('dosen_name');
|
|
const dosenId = localStorage.getItem('dosen_id');
|
|
|
|
if (dosenName) document.getElementById('dosenName').textContent = dosenName;
|
|
if (dosenId) document.getElementById('dosenId').value = dosenId;
|
|
|
|
// Fetch current profile image
|
|
$.get(`/api/dosen`, function (data) {
|
|
const dosen = data.find(d => d.dosen_id === dosenId);
|
|
if (dosen && dosen.dosen_image) {
|
|
const imgUrl = `/api/images/dosen/${dosen.dosen_image}`;
|
|
$('#profileImagePreview').attr('src', imgUrl);
|
|
$('#foto_dosen').attr('src', imgUrl);
|
|
}
|
|
});
|
|
|
|
// 1. Populate Years for the Form (Tambah/Edit)
|
|
const yearSelect = document.getElementById('tahun_penelitian');
|
|
for (let y = 2026; y >= 2010; y--) {
|
|
let opt = document.createElement('option');
|
|
opt.value = y;
|
|
opt.innerHTML = y;
|
|
yearSelect.appendChild(opt);
|
|
}
|
|
|
|
// 2. Populate "Tahun Dari" (Search Filter)
|
|
const fromSelect = document.getElementById('searchTahunFrom');
|
|
const toSelect = document.getElementById('searchTahunTo');
|
|
|
|
// Populate all years in "Tahun Dari" from 2010 to 2026
|
|
for (let y = 2010; y <= 2026; y++) {
|
|
let opt = document.createElement('option');
|
|
opt.value = y;
|
|
opt.innerHTML = y;
|
|
fromSelect.appendChild(opt);
|
|
}
|
|
|
|
// Set "Tahun Sampai" to be disabled initially
|
|
toSelect.disabled = true;
|
|
toSelect.innerHTML = '<option value="">-- Pilih Tahun Dari --</option>';
|
|
|
|
// 3. Add Event Listener to "Tahun Dari"
|
|
$('#searchTahunFrom').on('change', function () {
|
|
const selectedFrom = $(this).val();
|
|
toSelect.innerHTML = '';
|
|
|
|
if (selectedFrom) {
|
|
toSelect.disabled = false;
|
|
toSelect.innerHTML = '<option value="">-- Pilih --</option>';
|
|
|
|
for (let y = parseInt(selectedFrom); y <= 2026; y++) {
|
|
let opt = document.createElement('option');
|
|
opt.value = y;
|
|
opt.innerHTML = y;
|
|
toSelect.appendChild(opt);
|
|
}
|
|
} else {
|
|
toSelect.disabled = true;
|
|
toSelect.innerHTML = '<option value="">-- Pilih Tahun Dari Dulu --</option>';
|
|
}
|
|
|
|
applyCustomFilter();
|
|
});
|
|
|
|
initDataTable(dosenId);
|
|
});
|
|
|
|
function initDataTable(dosenId) {
|
|
dataTable = $('#tablePenelitian').DataTable({
|
|
ajax: {
|
|
url: `/api/penelitian/dosen/${dosenId}`,
|
|
dataSrc: ''
|
|
},
|
|
columns: [
|
|
{ data: null, render: (data, type, row, meta) => meta.row + 1 },
|
|
{ data: 'judul_penelitian' },
|
|
{ data: 'tahun_penelitian' },
|
|
{
|
|
data: 'status_penelitian',
|
|
render: function (data) {
|
|
let badge = data === 'Berjalan' ? 'label-warning' : 'label-success';
|
|
return `<span class="label ${badge}">${data}</span>`;
|
|
}
|
|
},
|
|
{
|
|
data: 'updated_at',
|
|
render: function (data) {
|
|
return formatDateOnly(data);
|
|
}
|
|
},
|
|
{
|
|
data: null,
|
|
render: function (data, type, row) {
|
|
return `
|
|
<button class="btn btn-info btn-xs" title="Lihat" onclick="viewPenelitian(${row.id})"><i class="fa fa-eye"></i></button>
|
|
<button class="btn btn-warning btn-xs" title="Edit" onclick="editPenelitian(${row.id})"><i class="fa fa-pencil"></i></button>
|
|
<button class="btn btn-danger btn-xs" title="Hapus" onclick="deletePenelitian(${row.id})"><i class="fa fa-trash"></i></button>
|
|
`;
|
|
}
|
|
}
|
|
],
|
|
order: [[4, "desc"]],
|
|
drawCallback: function () {
|
|
const data = this.api().rows().data().toArray();
|
|
updateStatistics(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Calculate and update the dashboard cards
|
|
function updateStatistics(data) {
|
|
let total = data.length;
|
|
let selesai = 0;
|
|
let berjalan = 0;
|
|
let latestUpdate = null;
|
|
|
|
data.forEach(item => {
|
|
if (item.status_penelitian === 'Selesai') selesai++;
|
|
if (item.status_penelitian === 'Berjalan') berjalan++;
|
|
|
|
if (item.updated_at) {
|
|
const itemDate = new Date(item.updated_at);
|
|
if (!latestUpdate || itemDate > latestUpdate) {
|
|
latestUpdate = itemDate;
|
|
}
|
|
}
|
|
});
|
|
|
|
$('#h_jumlah_penelitian').text(total);
|
|
$('#h_penelitian_selesai').text(selesai);
|
|
$('#h_penelitian_berjalan').text(berjalan);
|
|
|
|
if (latestUpdate) {
|
|
const options = { day: '2-digit', month: 'short', year: 'numeric' };
|
|
$('#h_terakhir_update').text(latestUpdate.toLocaleDateString('id-ID', options));
|
|
} else {
|
|
$('#h_terakhir_update').text('-');
|
|
}
|
|
}
|
|
|
|
// --- MODAL FUNCTIONS ---
|
|
|
|
function resetModal() {
|
|
$('#formPenelitian')[0].reset();
|
|
$('#penelitianId').val('');
|
|
$('#files').val('');
|
|
$('#existingFilesContainer').empty();
|
|
$('#fileListSection').hide();
|
|
$('#timestampInfo').hide();
|
|
$('#btnHistory').hide();
|
|
currentEditFiles = [];
|
|
isViewMode = false;
|
|
currentViewId = null;
|
|
|
|
$('#formPenelitian input, #formPenelitian select, #formPenelitian textarea').prop('disabled', false);
|
|
$('#btnSave').show();
|
|
$('#uploadSection').show();
|
|
}
|
|
|
|
function openAddModal() {
|
|
resetModal();
|
|
$('#modalLabel').text('Tambah Penelitian');
|
|
$('#modalPenelitian').modal('show');
|
|
}
|
|
|
|
function viewPenelitian(id) {
|
|
resetModal();
|
|
isViewMode = true;
|
|
currentViewId = id;
|
|
$('#modalLabel').text('Lihat Penelitian');
|
|
|
|
$('#formPenelitian input, #formPenelitian select, #formPenelitian textarea').prop('disabled', true);
|
|
$('#btnSave').hide();
|
|
$('#uploadSection').hide();
|
|
$('#btnHistory').show();
|
|
|
|
$('#modalPenelitian').modal('show');
|
|
|
|
$.get(`/api/penelitian/dosen/${localStorage.getItem('dosen_id')}`, function (data) {
|
|
const item = data.find(p => p.id === id);
|
|
if (item) {
|
|
$('#judul_penelitian').val(item.judul_penelitian);
|
|
$('#tahun_penelitian').val(item.tahun_penelitian);
|
|
$('#status_penelitian').val(item.status_penelitian);
|
|
$('#keterangan').val(item.keterangan || '');
|
|
renderExistingFiles(item.hasil_publikasi);
|
|
|
|
$('#lblCreated').text(formatDateOnly(item.created_at));
|
|
$('#lblUpdated').text(formatDateOnly(item.updated_at));
|
|
$('#timestampInfo').show();
|
|
}
|
|
});
|
|
}
|
|
|
|
function editPenelitian(id) {
|
|
resetModal();
|
|
$('#modalLabel').text('Update Penelitian');
|
|
$('#penelitianId').val(id);
|
|
$('#modalPenelitian').modal('show');
|
|
|
|
$('#judul_penelitian').prop('disabled', true);
|
|
$('#tahun_penelitian').prop('disabled', true);
|
|
|
|
$.get(`/api/penelitian/dosen/${localStorage.getItem('dosen_id')}`, function (data) {
|
|
const item = data.find(p => p.id === id);
|
|
if (item) {
|
|
$('#judul_penelitian').val(item.judul_penelitian);
|
|
$('#tahun_penelitian').val(item.tahun_penelitian);
|
|
$('#status_penelitian').val(item.status_penelitian);
|
|
$('#keterangan').val(item.keterangan || '');
|
|
renderExistingFiles(item.hasil_publikasi);
|
|
}
|
|
});
|
|
}
|
|
|
|
function renderExistingFiles(filesData) {
|
|
if (Array.isArray(filesData)) {
|
|
currentEditFiles = filesData;
|
|
} else if (typeof filesData === 'string') {
|
|
try {
|
|
currentEditFiles = JSON.parse(filesData);
|
|
} catch (e) {
|
|
currentEditFiles = [];
|
|
}
|
|
} else {
|
|
currentEditFiles = [];
|
|
}
|
|
|
|
const container = $('#existingFilesContainer');
|
|
container.empty();
|
|
|
|
if (currentEditFiles.length > 0) {
|
|
$('#fileListSection').show();
|
|
|
|
currentEditFiles.forEach((filename, index) => {
|
|
let displayName = filename.substring(filename.indexOf('-') + 1);
|
|
|
|
let actionBtn = '';
|
|
if (!isViewMode) {
|
|
actionBtn = `<button type="button" class="btn btn-danger btn-xs" onclick="removeExistingFile(${index})">Hapus</button>`;
|
|
}
|
|
|
|
container.append(`
|
|
<div class="file-item">
|
|
<a href="/api/uploads/${filename}" target="_blank"><i class="fa fa-file-pdf-o text-danger"></i> ${displayName}</a>
|
|
${actionBtn}
|
|
</div>
|
|
`);
|
|
});
|
|
} else {
|
|
$('#fileListSection').hide();
|
|
}
|
|
}
|
|
|
|
function removeExistingFile(index) {
|
|
currentEditFiles.splice(index, 1);
|
|
renderExistingFiles(currentEditFiles);
|
|
}
|
|
|
|
// --- HISTORY FUNCTION ---
|
|
function viewHistory() {
|
|
if (!currentViewId) return;
|
|
$('#historyContainer').empty();
|
|
$('#modalPenelitian').modal('hide');
|
|
$('#modalHistory').modal('show');
|
|
|
|
$.get(`/api/laporan/${currentViewId}`, function (data) {
|
|
if (data.length === 0) {
|
|
$('#historyContainer').html('<p class="text-center text-muted">Belum ada riwayat.</p>');
|
|
return;
|
|
}
|
|
|
|
data.forEach((log, index) => {
|
|
let filesHtml = '';
|
|
if (log.hasil_publikasi) {
|
|
try {
|
|
const files = typeof log.hasil_publikasi === 'string' ? JSON.parse(log.hasil_publikasi) : log.hasil_publikasi;
|
|
files.forEach(f => {
|
|
let displayName = f.substring(f.indexOf('-') + 1);
|
|
filesHtml += `<div class="file-item" style="margin-top:5px;">
|
|
<a href="/api/uploads/${f}" target="_blank"><i class="fa fa-file-pdf-o text-danger"></i> ${displayName}</a>
|
|
</div>`;
|
|
});
|
|
} catch (e) { }
|
|
}
|
|
|
|
$('#historyContainer').append(`
|
|
<div class="history-panel">
|
|
<div class="history-header">
|
|
Update #${data.length - index}
|
|
<span class="pull-right text-muted" style="font-size: 12px; font-weight: normal;">
|
|
${formatDateOnly(log.created_at)}
|
|
</span>
|
|
</div>
|
|
<div class="history-body">
|
|
<table class="table table-condensed" style="margin-bottom: 0;">
|
|
<tr><td width="120"><strong>Status</strong></td><td>: <span class="label ${log.status_penelitian === 'Berjalan' ? 'label-warning' : 'label-success'}">${log.status_penelitian}</span></td></tr>
|
|
<tr><td><strong>Keterangan</strong></td><td>: ${log.keterangan || '-'}</td></tr>
|
|
<tr><td><strong>File</strong></td><td>${filesHtml || '-'}</td></tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
`);
|
|
});
|
|
});
|
|
}
|
|
|
|
function printLaporan() {
|
|
if (currentViewId) {
|
|
window.open(`laporan.html?id=${currentViewId}`, '_blank');
|
|
} else {
|
|
swal("Gagal", "ID Penelitian tidak ditemukan.", "error");
|
|
}
|
|
}
|
|
|
|
// --- CRUD ACTIONS ---
|
|
|
|
function savePenelitian() {
|
|
const id = $('#penelitianId').val();
|
|
const dosenId = $('#dosenId').val();
|
|
const judul = $('#judul_penelitian').val();
|
|
const tahun = $('#tahun_penelitian').val();
|
|
const status = $('#status_penelitian').val();
|
|
const keterangan = $('#keterangan').val();
|
|
const files = $('#files')[0].files;
|
|
|
|
if (!judul || !tahun || !status) {
|
|
swal("Peringatan", "Judul, Tahun, dan Status wajib diisi!", "warning");
|
|
return;
|
|
}
|
|
|
|
if (files.length > 3) {
|
|
swal("Peringatan", "Maksimal 3 file publikasi!", "warning");
|
|
return;
|
|
}
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
if (files[i].type !== 'application/pdf') {
|
|
swal("Peringatan", "Hanya file PDF yang diizinkan!", "warning");
|
|
return;
|
|
}
|
|
if (files[i].size > 1024 * 1024) {
|
|
swal("Peringatan", "Ukuran file maksimal 1MB!", "warning");
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (currentEditFiles.length + files.length > 3) {
|
|
swal("Peringatan", "Total file (lama + baru) tidak boleh lebih dari 3!", "warning");
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('judul_penelitian', judul);
|
|
formData.append('tahun_penelitian', tahun);
|
|
formData.append('status_penelitian', status);
|
|
formData.append('keterangan', keterangan);
|
|
|
|
if (id) {
|
|
formData.append('existing_files', JSON.stringify(currentEditFiles));
|
|
for (let i = 0; i < files.length; i++) {
|
|
formData.append('files', files[i]);
|
|
}
|
|
$.ajax({
|
|
url: `/api/penelitian/${id}`,
|
|
type: 'PUT',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
beforeSend: function () {
|
|
$('#modalPenelitian').modal('hide');
|
|
blockUI();
|
|
},
|
|
success: function () {
|
|
swal("Berhasil!", "Data berhasil diupdate.", "success");
|
|
dataTable.ajax.reload();
|
|
},
|
|
complete: function () { $.unblockUI() },
|
|
error: function (xhr) {
|
|
$.unblockUI();
|
|
swal("Gagal", xhr.responseJSON?.error || "Terjadi kesalahan", "error");
|
|
}
|
|
});
|
|
} else {
|
|
formData.append('dosen_id', dosenId);
|
|
for (let i = 0; i < files.length; i++) {
|
|
formData.append('files', files[i]);
|
|
}
|
|
$.ajax({
|
|
url: `/api/penelitian`,
|
|
type: 'POST',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
beforeSend: function () {
|
|
$('#modalPenelitian').modal('hide');
|
|
blockUI({ message: 'Menyimpan perubahan...' });
|
|
},
|
|
success: function () {
|
|
swal("Berhasil!", "Data berhasil ditambahkan.", "success");
|
|
dataTable.ajax.reload();
|
|
},
|
|
complete: function () { $.unblockUI(); },
|
|
error: function (xhr) {
|
|
$.unblockUI();
|
|
swal("Gagal", xhr.responseJSON?.error || "Terjadi kesalahan", "error");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function deletePenelitian(id) {
|
|
swal({
|
|
title: "Hapus Data?",
|
|
text: "Data penelitian ini akan dihapus permanen.",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#DD6B55",
|
|
confirmButtonText: "Ya, Hapus!",
|
|
closeOnConfirm: false
|
|
}, function () {
|
|
$.ajax({
|
|
url: `/api/penelitian/${id}`,
|
|
type: 'DELETE',
|
|
success: function () {
|
|
swal("Terhapus!", "Data penelitian telah dihapus.", "success");
|
|
dataTable.ajax.reload();
|
|
},
|
|
error: function (xhr) {
|
|
swal("Gagal", xhr.responseJSON?.error || "Terjadi kesalahan", "error");
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function logout() {
|
|
swal({
|
|
title: "Logout?",
|
|
text: "Anda akan keluar dari halaman dosen.",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#DD6B55",
|
|
confirmButtonText: "Ya, Logout!",
|
|
closeOnConfirm: true
|
|
}, function () {
|
|
localStorage.clear();
|
|
window.location.href = 'index.html';
|
|
});
|
|
}
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
|
</html> |