389 lines
13 KiB
PHP
389 lines
13 KiB
PHP
<script>
|
|
$(document).ready(function() {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
|
}
|
|
});
|
|
});
|
|
|
|
function deleteItem(url, message) {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: message,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, hapus!',
|
|
cancelButtonText: 'Batal',
|
|
reverseButtons: true
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
type: "DELETE",
|
|
url: url,
|
|
success: function(response) {
|
|
if (response.status === 'failed') {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Gagal',
|
|
text: response.message,
|
|
confirmButtonText: 'OK'
|
|
});
|
|
}else if (response.status === 'warning') {
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Informasi',
|
|
text: response.message,
|
|
confirmButtonText: 'OK'
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Berhasil',
|
|
text: 'Data berhasil dihapus.',
|
|
confirmButtonText: 'OK'
|
|
}).then(() => location.reload());
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
Swal.fire(
|
|
'Terjadi kesalahan!',
|
|
xhr.responseText,
|
|
'error'
|
|
);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
|
}
|
|
});
|
|
});
|
|
|
|
function deleteUndoItem(urlDelete, route, message) {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: message,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, hapus!',
|
|
cancelButtonText: 'Batal',
|
|
reverseButtons: true
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
type: "DELETE",
|
|
url: urlDelete,
|
|
success: function(response) {
|
|
if (response.status === 'failed') {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Gagal',
|
|
text: response.message ?? 'Terjadi kesalahan saat menghapus.',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Berhasil',
|
|
text: 'Data berhasil dihapus.',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Undo',
|
|
cancelButtonText: 'Tutup',
|
|
}).then((res) => {
|
|
if (res.isConfirmed) {
|
|
if (!route || !response.id) {
|
|
return Swal.fire('Gagal!', 'Tidak dapat mengembalikan data (data tidak lengkap).', 'error');
|
|
}
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: `/dashboard/${route}/${response.id}/restore`,
|
|
success: function(res) {
|
|
Swal.fire('Dikembalikan!', res.message ?? 'Data berhasil dikembalikan.', 'success').then(() => location.reload());
|
|
},
|
|
error: function() {
|
|
Swal.fire('Gagal!', 'Tidak dapat mengembalikan data.', 'error');
|
|
}
|
|
});
|
|
} else {
|
|
location.reload();
|
|
}
|
|
});
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
Swal.fire(
|
|
'Terjadi kesalahan!',
|
|
xhr.responseText ?? 'Server tidak merespon.',
|
|
'error'
|
|
);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
|
}
|
|
});
|
|
});
|
|
|
|
function restoreItem(url, message) {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: message,
|
|
icon: 'question',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, pulihkan!',
|
|
cancelButtonText: 'Batal',
|
|
reverseButtons: true
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: url,
|
|
success: function(response) {
|
|
$('#usersTable').DataTable().ajax.reload();
|
|
Swal.fire(
|
|
'Terhapus!',
|
|
response.message,
|
|
'success'
|
|
).then(() => {
|
|
location.reload();
|
|
});
|
|
},
|
|
error: function(xhr) {
|
|
Swal.fire(
|
|
'Terjadi kesalahan!',
|
|
xhr.responseText,
|
|
'error'
|
|
);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
|
}
|
|
});
|
|
});
|
|
|
|
function statusAction(url, message, confirmButtonAction) {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: message,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: confirmButtonAction,
|
|
cancelButtonText: 'Batal',
|
|
reverseButtons: true
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
type: "PUT",
|
|
url: url,
|
|
success: function(response) {
|
|
$('#usersTable').DataTable().ajax.reload();
|
|
Swal.fire(
|
|
'Proses Berhasil!',
|
|
response.message,
|
|
'success'
|
|
).then(() => {
|
|
location.reload();
|
|
});
|
|
},
|
|
error: function(xhr) {
|
|
Swal.fire(
|
|
'Terjadi kesalahan!',
|
|
xhr.responseText,
|
|
'error'
|
|
);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
@if (session('success-status'))
|
|
<script>
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Sukses',
|
|
text: '{{ session('success-status') }}',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
</script>
|
|
@endif
|
|
|
|
@if (session('failed-status'))
|
|
<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Gagal',
|
|
text: '{{ session('failed-status') }}',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
</script>
|
|
@endif
|
|
|
|
@if (session('warning-status'))
|
|
<script>
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Informasi',
|
|
text: '{{ session('warning-status') }}',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
</script>
|
|
@endif
|
|
|
|
<script>
|
|
$('#submitButton').click(function(e) {
|
|
e.preventDefault();
|
|
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: 'Pastikan data yang Anda masukkan sudah benar.',
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, kirim!',
|
|
cancelButtonText: 'Batal',
|
|
reverseButtons: true
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
// console.log("Form akan dikirim...");
|
|
|
|
$('#myForm').off('submit').submit(); // Pastikan hanya submit 1x
|
|
}
|
|
});
|
|
});
|
|
|
|
</script>
|
|
<script>
|
|
function showDetail(reason) {
|
|
Swal.fire({
|
|
title: 'Alasan Penolakan', // Judul utama
|
|
html: `
|
|
<div class="card" style="border: none; border-radius: 12px; padding: 15px; text-align: left; background-color: #f8f9fa; max-width: 500px; margin: auto; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); margin-top:0.5rem;">
|
|
<div class="card-body" style="font-size: 14px; color: #555; line-height: 1.6;">
|
|
<p style="margin: 0; padding: 10px 0; font-style: italic; color: #888;">
|
|
${reason || "<i>Tidak ada alasan yang diberikan.</i>"}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
`,
|
|
icon: 'info',
|
|
confirmButtonText: 'Tutup',
|
|
confirmButtonColor: '#3085d6', // Mengubah warna tombol
|
|
padding: '25px', // Padding sekitar modal
|
|
backdrop: true, // Mengaktifkan backdrop
|
|
customClass: {
|
|
popup: 'custom-popup',
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<script>
|
|
function showEditDescription(reason) {
|
|
Swal.fire({
|
|
title: 'Alasan Edit', // Judul utama
|
|
html: `
|
|
<div class="card" style="border: none; border-radius: 12px; padding: 15px; text-align: left; background-color: #f8f9fa; max-width: 500px; margin: auto; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); margin-top:0.5rem;">
|
|
<div class="card-body" style="font-size: 14px; color: #555; line-height: 1.6;">
|
|
<p style="margin: 0; padding: 10px 0; font-style: italic; color: #888;">
|
|
${reason || "<i>Tidak ada alasan yang diberikan.</i>"}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
`,
|
|
icon: 'info',
|
|
confirmButtonText: 'Tutup',
|
|
confirmButtonColor: '#3085d6', // Mengubah warna tombol
|
|
padding: '25px', // Padding sekitar modal
|
|
backdrop: true, // Mengaktifkan backdrop
|
|
customClass: {
|
|
popup: 'custom-popup',
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
|
}
|
|
});
|
|
});
|
|
|
|
function itemConfirm(url, message, buttonText) {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: message,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: buttonText,
|
|
cancelButtonText: 'Batal',
|
|
reverseButtons: true
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: url,
|
|
success: function(response) {
|
|
$('#usersTable').DataTable().ajax.reload();
|
|
Swal.fire(
|
|
'Berhasil!',
|
|
response.message,
|
|
'success'
|
|
).then(() => {
|
|
location.reload();
|
|
});
|
|
},
|
|
error: function(xhr) {
|
|
Swal.fire(
|
|
'Terjadi kesalahan!',
|
|
xhr.responseText,
|
|
'error'
|
|
);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
</script>
|