Files
siakad/resources/views/operator/satu/remote-list.blade.php
T
2026-11-11 11:20:49 +07:00

301 lines
20 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{--
Halaman daftar SATU dengan data asli DB lama: markup sama dengan operator/satu/list (filter, bilah cari + tombol
menurut flags katalog, centang, kolom, aksi baris, satu-foot), tetapi baris diambil server lewat satuRemoteTable
(fetch JSON ke $url), sehingga alamat halaman tidak berubah. Halaman pertama ikut dirender sebagai data awal.
columns: [['key', 'label', 'num' => bool, 'badge' => bool]]; kolom badge memakai row.{key} dan nada row.tone.
filters: [['name', 'label', 'options' => [], 'value' => bawaan]] atau ['name', 'label', 'type' => 'check'].
Opsional: $tools (kunci tombol bilah yang boleh tampil, [] = tanpa tombol), $selectable (false = tanpa kotak centang),
$editable (false = tanpa aksi Ubah di baris; $form hanya untuk Tambah),
$viewable (false = tanpa aksi Lihat dan modal detail di baris),
kolom 'swatch' => true (kotak warna + kode dari row.{key}), isian form type 'color' (pemilih warna + kode heksa), dan
isian 'wide' => true (selebar penuh baris), select 'tags' => true (daftar yang bisa dicari sekaligus boleh membuat nilai baru dengan mengetik; nilai = teks) serta
'placeholder' (teks placeholder select),
$ownRowsOnly (true = kotak centang dan Hapus per baris hanya pada baris yang membawa row.form; baris lain hanya dibaca),
$viewUrl (aksi Lihat, "__ID__" diganti row.id), $destroyUrl + $destroy['title'|'message'] (Hapus sungguhan
lewat POST {ids}); $form = ['title', 'withFilters' (opsional: nama filter yang nilainya ikut dikirim saat simpan), 'storeUrl', 'updateUrl' ("__ID__"), 'fields' => [['name', 'label', 'type' =>
text|number|date|select, 'options', 'required', 'max', 'min', 'hint', 'multiple', 'default']]] untuk Tambah/Ubah lewat
modal (baris data menyediakan row.form = nilai isian). Hanya tombol yang sungguh bekerja yang ditampilkan; Lihat tanpa
$viewUrl membuka modal detail seluruh kolom baris.
--}}
@php
$viewUrl ??= null;
$destroyUrl ??= null;
$form ??= null;
$selectable ??= true;
$editable ??= true;
$ownRowsOnly ??= false;
$viewable ??= true;
$destroy = ($destroy ?? []) + ['title' => 'Hapus data terpilih?', 'message' => 'Data yang dipilih akan dihapus.'];
$allTools = [
'T' => ['Tambah', 'plus', 'primary', 'startInsert()'],
'H' => ['Hapus', 'trash', 'danger', 'remove()'],
'C' => ['Cetak', 'printer', 'secondary', 'window.print()'],
];
// $tools (opsional): daftar kunci tombol yang boleh tampil (T, H, C); kosong = tanpa tombol. Bawaan: menurut flags katalog.
$allowed = isset($tools) ? array_flip($tools) : $allTools;
$active = array_filter($allTools, fn (string $key): bool => isset($allowed[$key]) && str_contains($page['flags'], $key)
&& match ($key) { 'T' => (bool) $form, 'H' => (bool) $destroyUrl, default => true }, ARRAY_FILTER_USE_KEY);
$checkbox = $selectable && in_array('#', $page['columns'], true);
$actions = in_array('Aksi', $page['columns'], true);
@endphp
<x-satu.frame :page="$page" :crumbs="$crumbs" :note="$note">
@if ($data === null)
<x-glass.panel padding="lg">
<x-ui.empty :icon="$empty['icon']" :title="$empty['title']" :description="$empty['description']" />
</x-glass.panel>
@else
@php
$config = [
'url' => $url,
'filters' => collect($filters)->mapWithKeys(fn (array $f): array => [$f['name'] => ($f['type'] ?? 'select') === 'check' ? false : (string) ($f['value'] ?? '')])->all(),
'data' => $data,
'ownRowsOnly' => $ownRowsOnly,
'viewUrl' => $viewUrl,
'destroyUrl' => $destroyUrl,
'form' => $form ? ['withFilters' => $form['withFilters'] ?? [], 'storeUrl' => $form['storeUrl'], 'updateUrl' => $form['updateUrl'] ?? null, 'fields' => array_map(fn (array $f): array => ['name' => $f['name'], 'default' => $f['default'] ?? (($f['multiple'] ?? false) ? [] : '')], $form['fields'])] : null,
'columns' => collect($columns)->map(fn (array $c): array => ['key' => $c['key'], 'label' => $c['label']])->values()->all(),
'token' => csrf_token(),
];
@endphp
<div class="stack" x-data="satuRemoteTable(@js($config))">
@if ($filters)
<x-glass.panel padding="sm" as="section" aria-label="Filter data">
<div class="filter-bar">
@foreach ($filters as $filter)
@if (($filter['type'] ?? 'select') === 'check')
<x-form.checkbox
:name="'filter_'.$filter['name']"
:label="$filter['label']"
x-model="values.{{ $filter['name'] }}"
x-on:change="search()"
/>
@else
<x-form.select
:name="'filter_'.$filter['name']"
:label="$filter['label']"
:options="$filter['options']"
:value="$filter['value'] ?? null"
placeholder=""
x-model="values.{{ $filter['name'] }}"
x-on:change="search()"
/>
@endif
@endforeach
</div>
</x-glass.panel>
@endif
<x-glass.panel padding="none" as="section" :aria-label="'Daftar '.$page['title']">
<div class="satu-bar">
<div class="satu-bar__search field">
<label class="visually-hidden" for="satu-q">Cari data</label>
<div class="field__control">
<span class="field__icon" aria-hidden="true"><x-heroicon-o-magnifying-glass /></span>
<input id="satu-q" type="search" class="field__input" style="--pad-start: 2.5rem" placeholder="Cari {{ Str::lower($page['title']) }}" autocomplete="off" x-model="q" x-on:input.debounce.400ms="search()">
</div>
</div>
<div class="satu-bar__tools">
@foreach ($active as [$label, $icon, $variant, $click])
<x-ui.button :variant="$variant" :icon="$icon" size="sm" x-on:click="{{ $click }}">{{ $label }}</x-ui.button>
@endforeach
</div>
</div>
<x-ui.table :label="'Tabel '.Str::lower($page['title'])">
<table class="table satu-table" x-bind:aria-busy="loading">
<thead>
<tr>
@if ($checkbox)
<th scope="col" class="satu-check"><input type="checkbox" class="check__input" aria-label="Pilih semua baris di halaman ini" x-bind:checked="allPicked" x-on:change="toggleAll()"></th>
@endif
@foreach ($columns as $column)
<th scope="col" @class(['num' => $column['num'] ?? false])>{{ $column['label'] }}</th>
@endforeach
@if ($actions)
<th scope="col" class="table__actions"><span class="visually-hidden">Aksi</span></th>
@endif
</tr>
</thead>
<tbody>
<template x-for="row in view" x-bind:key="row.id">
<tr>
@if ($checkbox)
<td class="satu-check">
@if ($ownRowsOnly)
<template x-if="row.form"><input type="checkbox" class="check__input" aria-label="Pilih baris" x-model="picked" x-bind:value="row.id"></template>
@else
<input type="checkbox" class="check__input" aria-label="Pilih baris" x-model="picked" x-bind:value="row.id">
@endif
</td>
@endif
@foreach ($columns as $column)
@if ($column['badge'] ?? false)
<td><span class="badge" x-bind:class="row.tone ? 'badge--' + row.tone : ''" x-text="row.{{ $column['key'] }}"></span></td>
@elseif ($column['swatch'] ?? false)
{{-- Kotak warna dari data (row.{key} = "#RRGGBB" atau null) + kode warnanya --}}
<td><span class="swatch"><i class="swatch__chip" aria-hidden="true" x-bind:style="row.{{ $column['key'] }} ? '--swatch: ' + row.{{ $column['key'] }} : ''"></i><span x-text="row.{{ $column['key'] }} ?? '–'"></span></span></td>
@else
<td @class(['num' => $column['num'] ?? false, 'table__title' => $loop->first && ! $checkbox])><span x-text="row.{{ $column['key'] }}"></span></td>
@endif
@endforeach
@if ($actions)
<td class="table__actions">
@if ($viewUrl)
<a class="btn btn--ghost btn--sm btn--icon" x-bind:href="link(row)" aria-label="Lihat"><x-heroicon-o-eye /></a>
@elseif ($viewable)
<x-ui.button variant="ghost" size="sm" icon="eye" :icon-only="true" aria-label="Lihat" x-on:click="startView(row)" />
@endif
@if ($form && $editable)
<template x-if="row.form">
<x-ui.button variant="ghost" size="sm" icon="pencil-square" :icon-only="true" aria-label="Ubah" x-on:click="startEdit(row)" />
</template>
@endif
@if ($destroyUrl)
@if ($ownRowsOnly)
<template x-if="row.form"><x-ui.button variant="ghost" size="sm" icon="trash" :icon-only="true" aria-label="Hapus" x-on:click="askRemove([row.id])" /></template>
@else
<x-ui.button variant="ghost" size="sm" icon="trash" :icon-only="true" aria-label="Hapus" x-on:click="askRemove([row.id])" />
@endif
@endif
</td>
@endif
</tr>
</template>
</tbody>
</table>
<p class="satu-empty" x-show="view.length === 0" x-cloak>Tidak ada data yang cocok dengan pencarian atau filter.</p>
</x-ui.table>
<div class="satu-foot">
<p class="satu-foot__info" aria-live="polite">Halaman <span x-text="page.toLocaleString('id-ID')"></span> dari <span x-text="pages.toLocaleString('id-ID')"></span> (<span x-text="total.toLocaleString('id-ID')"></span> data)</p>
<label class="satu-foot__per">
<span class="visually-hidden">Jumlah data per halaman</span>
<select class="field__input field__select" data-no-clear x-model.number="per" x-on:change="search()">
@foreach ($perPage as $n)
<option value="{{ $n }}">{{ $n }} data</option>
@endforeach
</select>
</label>
<nav class="satu-pager" aria-label="Halaman data">
<button type="button" class="satu-pager__btn" aria-label="Halaman sebelumnya" x-bind:disabled="page === 1" x-on:click="go(page - 1)"><x-heroicon-m-chevron-left /></button>
<template x-for="n in window" x-bind:key="n">
<button type="button" class="satu-pager__btn" x-text="n" x-bind:aria-current="n === page ? 'page' : false" x-on:click="go(n)"></button>
</template>
<button type="button" class="satu-pager__btn" aria-label="Halaman berikutnya" x-bind:disabled="page === pages" x-on:click="go(page + 1)"><x-heroicon-m-chevron-right /></button>
</nav>
</div>
</x-glass.panel>
@if ($actions && ! $viewUrl && $viewable)
{{-- Modal Lihat: seluruh kolom baris terpilih, hanya baca --}}
<dialog x-ref="detail" class="dialog dialog--wide" aria-labelledby="satu-detail-judul" x-on:click="if ($event.target === $refs.detail) $refs.detail.close()">
<div class="dialog__body">
<div class="dialog__head">
<span class="dialog__icon" aria-hidden="true"><x-heroicon-o-eye /></span>
<p id="satu-detail-judul" class="dialog__title">Detail {{ Str::lower($page['title']) }}</p>
<x-ui.dialog-close />
</div>
<dl class="satu-form satu-detail">
<template x-for="col in columns" x-bind:key="col.key">
<div>
<dt x-text="col.label"></dt>
<dd x-text="viewing && viewing[col.key] !== null && viewing[col.key] !== '' && viewing[col.key] !== undefined ? viewing[col.key] : '-'"></dd>
</div>
</template>
</dl>
<div class="dialog__actions">
<x-ui.button variant="secondary" x-on:click="$refs.detail.close()">Tutup</x-ui.button>
</div>
</div>
</dialog>
@endif
@if ($form)
{{-- Modal formulir tambah/ubah: kolom menurut $form['fields'], nilai di formData --}}
<dialog x-ref="form" class="dialog dialog--wide" aria-labelledby="satu-form-judul" x-on:click="formBackdrop($event)" x-on:close="setTimeout(() => $refs.form.open || (editing = null), 300)">
<form class="dialog__body" x-on:submit.prevent="save()" novalidate>
<div class="dialog__head">
<span class="dialog__icon" aria-hidden="true"><x-heroicon-o-pencil-square /></span>
<p id="satu-form-judul" class="dialog__title" x-text="editing === 'new' ? 'Tambah {{ $form['title'] }}' : 'Ubah {{ $form['title'] }}'"></p>
<x-ui.dialog-close />
</div>
<div class="satu-form">
@foreach ($form['fields'] as $f)
{{-- 'wide' => true: isian selebar penuh baris --}}
@if ($f['wide'] ?? false) <div class="col-span-full"> @endif
@if (($f['type'] ?? 'text') === 'select')
<x-form.select
:name="'form_'.$f['name']"
:label="$f['label']"
:options="$f['options']"
:optional="! ($f['required'] ?? false)"
:hint="$f['hint'] ?? null"
placeholder=""
:required="$f['required'] ?? false"
:multiple="$f['multiple'] ?? false"
:data-tags="! empty($f['tags']) ? 'true' : null"
:data-placeholder="$f['placeholder'] ?? null"
x-model="formData.{{ $f['name'] }}"
/>
@elseif (($f['type'] ?? 'text') === 'color')
{{-- Warna: pemilih warna + kode heksa "#RRGGBB" (opsional) --}}
<div class="field">
<label class="field__label" for="field-form_{{ $f['name'] }}">{{ $f['label'] }} <span class="field__optional">(opsional)</span></label>
<div class="satu-inline__color">
<input type="color" class="satu-inline__picker" aria-label="Pilih warna" x-bind:value="formData.{{ $f['name'] }} || undefined" x-on:input="formData.{{ $f['name'] }} = $event.target.value.toUpperCase()">
<input id="field-form_{{ $f['name'] }}" class="field__input" maxlength="7" pattern="#[0-9A-Fa-f]{6}" x-model="formData.{{ $f['name'] }}" placeholder="#RRGGBB" autocomplete="off">
</div>
</div>
@else
<x-form.field
:name="'form_'.$f['name']"
:label="$f['label']"
:type="$f['type'] ?? 'text'"
:optional="! ($f['required'] ?? false)"
:hint="$f['hint'] ?? null"
:placeholder="$f['placeholder'] ?? (in_array($f['type'] ?? 'text', ['text', 'number'], true) ? 'Masukkan '.ucwords($f['label']) : null)"
:required="$f['required'] ?? false"
:maxlength="($f['type'] ?? 'text') === 'text' ? ($f['max'] ?? null) : null"
:min="($f['type'] ?? 'text') === 'number' ? ($f['min'] ?? null) : null"
:max="($f['type'] ?? 'text') === 'number' ? ($f['max'] ?? null) : null"
x-model="formData.{{ $f['name'] }}"
/>
@endif
@if ($f['wide'] ?? false) </div> @endif
@endforeach
</div>
<div class="dialog__actions">
<x-ui.button type="submit" variant="primary" icon="check" x-bind:disabled="loading">Simpan</x-ui.button>
<x-ui.button variant="secondary" x-on:click="closeForm()">Batal</x-ui.button>
</div>
</form>
</dialog>
@endif
@if ($destroyUrl)
<dialog x-ref="dialog" class="dialog dialog--danger" aria-labelledby="satu-hapus-judul" aria-describedby="satu-hapus-pesan" x-on:click="backdrop($event)" x-on:close="setTimeout(() => $refs.dialog.open || (pending = []), 300)">
<div class="dialog__body">
<div class="dialog__head">
<span class="dialog__icon" aria-hidden="true"><x-heroicon-o-exclamation-triangle /></span>
<p id="satu-hapus-judul" class="dialog__title">{{ $destroy['title'] }}</p>
<x-ui.dialog-close />
</div>
<p id="satu-hapus-pesan" class="dialog__message"><span x-text="pending.length"></span> baris dipilih. {{ $destroy['message'] }}</p>
<div class="dialog__actions">
<x-ui.button variant="danger" x-on:click="confirmRemove()" x-bind:disabled="loading">Ya, hapus</x-ui.button>
<x-ui.button variant="secondary" x-on:click="closeDialog()">Batal</x-ui.button>
</div>
</div>
</dialog>
@endif
</div>
@endif
</x-satu.frame>