bps-rw/Views/Lokasi/Index.cshtml

196 lines
8.0 KiB
Plaintext

@{
ViewData["Title"] = "Lokasi TP3SR & Parkir Pengumpulan Sampah";
}
<!-- Breadcrumb -->
<div class="breadcrumbs text-sm">
<ul>
<li class="text-gray-500"><a>Profil RW</a></li>
<li id="breadcrumb-active">Lokasi TP3SR & Parkir Pengumpulan Sampah</li>
</ul>
</div>
<!-- Header -->
<div class="grid grid-cols-1 gap-4 lg:grid-cols-2">
<div class="prose">
<h3 class="mb-2">Profil Rw</h3>
</div>
<div class="justify-self-end lg:self-center">
<label for="modal-tambah"
class="btn rounded-full bg-green-600 hover:bg-green-700 text-white border-0 shadow-sm transition duration-200">
<span class="icon icon-fill me-2">add</span>
Tambah
</label>
</div>
</div>
<div class="h-8"></div>
<!-- Tabs -->
<div class="tabs tabs-lift">
<input type="radio" name="tab_profil_rw" class="tab checked:text-white [--tab-bg:green]" aria-label="Profil" />
<div class="tab-content bg-base-100 border-base-300 p-0"></div>
<input type="radio" name="tab_profil_rw" class="tab checked:text-white [--tab-bg:green]" aria-label="BPS-RW" />
<div class="tab-content bg-base-100 border-base-300 p-0"></div>
<input type="radio" name="tab_profil_rw" class="tab checked:text-white [--tab-bg:green]" aria-label="Surat Usulan" />
<div class="tab-content bg-base-100 border-base-300 p-0"></div>
<input type="radio" name="tab_profil_rw" class="tab checked:text-white [--tab-bg:green]" aria-label="Pengadaan Wadah" />
<div class="tab-content bg-base-100 border-base-300 p-0"></div>
<input type="radio" name="tab_profil_rw" class="tab checked:text-white [--tab-bg:green]" aria-label="Kebutuhan Sarpras" />
<div class="tab-content bg-base-100 border-base-300 p-0"></div>
<input type="radio" name="tab_profil_rw" checked class="tab checked:text-white [--tab-bg:green]" aria-label="Lokasi TP3SR & Parkir Pengumpulan Sampah" />
<div class="tab-content bg-base-100 border-base-300 p-0">
<div class="overflow-x-auto">
<table class="table table-zebra w-full text-sm" id="lokasiTable">
<thead>
<tr>
<th class="w-[5%]">No</th>
<th class="w-[10%]">Usulan</th>
<th class="w-[20%]">Alamat Lokasi</th>
<th class="w-[10%]">Status Lahan</th>
<th class="w-[20%]">Pemilik Lahan</th>
<th class="w-[10%]">Luas Lahan</th>
<th class="w-[10%]">Status Usulan</th>
<th class="w-[15%] text-center">Aksi</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<!-- Modal adding location -->
@await Html.PartialAsync("_ModalTambah")
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdn.datatables.net/2.3.4/js/dataTables.js"></script>
<script src="/plugins/datatables/dataTables.tailwindcss.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script type="text/javascript">
$(document).ready(function () {
// Datatable setup
const table = new DataTable('#lokasiTable', {
ajax: '@Url.Action("Table", "Lokasi")',
scrollX: true,
autoWidth: false,
initComplete: function () {
$('div.dt-scroll-body thead').css('visibility', 'collapse');
},
columns: [
{ data: null, render: (d, t, r, m) => m.row + 1, orderable: false, searchable: false },
{ data: 'usulan' },
{ data: 'alamat' },
{ data: 'statusLahan' },
{ data: 'pemilikLahan' },
{ data: 'luasLahan' },
{
data: 'statusUsulan',
render: (data) => `
<span class="badge bg-green-100 text-green-700 px-3 py-1 rounded-full text-xs font-medium">
${data}
</span>`
},
{
data: null,
className: "text-center",
render: (data, type, row) => `
<div class="flex justify-center gap-2">
<button class="btn btn-xs btn-outline border-gray-300 text-gray-700 rounded-full hover:bg-gray-50 btn-detail" data-id="${row.id}">Detail</button>
<button class="btn btn-xs btn-outline border-gray-300 text-gray-700 rounded-full hover:bg-gray-50 btn-edit" data-id="${row.id}">Edit</button>
<button class="btn btn-xs btn-outline border-red-300 text-red-600 rounded-full hover:bg-red-50 btn-delete" data-id="${row.id}">Delete</button>
</div>
`,
orderable: false,
searchable: false
}
]
});
// Breadcrumbs update on tab change
const updateBreadcrumbs = () => {
const activeTab = $('input[name="tab_profil_rw"]:checked');
$('#breadcrumb-active').text(activeTab.attr('aria-label'));
};
updateBreadcrumbs();
$('input[name="tab_profil_rw"]').on('change', updateBreadcrumbs);
// Form submission
$('#formTambahLokasi').on('submit', function (e) {
e.preventDefault();
const data = $(this).serialize();
$.post('@Url.Action("Create", "Lokasi")', data, function () {
table.ajax.reload();
$('#modal-tambah').prop('checked', false);
$('#formTambahLokasi')[0].reset();
});
});
// Edit button handler
$('#lokasiTable').on('click', '.btn-edit', function () {
const id = $(this).data('id');
$.get('@Url.Action("GetById", "Lokasi")', { id: id }, function (data) {
$('#modal-tambah input[name="id"]').val(data.id);
$('#modal-tambah input[name="usulan"]').val(data.usulan);
$('#modal-tambah input[name="alamat"]').val(data.alamat);
$('#modal-tambah input[name="statusLahan"]').val(data.statusLahan);
$('#modal-tambah input[name="pemilikLahan"]').val(data.pemilikLahan);
$('#modal-tambah input[name="luasLahan"]').val(data.luasLahan);
$('#modal-tambah select[name="statusUsulan"]').val(data.statusUsulan);
// Open modal
$('#modal-tambah').prop('checked', true);
});
});
// Delete Button
$('#lokasiTable').on('click', '.btn-delete', function () {
const id = $(this).data('id');
Swal.fire({
title: 'Apakah Anda yakin?',
text: "Data yang dihapus tidak dapat dikembalikan!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#ef4444',
cancelButtonColor: '#6b7280',
confirmButtonText: 'Ya, Hapus!',
cancelButtonText: 'Batal'
}).then((result) => {
if (result.isConfirmed) {
$.post('@Url.Action("Delete", "Lokasi")', { id: id }, function () {
table.ajax.reload();
Swal.fire(
'Terhapus!',
'Data berhasil dihapus.',
'success'
);
}).fail(function () {
Swal.fire(
'Gagal!',
'Terjadi kesalahan saat menghapus data.',
'error'
);
});
}
});
});
// Detail button handler
$('#lokasiTable').on('click', '.btn-detail', function () {
const id = $(this).data('id');
console.log('Detail clicked for ID:', id);
});
});
</script>