perbaikan upadte assign team activity jika berhalangan by region dan team
This commit is contained in:
@@ -249,7 +249,7 @@
|
||||
|
||||
paparan: {
|
||||
title: 'Paparan',
|
||||
render: (item, data) => {
|
||||
render: (item, data) => {
|
||||
if (!data.due_date_sla) {
|
||||
return `<span class="badge badge-sm badge-danger uppercase flex justify-center">Sudah melewati batas</span>`;
|
||||
}
|
||||
@@ -279,7 +279,7 @@
|
||||
actions: {
|
||||
title: 'Action',
|
||||
render: (item, data) => `
|
||||
<a class="btn btn-sm btn-icon btn-clear btn-primary" onclick="updateTeam(${data.user_penilai[0].penilaian_id}, ${data.permohonan.id}, ${data.user_penilai[0].user_id})" title="Ganti Team">
|
||||
<a class="btn btn-sm btn-icon btn-clear btn-primary" onclick="updateTeam(${data.user_penilai[0].penilaian_id}, ${data.permohonan.id}, ${data.user_penilai[0].user_id}, ${data.user_penilai[0].team_id})" title="Ganti Team">
|
||||
<i class="ki-filled ki-user-edit"></i>
|
||||
</a>`,
|
||||
},
|
||||
@@ -311,68 +311,110 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function updateTeam(penilaaniId, permohonanId, userId) {
|
||||
<script type="text/javascript">
|
||||
function updateTeam(penilaaniId, permohonanId, userId, teamId) {
|
||||
const selectCategory = () => {
|
||||
Swal.fire({
|
||||
title: 'Pilih Tim',
|
||||
title: 'Pilih Kategori',
|
||||
input: 'select',
|
||||
inputOptions: {
|
||||
@foreach ($teamsActivity as $item)
|
||||
{{ $item->user->id }}: '{{ $item->user->name }}',
|
||||
@endforeach
|
||||
team: 'Pilih dari Team',
|
||||
region: 'Pilih dari Wilayah'
|
||||
},
|
||||
inputPlaceholder: 'Pilih anggota tim',
|
||||
inputPlaceholder: 'Pilih kategori Pengganti',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Ya',
|
||||
confirmButtonText: 'Lanjut',
|
||||
cancelButtonText: 'Batal',
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
if (!result.value) {
|
||||
// Tampilkan pesan error jika tidak ada pilihan
|
||||
Swal.fire('Error!', 'Anda harus memilih anggota tim sebelum melanjutkan.', 'error');
|
||||
return;
|
||||
const selectedCategory = result.value;
|
||||
let subOptions = {};
|
||||
|
||||
if (selectedCategory === 'team') {
|
||||
subOptions = {
|
||||
@foreach ($teamsActivity as $item)
|
||||
{{ $item->user->id }}: '{{ $item->user->name }}',
|
||||
@endforeach
|
||||
};
|
||||
} else if (selectedCategory === 'region') {
|
||||
subOptions = {
|
||||
@foreach ($teamPenilai as $item)
|
||||
{{ $item->regions->id }}: '{{ $item->regions->name }}',
|
||||
@endforeach
|
||||
};
|
||||
}
|
||||
|
||||
// Define variables
|
||||
let token = "{{ csrf_token() }}";
|
||||
let useURL = "{{ URL::to('/activity/update-team') }}";
|
||||
|
||||
// Prepare input data
|
||||
let input_data = {
|
||||
_token: token,
|
||||
id: penilaaniId,
|
||||
team_member_id: result.value,
|
||||
permohonan_id: permohonanId,
|
||||
user_id: userId,
|
||||
};
|
||||
|
||||
// AJAX request
|
||||
$.ajax({
|
||||
url: useURL,
|
||||
type: "PUT",
|
||||
cache: false,
|
||||
data: input_data,
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
if (response.status === 'success') {
|
||||
Swal.fire('Sukses!', response.message, 'success').then(() => {
|
||||
location.reload(true);
|
||||
});
|
||||
} else {
|
||||
Swal.fire('Error!', response.message, 'error');
|
||||
Swal.fire({
|
||||
title: 'Pilih ' + (selectedCategory === 'team' ? 'Anggota Tim' : 'Wilayah'),
|
||||
input: 'select',
|
||||
inputOptions: subOptions,
|
||||
inputPlaceholder: 'Pilih salah satu ' + (selectedCategory === 'team' ? 'Anggota Tim' : 'Wilayah'),
|
||||
icon: 'info',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Ya',
|
||||
cancelButtonText: 'Kembali',
|
||||
}).then((subResult) => {
|
||||
if (subResult.dismiss === Swal.DismissReason.cancel) {
|
||||
// Kembali ke tahap pemilihan kategori
|
||||
selectCategory();
|
||||
} else if (subResult.isConfirmed) {
|
||||
if (!subResult.value) {
|
||||
Swal.fire('Error!', 'Anda harus memilih opsi sebelum melanjutkan.', 'error');
|
||||
return;
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
console.error(xhr);
|
||||
Swal.fire('Error!', 'Terjadi kesalahan saat memproses permintaan.',
|
||||
'error');
|
||||
},
|
||||
|
||||
// Define variables
|
||||
let token = "{{ csrf_token() }}";
|
||||
let useURL = "{{ URL::to('/activity/update-team') }}";
|
||||
|
||||
// Tentukan tipe parameter berdasarkan kategori
|
||||
const paramKey = selectedCategory === 'team' ? 'team_member_id' : 'region_id';
|
||||
|
||||
// Prepare input data
|
||||
let input_data = {
|
||||
_token: token,
|
||||
id: penilaaniId,
|
||||
[paramKey]: subResult.value,
|
||||
permohonan_id: permohonanId,
|
||||
user_id: userId,
|
||||
team_id: teamId,
|
||||
};
|
||||
|
||||
// AJAX request
|
||||
$.ajax({
|
||||
url: useURL,
|
||||
type: "PUT",
|
||||
cache: false,
|
||||
data: input_data,
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
if (response.status === 'success') {
|
||||
Swal.fire('Sukses!', response.message, 'success').then(() => {
|
||||
location.reload(true);
|
||||
});
|
||||
} else {
|
||||
Swal.fire('Error!', response.message, 'error');
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
console.error(xhr);
|
||||
Swal.fire('Error!', 'Terjadi kesalahan saat memproses permintaan.', 'error');
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
};
|
||||
|
||||
// Mulai dari pemilihan kategori
|
||||
selectCategory();
|
||||
}
|
||||
</script>
|
||||
|
||||
@endpush
|
||||
|
||||
Reference in New Issue
Block a user