Update Pendidikan Pelatihan
This commit is contained in:
@@ -285,7 +285,7 @@
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ route('petani.edit', $petani->id) }}">
|
||||
<a class="nav-link {{ request()->routeIs('petani.pendidikan-pelatihan.*') ? 'active' : '' }}" href="{{ route('petani.pendidikan-pelatihan.index', $petani->id) }}">
|
||||
<i class="icon-base ti tabler-books me-1_5 icon-sm"></i>Pendidikan & Pelatihan
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -0,0 +1,539 @@
|
||||
@extends('layout.main')
|
||||
|
||||
@push('style')
|
||||
<style>
|
||||
.status-switch-row {
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
gap: 12px !important;
|
||||
white-space: nowrap !important;
|
||||
}
|
||||
|
||||
.status-switch-row .switch {
|
||||
width: 52px !important;
|
||||
min-width: 52px !important;
|
||||
max-width: 52px !important;
|
||||
padding-left: 0 !important;
|
||||
margin: 0 !important;
|
||||
position: relative !important;
|
||||
display: inline-block !important;
|
||||
flex: 0 0 52px !important;
|
||||
}
|
||||
|
||||
.status-switch-row .switch-toggle-slider {
|
||||
left: 0 !important;
|
||||
}
|
||||
|
||||
.status-switch-row .status-text {
|
||||
display: inline-block !important;
|
||||
white-space: nowrap !important;
|
||||
line-height: 1.5 !important;
|
||||
}
|
||||
</style>
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul class="mb-0">
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="row">
|
||||
|
||||
<!-- PROFIL PETANI -->
|
||||
|
||||
<div class="col-md-12">
|
||||
|
||||
@include('produktivitas.petani.header', ['petani' => $petani])
|
||||
<div class="card mb-6">
|
||||
<div class="card-body pt-12">
|
||||
<h5 class="pb-4 border-bottom mb-4">
|
||||
Riwayat Pelatihan
|
||||
</h5>
|
||||
|
||||
{{-- DATA LAMA --}}
|
||||
@if ($petani->surveyPelatihan->count() > 0)
|
||||
@foreach ($petani->surveyPelatihan as $row)
|
||||
<div class="row align-items-end border-bottom pb-3 mb-3">
|
||||
<div class="col-md-5">
|
||||
<label class="form-label">Jenis Pelatihan</label>
|
||||
<input type="text" class="form-control" value="{{ $row->jenis_pelatihan }}" disabled>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Penyelenggara</label>
|
||||
<input type="text" class="form-control" value="{{ $row->penyelenggara }}" disabled>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Tahun</label>
|
||||
<input type="text" class="form-control" value="{{ $row->tahun_pelaksanaan }}" disabled>
|
||||
</div>
|
||||
|
||||
<div class="col-md-1">
|
||||
<form
|
||||
method="POST"
|
||||
action="{{ route('petani.pendidikan-pelatihan.pelatihan.destroy', [$petani->id, $row->id]) }}"
|
||||
class="delete-db-form">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
|
||||
<button type="submit" class="btn btn-outline-danger">
|
||||
<i class="icon-base ti tabler-trash icon-sm"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@else
|
||||
<p class="text-muted mb-4">Belum ada riwayat pelatihan.</p>
|
||||
@endif
|
||||
|
||||
{{-- FORM TAMBAH DATA BARU --}}
|
||||
<form
|
||||
method="POST"
|
||||
action="{{ route('petani.pendidikan-pelatihan.pelatihan.store', $petani->id) }}"
|
||||
class="form-repeater-pelatihan">
|
||||
@csrf
|
||||
|
||||
<div data-repeater-list="riwayat_pelatihan">
|
||||
<div data-repeater-item>
|
||||
<div class="row align-items-end">
|
||||
<div class="col-md-5 mb-3">
|
||||
<label class="form-label">Jenis Pelatihan</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control pelatihan-input"
|
||||
name="jenis_pelatihan"
|
||||
placeholder="Contoh: Pelatihan GAP">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Penyelenggara</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control pelatihan-input"
|
||||
name="penyelenggara"
|
||||
placeholder="Contoh: Dinas Pertanian">
|
||||
</div>
|
||||
|
||||
<div class="col-md-2 mb-3">
|
||||
<label class="form-label d-block">Tahun</label>
|
||||
<input
|
||||
type="number"
|
||||
class="form-control pelatihan-input"
|
||||
name="tahun"
|
||||
placeholder="Contoh: 2024"
|
||||
min="1900"
|
||||
max="{{ date('Y') }}">
|
||||
</div>
|
||||
|
||||
<div class="col-md-1 mb-3">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-danger btn-delete-pelatihan"
|
||||
data-repeater-delete
|
||||
disabled>
|
||||
<i class="icon-base ti tabler-trash icon-sm"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 d-flex justify-content-between">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-success"
|
||||
id="btn-tambah-pelatihan"
|
||||
data-repeater-create
|
||||
disabled>
|
||||
<i class="icon-base ti tabler-plus me-1_5 icon-sm"></i>
|
||||
Tambah Pelatihan
|
||||
</button>
|
||||
|
||||
<button type="submit" class="btn btn-success">
|
||||
<i class="icon-base ti tabler-check me-1_5 icon-sm"></i>
|
||||
Simpan Riwayat Pelatihan
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- SERTIFIKASI KEAHLIAN --}}
|
||||
<div class="card mb-6">
|
||||
<div class="card-body pt-12">
|
||||
<h5 class="pb-4 border-bottom mb-4">
|
||||
Sertifikasi Keahlian
|
||||
</h5>
|
||||
|
||||
{{-- DATA LAMA --}}
|
||||
@if ($petani->surveySertifikasi->count() > 0)
|
||||
@foreach ($petani->surveySertifikasi as $row)
|
||||
<div class="row align-items-end border-bottom pb-3 mb-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Jenis Keahlian Yang Disertifikasi</label>
|
||||
<input type="text" class="form-control" value="{{ $row->jenis_sertifikasi }}" disabled>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Lembaga Penerbit</label>
|
||||
<input type="text" class="form-control" value="{{ $row->lembaga_penerbit }}" disabled>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Tahun</label>
|
||||
<input type="text" class="form-control" value="{{ $row->tahun_pelaksanaan }}" disabled>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<label class="form-label d-block mb-1">Status</label>
|
||||
|
||||
@php
|
||||
$statusBerlaku = (bool) $row->is_aktif;
|
||||
@endphp
|
||||
|
||||
<div class="status-switch-row">
|
||||
<label class="switch switch-lg">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="switch-input"
|
||||
{{ $statusBerlaku ? 'checked' : '' }}
|
||||
onclick="return false;"
|
||||
tabindex="-1">
|
||||
|
||||
<span class="switch-toggle-slider">
|
||||
<span class="switch-on">
|
||||
<i class="icon-base ti tabler-check"></i>
|
||||
</span>
|
||||
<span class="switch-off">
|
||||
<i class="icon-base ti tabler-x"></i>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<span class="status-text">
|
||||
{{ $statusBerlaku ? 'Masih Berlaku' : 'Tidak Berlaku' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-1">
|
||||
<form
|
||||
method="POST"
|
||||
action="{{ route('petani.pendidikan-pelatihan.sertifikasi.destroy', [$petani->id, $row->id]) }}"
|
||||
class="delete-db-form">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
|
||||
<button type="submit" class="btn btn-outline-danger">
|
||||
<i class="icon-base ti tabler-trash icon-sm"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@else
|
||||
<p class="text-muted mb-4">Belum ada data sertifikasi.</p>
|
||||
@endif
|
||||
|
||||
{{-- FORM TAMBAH DATA BARU --}}
|
||||
<form
|
||||
method="POST"
|
||||
action="{{ route('petani.pendidikan-pelatihan.sertifikasi.store', $petani->id) }}"
|
||||
class="form-repeater-sertifikasi">
|
||||
@csrf
|
||||
|
||||
<div data-repeater-list="sertifikasi">
|
||||
<div data-repeater-item>
|
||||
<div class="row align-items-end">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Jenis Keahlian Yang Disertifikasi</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control sertifikasi-input"
|
||||
name="jenis_sertifikasi"
|
||||
placeholder="Contoh: Sertifikasi GAP">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3 mb-3">
|
||||
<label class="form-label">Lembaga Penerbit</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control sertifikasi-input"
|
||||
name="lembaga_penerbit"
|
||||
placeholder="Contoh: BNSP">
|
||||
</div>
|
||||
|
||||
<div class="col-md-2 mb-3">
|
||||
<label class="form-label d-block">Tahun</label>
|
||||
<input
|
||||
type="number"
|
||||
class="form-control sertifikasi-input"
|
||||
name="tahun"
|
||||
placeholder="Contoh: 2024"
|
||||
min="1900"
|
||||
max="{{ date('Y') }}">
|
||||
</div>
|
||||
|
||||
<div class="col-md-2 mb-3">
|
||||
<label class="form-label d-block">Status</label>
|
||||
|
||||
<label class="switch switch-lg">
|
||||
<input type="hidden" name="status_berlaku_sertifikat" value="0">
|
||||
|
||||
<input
|
||||
type="checkbox"
|
||||
class="switch-input sertifikasi-status-switch"
|
||||
name="status_berlaku_sertifikat"
|
||||
value="1">
|
||||
|
||||
<span class="switch-toggle-slider">
|
||||
<span class="switch-on">
|
||||
<i class="icon-base ti tabler-check"></i>
|
||||
</span>
|
||||
<span class="switch-off">
|
||||
<i class="icon-base ti tabler-x"></i>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<span class="switch-label">
|
||||
<span class="sertifikasi-switch-text">Tidak Berlaku</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="col-md-1 mb-3">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-danger btn-delete-sertifikasi"
|
||||
data-repeater-delete
|
||||
disabled>
|
||||
<i class="icon-base ti tabler-trash icon-sm"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 d-flex justify-content-between">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-success"
|
||||
id="btn-tambah-sertifikasi"
|
||||
data-repeater-create
|
||||
disabled>
|
||||
<i class="icon-base ti tabler-plus me-1_5 icon-sm"></i>
|
||||
Tambah Sertifikasi
|
||||
</button>
|
||||
|
||||
<button type="submit" class="btn btn-success">
|
||||
<i class="icon-base ti tabler-check me-1_5 icon-sm"></i>
|
||||
Simpan Sertifikasi Keahlian
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
$(function () {
|
||||
function initRepeaterWithValidation(config) {
|
||||
const $form = $(config.formSelector);
|
||||
const $btnTambah = $(config.addButtonSelector);
|
||||
|
||||
if (!$form.length || !$btnTambah.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
function getRows() {
|
||||
return $form.find('[data-repeater-item]');
|
||||
}
|
||||
|
||||
function rowAdaIsi($row) {
|
||||
return $row.find(config.inputSelector).toArray().some(function (input) {
|
||||
return String($(input).val() || '').trim() !== '';
|
||||
});
|
||||
}
|
||||
|
||||
function rowLengkap($row) {
|
||||
const $inputs = $row.find(config.inputSelector);
|
||||
|
||||
if ($inputs.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $inputs.toArray().every(function (input) {
|
||||
return String($(input).val() || '').trim() !== '';
|
||||
});
|
||||
}
|
||||
|
||||
function updateSwitchText($switch) {
|
||||
if (!config.switchSelector || !config.switchTextSelector) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $row = $switch.closest('[data-repeater-item]');
|
||||
const $text = $row.find(config.switchTextSelector);
|
||||
|
||||
if ($switch.is(':checked')) {
|
||||
$text.text(config.switchTextOn || 'Ya');
|
||||
} else {
|
||||
$text.text(config.switchTextOff || 'Tidak');
|
||||
}
|
||||
}
|
||||
|
||||
function updateAllSwitchText() {
|
||||
if (!config.switchSelector) {
|
||||
return;
|
||||
}
|
||||
|
||||
$form.find(config.switchSelector).each(function () {
|
||||
updateSwitchText($(this));
|
||||
});
|
||||
}
|
||||
|
||||
function updateButtons() {
|
||||
const $rows = getRows();
|
||||
const $lastRow = $rows.last();
|
||||
|
||||
$rows.each(function () {
|
||||
const $row = $(this);
|
||||
const $deleteButton = $row.find(config.deleteButtonSelector);
|
||||
|
||||
$deleteButton.prop('disabled', !rowAdaIsi($row));
|
||||
});
|
||||
|
||||
$btnTambah.prop('disabled', !rowLengkap($lastRow));
|
||||
}
|
||||
|
||||
$form.repeater({
|
||||
initEmpty: false,
|
||||
|
||||
show: function () {
|
||||
const $row = $(this);
|
||||
|
||||
$row.find(config.inputSelector).val('');
|
||||
$row.find(config.deleteButtonSelector).prop('disabled', true);
|
||||
|
||||
if (config.switchSelector) {
|
||||
$row.find(config.switchSelector).prop('checked', false);
|
||||
}
|
||||
|
||||
updateAllSwitchText();
|
||||
|
||||
$row.slideDown();
|
||||
|
||||
setTimeout(updateButtons, 50);
|
||||
},
|
||||
|
||||
hide: function (deleteElement) {
|
||||
const $row = $(this);
|
||||
|
||||
// Kalau baris kosong, jangan lakukan apa-apa
|
||||
if (!rowAdaIsi($row)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ini hanya hapus baris di form, tidak kirim ke DB
|
||||
Swal.fire({
|
||||
title: config.deleteTitle || 'Hapus baris ini?',
|
||||
text: 'Baris ini hanya akan dihapus dari form.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Ya, hapus',
|
||||
cancelButtonText: 'Batal',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-danger me-3',
|
||||
cancelButton: 'btn btn-label-secondary'
|
||||
},
|
||||
buttonsStyling: false
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
$row.slideUp(deleteElement);
|
||||
setTimeout(updateButtons, 300);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('input keyup change', config.formSelector + ' ' + config.inputSelector, function () {
|
||||
updateButtons();
|
||||
});
|
||||
|
||||
if (config.switchSelector) {
|
||||
$(document).on('change', config.formSelector + ' ' + config.switchSelector, function () {
|
||||
updateSwitchText($(this));
|
||||
updateButtons();
|
||||
});
|
||||
}
|
||||
|
||||
updateAllSwitchText();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
initRepeaterWithValidation({
|
||||
formSelector: '.form-repeater-pelatihan',
|
||||
addButtonSelector: '#btn-tambah-pelatihan',
|
||||
inputSelector: '.pelatihan-input',
|
||||
deleteButtonSelector: '.btn-delete-pelatihan',
|
||||
deleteTitle: 'Hapus baris pelatihan ini?'
|
||||
});
|
||||
|
||||
initRepeaterWithValidation({
|
||||
formSelector: '.form-repeater-sertifikasi',
|
||||
addButtonSelector: '#btn-tambah-sertifikasi',
|
||||
inputSelector: '.sertifikasi-input',
|
||||
deleteButtonSelector: '.btn-delete-sertifikasi',
|
||||
deleteTitle: 'Hapus baris sertifikasi ini?',
|
||||
switchSelector: '.sertifikasi-status-switch',
|
||||
switchTextSelector: '.sertifikasi-switch-text',
|
||||
switchTextOn: 'Masih Berlaku',
|
||||
switchTextOff: 'Tidak Berlaku'
|
||||
});
|
||||
|
||||
// Ini khusus untuk data yang SUDAH ADA DI DATABASE
|
||||
$(document).on('submit', '.delete-db-form', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const form = this;
|
||||
|
||||
Swal.fire({
|
||||
title: 'Hapus data ini?',
|
||||
text: 'Data yang sudah dihapus tidak bisa dikembalikan.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Ya, hapus',
|
||||
cancelButtonText: 'Batal',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-danger me-3',
|
||||
cancelButton: 'btn btn-label-secondary'
|
||||
},
|
||||
buttonsStyling: false
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
Reference in New Issue
Block a user