[Operator] Perbaikan Laman Kegiatan

This commit is contained in:
Ariyutta
2026-11-11 11:20:49 +07:00
parent f9ad783162
commit eba6ab77b4
15 changed files with 906 additions and 214 deletions
+51 -13
View File
@@ -625,8 +625,13 @@ Alpine.data('satuTable', (config) => ({
return Array.from({ length: Math.min(5, this.pages) }, (_, i) => start + i);
},
// Baris yang boleh dicentang
get pickable() {
return this.ownRowsOnly ? this.view.filter((row) => row.form) : this.view;
},
get allPicked() {
return this.view.length > 0 && this.view.every((row) => this.picked.includes(row.id));
return this.pickable.length > 0 && this.pickable.every((row) => this.picked.includes(row.id));
},
reset() {
@@ -645,7 +650,7 @@ Alpine.data('satuTable', (config) => ({
},
toggleAll() {
const ids = this.view.map((row) => row.id);
const ids = this.pickable.map((row) => row.id);
this.picked = this.allPicked ? this.picked.filter((id) => !ids.includes(id)) : [...new Set([...this.picked, ...ids])];
},
@@ -851,6 +856,8 @@ Alpine.data('satuRemoteTable', (config) => ({
// Opsional: tautan Lihat per baris ("__ID__" diganti id) dan penghapusan sungguhan (POST {ids})
viewUrl: config.viewUrl ?? null,
destroyUrl: config.destroyUrl ?? null,
// true: hanya baris yang membawa row.form yang bisa dicentang/dihapus (mis. kegiatan milik unit sendiri)
ownRowsOnly: config.ownRowsOnly ?? false,
token: config.token ?? '',
pending: [],
// Opsional: formulir tambah/ubah lewat modal ({storeUrl, updateUrl, fields:[{name, default}]}); baris memberi row.form
@@ -871,8 +878,13 @@ Alpine.data('satuRemoteTable', (config) => ({
return Array.from({ length: Math.min(5, this.pages) }, (_, i) => start + i);
},
// Baris yang boleh dicentang
get pickable() {
return this.ownRowsOnly ? this.view.filter((row) => row.form) : this.view;
},
get allPicked() {
return this.view.length > 0 && this.view.every((row) => this.picked.includes(row.id));
return this.pickable.length > 0 && this.pickable.every((row) => this.picked.includes(row.id));
},
// Filter, kata cari, atau jumlah per halaman berubah: kembali ke halaman 1
@@ -913,6 +925,10 @@ Alpine.data('satuRemoteTable', (config) => ({
const isNew = this.editing === 'new';
const url = isNew ? this.form.storeUrl : this.form.updateUrl.replace('__ID__', encodeURIComponent(this.editing));
const body = Object.fromEntries(Object.entries(this.formData).map(([k, v]) => [k, v === '' ? null : v]));
// Filter yang ikut dikirim (mis. periode akademik yang sedang dipilih); filter kosong tidak dikirim
(this.form.withFilters ?? []).forEach((name) => {
if (this.values[name] !== '' && this.values[name] !== null && this.values[name] !== false) body[name] = this.values[name];
});
this.loading = true;
try {
const response = await fetch(url, {
@@ -984,7 +1000,7 @@ Alpine.data('satuRemoteTable', (config) => ({
},
toggleAll() {
const ids = this.view.map((row) => row.id);
const ids = this.pickable.map((row) => row.id);
this.picked = this.allPicked ? this.picked.filter((id) => !ids.includes(id)) : [...new Set([...this.picked, ...ids])];
},
@@ -1129,7 +1145,7 @@ Alpine.data('bioDetail', (config) => ({
}));
/*
* Kegiatan Akademik (Portal operator, akun DB lama): tabel jenis kegiatan dengan tambah/ubah sebaris dan hapus
* Kegiatan Akademik (Portal operator, akun DB lama): tabel jenis kegiatan dengan tambah/ubah lewat modal dan hapus
* berdialog. Baris disaring dan dihalamankan di sisi klien (jumlahnya puluhan); setiap simpan mengirim JSON dan
* memakai daftar segar dari server.
*/
@@ -1177,17 +1193,27 @@ Alpine.data('satuKegiatan', (config) => ({
startInsert() {
this.editing = 'new';
this.form = { kode: '', nama: '', warna: '' };
this.$nextTick(() => this.$refs.nama?.focus());
this.openForm();
},
startEdit(row) {
this.editing = row.id;
this.form = { kode: row.kode, nama: row.nama, warna: row.warna ?? '' };
this.openForm();
},
openForm() {
const dialog = this.$refs.form;
if (dialog && !dialog.open) dialog.showModal();
this.$nextTick(() => this.$refs.nama?.focus());
},
cancel() {
this.editing = null;
closeForm() {
this.$refs.form?.close();
},
formBackdrop(event) {
if (event.target === this.$refs.form) this.closeForm();
},
async request(url, method, body) {
@@ -1219,7 +1245,7 @@ Alpine.data('satuKegiatan', (config) => ({
try {
const data = await this.request(url, isNew ? 'POST' : 'PUT', body);
this.rows = data.rows;
this.editing = null;
this.closeForm();
window.toast('success', data.message);
} catch (error) {
window.toast('danger', error.message);
@@ -1470,7 +1496,8 @@ document.addEventListener('click', (event) => {
* Select2 untuk semua <select> formulir (form.select dan <select class="field__select">): pencarian pada
* daftar panjang, tombol hapus (allowClear) dan placeholder "Pilih {nama kolom}". Pemilihan diteruskan ke
* x-model/x-on:change Alpine lewat event bawaan; perubahan dari Alpine disinkronkan balik ke tampilan.
* Atribut: data-no-clear (tanpa tombol hapus), data-no-select2 (biarkan <select> bawaan).
* Atribut: data-no-clear (tanpa tombol hapus), data-no-select2 (biarkan <select> bawaan), data-placeholder (teks
* placeholder sendiri), data-tags (daftar yang bisa dicari sekaligus boleh membuat nilai baru dengan mengetik).
*/
const SELECT2_ID = {
noResults: () => 'Data tidak ditemukan',
@@ -1501,7 +1528,8 @@ const enhanceSelect = (el) => {
const hasEmpty = [...el.options].some((option) => option.value === '');
const name = labelOf(el);
const placeholder = name ? `Pilih ${name}` : 'Pilih...';
const placeholder = el.dataset.placeholder || (name ? `Pilih ${name}` : 'Pilih...');
const tags = el.hasAttribute('data-tags');
const $el = $(el);
// Di dalam <dialog> (lapisan atas) dropdown harus ikut di dalam dialog; di body ia tertutup modal
@@ -1511,8 +1539,16 @@ const enhanceSelect = (el) => {
width: '100%',
placeholder: hasEmpty ? placeholder : undefined,
allowClear: !noClear && hasEmpty,
language: SELECT2_ID,
minimumResultsForSearch: el.options.length > 8 ? 0 : Infinity,
language: tags ? { ...SELECT2_ID, noResults: () => 'Ketik untuk membuat nama baru' } : SELECT2_ID,
tags,
// Nama yang sudah ada (tanpa memandang huruf) dipilih dari daftar, bukan dibuat ulang
createTag: tags ? (params) => {
const term = params.term.trim();
if (term === '' || [...el.options].some((option) => option.text.trim().toLowerCase() === term.toLowerCase())) return null;
return { id: term, text: term, isNew: true };
} : undefined,
templateResult: tags ? (item) => (item.isNew ? $('<span>').text(`Buat baru: ${item.text}`) : item.text) : undefined,
minimumResultsForSearch: tags || el.options.length > 8 ? 0 : Infinity,
dropdownCssClass: 'select2-glass',
selectionCssClass: 'select2-glass',
dropdownParent: dialog ? $(dialog) : $(document.body),
@@ -1534,6 +1570,8 @@ const enhanceSelect = (el) => {
Alpine.effect(() => {
const value = Alpine.evaluate(el, model.value);
const next = value === null || value === undefined ? '' : String(value);
// Nilai baru buatan pengguna belum ada sebagai <option> (mis. saat mengubah baris yang namanya baru dibuat)
if (tags && next !== '' && ![...el.options].some((option) => option.value === next)) el.appendChild(new Option(next, next));
// x-model sudah mengubah nilai <select> asli; Select2 tetap perlu menyegarkan tampilannya
Alpine.nextTick(() => {
if (String($el.val() ?? '') !== next) $el.val(next);