Feat:module master pendamping
parent
5f3268692b
commit
bf9fa3ef9d
|
|
@ -0,0 +1,92 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BankSampahApp.Controllers.Master
|
||||
{
|
||||
[Route("Master/[controller]/[action]")]
|
||||
public class PendampingController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View("~/Views/Master/Pendamping/Index.cshtml");
|
||||
}
|
||||
|
||||
public IActionResult Table(){
|
||||
var data = new[]
|
||||
{
|
||||
new {
|
||||
nama = "Andi Prabowo",
|
||||
alamat = "Jl. Melati No. 12",
|
||||
kelurahan = "Cipayung",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Siti Nurhaliza",
|
||||
alamat = "Jl. Kenanga No. 5",
|
||||
kelurahan = "Matraman",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Budi Santoso",
|
||||
alamat = "Jl. Dahlia No. 8",
|
||||
kelurahan = "Kramat Jati",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Nina Sari",
|
||||
alamat = "Jl. Anggrek No. 7",
|
||||
kelurahan = "Pulogadung",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Dewi Lestari",
|
||||
alamat = "Jl. Flamboyan No. 22",
|
||||
kelurahan = "Cakung",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Rudi Hartono",
|
||||
alamat = "Jl. Mawar No. 33",
|
||||
kelurahan = "Jatinegara",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Ratna Wijaya",
|
||||
alamat = "Jl. Cempaka No. 10",
|
||||
kelurahan = "Durensawit",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Fahri Setyawan",
|
||||
alamat = "Jl. Teratai No. 15",
|
||||
kelurahan = "Pasar Rebo",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Laras Putri",
|
||||
alamat = "Jl. Padi Raya No. 9",
|
||||
kelurahan = "Ciracas",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Agus Setiawan",
|
||||
alamat = "Jl. Karet No. 20",
|
||||
kelurahan = "Makassar",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
},
|
||||
new {
|
||||
nama = "Yuni Kartika",
|
||||
alamat = "Jl. Cemara No. 3",
|
||||
kelurahan = "Matraman",
|
||||
aksi = "<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>"
|
||||
}
|
||||
};
|
||||
|
||||
var response = new
|
||||
{
|
||||
data = data
|
||||
};
|
||||
|
||||
return Json(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,191 @@
|
|||
@{
|
||||
ViewData["Title"] = "Pendamping";
|
||||
}
|
||||
|
||||
<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">
|
||||
Master Data Pendamping Bank Sampah
|
||||
</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="modal_tambah.showModal()">
|
||||
<i class="ph ph-plus"></i>
|
||||
Tambah Pendamping Bank Sampah
|
||||
</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 Mitra</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">
|
||||
Nama Pendamping<span class="text-red-500">*</span>
|
||||
</legend>
|
||||
<input type="text" id="nama" class="input w-full" placeholder="Nama Mitra" required />
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<fieldset class="fieldset">
|
||||
<legend class="fieldset-legend">
|
||||
NIK<span class="text-red-500">*</span>
|
||||
</legend>
|
||||
<input type="text" id="nama" class="input w-full" placeholder="Nama Mitra" required />
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<fieldset class="fieldset">
|
||||
<legend class="fieldset-legend">
|
||||
Alamat<span class="text-red-500">*</span>
|
||||
</legend>
|
||||
<textarea id="alamat" class="textarea w-full h-32" placeholder="Alamat" required></textarea>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<fieldset class="fieldset">
|
||||
<legend class="fieldset-legend">
|
||||
Kelurahan
|
||||
<span class="text-red-500">*</span>
|
||||
</legend>
|
||||
<select id="kelurahan" class="select w-full" required>
|
||||
<option value="" disabled selected>Pilih salah satu</option>
|
||||
<option value="Kampung Melayu">Kampung Melayu</option>
|
||||
<option value="Tanjung Barat">Tanjung Barat</option>
|
||||
<option value="Petukangan Selatan">Petukangan Selatan</option>
|
||||
<option value="Slipi">Slipi</option>
|
||||
<option value="Gondangdia">Gondangdia</option>
|
||||
<option value="Sunter Agung">Sunter Agung</option>
|
||||
<option value="Cakung Timur">Cakung Timur</option>
|
||||
<option value="Kelapa Dua">Kelapa Dua</option>
|
||||
<option value="Pejaten Timur">Pejaten Timur</option>
|
||||
<option value="Batu Ampar">Batu Ampar</option>
|
||||
</select>
|
||||
</fieldset>
|
||||
</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-[5%]">No</th>
|
||||
<th class="w-[25%]">Nama</th>
|
||||
<th class="w-[25%]">Alamat</th>
|
||||
<th class="w-[20%]">Kelurahan</th>
|
||||
<th class="w-[25%]">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@section Scripts {
|
||||
<script type="text/javascript">
|
||||
var table;
|
||||
|
||||
$(document).ready(function () {
|
||||
table = new DataTable('#example', {
|
||||
ajax: '/Master/Pendamping/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: 'nama' },
|
||||
{ data: 'alamat' },
|
||||
{ data: 'kelurahan' },
|
||||
{ data: 'aksi' },
|
||||
]
|
||||
});
|
||||
|
||||
// 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 Mitra');
|
||||
|
||||
// Populate form with row data
|
||||
$('#nama').val(row.nama);
|
||||
|
||||
// Open modal
|
||||
modal_tambah.showModal();
|
||||
});
|
||||
});
|
||||
|
||||
function closeModal() {
|
||||
// Reset form
|
||||
$('#formTambah')[0].reset();
|
||||
$('#edit_mode').val('false');
|
||||
$('#modal_title').text('Tambah Mitra');
|
||||
|
||||
// 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>
|
||||
}
|
||||
Loading…
Reference in New Issue