[Operator] Perbaikan Laman Jadwal

This commit is contained in:
Ariyutta
2026-11-17 08:46:36 +07:00
parent 8f52669aa1
commit 54d2b00369
43 changed files with 1378 additions and 145 deletions
+56
View File
@@ -203,6 +203,31 @@ Alpine.data('confirmDialog', () => ({
},
}));
/*
* Dialog formulir tambah di panel halaman rincian (kelas-detail): tombol Tambah membuka <dialog> modal berisi formulir.
* Bila halaman dimuat ulang dengan galat validasi (data-open="true"), dialog dibuka lagi agar pesan galatnya terlihat.
*/
Alpine.data('formDialog', () => ({
opener: null,
init() {
if (this.$el.dataset.open === 'true') this.$nextTick(() => this.$refs.dialog.showModal());
},
show() {
this.opener = document.activeElement;
this.$refs.dialog.showModal();
},
close() {
this.$refs.dialog.close();
this.opener?.focus();
},
backdrop(event) {
if (event.target === this.$refs.dialog) this.close();
},
}));
/*
* Status sibuk untuk setiap formulir: tombol kirim menampilkan pemintal dan
* kirim ganda ditahan. Formulir yang tidak ingin ini memberi atribut data-no-busy.
@@ -869,6 +894,37 @@ Alpine.data('satuRemoteTable', (config) => ({
// Modal Lihat: kolom tabel dan baris yang sedang dilihat
columns: config.columns ?? [],
viewing: null,
// Daftar sakelar di modal Lihat ({kunci rincian: url "__ID__"}): tiap butir {id, nama, aktif, meta} dikirim POST {id, aktif}
switches: config.switches ?? {},
async toggleSwitch(key, item) {
const url = this.switches[key];
if (!url || !this.viewing || this.loading) return;
const id = this.viewing.id;
const target = url.replace('__ID__', encodeURIComponent(id));
this.loading = true;
try {
const response = await fetch(target, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRF-TOKEN': this.token, 'X-Requested-With': 'XMLHttpRequest' },
body: JSON.stringify({ id: item.id, aktif: !item.aktif }),
});
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 || 'Perubahan tidak dapat disimpan. Muat ulang halaman lalu coba lagi.');
}
console.info(`[SIAKAD] POST ${target}`, { id: item.id, aktif: !item.aktif, hasil: data?.message });
window.toast('success', data?.message || 'Perubahan disimpan.');
this.loading = false;
// Baris dimuat ulang agar sakelar dan kolom Aktif? mencerminkan keadaan terbaru; modal tetap terbuka.
await this.load(this.page);
this.viewing = this.view.find((row) => row.id === id) ?? this.viewing;
} catch (error) {
window.toast('danger', error.message);
this.loading = false;
}
},
startView(row) {
this.viewing = row;