function editData(value){ const uid = $(value).data('uid') const name = $(value).data('name') $("#edit_modal").modal('show') $("#edit_name").val(name) formEdit.attr('action', `/ruangan-pelayanan/${uid}`) formEdit.off("submit").on("submit", async function(e){ e.preventDefault() const formDataEdit = new FormData(formEdit[0]) try { const responseEdit = await fetch(formEdit.attr("action"), { method:"POST", body:formDataEdit, }) const resultEdit = await responseEdit.json() if(responseEdit.ok && resultEdit.status === "success"){ Swal.fire({ title:"Success", text:"Data Berhasil diupdate", icon:"success", showConfirmButton: false, timer:1200 }); formEdit[0].reset() $("#edit_modal").modal('hide') dataTable.bootstrapTable("refresh") } } catch (error) { Swal.fire({ title:"Error", text:"Message:" + error, icon:"error", }) } }) } function deleteData(uid, name){ Swal.fire({ title: "Apakah kamu yakin ingin menghapus data ini?", text : name, icon: "warning", showCancelButton: true }).then((result) => { if(result.isConfirmed){ fetch(`/ruangan-pelayanan/${uid}`, { method:'DELETE', headers: { "X-CSRF-TOKEN": document.querySelector('meta[name="csrf-token"]').getAttribute('content'), "Content-Type": "application/json" } }).then((response) => { if(!response.ok){ throw new Error("Network response was not ok"); } return response.json(); }) .then((data) => { if(data.status === "success"){ Swal.fire({ title: "Success", text: "Data berhasil dihapus", icon:"success", showConfirmButton: false, timer: 1000 }).then(() => { dataTable.bootstrapTable("refresh") }) }else{ Swal.fire({ title: "Error!", text: data.message || "Failed to delete Schedule.", icon: "error" }); } }) .catch(error => { Swal.fire({ title: "Error!", text: "Something went wrong. Please try again later.", icon: "error" }); }); } }) } $("#addroomService").on("click", function() { const newInput = `