Fix file upload size limits and toast messages on failure

This commit is contained in:
ilham_gmail
2026-06-11 19:43:52 +07:00
parent 0593d25080
commit 3b62f71946
4 changed files with 34 additions and 13 deletions
+25 -13
View File
@@ -1883,6 +1883,7 @@ function openEdit(id){
payload.assistance_notes = null;
}
(async function(){
let updateSuccess = false;
try{
const respUpdate = await fetch('src/api/update_lokasi.php',{method:'POST',headers:buildHeaders(),body:JSON.stringify(payload),credentials:'same-origin'});
const jrUpdate = await respUpdate.json().catch(()=>null);
@@ -1890,7 +1891,7 @@ function openEdit(id){
const reason = jrUpdate && jrUpdate.error ? jrUpdate.error : 'unknown';
showToast('Gagal menyimpan perubahan: ' + reason, 'error', 6000);
} else {
try{ showToast('Perubahan tersimpan', 'success', 2600); }catch(e){}
updateSuccess = true;
// optimistically update marker on the map so UI reflects change immediately
try{
const idStr = String(id);
@@ -1915,19 +1916,30 @@ function openEdit(id){
}catch(e){}
}
}catch(e){ console.error('update failed', e); showToast('Gagal menyimpan perubahan: ' + (e && e.message ? e.message : e), 'error', 6000); }
// use captured file from modal submit
if(file){
try{
const fdata = new FormData(); fdata.append('file', file); fdata.append('id', id);
const resp = await fetch('src/api/upload_photo.php',{method:'POST',headers:buildHeaders(null),body:fdata,credentials:'same-origin'});
const jr = await resp.json().catch(()=>null);
if(!jr || !jr.success){
const reason = jr && (jr.error || (jr.last_error && jr.last_error.message)) ? (jr.error || jr.last_error.message) : 'unknown';
showToast('Gagal mengunggah foto: ' + reason, 'error', 7000);
} else {
showToast('Foto berhasil diunggah', 'success', 3000);
if(updateSuccess){
let uploadSuccess = true;
if(file){
try{
const fdata = new FormData(); fdata.append('file', file); fdata.append('id', id);
const resp = await fetch('src/api/upload_photo.php',{method:'POST',headers:buildHeaders(null),body:fdata,credentials:'same-origin'});
const jr = await resp.json().catch(()=>null);
if(!jr || !jr.success){
uploadSuccess = false;
const reason = jr && (jr.error || (jr.last_error && jr.last_error.message)) ? (jr.error || jr.last_error.message) : 'unknown';
showToast('Gagal mengunggah foto: ' + reason, 'error', 7000);
} else {
showToast('Foto berhasil diunggah', 'success', 3000);
}
}catch(e){
uploadSuccess = false;
console.error('upload failed',e);
showToast('Gagal mengunggah foto: ' + (e && e.message ? e.message : e), 'error', 7000);
}
}catch(e){ console.error('upload failed',e); showToast('Gagal mengunggah foto: ' + (e && e.message ? e.message : e), 'error', 7000); }
}
if(uploadSuccess){
showToast('Perubahan tersimpan', 'success', 2600);
}
}
loadData();
})();