fix(penilai/so): prbaikkan pindah penilai dan tambah filter role penilai
This commit is contained in:
@@ -292,10 +292,16 @@
|
||||
},
|
||||
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}, ${data.user_penilai[0].team_id})" title="Ganti Team">
|
||||
render: (item, data) => {
|
||||
const roles = data.user_penilai.map(d => d.role)
|
||||
let htmlData = ''
|
||||
|
||||
htmlData = `<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}, '${roles}')" title="Ganti Team">
|
||||
<i class="ki-filled ki-user-edit"></i>
|
||||
</a>`,
|
||||
</a>`
|
||||
|
||||
return htmlData;
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -326,114 +332,181 @@
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function updateTeam(penilaaniId, permohonanId, userId, teamId) {
|
||||
const selectCategory = () => {
|
||||
function updateTeam(penilaaniId, permohonanId, userId, teamId, roles) {
|
||||
|
||||
|
||||
const selectCategory = () => {
|
||||
Swal.fire({
|
||||
title: 'Pilih Kategori',
|
||||
html: `
|
||||
<select id="categorySelect" class="input">
|
||||
<option value="" selected disabled>Pilih kategori Pengganti</option>
|
||||
<option value="team">Pilih dari Team</option>
|
||||
<option value="region">Pilih dari Wilayah</option>
|
||||
</select>
|
||||
`,
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Lanjut',
|
||||
cancelButtonText: 'Batal',
|
||||
preConfirm: () => {
|
||||
const selectedCategory = document.getElementById('categorySelect').value;
|
||||
if (!selectedCategory) {
|
||||
Swal.showValidationMessage('Anda harus memilih kategori!');
|
||||
}
|
||||
return selectedCategory;
|
||||
}
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
const selectedCategory = result.value;
|
||||
let subOptionsHtml = '';
|
||||
|
||||
if (selectedCategory === 'team') {
|
||||
if (roles === 'surveyor' || roles === 'penilai') {
|
||||
subOptionsHtml = `
|
||||
<div class="flex grid gap-2">
|
||||
<select id="subOptionsPenugasan" class="input" disabled>
|
||||
<option value="${roles}" selected>${roles}</option>
|
||||
</select>
|
||||
<select id="subOptionsSelect" class="input">
|
||||
<option value="" selected disabled>Pilih Anggota Tim</option>
|
||||
@foreach ($teamsActivity as $item)
|
||||
<option value="{{ $item->user->id }}">{{ $item->user->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
subOptionsHtml = `
|
||||
<div class="flex grid gap-2">
|
||||
<select id="subOptionsPenugasan" class="input">
|
||||
<option value="" selected disabled>Pilih Penugasan</option>
|
||||
<option value="surveyor">Surveyor</option>
|
||||
<option value="penilai">Penilai</option>
|
||||
<option value="sama">Penilai dan Surveyor Sama</option>
|
||||
</select>
|
||||
<select id="subOptionsSelect" class="input">
|
||||
<option value="" selected disabled>Pilih Anggota Tim</option>
|
||||
@foreach ($teamsActivity as $item)
|
||||
<option value="{{ $item->user->id }}">{{ $item->user->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
} else if (selectedCategory === 'region') {
|
||||
if (roles === 'surveyor' || roles === 'penilai') {
|
||||
subOptionsHtml = `
|
||||
<div class="flex grid gap-2">
|
||||
<select id="subOptionsPenugasan" class="input" disabled>
|
||||
<option value="${roles}" selected>${roles}</option>
|
||||
</select>
|
||||
<select id="subOptionsSelect" class="input">
|
||||
<option value="" selected disabled>Pilih Anggota Tim</option>
|
||||
@foreach ($teamsActivity as $item)
|
||||
<option value="{{ $item->user->id }}">{{ $item->user->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
subOptionsHtml = `
|
||||
<div>
|
||||
<select id="subOptionsPenugasan" class="input">
|
||||
<option value="" selected disabled>Pilih Penugasan</option>
|
||||
<option value="surveyor">Surveyor</option>
|
||||
<option value="penilai">Penilai</option>
|
||||
<option value="sama">Penilai dan Surveyor Sama</option>
|
||||
</select>
|
||||
<select id="subOptionsSelect" class="input">
|
||||
<option value="" selected disabled>Pilih Wilayah</option>
|
||||
@foreach ($teamPenilai as $item)
|
||||
<option value="{{ $item->regions->id }}">{{ $item->regions->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
Swal.fire({
|
||||
title: 'Pilih Kategori',
|
||||
input: 'select',
|
||||
inputOptions: {
|
||||
team: 'Pilih dari Team',
|
||||
region: 'Pilih dari Wilayah'
|
||||
},
|
||||
inputPlaceholder: 'Pilih kategori Pengganti',
|
||||
icon: 'warning',
|
||||
title: `Pilih ${selectedCategory === 'team' ? 'Anggota Tim' : 'Wilayah'}`,
|
||||
html: subOptionsHtml,
|
||||
icon: 'info',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Lanjut',
|
||||
cancelButtonText: 'Batal',
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
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
|
||||
};
|
||||
confirmButtonText: 'Ya',
|
||||
cancelButtonText: 'Kembali',
|
||||
preConfirm: () => {
|
||||
const subOptionsPenugasan = document.getElementById('subOptionsPenugasan')?.value;
|
||||
const subSelected = document.getElementById('subOptionsSelect').value;
|
||||
if (!subSelected) {
|
||||
Swal.showValidationMessage('Anda harus memilih opsi!');
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
return {
|
||||
penugasan: subOptionsPenugasan || null,
|
||||
selectedOption: subSelected || null,
|
||||
};
|
||||
}
|
||||
}).then((subResult) => {
|
||||
|
||||
console.log(subResult);
|
||||
|
||||
if (subResult.dismiss === Swal.DismissReason.cancel) {
|
||||
selectCategory();
|
||||
} else if (subResult.isConfirmed) {
|
||||
if (!subResult.value) {
|
||||
Swal.fire('Error!', 'Anda harus memilih opsi sebelum melanjutkan.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
let token = "{{ csrf_token() }}";
|
||||
let useURL = "{{ URL::to('/activity/update-team') }}";
|
||||
const paramKey = selectedCategory === 'team' ? 'team_member_id' : 'region_id';
|
||||
|
||||
let input_data = {
|
||||
_token: token,
|
||||
id: penilaaniId,
|
||||
[paramKey]: subResult.value.selectedOption,
|
||||
penugasan: subResult.value.penugasan,
|
||||
permohonan_id: permohonanId,
|
||||
user_id: userId,
|
||||
team_id: teamId,
|
||||
};
|
||||
|
||||
$.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');
|
||||
}
|
||||
|
||||
// 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');
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
console.error(xhr);
|
||||
Swal.fire('Error!', 'Terjadi kesalahan saat memproses permintaan.', 'error');
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
selectCategory();
|
||||
}
|
||||
|
||||
// Mulai dari pemilihan kategori
|
||||
selectCategory();
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
Reference in New Issue
Block a user