agper-agen/modules/agen.html

100 lines
3.5 KiB
HTML

<group-el label="Manajemen Agen Perubahan" style="padding: 3ch 1ch;">
<table id="agents" class="fullwidth bordered selectable">
<thead>
<tr>
<th style="width: 22ch;">NIP</th>
<th style="min-width: 12ch;">Nama Agen</th>
<th style="min-width: 12ch;">Jabatan</th>
<th style="min-width: 12ch;">Unit Kerja</th>
</tr>
</thead>
<tbody id="agContent">
<tr>
<td colspan="4" style="height: 4em; text-align: center;">&nbsp;</td>
</tr>
</tbody>
</table>
</group-el>
<group-el label="Manajemen Akun Pengguna" style="padding: 3ch 1ch;">
<table id="users" class="fullwidth bordered selectable">
<thead>
<tr>
<th style="width: 22ch;">NIP</th>
<th style="min-width: 12ch;">Username</th>
<th style="width: 12ch;">Level</th>
<th style="width: 6ch;">Active</th>
</tr>
</thead>
<tbody id="usContent">
<tr>
<td colspan="4" style="height: 4em; text-align: center;">&nbsp;</td>
</tr>
</tbody>
</table>
</group-el>
<script type="module">
let agents = {};
let units = {};
let users = {};
async function populateAgents()
{
units = await getJson('/api/getunits');
if (units.status != 200) return false;
units = units.data;
agents = await getJson('/api/getagents');
if (agents.status != 200) return false;
agents = agents.data;
$('#agContent').empty();
$.each(agents,(_,v)=>{
const fu = units.find(e=>e.deplID == v.deplID);
v.unitKerja = fu.unitKerja
const ro = moly.newElement("tr");
const id = moly.newElement("td");
const nm = moly.newElement("td");
const jb = moly.newElement("td");
const uk = moly.newElement("td");
ro.append(id);
ro.append(nm);
ro.append(jb);
ro.append(uk);
id.append(v.agentID);
nm.append(v.name);
jb.append(v.jabatan);
uk.append(v.unitKerja);
$('#agContent').append(ro);
$(ro).click(async()=>{
const aksi = await moly.dialog.show({title: "Profil Agen Perubahan",content:"/modules/agen-profil.html",fetching: true, data: v});
if(aksi.edit)
{
const edit = await moly.dialog.show({title: "Update Agen Perubahan",content:"/modules/agen-edit.html",fetching: true, data: aksi.data});
}
});
});
}
async function populateUsers()
{
users = await getJson('/api/getusers');
if (users.status != 200) return false;
users = users.data;
$('#usContent').empty();
$.each(users,(_,v)=>{
const ro = moly.newElement("tr");
const id = moly.newElement("td");
const un = moly.newElement("td");
const lv = moly.newElement("td");
const ac = moly.newElement("td");
ac.style = "text-align: center;"
ro.append(id);
ro.append(un);
ro.append(lv);
ro.append(ac);
id.append(v.agentID);
un.append(v.username);
lv.append(v.level);
ac.append(v.active ? "Ya" : "Tidak");
$('#usContent').append(ro);
});
}
await populateAgents();
await populateUsers();
</script>