301 lines
12 KiB
PHP
301 lines
12 KiB
PHP
<?php $__env->startPush('scripts'); ?>
|
|
<script>
|
|
var activitiesTable = null;
|
|
$(document).ready(function() {
|
|
// Initialize Select2 for year and unit code dropdowns
|
|
$('#inventoryYear').select2({
|
|
placeholder: 'Pilih Tahun',
|
|
}).on('change', function() {
|
|
$('#filterForm').submit();
|
|
});
|
|
|
|
$('#instansi').select2({
|
|
placeholder: 'Pilih Instansi',
|
|
}).on('change', function() {
|
|
$('#filterForm').submit();
|
|
});
|
|
|
|
$('#from_year').select2({
|
|
placeholder: 'Pilih Tahun',
|
|
width: '100%',
|
|
});
|
|
|
|
$('.unit-code').select2({
|
|
placeholder: 'Pilih Unit',
|
|
});
|
|
|
|
// Handle metadata form submission via AJAX
|
|
$('#metadataForm').on('submit', function(e) {
|
|
e.preventDefault();
|
|
var formData = new FormData(this);
|
|
$.ajax({
|
|
url: '<?php echo e(route('form.metadata.store')); ?>',
|
|
type: 'POST',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(response) {
|
|
Swal.fire({
|
|
title: 'Success!',
|
|
text: response.success,
|
|
icon: 'success',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
|
|
$('#name').val('');
|
|
$('#publisher').val('');
|
|
$('#published_year').val('');
|
|
$('#contact_name').val('');
|
|
$('#contact_phone').val('');
|
|
$('#contact_email').val('');
|
|
$('#description').val('');
|
|
$('#file_document').val('');
|
|
fetchMetadata();
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error);
|
|
if (xhr.status === 422) {
|
|
let errors = xhr.responseJSON.errors;
|
|
let errorMessages = '';
|
|
for (let field in errors) {
|
|
errorMessages += errors[field].join('<br>') + '<br>';
|
|
}
|
|
Swal.fire({
|
|
title: 'Validation Error',
|
|
html: errorMessages,
|
|
icon: 'error',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
title: 'Error!',
|
|
text: xhr.responseJSON.error ||
|
|
'Terjadi kesalahan saat menyimpan metadata.',
|
|
icon: 'error',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
}
|
|
$('#isLoadMetadata').hide();
|
|
}
|
|
});
|
|
});
|
|
|
|
// Event listener for unit code change
|
|
$('.unit-code').on('change', function() {
|
|
var activityCode = $(this).data('activity-code');
|
|
var fromUnitCode = $(this).data('current-unit');
|
|
var toUnitCode = $(this).val();
|
|
|
|
$('[name^="data"]').each(function() {
|
|
if ($(this).attr('name').includes(activityCode)) {
|
|
const sector = '<?php echo e($form->sector); ?>';
|
|
const code = '<?php echo e($form->code); ?>';
|
|
const url = `/${sector}/${code}/conversion`;
|
|
|
|
convertUnitValue($(this), fromUnitCode, toUnitCode, url);
|
|
}
|
|
});
|
|
|
|
$(this).data('current-unit', toUnitCode);
|
|
});
|
|
});
|
|
|
|
function convertUnitValue(input, fromUnitCode, toUnitCode, url) {
|
|
let value = input.val();
|
|
value = value.replace(/\./g, '');
|
|
value = value.replace(/,/g, '.');
|
|
|
|
if (value && fromUnitCode && toUnitCode) {
|
|
fetch(`${url}?from=${fromUnitCode}&to=${toUnitCode}&value=${value}`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
input.val(data.convertedValue);
|
|
// numberFormat(input);
|
|
}
|
|
})
|
|
.catch(error => console.error('Error converting value:', error));
|
|
}
|
|
}
|
|
|
|
function showMetadataModal() {
|
|
$('#metadataModal').modal('show');
|
|
fetchMetadata();
|
|
}
|
|
|
|
function fetchMetadata() {
|
|
$('#metadataContent').hide();
|
|
$('#isLoadMetadata').show();
|
|
$.ajax({
|
|
url: '<?php echo e(route('form.metadata.index', ['form_id' => $instansi === 'all' ? 0 : $activityForm->id ?? 0])); ?>',
|
|
type: 'GET',
|
|
success: function(data) {
|
|
$('#metadataContent').html(data);
|
|
$('#metadataContent').show();
|
|
$('#isLoadMetadata').hide();
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error);
|
|
$('#isLoadMetadata').hide();
|
|
}
|
|
});
|
|
}
|
|
|
|
function showActivityUserModal() {
|
|
$('#userActivityModal').modal('show');
|
|
fetchUserActivity();
|
|
}
|
|
|
|
function fetchUserActivity() {
|
|
if (activitiesTable) {
|
|
activitiesTable.destroy();
|
|
}
|
|
|
|
activitiesTable = $('#activities-table').DataTable({
|
|
pageLength: 10,
|
|
responsive: true,
|
|
serverSide: true,
|
|
scrollX: true,
|
|
searchDelay: 1000,
|
|
ajax: {
|
|
url: '<?php echo e(route('form.aktivitasUser', ['form_id' => $instansi === 'all' ? 0 : $activityForm->id ?? 0])); ?>',
|
|
type: 'GET',
|
|
dataSrc: 'data'
|
|
},
|
|
columns: [{
|
|
data: 'user_name',
|
|
name: 'user_name'
|
|
},
|
|
{
|
|
data: 'activity_type',
|
|
name: 'activity_type'
|
|
},
|
|
{
|
|
data: 'ip_address',
|
|
name: 'ip_address'
|
|
},
|
|
{
|
|
data: 'created_at',
|
|
name: 'created_at'
|
|
}
|
|
],
|
|
order: [
|
|
[3, 'desc']
|
|
]
|
|
});
|
|
}
|
|
|
|
function deleteMetadata(metadataId, storagePath) {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: 'Data akan dihapus secara permanen!',
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, hapus!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
url: '<?php echo e(route('form.metadata.destroy', ':id')); ?>'.replace(':id', metadataId),
|
|
type: 'POST',
|
|
data: {
|
|
_token: '<?php echo e(csrf_token()); ?>',
|
|
_method: 'DELETE',
|
|
storage_path: storagePath
|
|
},
|
|
success: function(response) {
|
|
// Swal.fire('Deleted!', 'Data berhasil dihapus.', 'success');
|
|
$('#metadata-' + metadataId).slideUp(500, function() {
|
|
$(this).remove();
|
|
reorderMetadata();
|
|
});
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error);
|
|
Swal.fire('Error!', 'Terjadi kesalahan saat menghapus data.', 'error');
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function reorderMetadata() {
|
|
$('.meta-content').each(function(index, element) {
|
|
$(element).animate({
|
|
top: 0
|
|
}, 500);
|
|
});
|
|
}
|
|
|
|
function confirmLock() {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: "Apakah Anda ingin mengunci data aktivitas ini?",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, Kunci Data!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById('lock-form').submit();
|
|
}
|
|
});
|
|
}
|
|
|
|
function confirmUnlock() {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: "Apakah Anda ingin membuka kunci data aktivitas ini?",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, Buka Kunci Data!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById('unlock-form').submit();
|
|
}
|
|
});
|
|
}
|
|
|
|
function confirmCopy() {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: "Apakah Anda ingin melakukan proses salin data aktivitas dari tahun tersebut?",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, Salin Data!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById('copy-form').submit();
|
|
}
|
|
});
|
|
}
|
|
|
|
function confirmApprove(isApproval) {
|
|
const action = isApproval ? 'menyetujui' : 'membatalkan persetujuan';
|
|
|
|
Swal.fire({
|
|
title: `Konfirmasi ${isApproval ? 'Persetujuan' : 'Pembatalan Persetujuan'}`,
|
|
text: `Apakah Anda yakin ingin ${action} Data Produsen ini? Fitur ini digunakan agar Data Produsen yang disetujui dapat dijumlahkan ke Data Konsolidasi.`,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: isApproval ? 'Ya, Setujui' : 'Ya, Batalkan',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById('confirmApprove').submit();
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
<?php $__env->stopPush(); ?>
|
|
<?php /**PATH /var/www/sigd/resources/views/form/scripts.blade.php ENDPATH**/ ?>
|