[Operator] Perbaikan Laman Portal -> Mahasiswa
This commit is contained in:
@@ -1047,6 +1047,82 @@ Alpine.data('satuRemoteTable', (config) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
/*
|
||||
* Detail mahasiswa (Portal operator > Mahasiswa): biodata per bagian yang bisa diubah di tempat. Tiap bagian punya nilai
|
||||
* isian (values) dan teks tampil (display); Simpan mengirim PUT JSON untuk satu bagian lalu memakai nilai segar dari server.
|
||||
* config: { tab, saveUrl ("__SECTION__"), token, values: { bagian: { kolom: nilai } }, display: { bagian: { kolom: teks } } }.
|
||||
*/
|
||||
Alpine.data('studentBiodata', (config) => ({
|
||||
tab: config.tab,
|
||||
values: config.values,
|
||||
display: config.display,
|
||||
editing: null,
|
||||
form: {},
|
||||
saving: false,
|
||||
reloading: false,
|
||||
|
||||
get nama() {
|
||||
return this.display.pribadi?.nama ?? '';
|
||||
},
|
||||
|
||||
// Inisial seperti ui.avatar: gelar bertitik dan bagian setelah koma dilewati
|
||||
get initials() {
|
||||
const words = this.nama.split(',')[0].trim().split(/\s+/).filter(Boolean);
|
||||
const plain = words.filter((word) => !word.endsWith('.'));
|
||||
const use = plain.length ? plain : words;
|
||||
return ((use[0]?.[0] ?? '?') + (use.length > 1 ? use[use.length - 1][0] : '')).toUpperCase();
|
||||
},
|
||||
|
||||
show(key) {
|
||||
this.tab = key;
|
||||
},
|
||||
|
||||
edit(key) {
|
||||
this.tab = key;
|
||||
this.editing = key;
|
||||
this.form = { ...this.values[key] };
|
||||
this.$nextTick(() => this.$refs['panel-' + key]?.querySelector('input:not([type=hidden]), select, textarea')?.focus());
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.editing = null;
|
||||
},
|
||||
|
||||
async save() {
|
||||
const key = this.editing;
|
||||
if (key === null || this.saving) return;
|
||||
const url = config.saveUrl.replace('__SECTION__', encodeURIComponent(key));
|
||||
this.saving = true;
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRF-TOKEN': config.token, 'X-Requested-With': 'XMLHttpRequest' },
|
||||
body: JSON.stringify(this.form),
|
||||
});
|
||||
const data = await response.json().catch(() => null);
|
||||
if (!response.ok) {
|
||||
const first = data?.errors ? Object.values(data.errors).flat()[0] : null;
|
||||
throw new Error(first || data?.message || 'Biodata tidak dapat disimpan. Muat ulang halaman lalu coba lagi.');
|
||||
}
|
||||
console.info(`[SIAKAD] PUT ${url}`, { hasil: data.message });
|
||||
// Data akademik mengubah ringkasan di atas halaman: muat ulang (pesan tampil lewat sesi); tombol tetap sibuk
|
||||
if (data.reload) {
|
||||
this.reloading = true;
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
this.values[key] = data.values;
|
||||
this.display[key] = data.display;
|
||||
this.editing = null;
|
||||
window.toast('success', data.message);
|
||||
} catch (error) {
|
||||
window.toast('danger', error.message);
|
||||
} finally {
|
||||
if (!this.reloading) this.saving = false;
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
/*
|
||||
* Kegiatan Akademik (Portal operator, akun DB lama): tabel jenis kegiatan dengan tambah/ubah sebaris dan hapus
|
||||
* berdialog. Baris disaring dan dihalamankan di sisi klien (jumlahnya puluhan); setiap simpan mengirim JSON dan
|
||||
|
||||
Reference in New Issue
Block a user