332 lines
13 KiB
Plaintext
332 lines
13 KiB
Plaintext
@{
|
|
ViewData["Title"] = "Lokasi Maggot, Bank Sampah, Composting";
|
|
}
|
|
|
|
<style>
|
|
/* Sesuaikan tampilan select2 dengan DaisyUI */
|
|
.select2-container .select2-selection--single {
|
|
height: 3rem;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 0.5rem;
|
|
border: 1px solid #d4d4d8;
|
|
}
|
|
|
|
.select2-selection__rendered {
|
|
line-height: 2rem !important;
|
|
}
|
|
|
|
.select2-selection__arrow {
|
|
height: 2rem !important;
|
|
}
|
|
</style>
|
|
|
|
|
|
<div class="flex flex-col gap-2 md:flex-row md:justify-between md:gap-0">
|
|
<div class="prose">
|
|
<span class="text-xl font-semibold text-black">
|
|
Lokasi Maggot, Bank Sampah, Composting
|
|
</span>
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-2 md:flex-row">
|
|
<button class="btn btn-sm bg-green-800 max-w-full rounded-full text-white hover:bg-green-900" onclick="openModal()">
|
|
<i class="ph ph-plus"></i>
|
|
Tambah Lokasi
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal Tambah/Edit Data -->
|
|
<dialog id="modal_tambah" class="modal modal-bottom sm:modal-middle">
|
|
<div class="modal-box w-full max-w-2xl p-6 bg-white rounded-2xl">
|
|
<h3 id="modal_title" class="text-gray-900 text-xl font-semibold font-['Plus_Jakarta_Sans'] leading-8 mb-8">Tambah Lokasi</h3>
|
|
<form id="formTambah" onsubmit="submitForm(event)">
|
|
<input type="hidden" id="edit_mode" value="false">
|
|
<div class="flex flex-col gap-6">
|
|
<!-- Field Nama -->
|
|
<div class="flex flex-col">
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">
|
|
Jenis Lokasi<span class="text-red-500">*</span>
|
|
</legend>
|
|
<select id="jenis_lokasi" class="select w-full select2" required>
|
|
<option value="" disabled selected>Pilih Jenis Lokasi</option>
|
|
<option value="">Bank Sampah</option>
|
|
<option value="">Composting</option>
|
|
<option value="">Maggot</option>
|
|
</select>
|
|
</fieldset>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-2 gap-6">
|
|
<div class="flex flex-col">
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">
|
|
Kota<span class="text-red-500">*</span>
|
|
</legend>
|
|
<select id="kota" class="select w-full select2" required>
|
|
<option value="" disabled selected>Pilih salah satu</option>
|
|
<option value="">Jakarta Barat</option>
|
|
<option value="">Jakarta Pusat</option>
|
|
<option value="">Jakarta Selatan</option>
|
|
<option value="">Jakarta Timur</option>
|
|
<option value="">Jakarta Utara</option>
|
|
</select>
|
|
</fieldset>
|
|
</div>
|
|
<div class="flex flex-col">
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">
|
|
Kecamatan<span class="text-red-500">*</span>
|
|
</legend>
|
|
<select id="kecamatan" class="select w-full select2" required>
|
|
<option value="" disabled selected>Pilih salah satu</option>
|
|
<option value="cengkareng">Cengkareng</option>
|
|
<option value="duren-sawit">Duren Sawit</option>
|
|
<option value="grogol-petamburan">Grogol Petamburan</option>
|
|
<option value="kebayoran-baru">Kebayoran Baru</option>
|
|
<option value="kemayoran">Kemayoran</option>
|
|
<option value="mampang-prapatan">Mampang Prapatan</option>
|
|
<option value="matraman">Matraman</option>
|
|
<option value="setiabudi">Setiabudi</option>
|
|
<option value="tanah-abang">Tanah Abang</option>
|
|
<option value="tanjung-priok">Tanjung Priok</option>
|
|
</select>
|
|
</fieldset>
|
|
</div>
|
|
<div class="flex flex-col">
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">
|
|
Keluarahan<span class="text-red-500">*</span>
|
|
</legend>
|
|
<select id="kelurahan" class="select w-full select2" required>
|
|
<option value="" disabled selected>Pilih salah satu</option>
|
|
<option value="cideng">Cideng</option>
|
|
<option value="gunung">Gunung</option>
|
|
<option value="kapuk">Kapuk</option>
|
|
<option value="karet-kuningan">Karet Kuningan</option>
|
|
<option value="kuningan-barat">Kuningan Barat</option>
|
|
<option value="palmeriam">Palmeriam</option>
|
|
<option value="pondok-bambu">Pondok Bambu</option>
|
|
<option value="serdang">Serdang</option>
|
|
<option value="sunter-agung">Sunter Agung</option>
|
|
<option value="tomang">Tomang</option>
|
|
</select>
|
|
</fieldset>
|
|
</div>
|
|
<div class="flex flex-col">
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">
|
|
RW<span class="text-red-500">*</span>
|
|
</legend>
|
|
<select id="rw" class="select w-full select2" required>
|
|
<option value="" disabled selected>Pilih salah satu</option>
|
|
<option value="001">001</option>
|
|
<option value="002">002</option>
|
|
<option value="003">003</option>
|
|
<option value="004">004</option>
|
|
<option value="005">005</option>
|
|
<option value="006">006</option>
|
|
<option value="007">007</option>
|
|
<option value="008">008</option>
|
|
<option value="009">009</option>
|
|
<option value="010">010</option>
|
|
</select>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Buttons -->
|
|
<div class="flex flex-col sm:flex-row gap-3 justify-end">
|
|
<button type="button" class="px-8 py-2.5 bg-white rounded-full outline outline-1 -outline-offset-1 outline-gray-300 text-slate-800 text-base font-semibold font-['Plus_Jakarta_Sans'] leading-6 hover:bg-gray-50 w-full sm:w-auto" onclick="closeModal()">
|
|
Batal
|
|
</button>
|
|
<button type="submit" class="px-8 py-2.5 bg-green-800 rounded-full text-white text-base font-semibold font-['Plus_Jakarta_Sans'] leading-6 hover:bg-green-900 w-full sm:w-auto">
|
|
Simpan
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<form method="dialog" class="modal-backdrop">
|
|
<button>close</button>
|
|
</form>
|
|
</dialog>
|
|
<!-- /modal tambah/edit -->
|
|
|
|
<div class="h-6"></div>
|
|
|
|
<div class="card bg-white">
|
|
<div class="card-body p-2">
|
|
<div class="w-full overflow-x-auto">
|
|
<table class="table-zebra table" id="example">
|
|
<!-- head -->
|
|
<thead>
|
|
<tr>
|
|
<th class="w-[10%]">No</th>
|
|
<th class="w-[15%]">Jenis Lokasi</th>
|
|
<th class="w-[20%]">Kota</th>
|
|
<th class="w-[20%]">Kecamatan</th>
|
|
<th class="w-[15%]">Kelurahan</th>
|
|
<th class="w-[10%]">RW</th>
|
|
<th class="w-[10%]">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
@section Scripts {
|
|
<script type="text/javascript">
|
|
$('.select2').select2({
|
|
dropdownParent: $('#modal_tambah'), // Penting untuk modal
|
|
width: '100%'
|
|
}
|
|
);
|
|
var table;
|
|
|
|
$(document).ready(function () {
|
|
table = new DataTable('#example', {
|
|
ajax: '/Master/Lokasi/Table',
|
|
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: 'jenis_lokasi' },
|
|
{ data: 'kota' },
|
|
{ data: 'kecamatan' },
|
|
{ data: 'kelurahan' },
|
|
{ data: 'rw' },
|
|
{ data: 'aksi', orderable: false, searchable: true },
|
|
]
|
|
});
|
|
|
|
// Delete button handler
|
|
$('#example').on('click', '.btn-circle.btn-error', function (e) {
|
|
e.preventDefault();
|
|
|
|
Swal.fire({
|
|
title: 'Apakah anda yakin?',
|
|
text: "Data yang dihapus tidak dapat dikembalikan lagi",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Ya, Hapus',
|
|
cancelButtonText: 'Batal',
|
|
buttonsStyling: false,
|
|
customClass: {
|
|
confirmButton: 'btn bg-red-500 text-white hover:bg-red-600 px-4 py-2 rounded-full mr-2',
|
|
cancelButton: 'btn bg-white text-gray-500 hover:bg-gray-50 px-4 py-2 rounded-full border border-gray-300',
|
|
},
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
// TODO: Implement actual delete API call
|
|
Swal.fire({
|
|
title: 'Terhapus!',
|
|
text: 'Data berhasil dihapus.',
|
|
icon: 'success',
|
|
confirmButtonText: 'OK',
|
|
buttonsStyling: false,
|
|
customClass: {
|
|
confirmButton: 'btn bg-green-800 text-white hover:bg-green-900 px-4 py-2 rounded-full',
|
|
},
|
|
}).then(() => {
|
|
// Reload table
|
|
table.ajax.reload();
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Edit button handler
|
|
$('#example').on('click', '.btn-circle.btn-warning', function (e) {
|
|
e.preventDefault();
|
|
|
|
// Get row data
|
|
var row = table.row($(this).parents('tr')).data();
|
|
|
|
// Set edit mode
|
|
$('#edit_mode').val('true');
|
|
$('#modal_title').text('Edit Lokasi');
|
|
|
|
// Populate form with row data
|
|
$('#nama').val(row.nama);
|
|
|
|
// Open modal
|
|
modal_tambah.showModal();
|
|
loadJenisSampah();
|
|
});
|
|
});
|
|
|
|
function openModal() {
|
|
modal_tambah.showModal();
|
|
|
|
// load dropdown setiap modal dibuka
|
|
loadJenisSampah();
|
|
}
|
|
|
|
function loadJenisSampah() {
|
|
$.ajax({
|
|
url: '/Master/JenisSampah/table', // Ganti sesuai endpoint kamu
|
|
method: 'GET',
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
// Buat HTML option dengan map
|
|
let options = response.data
|
|
.map(item => `<option value="${item.nama}">${item.nama}</option>`)
|
|
.join("");
|
|
|
|
// Masukkan ke dropdown
|
|
$("#jenis_sampah").html(`
|
|
<option value="" disabled selected>Pilih Jenis Sampah</option>
|
|
${options}
|
|
`);
|
|
},
|
|
error: function () {
|
|
console.error('Gagal memuat data jenis sampah.');
|
|
}
|
|
});
|
|
}
|
|
|
|
function closeModal() {
|
|
// Reset form
|
|
$('#formTambah')[0].reset();
|
|
$('#edit_mode').val('false');
|
|
$('#modal_title').text('Tambah Kategori Sampah');
|
|
|
|
// Close modal
|
|
modal_tambah.close();
|
|
}
|
|
|
|
function submitForm(e) {
|
|
e.preventDefault();
|
|
|
|
var isEditMode = $('#edit_mode').val() === 'true';
|
|
|
|
// TODO: Implement form submission logic
|
|
Swal.fire({
|
|
title: 'Berhasil!',
|
|
text: isEditMode ? 'Data berhasil diperbarui' : 'Data berhasil ditambahkan',
|
|
icon: 'success',
|
|
confirmButtonText: 'OK',
|
|
buttonsStyling: false,
|
|
customClass: {
|
|
confirmButton: 'btn bg-green-800 text-white hover:bg-green-900 px-4 py-2 rounded-full',
|
|
},
|
|
}).then(() => {
|
|
closeModal();
|
|
|
|
// Reload table
|
|
table.ajax.reload();
|
|
});
|
|
}
|
|
</script>
|
|
}
|