perbaikan laporan so , form inspksi alat berat, kendaraan dan mesin
This commit is contained in:
@@ -177,4 +177,129 @@
|
||||
});
|
||||
newElement.dispatchEvent(event);
|
||||
}
|
||||
|
||||
async function loadSavedLocationData() {
|
||||
const provinceCode = '{{ $cekAlamat['province_code'] ?? '' }}';
|
||||
const cityCode = '{{ $cekAlamat['city_code'] ?? '' }}';
|
||||
const districtCode = '{{ $cekAlamat['district_code'] ?? '' }}';
|
||||
const villageCode = '{{ $cekAlamat['village_code'] ?? '' }}';
|
||||
|
||||
// Set province
|
||||
const provinceSelect = document.getElementById('province_code');
|
||||
if (provinceCode && provinceSelect) {
|
||||
provinceSelect.value = provinceCode;
|
||||
await getCity(provinceCode);
|
||||
}
|
||||
|
||||
// Set city
|
||||
const citySelect = document.getElementById('city_code');
|
||||
if (cityCode && citySelect) {
|
||||
citySelect.value = cityCode;
|
||||
await getDistrict(cityCode);
|
||||
}
|
||||
|
||||
// Set district
|
||||
const districtSelect = document.getElementById('district_code');
|
||||
if (districtCode && districtSelect) {
|
||||
districtSelect.value = districtCode;
|
||||
await getVillage(districtCode);
|
||||
}
|
||||
|
||||
// Set village
|
||||
const villageSelect = document.getElementById('village_code');
|
||||
if (villageCode && villageSelect) {
|
||||
villageSelect.value = villageCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Modifikasi fungsi existing
|
||||
async function getCity(provinceId) {
|
||||
try {
|
||||
const response = await fetch(`/locations/cities/province/${provinceId}`);
|
||||
const data = await response.json();
|
||||
|
||||
const cityDropdown = document.getElementById('city_code');
|
||||
if (cityDropdown) {
|
||||
cityDropdown.innerHTML = '<option value="">Pilih Kota/Kabupaten</option>';
|
||||
data.forEach(city => {
|
||||
const option = document.createElement('option');
|
||||
option.value = city.code;
|
||||
option.textContent = city.name;
|
||||
@if (isset($debitur->city_code))
|
||||
if (city.code === '{{ $debitur->city_code }}') {
|
||||
option.selected = true;
|
||||
}
|
||||
@endif
|
||||
|
||||
cityDropdown.appendChild(option);
|
||||
});
|
||||
|
||||
// Reset dropdown kecamatan dan desa
|
||||
document.getElementById('district_code').innerHTML = '<option value="">Pilih Kecamatan</option>';
|
||||
document.getElementById('village_code').innerHTML = '<option value="">Pilih Kelurahan</option>';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching cities:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Lakukan hal serupa untuk getDistrict dan getVillage
|
||||
async function getDistrict(cityId) {
|
||||
try {
|
||||
const response = await fetch(`/locations/districts/city/${cityId}`);
|
||||
const data = await response.json();
|
||||
|
||||
const districtDropdown = document.getElementById('district_code');
|
||||
if (districtDropdown) {
|
||||
districtDropdown.innerHTML = '<option value="">Pilih Kecamatan</option>';
|
||||
data.forEach(district => {
|
||||
const option = document.createElement('option');
|
||||
option.value = district.code;
|
||||
option.textContent = district.name;
|
||||
|
||||
// Cek apakah ini adalah kecamatan yang sebelumnya dipilih
|
||||
@if (isset($debitur->district_code))
|
||||
if (district.code === '{{ $debitur->district_code }}') {
|
||||
option.selected = true;
|
||||
}
|
||||
@endif
|
||||
|
||||
districtDropdown.appendChild(option);
|
||||
});
|
||||
|
||||
// Reset dropdown desa
|
||||
document.getElementById('village_code').innerHTML = '<option value="">Pilih Kelurahan</option>';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching districts:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function getVillage(districtId) {
|
||||
try {
|
||||
const response = await fetch(`/locations/villages/district/${districtId}`);
|
||||
const data = await response.json();
|
||||
|
||||
const villageDropdown = document.getElementById('village_code');
|
||||
if (villageDropdown) {
|
||||
villageDropdown.innerHTML = '<option value="">Pilih Desa/Kelurahan</option>';
|
||||
data.forEach(village => {
|
||||
const option = document.createElement('option');
|
||||
option.value = village.code;
|
||||
option.textContent = village.name;
|
||||
|
||||
// Cek apakah ini adalah desa yang sebelumnya dipilih
|
||||
@if (isset($debitur->village_code))
|
||||
if (village.code === '{{ $debitur->village_code }}') {
|
||||
option.selected = true;
|
||||
}
|
||||
@endif
|
||||
|
||||
villageDropdown.appendChild(option);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching villages:', error);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user