335 lines
13 KiB
Plaintext
335 lines
13 KiB
Plaintext
@{
|
|
ViewData["Title"] = "Data Rumah";
|
|
}
|
|
|
|
<div class="breadcrumbs text-sm">
|
|
<ul>
|
|
<li class="text-gray-500"><a>Data Rumah</a></li>
|
|
<li><a>Rumah</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<!-- Header -->
|
|
<div class="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
|
<div class="prose">
|
|
<h3 class="mb-2">Rumah</h3>
|
|
</div>
|
|
<div class="justify-self-end lg:self-center flex flex-wrap gap-3">
|
|
@* <button id="btn-tambah-rumah" type="button" class="btn btn-primary rounded-full text-white border-0">
|
|
<span class="icon icon-fill me-2">add</span>
|
|
Tambah
|
|
</button> *@
|
|
<button class="btn rounded-full bg-white" onclick="modal_filter.showModal()">
|
|
<span class="icon icon-fill me-2">filter_list</span>
|
|
Filter
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
@* <!-- Create Modal -->
|
|
<dialog id="modal_create" class="modal modal-bottom sm:modal-middle">
|
|
<div class="modal-box w-full sm:max-w-md">
|
|
<div class="flex items-start justify-between gap-4">
|
|
<div>
|
|
<h3 class="text-lg font-semibold">Tambah Rumah</h3>
|
|
<p class="text-sm text-gray-500">Lengkapi informasi rumah sebelum menyimpan.</p>
|
|
</div>
|
|
<form method="dialog">
|
|
<button type="submit" class="btn btn-sm btn-circle btn-ghost">✕</button>
|
|
</form>
|
|
</div>
|
|
<form id="form-create-rumah" class=" space-y-4 mt-6">
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">RT</legend>
|
|
<input id="create-rt" name="rt" type="text" class="input w-full" placeholder="001" />
|
|
</fieldset>
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">Nama Pemilik Rumah</legend>
|
|
<input id="create-nama-pemilik" name="nama_pemilik" type="text" class="input w-full"
|
|
placeholder="Nama lengkap" />
|
|
</fieldset>
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">Alamat</legend>
|
|
<textarea id="create-alamat" name="alamat" class="textarea w-full" rows="4"
|
|
placeholder="Tulis alamat lengkap"></textarea>
|
|
</fieldset>
|
|
<div class="modal-action">
|
|
<button type="button" class="btn rounded-full" onclick="modal_create.close()">
|
|
<span class="icon me-1">cancel</span>
|
|
Batal
|
|
</button>
|
|
<button type="submit" class="btn btn-primary rounded-full text-white">
|
|
<span class="icon me-1">save</span>
|
|
Simpan
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</dialog> *@
|
|
|
|
<!-- Edit Modal -->
|
|
<dialog id="modal_edit" class="modal modal-bottom sm:modal-middle">
|
|
<div class="modal-box w-full sm:max-w-md">
|
|
<div class="flex items-start justify-between gap-4">
|
|
<div>
|
|
<h3 class="text-lg font-semibold">Edit Rumah</h3>
|
|
<p class="text-sm text-gray-500">Ubah data rumah dan simpan untuk memperbarui.</p>
|
|
</div>
|
|
<form method="dialog">
|
|
<button type="submit" class="btn btn-sm btn-circle btn-ghost">✕</button>
|
|
</form>
|
|
</div>
|
|
<form id="form-edit-rumah" class="mt-6 space-y-4">
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">RT <span class="text-red-500">*</span></legend>
|
|
<input id="edit-rt" name="rt" type="text" class="input w-full" placeholder="001" required />
|
|
</fieldset>
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">Nama Pemilik Rumah</legend>
|
|
<input id="edit-nama-pemilik" name="nama_pemilik" type="text" class="input w-full"
|
|
placeholder="Nama lengkap" />
|
|
</fieldset>
|
|
<fieldset class="fieldset">
|
|
<legend class="fieldset-legend">Alamat <span class="text-red-500">*</span></legend>
|
|
<textarea id="edit-alamat" name="alamat" class="textarea w-full" rows="4"
|
|
placeholder="Tulis alamat lengkap" required></textarea>
|
|
</fieldset>
|
|
<div class="modal-action">
|
|
<button type="button" class="btn rounded-full" onclick="modal_edit.close()">
|
|
<span class="icon me-1">cancel</span>
|
|
Batal
|
|
</button>
|
|
<button type="submit" class="btn btn-primary rounded-full text-white">
|
|
<span class="icon me-1">save</span>
|
|
Simpan
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</dialog>
|
|
|
|
<!-- Filter Modal -->
|
|
<dialog id="modal_filter" class="modal modal-bottom sm:modal-middle">
|
|
<div class="modal-box w-full sm:max-w-sm">
|
|
<div class="flex items-center justify-between">
|
|
<h3 class="text-lg font-bold">Filter</h3>
|
|
<button type="button" class="btn btn-sm btn-circle btn-ghost" onclick="modal_filter.close()">✕</button>
|
|
</div>
|
|
|
|
<form id="form-filter" action="#" method="get">
|
|
<fieldset class="fieldset max-w-sm">
|
|
<legend class="fieldset-legend">Kelurahan</legend>
|
|
<select id="filter-kelurahan" name="kelurahan" class="w-full">
|
|
<option value="">Pilih Kelurahan</option>
|
|
<option value="Duren Sawit">Duren Sawit</option>
|
|
<option value="Pondok Bambu">Pondok Bambu</option>
|
|
<option value="Rawamangun">Rawamangun</option>
|
|
<option value="Cengkareng Barat">Cengkareng Barat</option>
|
|
<option value="Kembangan Selatan">Kembangan Selatan</option>
|
|
<option value="Tanjung Duren Utara">Tanjung Duren Utara</option>
|
|
<option value="Sunter Jaya">Sunter Jaya</option>
|
|
<option value="Kelapa Gading Timur">Kelapa Gading Timur</option>
|
|
<option value="Pademangan Barat">Pademangan Barat</option>
|
|
<option value="Koja">Koja</option>
|
|
</select>
|
|
</fieldset>
|
|
|
|
<fieldset class="fieldset max-w-sm">
|
|
<legend class="fieldset-legend">RW</legend>
|
|
<select id="filter-rw" name="rw" class="w-full">
|
|
<option value="">Pilih RW</option>
|
|
<option value="01">01</option>
|
|
<option value="02">02</option>
|
|
<option value="03">03</option>
|
|
</select>
|
|
</fieldset>
|
|
|
|
<fieldset class="fieldset max-w-sm">
|
|
<legend class="fieldset-legend">RT</legend>
|
|
<select id="filter-rt" name="rt" class="w-full">
|
|
<option value="">Pilih RT</option>
|
|
<option value="001">001</option>
|
|
<option value="002">002</option>
|
|
<option value="003">003</option>
|
|
</select>
|
|
</fieldset>
|
|
|
|
<div class="modal-action">
|
|
<button type="button" class="btn" onclick="modal_filter.close()">Bersihkan</button>
|
|
<button type="submit" class="btn btn-neutral">Terapkan Filter</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</dialog>
|
|
|
|
|
|
<div class="h-8"></div>
|
|
|
|
<div class="card bg-white shadow-sm">
|
|
<div class="card-body p-0">
|
|
<table class="table-zebra table" id="example">
|
|
<thead>
|
|
<tr>
|
|
<th class="w-[5%]">No</th>
|
|
<th class="w-[5%]">RT</th>
|
|
<th class="w-[5%]">RW</th>
|
|
<th class="w-[35%] whitespace-normal">Alamat</th>
|
|
<th class="w-[15%]">Kota</th>
|
|
<th class="w-[10%]">Nama Pemilik</th>
|
|
<th class="w-[10%]">Status Rumah Memilah</th>
|
|
<th class="w-[10%]">Status Nasabah Bank Sampah</th>
|
|
<th class="w-[5%]">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<script src="/lib/jquery/jquery-3.7.1.js"></script>
|
|
<script src="/lib/datatables/dataTables.js"></script>
|
|
<script src="/plugins/datatables/dataTables.tailwindcss.js"></script>
|
|
<script src="/lib/sweetalert2/sweetalert2-11.26.4.js"></script>
|
|
<link href="https://cdn.jsdelivr.net/npm/tom-select@2.2.2/dist/css/tom-select.css" rel="stylesheet">
|
|
<script src="https://cdn.jsdelivr.net/npm/tom-select@2.2.2/dist/js/tom-select.complete.min.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
var table;
|
|
|
|
$(document).ready(function () {
|
|
new TomSelect("#filter-kelurahan", {
|
|
closeAfterSelect: true,
|
|
maxItems: 1,
|
|
placeholder: "Pilih Kelurahan",
|
|
});
|
|
|
|
new TomSelect("#filter-rw", {
|
|
closeAfterSelect: true,
|
|
maxItems: 1,
|
|
placeholder: "Pilih RW",
|
|
});
|
|
|
|
new TomSelect("#filter-rt", {
|
|
closeAfterSelect: true,
|
|
maxItems: 1,
|
|
placeholder: "Pilih RT",
|
|
});
|
|
|
|
table = new DataTable('#example', {
|
|
ajax: '@Url.Action("Table", "DataRumahRumah")',
|
|
scrollX: true,
|
|
autoWidth: true,
|
|
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: 'rt' },
|
|
{ data: 'rw' },
|
|
{ data: 'alamat' },
|
|
{ data: 'kota' },
|
|
{ data: 'pemilik_rumah' },
|
|
{ data: 'status_rumah_memilah' },
|
|
{ data: 'status_nasabah_bank_sampah' },
|
|
{
|
|
data: 'aksi',
|
|
orderable: false,
|
|
searchable: false,
|
|
},
|
|
],
|
|
"columnDefs": [
|
|
{ "className": "whitespace-normal", "targets": 3 }
|
|
]
|
|
});
|
|
|
|
const btnTambahRumah = document.getElementById('btn-tambah-rumah');
|
|
const formCreateRumah = document.getElementById('form-create-rumah');
|
|
const formEditRumah = document.getElementById('form-edit-rumah');
|
|
const editRtInput = document.getElementById('edit-rt');
|
|
const editNamaPemilikInput = document.getElementById('edit-nama-pemilik');
|
|
const editAlamatInput = document.getElementById('edit-alamat');
|
|
const modalCreateElement = document.getElementById('modal_create');
|
|
const modalEditElement = document.getElementById('modal_edit');
|
|
|
|
window.modal_create = modalCreateElement;
|
|
window.modal_edit = modalEditElement;
|
|
|
|
btnTambahRumah?.addEventListener('click', () => {
|
|
formCreateRumah?.reset();
|
|
modalCreateElement?.showModal();
|
|
});
|
|
|
|
$('#example').on('click', '.btn-edit-rumah', function () {
|
|
const rowData = table.row($(this).closest('tr')).data();
|
|
|
|
if (!rowData) {
|
|
return;
|
|
}
|
|
|
|
editRtInput.value = rowData.rt ?? '';
|
|
editNamaPemilikInput.value = rowData.pemilik_rumah ?? '';
|
|
editAlamatInput.value = rowData.alamat ?? '';
|
|
|
|
modalEditElement?.showModal();
|
|
});
|
|
|
|
// Success Alert on Create
|
|
$('#form-create-rumah').on('submit', function (e) {
|
|
e.preventDefault();
|
|
|
|
modalCreateElement.close();
|
|
|
|
Swal.fire({
|
|
title: 'Simpan Data Rumah?',
|
|
text: "Pastikan semua data sudah benar.",
|
|
icon: 'question',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#22c55e',
|
|
cancelButtonColor: '#6b7280',
|
|
confirmButtonText: 'Simpan',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
Swal.fire({
|
|
title: 'Berhasil!',
|
|
text: 'Data rumah berhasil ditambahkan.',
|
|
icon: 'success',
|
|
confirmButtonText: 'OK',
|
|
confirmButtonColor: '#22c55e'
|
|
}).then(() => {
|
|
document.getElementById("form-create-rumah").submit();
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Success Alert on Edit
|
|
$('#form-edit-rumah').on('submit', function (e) {
|
|
e.preventDefault();
|
|
|
|
modalEditElement.close();
|
|
|
|
Swal.fire({
|
|
title: 'Perbarui Data Rumah?',
|
|
text: "Perubahan akan disimpan.",
|
|
icon: 'question',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#22c55e',
|
|
cancelButtonColor: '#6b7280',
|
|
confirmButtonText: 'Simpan',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
Swal.fire({
|
|
title: 'Berhasil!',
|
|
text: 'Data rumah berhasil diperbarui.',
|
|
icon: 'success',
|
|
confirmButtonText: 'OK',
|
|
confirmButtonColor: '#22c55e'
|
|
}).then(() => {
|
|
document.getElementById("form-edit-rumah").submit();
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script> |