update
parent
2c57fd3c80
commit
d928c2df91
|
|
@ -1,368 +0,0 @@
|
|||
@extends('layouts.master')
|
||||
|
||||
@section('title', $form->name)
|
||||
|
||||
@section('content')
|
||||
@php
|
||||
$user = Auth::user();
|
||||
$scope = $user->getScope();
|
||||
|
||||
$inventoryYear = request('inventoryYear') ?? date('Y');
|
||||
$instansi = request('instansi') ?? null;
|
||||
|
||||
if ($agencies->count() === 1 && $scope === \App\Enums\LingkupAksesData::INTERNAL->value) {
|
||||
$instansi = $agencies[0]->name;
|
||||
}
|
||||
|
||||
$param = [
|
||||
'sector' => $form->sector,
|
||||
'code' => $form->code,
|
||||
'inventoryYear' => $inventoryYear,
|
||||
'instansi' => $instansi,
|
||||
];
|
||||
|
||||
$routeImport = route('modules.form.import', $param);
|
||||
$routeExport = route('modules.form.export', $param);
|
||||
$routeExportTemplate = route('modules.form.export', array_merge($param, ['isTemplate' => true]));
|
||||
$routeApproval = route('modules.form.approval', $param);
|
||||
|
||||
$internal = $internal ?? null;
|
||||
$limitInternal = ($internal !== null) && !$agencies->isNotEmpty();
|
||||
@endphp
|
||||
|
||||
<div class="card shadow-sm" data-sector="{{ $form->sector }}" data-code="{{ $form->code }}">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h5 class="mb-0 font-weight-bold">{{ $form->name }}</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
@include('modules.form.action')
|
||||
@include('modules.form.table')
|
||||
{{-- @include('modules.form.copy') --}}
|
||||
</div>
|
||||
</div>
|
||||
@include('modules.form.import')
|
||||
|
||||
@if ($instansi !== 'all')
|
||||
@include('modules.form.aktivitas-user')
|
||||
@include('modules.form.metadata.index')
|
||||
@endif
|
||||
|
||||
{{-- @include('modules.form.form') --}}
|
||||
@endsection
|
||||
|
||||
@section('js')
|
||||
<script>
|
||||
var activitiesTable = null;
|
||||
$(document).ready(function() {
|
||||
$('#inventoryYear').select2({
|
||||
placeholder: 'Pilih Tahun',
|
||||
}).on('change', function() {
|
||||
$('#filterForm').submit();
|
||||
});
|
||||
|
||||
$('#instansi').select2().on('change', function() {
|
||||
$('#filterForm').submit();
|
||||
});
|
||||
|
||||
$('#from_year').select2({
|
||||
placeholder: 'Pilih Tahun',
|
||||
width: '100%',
|
||||
});
|
||||
|
||||
$('.unit-code').select2({
|
||||
placeholder: 'Pilih Unit',
|
||||
});
|
||||
|
||||
$('#metadataForm').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
var formData = new FormData(this);
|
||||
$.ajax({
|
||||
url: '{{ route('modules.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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.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 = '{{ $form->sector }}';
|
||||
const code = '{{ $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);
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error converting value:', error));
|
||||
}
|
||||
}
|
||||
function showMetadataModal() {
|
||||
$('#metadataModal').modal('show');
|
||||
fetchMetadata();
|
||||
}
|
||||
function fetchMetadata() {
|
||||
$('#metadataContent').hide();
|
||||
$('#isLoadMetadata').show();
|
||||
$.ajax({
|
||||
url: '{{ route('modules.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 showCreateModal() {
|
||||
$('#formModal').modal('show');
|
||||
fetchFormdata();
|
||||
}
|
||||
|
||||
function fetchFormdata() {
|
||||
$('#formContent').hide();
|
||||
$('#isLoadForm').show();
|
||||
$.ajax({
|
||||
url: '{{ route('modules.form.create', ['sector' => $form->sector, 'code' => $form->code]) }}',
|
||||
type: 'GET',
|
||||
success: function(data) {
|
||||
$('#formContent').html(data);
|
||||
$('#formContent').show();
|
||||
$('#isLoadForm').hide();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error(error);
|
||||
$('#isLoadForm').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: '{{ route('modules.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: '{{ route('modules.form.metadata.destroy', ':id') }}'.replace(':id', metadataId),
|
||||
type: 'POST',
|
||||
data: {
|
||||
_token: '{{ csrf_token() }}',
|
||||
_method: 'DELETE',
|
||||
storage_path: storagePath
|
||||
},
|
||||
success: function(response) {
|
||||
$('#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>
|
||||
@endsection
|
||||
Loading…
Reference in New Issue