initiall comit
This commit is contained in:
+80
-1
@@ -634,12 +634,31 @@ function attachEventListeners() {
|
||||
const form_jalan = document.getElementById('form-jalan');
|
||||
const form_polygon = document.getElementById('form-polygon');
|
||||
const form_spbu = document.getElementById('form-spbu');
|
||||
const form_bantuan = document.getElementById('form-bantuan');
|
||||
|
||||
if (form_masyarakat) form_masyarakat.addEventListener('submit', function(e) { e.preventDefault(); submitFormMasyarakat(); });
|
||||
if (form_ibadah) form_ibadah.addEventListener('submit', function(e) { e.preventDefault(); submitFormIbadah(); });
|
||||
if (form_jalan) form_jalan.addEventListener('submit', function(e) { e.preventDefault(); submitFormJalan(); });
|
||||
if (form_polygon) form_polygon.addEventListener('submit', function(e) { e.preventDefault(); submitFormPolygon(); });
|
||||
if (form_spbu) form_spbu.addEventListener('submit', function(e) { e.preventDefault(); submitFormSPBU(); });
|
||||
if (form_bantuan) form_bantuan.addEventListener('submit', function(e) { e.preventDefault(); submitFormBantuan(); });
|
||||
|
||||
// BPJS Fields Toggle
|
||||
const bpjs_status_select = document.getElementById('form-status-bpjs');
|
||||
const bpjs_detail_fields = document.getElementById('bpjs-detail-fields');
|
||||
if (bpjs_status_select && bpjs_detail_fields) {
|
||||
bpjs_status_select.addEventListener('change', function() {
|
||||
if (this.value === 'Ya') {
|
||||
bpjs_detail_fields.style.display = 'block';
|
||||
const dateInput = bpjs_detail_fields.querySelector('input[type="date"]');
|
||||
if (dateInput && !dateInput.value) {
|
||||
dateInput.value = new Date().toISOString().substring(0, 10);
|
||||
}
|
||||
} else {
|
||||
bpjs_detail_fields.style.display = 'none';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Shortcut keyboard untuk membuka formulir penambahan data baru
|
||||
document.addEventListener('keydown', function(e) {
|
||||
@@ -757,8 +776,30 @@ function submitFormMasyarakat() {
|
||||
.then(handleFetchResponse)
|
||||
.then(result => {
|
||||
if (result.status === 'success') {
|
||||
// Tambahkan detail BPJS jika status_bpjs adalah Ya
|
||||
const status_bpjs = form_data.get('status_bpjs');
|
||||
if (status_bpjs === 'Ya') {
|
||||
const bpjs_data = new FormData();
|
||||
bpjs_data.append('id_masyarakat', result.data.id);
|
||||
bpjs_data.append('no_peserta', form_data.get('bpjs_no_peserta'));
|
||||
bpjs_data.append('jenis_bpjs', form_data.get('bpjs_jenis_bpjs'));
|
||||
bpjs_data.append('tingkat', form_data.get('bpjs_tingkat'));
|
||||
bpjs_data.append('status_aktif', form_data.get('bpjs_status_aktif'));
|
||||
bpjs_data.append('tanggal_daftar', form_data.get('bpjs_tanggal_daftar'));
|
||||
bpjs_data.append('faskes_tingkat_1', form_data.get('bpjs_faskes_tingkat_1'));
|
||||
|
||||
fetch(API_PATH + 'simpan_bpjs.php', {
|
||||
method: 'POST',
|
||||
body: bpjs_data
|
||||
})
|
||||
.then(handleFetchResponse)
|
||||
.catch(err => console.error("Gagal menyimpan detail BPJS:", err));
|
||||
}
|
||||
|
||||
showAlert('alert-form', 'Data berhasil disimpan!', 'success');
|
||||
form.reset();
|
||||
const bpjs_detail_fields = document.getElementById('bpjs-detail-fields');
|
||||
if (bpjs_detail_fields) bpjs_detail_fields.style.display = 'none';
|
||||
setTimeout(() => {
|
||||
closeModal('modal-form-masyarakat');
|
||||
loadMasyarakat();
|
||||
@@ -879,7 +920,45 @@ function hapusData(tipe, id) {
|
||||
}
|
||||
|
||||
function editBantuan(id) {
|
||||
alert('Fitur tambah bantuan dengan ID ' + id + ' akan ditambahkan segera');
|
||||
const form = document.getElementById('form-bantuan');
|
||||
if (form) form.reset();
|
||||
|
||||
const idInput = document.getElementById('bantuan-id-masyarakat');
|
||||
if (idInput) idInput.value = id;
|
||||
|
||||
const dateInput = document.querySelector('#form-bantuan input[name="tanggal_bantuan"]');
|
||||
if (dateInput) dateInput.value = new Date().toISOString().substring(0, 10);
|
||||
|
||||
openModal('modal-form-bantuan');
|
||||
}
|
||||
|
||||
function submitFormBantuan() {
|
||||
const form = document.getElementById('form-bantuan');
|
||||
if (!form) return;
|
||||
const form_data = new FormData(form);
|
||||
|
||||
fetch(API_PATH + 'simpan_bantuan.php', {
|
||||
method: 'POST',
|
||||
body: form_data
|
||||
})
|
||||
.then(handleFetchResponse)
|
||||
.then(result => {
|
||||
if (result.status === 'success') {
|
||||
showAlert('alert-form-bantuan', 'Riwayat bantuan berhasil disimpan!', 'success');
|
||||
form.reset();
|
||||
const citizenId = form_data.get('id_masyarakat');
|
||||
setTimeout(() => {
|
||||
closeModal('modal-form-bantuan');
|
||||
// Refresh detail modal
|
||||
showDetail(citizenId);
|
||||
}, 1000);
|
||||
} else {
|
||||
showAlert('alert-form-bantuan', result.message || 'Gagal menyimpan riwayat bantuan.', 'error');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
showAlert('alert-form-bantuan', 'Terjadi kesalahan sistem: ' + error.message, 'error');
|
||||
});
|
||||
}
|
||||
|
||||
function openModal(modalId) {
|
||||
|
||||
Reference in New Issue
Block a user