Update Master
This commit is contained in:
@@ -0,0 +1,228 @@
|
||||
@extends('layout.main')
|
||||
|
||||
@section('content')
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom mb-4">
|
||||
<h5 class="card-title mb-0">Tambah Data Keluarga</h5>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<form id="addKeluargaForm" action="{{ route('keluarga.store') }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
|
||||
<h6 class="mb-3 text-primary"><i class="ti tabler-id me-1"></i> Informasi Kartu Keluarga</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label">No. Kartu Keluarga (KK)<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="kk" placeholder="Masukkan 16 Digit No KK" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-4">
|
||||
<h6 class="mb-3 text-primary"><i class="ti tabler-map-pin me-1"></i> Wilayah & Adat</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label">Provinsi</label>
|
||||
<select id="provinsi" class="select2 form-select" data-placeholder="Pilih Provinsi">
|
||||
<option value="">Pilih Provinsi</option>
|
||||
@foreach($provinsi as $prov)
|
||||
<option value="{{ $prov->id }}">{{ $prov->nama }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label">Kabupaten/Kota</label>
|
||||
<select id="kabupaten" class="select2 form-select" data-placeholder="Pilih Kabupaten/Kota" disabled>
|
||||
<option value="">Pilih Kabupaten/Kota</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label">Kecamatan</label>
|
||||
<select id="kecamatan" class="select2 form-select" data-placeholder="Pilih Kecamatan" disabled>
|
||||
<option value="">Pilih Kecamatan</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label">Desa/Kelurahan<span class="text-danger">*</span></label>
|
||||
<select id="desa" name="desa_kelurahan_id" class="select2 form-select" data-placeholder="Pilih Desa/Kelurahan" disabled>
|
||||
<option value="">Pilih Desa/Kelurahan</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label">Pilih Adat</label>
|
||||
<select id="adat" name="adat_id" class="select2 form-select" data-placeholder="Pilih Adat" disabled>
|
||||
<option value="">Pilih Adat</option>
|
||||
</select>
|
||||
<small class="text-muted d-block mt-1">Data adat otomatis difilter berdasarkan Desa/Kelurahan yang dipilih.</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-4">
|
||||
<h6 class="mb-3 text-primary"><i class="ti tabler-upload me-1"></i> Dokumen</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label">Upload File KK</label>
|
||||
<input type="file" class="form-control" id="file_kk" name="file_kk" accept="image/*,.pdf" />
|
||||
|
||||
<div id="preview-container" class="mt-3 d-none">
|
||||
<img id="preview-image" src="" alt="Preview KK" class="img-thumbnail d-none" style="width: 100%; max-height: 250px; object-fit: contain; background-color: #f8f9fa;">
|
||||
<div id="preview-pdf" class="badge bg-label-danger p-2 d-none w-100"><i class="ti tabler-file-type-pdf ti-sm me-1"></i> Dokumen PDF Terpilih</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 text-end">
|
||||
<a href="{{ route('keluarga.index') }}" class="btn btn-label-secondary me-2">Kembali</a>
|
||||
<button type="submit" class="btn btn-primary data-submit">Simpan Data</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
'use strict';
|
||||
$(document).ready(function () {
|
||||
$('.select2').select2();
|
||||
|
||||
$('#file_kk').on('change', function(event) {
|
||||
const file = event.target.files[0];
|
||||
const $container = $('#preview-container');
|
||||
const $image = $('#preview-image');
|
||||
const $pdf = $('#preview-pdf');
|
||||
|
||||
if (file) {
|
||||
$container.removeClass('d-none');
|
||||
if (file.type.match('image.*')) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
$image.attr('src', e.target.result).removeClass('d-none');
|
||||
$pdf.addClass('d-none');
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
} else if (file.type === 'application/pdf') {
|
||||
$image.addClass('d-none').attr('src', '');
|
||||
$pdf.removeClass('d-none');
|
||||
} else {
|
||||
$container.addClass('d-none');
|
||||
}
|
||||
} else {
|
||||
$container.addClass('d-none');
|
||||
}
|
||||
});
|
||||
|
||||
$('#provinsi').on('change', function () {
|
||||
let id = $(this).val();
|
||||
$('#kabupaten').empty().append('<option value="">Pilih Kabupaten/Kota</option>').prop('disabled', true).trigger('change');
|
||||
$('#kecamatan').empty().append('<option value="">Pilih Kecamatan</option>').prop('disabled', true).trigger('change');
|
||||
$('#desa').empty().append('<option value="">Pilih Desa/Kelurahan</option>').prop('disabled', true).trigger('change');
|
||||
$('#adat').empty().append('<option value="">Pilih Adat</option>').prop('disabled', true).trigger('change');
|
||||
if (id) {
|
||||
$.get(`/kabupatenkotabyprovinsi/${id}`, function (res) {
|
||||
$('#kabupaten').prop('disabled', false);
|
||||
let dataList = Array.isArray(res) ? res : (res.data || []);
|
||||
$.each(dataList, function (key, val) { $('#kabupaten').append(`<option value="${val.id}">${val.nama}</option>`); });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#kabupaten').on('change', function () {
|
||||
let id = $(this).val();
|
||||
$('#kecamatan').empty().append('<option value="">Pilih Kecamatan</option>').prop('disabled', true).trigger('change');
|
||||
$('#desa').empty().append('<option value="">Pilih Desa/Kelurahan</option>').prop('disabled', true).trigger('change');
|
||||
$('#adat').empty().append('<option value="">Pilih Adat</option>').prop('disabled', true).trigger('change');
|
||||
if (id) {
|
||||
$.get(`/kecamatanbykabupatenkota/${id}`, function (res) {
|
||||
$('#kecamatan').prop('disabled', false);
|
||||
let dataList = Array.isArray(res) ? res : (res.data || []);
|
||||
$.each(dataList, function (key, val) { $('#kecamatan').append(`<option value="${val.id}">${val.nama}</option>`); });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#kecamatan').on('change', function () {
|
||||
let id = $(this).val();
|
||||
$('#desa').empty().append('<option value="">Pilih Desa/Kelurahan</option>').prop('disabled', true).trigger('change');
|
||||
$('#adat').empty().append('<option value="">Pilih Adat</option>').prop('disabled', true).trigger('change');
|
||||
if (id) {
|
||||
$.get(`/desakelurahanbykecamatan/${id}`, function (res) {
|
||||
$('#desa').prop('disabled', false);
|
||||
let dataList = Array.isArray(res) ? res : (res.data || []);
|
||||
$.each(dataList, function (key, val) { $('#desa').append(`<option value="${val.id}">${val.nama}</option>`); });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#desa').on('change', function () {
|
||||
let id = $(this).val();
|
||||
$('#adat').empty().append('<option value="">Pilih Adat</option>').prop('disabled', true).trigger('change');
|
||||
if (id) {
|
||||
$.get(`/adatbydesa/${id}`, function (res) {
|
||||
$('#adat').prop('disabled', false);
|
||||
let dataList = Array.isArray(res) ? res : (res.data || []);
|
||||
$.each(dataList, function (key, val) { $('#adat').append(`<option value="${val.id}">${val.nama}</option>`); });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const addForm = document.getElementById('addKeluargaForm');
|
||||
let fvAdd = FormValidation.formValidation(addForm, {
|
||||
fields: {
|
||||
kk: { validators: { notEmpty: { message: 'Nomor KK wajib diisi' }, stringLength: { min: 16, max: 16, message: 'Nomor KK harus 16 digit' } } },
|
||||
desa_kelurahan_id: { validators: { notEmpty: { message: 'Desa/Kelurahan wajib dipilih' } } },
|
||||
file_kk: { validators: { file: { extension: 'jpeg,jpg,png,pdf', maxSize: 2097152, message: 'Maksimal 2MB (JPG/PNG/PDF)' } } }
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap5: new FormValidation.plugins.Bootstrap5({ eleValidClass: '', rowSelector: '.form-control-validation' }),
|
||||
submitButton: new FormValidation.plugins.SubmitButton(),
|
||||
}
|
||||
}).on('core.form.valid', function () {
|
||||
$(addForm).find('select').prop('disabled', false);
|
||||
let formData = new FormData(addForm);
|
||||
|
||||
$.ajax({
|
||||
url: addForm.action,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (res) {
|
||||
Swal.fire({ icon: 'success', title: 'Berhasil!', text: res.message, timer: 1500, showConfirmButton: false })
|
||||
.then(() => window.location.href = "{{ route('keluarga.index') }}");
|
||||
},
|
||||
error: function (xhr) {
|
||||
if (xhr.status === 422) {
|
||||
const errors = xhr.responseJSON.errors || {};
|
||||
Object.keys(errors).forEach(key => {
|
||||
fvAdd.updateFieldStatus(key, 'Invalid', 'notEmpty');
|
||||
const fieldRow = addForm.querySelector(`[name="${key}"]`).closest('.form-control-validation');
|
||||
const messageContainer = fieldRow.querySelector('.fv-plugins-message-container');
|
||||
if (messageContainer) messageContainer.innerHTML = `<div class="fv-help-block text-danger">${errors[key][0]}</div>`;
|
||||
});
|
||||
} else {
|
||||
Swal.fire({ icon: 'error', title: 'Gagal!', text: xhr.responseJSON?.message || 'Error' });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.select2').on('change', function() {
|
||||
const name = $(this).attr('name');
|
||||
if (name && addForm.querySelector(`[name="${name}"]`)) fvAdd.revalidateField(name);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@@ -0,0 +1,252 @@
|
||||
@extends('layout.main')
|
||||
|
||||
@section('content')
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom mb-4">
|
||||
<h5 class="card-title mb-0">Edit Data Keluarga</h5>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<form id="editKeluargaForm" action="{{ route('keluarga.update', $keluarga->id) }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
<input type="hidden" name="_method" value="PUT">
|
||||
|
||||
<h6 class="mb-3 text-primary"><i class="ti tabler-id me-1"></i> Informasi Kartu Keluarga</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label">No. Kartu Keluarga (KK)<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="kk" value="{{ $keluarga->kk }}" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-4">
|
||||
<h6 class="mb-3 text-primary"><i class="ti tabler-map-pin me-1"></i> Wilayah & Adat</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label">Provinsi</label>
|
||||
<select id="provinsi" class="select2 form-select" data-placeholder="Pilih Provinsi">
|
||||
<option value="">Pilih Provinsi</option>
|
||||
@php
|
||||
$provId = $keluarga->desakelurahan->kecamatan->kabupatenkota->provinsi_id ?? null;
|
||||
@endphp
|
||||
@foreach($provinsi as $prov)
|
||||
<option value="{{ $prov->id }}" {{ $provId == $prov->id ? 'selected' : '' }}>{{ $prov->nama }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label">Kabupaten/Kota</label>
|
||||
<select id="kabupaten" class="select2 form-select" data-placeholder="Pilih Kabupaten/Kota">
|
||||
@if($keluarga->desakelurahan)
|
||||
<option value="{{ $keluarga->desakelurahan->kecamatan->kabupaten_kota_id }}" selected>
|
||||
{{ $keluarga->desakelurahan->kecamatan->kabupatenkota->nama }}
|
||||
</option>
|
||||
@else
|
||||
<option value="">Pilih Kabupaten/Kota</option>
|
||||
@endif
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label">Kecamatan</label>
|
||||
<select id="kecamatan" class="select2 form-select" data-placeholder="Pilih Kecamatan">
|
||||
@if($keluarga->desakelurahan)
|
||||
<option value="{{ $keluarga->desakelurahan->kecamatan_id }}" selected>
|
||||
{{ $keluarga->desakelurahan->kecamatan->nama }}
|
||||
</option>
|
||||
@else
|
||||
<option value="">Pilih Kecamatan</option>
|
||||
@endif
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label">Desa/Kelurahan<span class="text-danger">*</span></label>
|
||||
<select id="desa" name="desa_kelurahan_id" class="select2 form-select" data-placeholder="Pilih Desa/Kelurahan">
|
||||
@if($keluarga->desakelurahan)
|
||||
<option value="{{ $keluarga->desa_kelurahan_id }}" selected>
|
||||
{{ $keluarga->desakelurahan->nama }}
|
||||
</option>
|
||||
@else
|
||||
<option value="">Pilih Desa/Kelurahan</option>
|
||||
@endif
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label">Pilih Adat</label>
|
||||
<select id="adat" name="adat_id" class="select2 form-select" data-placeholder="Pilih Adat">
|
||||
@if($keluarga->adat)
|
||||
<option value="{{ $keluarga->adat_id }}" selected>
|
||||
{{ $keluarga->adat->nama }}
|
||||
</option>
|
||||
@else
|
||||
<option value="">Pilih Adat</option>
|
||||
@endif
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-4">
|
||||
<h6 class="mb-3 text-primary"><i class="ti tabler-upload me-1"></i> Dokumen</h6>
|
||||
<small class="text-muted d-block mb-3">*Biarkan field upload kosong jika tidak ingin mengubah dokumen lama.</small>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label">Ganti File KK</label>
|
||||
<input type="file" class="form-control" id="file_kk" name="file_kk" accept="image/*,.pdf" />
|
||||
|
||||
@php
|
||||
$hasKk = !empty($keluarga->path_kk);
|
||||
$isKkPdf = $hasKk && strtolower(pathinfo($keluarga->path_kk, PATHINFO_EXTENSION)) === 'pdf';
|
||||
@endphp
|
||||
|
||||
<div id="preview-container" class="mt-3 {{ $hasKk ? '' : 'd-none' }}">
|
||||
<img id="preview-image" src="{{ $hasKk && !$isKkPdf ? asset('storage/' . $keluarga->path_kk) : '' }}" alt="Preview KK" class="img-thumbnail {{ $hasKk && !$isKkPdf ? '' : 'd-none' }}" style="width: 100%; max-height: 250px; object-fit: contain; background-color: #f8f9fa;">
|
||||
<div id="preview-pdf" class="badge bg-label-danger p-2 w-100 {{ $isKkPdf ? '' : 'd-none' }}"><i class="ti tabler-file-type-pdf ti-sm me-1"></i> Dokumen PDF (Tersimpan)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 text-end">
|
||||
<a href="{{ route('keluarga.index') }}" class="btn btn-label-secondary me-2">Batal</a>
|
||||
<button type="submit" class="btn btn-primary data-submit">Simpan Perubahan</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
'use strict';
|
||||
$(document).ready(function () {
|
||||
$('.select2').select2();
|
||||
|
||||
$('#file_kk').on('change', function(event) {
|
||||
const file = event.target.files[0];
|
||||
const $container = $('#preview-container');
|
||||
const $image = $('#preview-image');
|
||||
const $pdf = $('#preview-pdf');
|
||||
|
||||
if (file) {
|
||||
$container.removeClass('d-none');
|
||||
if (file.type.match('image.*')) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
$image.attr('src', e.target.result).removeClass('d-none');
|
||||
$pdf.addClass('d-none');
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
} else if (file.type === 'application/pdf') {
|
||||
$image.addClass('d-none').attr('src', '');
|
||||
$pdf.removeClass('d-none').html('<i class="ti tabler-file-type-pdf ti-sm me-1"></i> Dokumen PDF (Baru Terpilih)');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#provinsi').on('change', function () {
|
||||
let id = $(this).val();
|
||||
$('#kabupaten').empty().append('<option value="">Pilih Kabupaten/Kota</option>').trigger('change');
|
||||
$('#kecamatan').empty().append('<option value="">Pilih Kecamatan</option>').trigger('change');
|
||||
$('#desa').empty().append('<option value="">Pilih Desa/Kelurahan</option>').trigger('change');
|
||||
$('#adat').empty().append('<option value="">Pilih Adat</option>').trigger('change');
|
||||
if (id) {
|
||||
$.get(`/kabupatenkotabyprovinsi/${id}`, function (res) {
|
||||
let dataList = Array.isArray(res) ? res : (res.data || []);
|
||||
$.each(dataList, function (key, val) { $('#kabupaten').append(`<option value="${val.id}">${val.nama}</option>`); });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#kabupaten').on('change', function () {
|
||||
let id = $(this).val();
|
||||
$('#kecamatan').empty().append('<option value="">Pilih Kecamatan</option>').trigger('change');
|
||||
$('#desa').empty().append('<option value="">Pilih Desa/Kelurahan</option>').trigger('change');
|
||||
$('#adat').empty().append('<option value="">Pilih Adat</option>').trigger('change');
|
||||
if (id) {
|
||||
$.get(`/kecamatanbykabupatenkota/${id}`, function (res) {
|
||||
let dataList = Array.isArray(res) ? res : (res.data || []);
|
||||
$.each(dataList, function (key, val) { $('#kecamatan').append(`<option value="${val.id}">${val.nama}</option>`); });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#kecamatan').on('change', function () {
|
||||
let id = $(this).val();
|
||||
$('#desa').empty().append('<option value="">Pilih Desa/Kelurahan</option>').trigger('change');
|
||||
$('#adat').empty().append('<option value="">Pilih Adat</option>').trigger('change');
|
||||
if (id) {
|
||||
$.get(`/desakelurahanbykecamatan/${id}`, function (res) {
|
||||
let dataList = Array.isArray(res) ? res : (res.data || []);
|
||||
$.each(dataList, function (key, val) { $('#desa').append(`<option value="${val.id}">${val.nama}</option>`); });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#desa').on('change', function () {
|
||||
let id = $(this).val();
|
||||
$('#adat').empty().append('<option value="">Pilih Adat</option>').trigger('change');
|
||||
if (id) {
|
||||
$.get(`/adatbydesa/${id}`, function (res) {
|
||||
let dataList = Array.isArray(res) ? res : (res.data || []);
|
||||
$.each(dataList, function (key, val) { $('#adat').append(`<option value="${val.id}">${val.nama}</option>`); });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const editForm = document.getElementById('editKeluargaForm');
|
||||
let fvEdit = FormValidation.formValidation(editForm, {
|
||||
fields: {
|
||||
kk: { validators: { notEmpty: { message: 'Nomor KK wajib diisi' }, stringLength: { min: 16, max: 16, message: 'Nomor KK harus 16 digit' } } },
|
||||
desa_kelurahan_id: { validators: { notEmpty: { message: 'Desa/Kelurahan wajib dipilih' } } },
|
||||
file_kk: { validators: { file: { extension: 'jpeg,jpg,png,pdf', maxSize: 2097152, message: 'Maksimal 2MB (JPG/PNG/PDF)' } } }
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap5: new FormValidation.plugins.Bootstrap5({ eleValidClass: '', rowSelector: '.form-control-validation' }),
|
||||
submitButton: new FormValidation.plugins.SubmitButton(),
|
||||
}
|
||||
}).on('core.form.valid', function () {
|
||||
let formData = new FormData(editForm);
|
||||
|
||||
$.ajax({
|
||||
url: editForm.action,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (res) {
|
||||
Swal.fire({ icon: 'success', title: 'Berhasil!', text: res.message, timer: 1500, showConfirmButton: false })
|
||||
.then(() => window.location.href = "{{ route('keluarga.index') }}");
|
||||
},
|
||||
error: function (xhr) {
|
||||
if (xhr.status === 422) {
|
||||
const errors = xhr.responseJSON.errors || {};
|
||||
Object.keys(errors).forEach(key => {
|
||||
fvEdit.updateFieldStatus(key, 'Invalid', 'notEmpty');
|
||||
const fieldRow = editForm.querySelector(`[name="${key}"]`).closest('.form-control-validation');
|
||||
const messageContainer = fieldRow.querySelector('.fv-plugins-message-container');
|
||||
if (messageContainer) messageContainer.innerHTML = `<div class="fv-help-block text-danger">${errors[key][0]}</div>`;
|
||||
});
|
||||
} else {
|
||||
Swal.fire({ icon: 'error', title: 'Gagal!', text: xhr.responseJSON?.message || 'Error' });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.select2').on('change', function() {
|
||||
const name = $(this).attr('name');
|
||||
if (name && editForm.querySelector(`[name="${name}"]`)) fvEdit.revalidateField(name);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@@ -0,0 +1,117 @@
|
||||
@extends('layout.main')
|
||||
|
||||
@section('content')
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom">
|
||||
<h5 class="card-title mb-0">Data Master Keluarga</h5>
|
||||
</div>
|
||||
|
||||
<div class="card-body border-bottom pt-4">
|
||||
<form method="GET" action="{{ route('keluarga.index') }}" class="d-flex justify-content-between align-items-center row gap-3 gap-md-0">
|
||||
<div class="col-md-auto">
|
||||
<div class="d-flex align-items-center">
|
||||
<label class="me-2 text-nowrap">Show</label>
|
||||
<select name="per_page" class="form-select form-select-sm w-auto" onchange="this.form.submit()">
|
||||
<option value="10" {{ request('per_page') == 10 ? 'selected' : '' }}>10</option>
|
||||
<option value="25" {{ request('per_page') == 25 ? 'selected' : '' }}>25</option>
|
||||
</select>
|
||||
<label class="ms-2 text-nowrap">entries</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-auto d-flex gap-2">
|
||||
<div class="input-group input-group-sm w-auto">
|
||||
<input type="text" name="search" class="form-control" placeholder="Cari No. KK..." value="{{ request('search') }}">
|
||||
<button type="submit" class="btn btn-outline-primary"><i class="ti tabler-search"></i></button>
|
||||
</div>
|
||||
<a href="{{ route('keluarga.create') }}" class="btn btn-sm btn-primary">
|
||||
<i class="ti tabler-plus me-1"></i> Tambah Data
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive text-nowrap">
|
||||
<table class="table table-hover">
|
||||
<thead class="border-top">
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>No. KK</th>
|
||||
<th>Desa/Kelurahan</th>
|
||||
<th>Adat</th>
|
||||
<th>File KK</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($keluarga as $index => $item)
|
||||
<tr>
|
||||
<td>{{ $keluarga->firstItem() + $index }}</td>
|
||||
<td><span class="text-heading fw-medium">{{ $item->kk }}</span></td>
|
||||
<td>{{ $item->desakelurahan->nama ?? '-' }}</td>
|
||||
<td>{{ $item->adat->nama ?? '-' }}</td>
|
||||
<td>
|
||||
@if($item->path_kk)
|
||||
<span class="badge bg-label-success"><i class="ti tabler-check"></i> Ada</span>
|
||||
@else
|
||||
<span class="badge bg-label-danger"><i class="ti tabler-x"></i> Tidak Ada</span>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center">
|
||||
<a href="{{ route('keluarga.edit', $item->id) }}" class="btn btn-icon btn-text-secondary rounded-pill"><i class="ti tabler-edit ti-md"></i></a>
|
||||
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill delete-record" data-id="{{ $item->id }}" data-nama="{{ $item->kk }}"><i class="ti tabler-trash ti-md"></i></a>
|
||||
<a href="{{ route('keluarga.show', $item->id) }}" class="btn btn-icon btn-text-secondary rounded-pill"><i class="ti tabler-eye ti-md"></i></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="6" class="text-center py-4">Tidak ada data ditemukan.</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card-footer d-flex justify-content-center justify-content-md-end border-top">
|
||||
{{ $keluarga->appends(request()->query())->links('pagination::bootstrap-5') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
'use strict';
|
||||
const csrfToken = "{{ csrf_token() }}";
|
||||
|
||||
$(document).ready(function () {
|
||||
$(document).on('click', '.delete-record', function (e) {
|
||||
e.preventDefault();
|
||||
const id = $(e.currentTarget).data('id');
|
||||
const name = $(e.currentTarget).data('nama');
|
||||
|
||||
Swal.fire({
|
||||
title: 'Hapus Data?',
|
||||
text: `Data KK "${name}" akan dihapus permanen!`,
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Ya, Hapus!',
|
||||
customClass: { confirmButton: 'btn btn-primary me-3', cancelButton: 'btn btn-label-secondary' },
|
||||
buttonsStyling: false
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
url: `/keluarga/${id}`,
|
||||
type: 'DELETE',
|
||||
headers: { 'X-CSRF-TOKEN': csrfToken },
|
||||
success: function (res) {
|
||||
Swal.fire({ icon: 'success', title: 'Terhapus!', text: res.message, showConfirmButton: false, timer: 1500 })
|
||||
.then(() => window.location.reload());
|
||||
},
|
||||
error: () => Swal.fire({ icon: 'error', title: 'Gagal!', text: 'Terjadi kesalahan sistem.' })
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@@ -0,0 +1,92 @@
|
||||
@extends('layout.main')
|
||||
|
||||
@section('content')
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom mb-4 d-flex justify-content-between align-items-center">
|
||||
<h5 class="card-title mb-0">Detail Data Keluarga</h5>
|
||||
<a href="{{ route('keluarga.index') }}" class="btn btn-sm btn-label-secondary">
|
||||
<i class="ti tabler-arrow-left me-1"></i> Kembali
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<form onsubmit="return false;">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 mb-4">
|
||||
<h6 class="mb-3 text-primary"><i class="ti tabler-id me-1"></i> Informasi KK</h6>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">No. Kartu Keluarga</label>
|
||||
<input type="text" class="form-control bg-lighter" value="{{ $keluarga->kk }}" readonly />
|
||||
</div>
|
||||
|
||||
<hr class="my-4">
|
||||
<h6 class="mb-3 text-primary"><i class="ti tabler-map-pin me-1"></i> Lokasi Wilayah & Adat</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Provinsi</label>
|
||||
<input type="text" class="form-control bg-lighter" value="{{ $keluarga->desakelurahan->kecamatan->kabupatenkota->provinsi->nama ?? '-' }}" readonly />
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Kabupaten/Kota</label>
|
||||
<input type="text" class="form-control bg-lighter" value="{{ $keluarga->desakelurahan->kecamatan->kabupatenkota->nama ?? '-' }}" readonly />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Kecamatan</label>
|
||||
<input type="text" class="form-control bg-lighter" value="{{ $keluarga->desakelurahan->kecamatan->nama ?? '-' }}" readonly />
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Desa/Kelurahan</label>
|
||||
<input type="text" class="form-control bg-lighter" value="{{ $keluarga->desakelurahan->nama ?? '-' }}" readonly />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Data Adat</label>
|
||||
<input type="text" class="form-control bg-lighter" value="{{ $keluarga->adat->nama ?? 'Tidak terikat adat' }}" readonly />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6 mb-4">
|
||||
<h6 class="mb-3 text-primary"><i class="ti tabler-upload me-1"></i> Dokumen Fisik</h6>
|
||||
|
||||
@if($keluarga->path_kk)
|
||||
@php
|
||||
$isPdf = strtolower(pathinfo($keluarga->path_kk, PATHINFO_EXTENSION)) === 'pdf';
|
||||
@endphp
|
||||
|
||||
@if($isPdf)
|
||||
<div class="p-5 border rounded text-center bg-lighter">
|
||||
<i class="ti tabler-file-type-pdf text-danger mb-3" style="font-size: 4rem;"></i>
|
||||
<p class="mb-3 text-muted fw-medium">{{ $keluarga->file_kk }}</p>
|
||||
<a href="{{ asset('storage/' . $keluarga->path_kk) }}" target="_blank" class="btn btn-primary">
|
||||
<i class="ti tabler-external-link me-1"></i> Buka PDF
|
||||
</a>
|
||||
</div>
|
||||
@else
|
||||
<div class="border rounded p-2 text-center bg-lighter">
|
||||
<a href="{{ asset('storage/' . $keluarga->path_kk) }}" target="_blank" title="Klik untuk memperbesar">
|
||||
<img src="{{ asset('storage/' . $keluarga->path_kk) }}" alt="File KK" class="img-fluid rounded" style="max-height: 400px; object-fit: contain;">
|
||||
</a>
|
||||
</div>
|
||||
<small class="text-muted mt-2 d-block text-center fst-italic">*Klik gambar untuk melihat resolusi penuh</small>
|
||||
@endif
|
||||
@else
|
||||
<div class="p-5 border rounded text-center bg-lighter">
|
||||
<i class="ti tabler-photo-off text-muted mb-3" style="font-size: 4rem;"></i>
|
||||
<p class="mb-0 text-muted fst-italic">Belum ada dokumen KK yang diunggah.</p>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user