diff --git a/povertymap/index.html b/povertymap/index.html index 65fda77..5dd3ba4 100644 --- a/povertymap/index.html +++ b/povertymap/index.html @@ -222,6 +222,48 @@ + + +
@@ -2168,6 +2210,7 @@ try { const res = await fetch(API.auth + '?action=users', { credentials: 'include' }).then(r => r.json()); const users = res.data || []; + window._cachedUsersList = users; const roleColors = { admin: '#f59e0b', surveyor: '#10b981', pemangku: '#3b82f6' }; area.innerHTML = `
@@ -2201,11 +2244,12 @@
${h(u.nama_lengkap)} @${h(u.username)}
${ROLE_LABELS[u.role] || u.role} ${!u.is_active ? '(Nonaktif)' : ''}
-
+
+ ${u.id != currentUser.id ? (u.is_active - ? `` - : ``) - : 'Anda'} + ? `` + : ``) + : ''}
`).join('')}
@@ -2248,6 +2292,50 @@ renderUsers(document.getElementById('page-content')); } + function openEditUserModal(id) { + const u = window._cachedUsersList?.find(x => x.id == id); + if (!u) return; + document.getElementById('eu-id').value = u.id; + document.getElementById('eu-username').value = u.username; + document.getElementById('eu-nama').value = u.nama_lengkap; + document.getElementById('eu-role').value = u.role; + document.getElementById('eu-pass').value = ''; + document.getElementById('edit-user-modal').classList.add('show'); + } + + function closeEditUserModal() { + document.getElementById('edit-user-modal').classList.remove('show'); + } + + async function confirmEditUser() { + const id = document.getElementById('eu-id').value; + const nama_lengkap = document.getElementById('eu-nama').value.trim(); + const role = document.getElementById('eu-role').value; + const password = document.getElementById('eu-pass').value; + + if (!nama_lengkap) { showToast('Nama lengkap wajib diisi', 'error'); return; } + if (password && password.length < 6) { showToast('Password baru min 6 karakter', 'error'); return; } + + const payload = { nama_lengkap, role }; + if (password) { + payload.password = password; + } + + try { + const res = await fetch(API.auth + `?action=update&id=${id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + credentials: 'include', + body: JSON.stringify(payload) + }).then(r => r.json()); + + if (!res.success) throw new Error(res.error); + showToast('Data user berhasil diperbarui!', 'success'); + closeEditUserModal(); + renderUsers(document.getElementById('page-content')); + } catch (e) { showToast('Error: ' + e.message, 'error'); } + } + // -- MAP FUNCTIONS