285 lines
15 KiB
PHP
285 lines
15 KiB
PHP
@extends('layout.main')
|
|
|
|
@section('content')
|
|
<div class="container-xxl flex-grow-1 container-p-y">
|
|
<div class="card">
|
|
<div class="card-header border-bottom mb-4">
|
|
<h5 class="card-title mb-0">Update Program</h5>
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
<form id="addViewProgramForm" method="POST">
|
|
|
|
<h6 class="mb-3">Informasi Program</h6>
|
|
<div class="row">
|
|
<div class="col-md-12 mb-4 form-control-validation">
|
|
<label class="form-label" for="add-program-nama">Nama Program<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="add-program-nama" name="nama" placeholder="Cth: Program Pertanian" value="{{ old('nama', $program->nama) }}" readonly />
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6 mb-4 form-control-validation">
|
|
<label class="form-label" for="add-program-nama-singkat">Nama Singkat<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="add-program-nama-singkat" name="nama_singkat" placeholder="Cth: PP" value="{{ old('nama_singkat', $program->nama_singkat) }}" readonly />
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-3 mb-4 form-control-validation">
|
|
<label class="form-label" for="add-program-subdomain">Sub Domain<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="add-program-subdomain" name="sub_domain" placeholder="Cth: budi@email.com" value="{{ old('sub_domain', $program->sub_domain) }}" readonly />
|
|
</div>
|
|
<div class="col-md-3 mb-4 form-control-validation">
|
|
<label class="form-label" for="add-program-tahun">Tahun<span class="text-danger">*</span></label>
|
|
<input type="number" class="form-control" id="add-program-tahun" name="tahun" placeholder="Cth: 2023" value="{{ old('tahun', $program->tahun) }}" readonly />
|
|
</div>
|
|
<div class="col-md-6 mb-4 form-control-validation">
|
|
<label class="form-label" for="add-program-instansi">Instansi</label>
|
|
<input type="text" class="form-control" id="add-program-instansi" name="instansi" placeholder="Cth: Dinas Pertanian" value="{{ old('instansi', $program->instansi) }}" readonly />
|
|
</div>
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<hr class="my-4 mx-n4" />
|
|
<div class="row">
|
|
<div class="col-md-4 col-sm-12 mb-4">
|
|
<h6 class="mb-3">Komoditas</h6>
|
|
|
|
<div class="row mb-4">
|
|
<div class="col-md-auto d-flex gap-2">
|
|
<button type="button" class="btn btn-sm btn-primary" data-bs-toggle="offcanvas" data-bs-target="#offcanvasAddProgramKomoditas">
|
|
<i class="ti tabler-plus me-1"></i> Tambah
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive text-nowrap mb-4">
|
|
<table class="table table-hover">
|
|
<thead class="border-top">
|
|
<tr>
|
|
<th>No</th>
|
|
<th>Komoditas</th>
|
|
<th>Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($program->komoditas as $index => $kmd)
|
|
<tr>
|
|
<td>{{ $loop->iteration }}</td>
|
|
<td>
|
|
<span class="text-heading">{{ $kmd->komoditas->nama }}</span>
|
|
@if($kmd->default)
|
|
<span class="badge rounded-pill text-bg-success ms-2">Default</span>
|
|
@endif
|
|
</td>
|
|
<td>
|
|
<div class="d-flex align-items-center">
|
|
@if(!$kmd->default)
|
|
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill default-komoditas"
|
|
data-id="{{ $kmd->id }}"><i class="ti tabler-square-check ti-md"></i></a>
|
|
@endif
|
|
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill delete-komoditas"
|
|
data-id="{{ $kmd->id }}" data-nama="{{ $kmd->komoditas->nama }}"><i class="ti tabler-trash ti-md"></i></a>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="6" class="text-center py-4">Tidak ada data ditemukan.</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-8 col-sm-12 mb-4">
|
|
<h6 class="mb-3">Lokasi</h6>
|
|
|
|
<div class="row mb-4">
|
|
<div class="col-md-auto d-flex gap-2">
|
|
<button class="btn btn-sm btn-primary" data-bs-toggle="offcanvas" data-bs-target="#offcanvasAddProgramLokasi">
|
|
<i class="ti tabler-plus me-1"></i> Tambah
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive text-nowrap mb-4">
|
|
<table class="table table-hover">
|
|
<thead class="border-top">
|
|
<tr>
|
|
<th>No</th>
|
|
<th>Provinsi</th>
|
|
<th>Kabupaten/Kota</th>
|
|
<th>Kecamatan</th>
|
|
<th>Kelurahan/Desa</th>
|
|
<th>Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($program->lokasi as $index => $lok)
|
|
<tr>
|
|
<td>{{ $loop->iteration }}</td>
|
|
<td>
|
|
<span class="text-heading">{{ $lok->provinsi->nama }}</span>
|
|
@if($lok->default && !$lok->kabupaten_kota_id && !$lok->kecamatan_id && !$lok->desa_kelurahan_id)
|
|
<span class="badge rounded-pill text-bg-success ms-2">Default</span>
|
|
@endif
|
|
</td>
|
|
<td>
|
|
<span class="text-muted">{{ $lok->kabupatenKota?->nama }}</span>
|
|
@if($lok->default && $lok->kabupaten_kota_id && !$lok->kecamatan_id && !$lok->desa_kelurahan_id)
|
|
<span class="badge rounded-pill text-bg-success ms-2">Default</span>
|
|
@endif
|
|
</td>
|
|
<td>
|
|
<span class="text-muted">{{ $lok->kecamatan?->nama }}</span>
|
|
@if($lok->default && $lok->kabupaten_kota_id && $lok->kecamatan_id && !$lok->desa_kelurahan_id)
|
|
<span class="badge rounded-pill text-bg-success ms-2">Default</span>
|
|
@endif
|
|
</td>
|
|
<td>
|
|
<span class="text-muted">{{ $lok->desaKelurahan?->nama }}</span>
|
|
@if($lok->default && $lok->kabupaten_kota_id && $lok->kecamatan_id && $lok->desa_kelurahan_id)
|
|
<span class="badge rounded-pill text-bg-success ms-2">Default</span>
|
|
@endif
|
|
</td>
|
|
<td>
|
|
@if(!$lok->default)
|
|
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill default-lokasi"
|
|
data-id="{{ $lok->id }}"><i class="ti tabler-square-check ti-md"></i></a>
|
|
@endif
|
|
<div class="d-flex align-items-center">
|
|
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill delete-lokasi"
|
|
data-id="{{ $lok->id }}"
|
|
data-provinsi="{{ $lok->provinsi->nama }}"
|
|
data-kabupaten="{{ $lok->kabupatenKota?->nama }}"
|
|
data-kecamatan="{{ $lok->kecamatan?->nama }}"
|
|
data-desa="{{ $lok->desaKelurahan?->nama }}">
|
|
<i class="ti tabler-trash ti-md"></i></a>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="6" class="text-center py-4">Tidak ada data ditemukan.</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-4 text-end">
|
|
<a href="{{ route('program.index') }}" class="btn btn-label-secondary me-2">Kembali</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@include('core.program-komoditas.add')
|
|
@include('core.program-lokasi.add')
|
|
</div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script>
|
|
'use strict';
|
|
$(document).ready(function () {
|
|
|
|
$(".delete-komoditas").click(function (e) {
|
|
e.preventDefault();
|
|
const id = $(this).data('id');
|
|
const name = $(this).data('nama');
|
|
|
|
Swal.fire({
|
|
title: 'Hapus?',
|
|
text: `Komoditas ${name} akan dihapus!`,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Ya, Hapus!',
|
|
customClass: { confirmButton: 'btn btn-danger me-3', cancelButton: 'btn btn-label-secondary' },
|
|
buttonsStyling: false
|
|
}).then(function (result) {
|
|
if (result.value) {
|
|
$.ajax({
|
|
url: "{{ route('program.komoditas.destroy', ['program' => $program->id, 'komodita' => ':id']) }}".replace(':id', id),
|
|
type: 'DELETE',
|
|
data: {
|
|
_token: '{{ csrf_token() }}'
|
|
},
|
|
success: function () {
|
|
Swal.fire({ icon: 'success', title: 'Terhapus!', showConfirmButton: false, timer: 1500 })
|
|
.then(() => window.location.reload());
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
$(".default-komoditas").click(function (e) {
|
|
e.preventDefault();
|
|
const id = $(this).data('id');
|
|
console.log(id);
|
|
|
|
$.ajax({
|
|
url: "{{ route('program.komoditas.update', ['program' => $program->id, 'komodita' => ':id']) }}".replace(':id', id),
|
|
type: 'PUT',
|
|
data: {
|
|
_token: '{{ csrf_token() }}',
|
|
default: 1
|
|
},
|
|
success: function () {
|
|
Swal.fire({ icon: 'success', title: 'Disimpan!', showConfirmButton: false, timer: 1500 })
|
|
.then(() => window.location.reload());
|
|
}
|
|
});
|
|
});
|
|
|
|
$(".delete-lokasi").click(function (e) {
|
|
e.preventDefault();
|
|
const id = $(this).data('id');
|
|
const name = $(this).data('provinsi') + ', ' + $(this).data('kabupaten') + ', ' + $(this).data('kecamatan') + ', ' + $(this).data('desa');
|
|
|
|
Swal.fire({
|
|
title: 'Hapus?',
|
|
text: `Lokasi ${name} akan dihapus!`,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Ya, Hapus!',
|
|
customClass: { confirmButton: 'btn btn-danger me-3', cancelButton: 'btn btn-label-secondary' },
|
|
buttonsStyling: false
|
|
}).then(function (result) {
|
|
if (result.value) {
|
|
$.ajax({
|
|
url: "{{ route('program.lokasi.destroy', ['program' => $program->id, 'lokasi' => ':id']) }}".replace(':id', id),
|
|
type: 'DELETE',
|
|
data: {
|
|
_token: '{{ csrf_token() }}'
|
|
},
|
|
success: function () {
|
|
Swal.fire({ icon: 'success', title: 'Terhapus!', showConfirmButton: false, timer: 1500 })
|
|
.then(() => window.location.reload());
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
$(".default-lokasi").click(function (e) {
|
|
e.preventDefault();
|
|
const id = $(this).data('id');
|
|
console.log(id);
|
|
|
|
$.ajax({
|
|
url: "{{ route('program.lokasi.update', ['program' => $program->id, 'lokasi' => ':id']) }}".replace(':id', id),
|
|
type: 'PUT',
|
|
data: {
|
|
_token: '{{ csrf_token() }}',
|
|
default: 1
|
|
},
|
|
success: function () {
|
|
Swal.fire({ icon: 'success', title: 'Disimpan!', showConfirmButton: false, timer: 1500 })
|
|
.then(() => window.location.reload());
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
@endpush |