TIF_NGANJUK_E41220949/resources/views/admin/tps/edit.blade.php

193 lines
9.4 KiB
PHP

@php
function decimalToDms($decimal, $type = 'lat')
{
if ($decimal === null || $decimal === '') {
return '';
}
$direction = $decimal >= 0 ? ($type === 'lat' ? 'N' : 'E') : ($type === 'lat' ? 'S' : 'W');
$decimal = abs($decimal);
$degree = floor($decimal);
$minuteFloat = ($decimal - $degree) * 60;
$minute = floor($minuteFloat);
$second = round(($minuteFloat - $minute) * 60, 2);
return "{$degree}°{$minute}'{$second}\"{$direction}";
}
@endphp
@extends('admin.template')
@section('content')
<div class="content-wrapper">
<div class="row">
<div class="col-12 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<h4 class="card-title">Edit Data TPS</h4>
<p class="card-description">
Form edit data Tempat Pembuangan Sampah
</p>
<form action="{{ route('admin.tps.update', $tps->id_tps) }}" method="POST"
enctype="multipart/form-data" class="forms-sample">
@csrf
@method('PUT')
{{-- Nama TPS --}}
<div class="form-group">
<label>Nama TPS</label>
<input type="text" name="nama_tps" class="form-control"
value="{{ old('nama_tps') ?? $tps->nama_tps }}" required>
@error('nama_tps')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
{{-- Alamat --}}
<div class="form-group">
<label>Alamat</label>
<input type="text" name="alamat_tps" class="form-control"
value="{{ old('alamat_tps') ?? $tps->alamat_tps }}" required>
@error('alamat_tps')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
{{-- Kategori TPS --}}
<div class="form-group">
<label>Kategori TPS</label>
<select name="kategori_tps_id" class="form-control" required>
<option value="">-- Pilih Kategori --</option>
@foreach ($kategori as $item)
<option value="{{ $item->id_kategori_tps }}"
{{ (old('kategori_tps_id') ?? $tps->kategori_tps_id) == $item->id_kategori_tps ? 'selected' : '' }}>
{{ $item->nama_kategori }}
</option>
@endforeach
</select>
@error('kategori_tps_id')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
{{-- Tahun Pembuatan --}}
<div class="form-group">
<label>Tahun Pembuatan</label>
<input type="number" name="tahun_pembuatan" class="form-control"
value="{{ old('tahun_pembuatan') ?? $tps->tahun_pembuatan }}" required>
@error('tahun_pembuatan')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
{{-- Kapasitas TPS --}}
<div class="form-group">
<label>Kapasitas TPS</label>
<input type="number" name="kapasitas_tps" class="form-control"
value="{{ old('kapasitas_tps') ?? $tps->kapasitas_tps }}" required>
@error('kapasitas_tps')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
{{-- Status TPS --}}
<div class="form-group">
<label>Status TPS</label>
<select name="status_tps" class="form-control" required>
<option value="Aktif"
{{ (old('status_tps') ?? $tps->status_tps) == 'Aktif' ? 'selected' : '' }}>Aktif
</option>
<option value="Tidak Aktif"
{{ (old('status_tps') ?? $tps->status_tps) == 'Tidak Aktif' ? 'selected' : '' }}>
Tidak Aktif</option>
<option value="Pembangunan"
{{ (old('status_tps') ?? $tps->status_tps) == 'Pembangunan' ? 'selected' : '' }}>
Pembangunan</option>
</select>
@error('status_tps')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
{{-- Latitude --}}
<div class="form-group">
<label>Latitude</label>
<input type="text" name="latitude" class="form-control" placeholder="Contoh: 7°35'17.25S"
value="{{ old('latitude') ?? decimalToDms($tps->latitude, 'lat') }}" required>
@error('latitude')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
{{-- Longitude --}}
<div class="form-group">
<label>Longitude</label>
<input type="text" name="longitude" class="form-control"
placeholder="Contoh: 111°55'0.97E"
value="{{ old('longitude') ?? decimalToDms($tps->longitude, 'lng') }}" required>
@error('longitude')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
{{-- Foto TPS --}}
<div class="form-group">
<label>Foto TPS</label>
<input type="file" name="foto_tps" id="foto_tps" class="file-upload-default">
<div class="input-group col-xs-12">
<input type="text" class="form-control file-upload-info" disabled
placeholder="Upload Foto TPS">
<span class="input-group-append">
<button class="file-upload-browse btn btn-primary" type="button">
Upload
</button>
</span>
</div>
@error('foto_tps')
<small class="text-danger">{{ $message }}</small>
@enderror
@if ($tps->foto_tps)
<div class="mt-2">
<img src="{{ asset('storage/' . $tps->foto_tps) }}" width="250"
class="img-thumbnail">
</div>
@endif
</div>
{{-- Button --}}
<button type="submit" class="mr-2 btn btn-primary">Simpan</button>
<a href="{{ route('admin.tps.index') }}" class="btn btn-light">Batal</a>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
document.querySelectorAll('.file-upload-browse').forEach(function(button) {
button.addEventListener('click', function() {
this.closest('.form-group')
.querySelector('.file-upload-default')
.click();
});
});
document.querySelectorAll('.file-upload-default').forEach(function(input) {
input.addEventListener('change', function() {
const fileName = this.files[0]?.name || '';
this.closest('.form-group')
.querySelector('.file-upload-info')
.value = fileName;
});
});
</script>
@endsection