fix(master-land): fix func update data
This commit is contained in:
parent
9e7b36520c
commit
2e69c62dbc
|
@ -3,12 +3,19 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\District;
|
||||
use App\Models\Province;
|
||||
use App\Models\Regency;
|
||||
use Dflydev\DotAccessData\Data;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LocationController extends Controller
|
||||
{
|
||||
public function getProvinces()
|
||||
{
|
||||
$provinces = Province::all();
|
||||
return response()->json(['success' => true, 'data' => $provinces]);
|
||||
}
|
||||
|
||||
public function getRegencies($provinceId)
|
||||
{
|
||||
$regencies = Regency::where('province_id', $provinceId)->get();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
var map;
|
||||
var currentMarker = null;
|
||||
var map, mapEdit;
|
||||
var currentMarker,
|
||||
currentMarkerEdit = null;
|
||||
|
||||
var form = document.getElementById("add-form");
|
||||
var provinceField = form.querySelector("#province-field");
|
||||
|
@ -26,20 +27,30 @@ var loading = form.querySelector("#loading");
|
|||
var btnContainer = form.querySelector("#add-footer");
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
// Initialize the first map
|
||||
map = L.map("map", {
|
||||
attributionControl: false,
|
||||
}).setView([-8.157416852745705, 113.72281580436439], 16);
|
||||
|
||||
// Add tile layers to both maps
|
||||
mapEdit = L.map("map-edit", {
|
||||
attributionControl: false,
|
||||
}).setView([-8.157416852745705, 113.72281580436439], 16);
|
||||
|
||||
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
||||
maxZoom: 19,
|
||||
}).addTo(map);
|
||||
|
||||
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
||||
maxZoom: 19,
|
||||
}).addTo(mapEdit);
|
||||
|
||||
$("#showModal").on("shown.bs.modal", function () {
|
||||
map.invalidateSize();
|
||||
});
|
||||
|
||||
$("#editModal").on("shown.bs.modal", function () {
|
||||
mapEdit.invalidateSize();
|
||||
});
|
||||
|
||||
map.on("click", onMapClick);
|
||||
});
|
||||
|
||||
|
@ -64,59 +75,6 @@ function validatePrice(input) {
|
|||
input.value = formatted.replace("Rp", "").trim();
|
||||
}
|
||||
|
||||
function getRegencies(provinceId) {
|
||||
regencyContainer.style.display = "none";
|
||||
districtContainer.style.display = "none";
|
||||
loading.style.display = "block";
|
||||
mapContainer.style.display = "none";
|
||||
|
||||
const url = "/location/get-regency/" + provinceId;
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: "GET",
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
loading.style.display = "none";
|
||||
const data = response.data;
|
||||
|
||||
regencyVal.clearStore();
|
||||
regencyVal.clearChoices();
|
||||
|
||||
regencyVal.value = "";
|
||||
regencyVal.setChoices([
|
||||
{
|
||||
value: "",
|
||||
label: "Pilih Kabupaten",
|
||||
selected: true,
|
||||
disabled: true,
|
||||
},
|
||||
]);
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
regencyVal.setChoices(
|
||||
data.map((regency) => ({
|
||||
value: regency.id,
|
||||
label: regency.name,
|
||||
selected: false,
|
||||
disabled: false,
|
||||
}))
|
||||
);
|
||||
regencyContainer.style.display = "block";
|
||||
} else {
|
||||
mapContainer.style.display = "block";
|
||||
mapContainer.innerHTML =
|
||||
"<p class='text-center text-muted'>Terjadi kesalaahan saat mengambil data, silahkan coba beberapa saat lagi</p>";
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
mapContainer.style.display = "block";
|
||||
mapContainer.innerHTML =
|
||||
"<p class='text-center text-muted'>Terjadi kesalaahan saat mengambil data, silahkan coba beberapa saat lagi</p>";
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function showmap(districtId) {
|
||||
if (!navigator.geolocation) {
|
||||
alert("Geolocation tidak didukung oleh browser ini.");
|
||||
|
@ -204,6 +162,82 @@ function onMapDragend() {
|
|||
lngField.value = coordinates.lng;
|
||||
}
|
||||
|
||||
function getProvinces(provinceId) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
$.ajax({
|
||||
url: "/location/get-province",
|
||||
type: "GET",
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
const province = response.data.find(
|
||||
(province) => province.id == provinceId
|
||||
);
|
||||
|
||||
resolve(province);
|
||||
} else {
|
||||
reject(new Error("Terjadi kesalahan saat mengambil data"));
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
reject(new Error("Terjadi kesalahan saat mengambil data"));
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getRegencies(provinceId) {
|
||||
regencyContainer.style.display = "none";
|
||||
districtContainer.style.display = "none";
|
||||
loading.style.display = "block";
|
||||
mapContainer.style.display = "none";
|
||||
|
||||
const url = "/location/get-regency/" + provinceId;
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: "GET",
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
loading.style.display = "none";
|
||||
const data = response.data;
|
||||
|
||||
regencyVal.clearStore();
|
||||
regencyVal.clearChoices();
|
||||
|
||||
regencyVal.value = "";
|
||||
regencyVal.setChoices([
|
||||
{
|
||||
value: "",
|
||||
label: "Pilih Kabupaten",
|
||||
selected: true,
|
||||
disabled: true,
|
||||
},
|
||||
]);
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
regencyVal.setChoices(
|
||||
data.map((regency) => ({
|
||||
value: regency.id,
|
||||
label: regency.name,
|
||||
selected: false,
|
||||
disabled: false,
|
||||
}))
|
||||
);
|
||||
regencyContainer.style.display = "block";
|
||||
} else {
|
||||
mapContainer.style.display = "block";
|
||||
mapContainer.innerHTML =
|
||||
"<p class='text-center text-muted'>Terjadi kesalaahan saat mengambil data, silahkan coba beberapa saat lagi</p>";
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
mapContainer.style.display = "block";
|
||||
mapContainer.innerHTML =
|
||||
"<p class='text-center text-muted'>Terjadi kesalaahan saat mengambil data, silahkan coba beberapa saat lagi</p>";
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function getDistricts(regencyId) {
|
||||
districtContainer.style.display = "none";
|
||||
loading.style.display = "block";
|
||||
|
@ -256,14 +290,34 @@ function getDistricts(regencyId) {
|
|||
});
|
||||
}
|
||||
|
||||
function updateData(land) {
|
||||
async function updateData(land) {
|
||||
var form = document.getElementById("edit-form");
|
||||
var landName = document.getElementById("landname-edit-field");
|
||||
var status = document.getElementById("status-edit-field");
|
||||
var ownerEditField = form.querySelector("#owner-edit-field");
|
||||
var noHpEditField = form.querySelector("#nohp-edit-field");
|
||||
var rentalPriceEditField = form.querySelector("#rentalprice-edit-field");
|
||||
var rentalStartEditField = form.querySelector("#rentalstart-edit-field");
|
||||
var rentalUntilEditField = form.querySelector("#rentaluntil-edit-field");
|
||||
var landNameEditField = form.querySelector("#landname-edit-field");
|
||||
var provinceEditField = form.querySelector("#province-edit-field");
|
||||
var provinceEditVal = new Choices(provinceEditField);
|
||||
var regencyEditField = form.querySelector("#regency-edit-field");
|
||||
var districtEditField = form.querySelector("#district-edit-field");
|
||||
var latEditField = form.querySelector("#lat-edit");
|
||||
var lngEditField = form.querySelector("#lng-edit");
|
||||
|
||||
landName.value = land.name;
|
||||
status.value = land.description;
|
||||
form.action = "/data-lahan/" + land.id;
|
||||
let rentalPrice = new Intl.NumberFormat("id-ID", {
|
||||
style: "currency",
|
||||
currency: "IDR",
|
||||
minimumFractionDigits: 0,
|
||||
}).format(land.rental_price);
|
||||
|
||||
ownerEditField.value = land.owner;
|
||||
noHpEditField.value = land.no_hp;
|
||||
rentalPriceEditField.value = rentalPrice.replace(/Rp\s?/g, "").trim();
|
||||
rentalStartEditField.value = land.rental_start;
|
||||
rentalUntilEditField.value = land.rental_until;
|
||||
landNameEditField.value = land.land_name;
|
||||
provinceEditField.value = land.province_code;
|
||||
}
|
||||
|
||||
function deleteData(id) {
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
height: 200px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#map-edit {
|
||||
height: 200px;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@endpush
|
||||
<div class="page-content">
|
||||
|
@ -310,19 +315,127 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
|||
readonly />
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="owner-edit-field" class="form-label">Pemilik Lahan</label>
|
||||
<input type="text" id="owner-edit-field" class="form-control" name="owner"
|
||||
value="{{ old('owner') }}" placeholder="Masukan Nama Pemilik Lahan" required />
|
||||
<div class="invalid-feedback">
|
||||
Masukan Nama Pemilik Lahan
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="nohp-edit-field" class="form-label">Nomor HP</label>
|
||||
<input type="text" id="nohp-edit-field" class="form-control" name="nohp"
|
||||
value="{{ old('nohp') }}" placeholder="Masukan Nomor HP" required
|
||||
oninput="validatePhoneNumber(this)" />
|
||||
<div class="invalid-feedback">
|
||||
Masukan Nomor HP
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="rentalprice-edit-field" class="form-label">Harga Sewa</label>
|
||||
<input type="text" id="rentalprice-edit-field" class="form-control"
|
||||
name="rental_price" value="{{ old('rental_price') }}"
|
||||
placeholder="Masukan Harga Sewa" required oninput="validatePrice(this)" />
|
||||
<div class="invalid-feedback">
|
||||
Masukan Harga Sewa
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="rentalstart-edit-field" class="form-label">Mulai Dari</label>
|
||||
<input type="date" id="rentalstart-edit-field" class="form-control"
|
||||
name="rental_start" value="{{ old('rental_start') }}"
|
||||
min="{{ date('Y-m-d') }}" placeholder="Masukan Tanggal Mulai" required />
|
||||
<div class="invalid-feedback">
|
||||
Masukan Tanggal Mulai
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="rentaluntil-edit-field" class="form-label">Sampai</label>
|
||||
<input type="date" id="rentaluntil-edit-field" class="form-control"
|
||||
name="rental_until" value="{{ old('rental_start') }}"
|
||||
min="{{ date('Y-m-d') }}" placeholder="Masukan Tanggal Sampai"
|
||||
required />
|
||||
<div class="invalid-feedback">
|
||||
Masukan Tanggal Sampai
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="landname-edit-field" class="form-label">Nama Lahan</label>
|
||||
<input type="text" id="landname-edit-field" class="form-control" name="land_name"
|
||||
value="{{ old('land_name') }}" placeholder="Masukan Nama Lahan" required />
|
||||
<div class="invalid-feedback">
|
||||
Masukan Nama Lahan
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="status-edit-field" class="form-label">Deskripsi</label>
|
||||
<textarea name="description" id="status-edit-field" rows="5" placeholder="Masukan Deskripsi"
|
||||
class="form-control" required>{{ old('description') }}</textarea>
|
||||
<div class="mb-3">
|
||||
<label for="province-edit-field" class="form-label">Provinsi</label>
|
||||
<select name="province_id" id="province-edit-field" class="form-control" required
|
||||
onchange="getRegencies(this.value)">
|
||||
<option value="" selected disabled>Pilih Provinsi</option>
|
||||
@foreach ($provinces as $province)
|
||||
<option value="{{ $province->id }}"
|
||||
{{ old('province_id') == $province->id ? 'selected' : '' }}>
|
||||
{{ $province->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<div class="invalid-feedback">
|
||||
Harap Pilih Provinsi
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
||||
<div class="mb-3" id="regency-edit-container">
|
||||
<label for="regency-edit-field" class="form-label">Kabupaten atau Kota</label>
|
||||
<select name="regency_id" id="regency-edit-field" class="form-control" required
|
||||
onchange="getDistricts(this.value)">
|
||||
<option value="" selected disabled>Pilih Kabupaten atau Kota</option>
|
||||
</select>
|
||||
<div class="invalid-feedback">
|
||||
Harap Pilih Kabupaten atau Kota
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3" id="district-edit-container">
|
||||
<label for="district-edit-field" class="form-label">Kecamatan</label>
|
||||
<select name="district_id" id="district-edit-field" class="form-control" required
|
||||
onchange="showmap(this.value)">
|
||||
<option value="" selected disabled>Pilih Kecamatan</option>
|
||||
</select>
|
||||
<div class="invalid-feedback">
|
||||
Harap Pilih Kecamatan
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="loading-edit" class="text-center" style="display: none">
|
||||
<div class="spinner-border text-primary" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="map-edit-container">
|
||||
<label for="map-edit" class="form-label">Lokasi</label>
|
||||
<div id="map-edit"></div>
|
||||
|
||||
<div class="mt-3">
|
||||
<input type="hidden" name="lat" id="lat-edit" class="form-control"
|
||||
readonly>
|
||||
<input type="hidden" name="lng" id="lng-edit" class="form-control"
|
||||
readonly>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer" id="edit-footer">
|
||||
<div class="hstack gap-2 justify-content-end">
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Tutup</button>
|
||||
<button type="submit" class="btn btn-success" id="add-btn">Ubah</button>
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])->name('auth.logout');
|
||||
|
||||
Route::prefix('location')->controller(LocationController::class)->name('location.')->group(function () {
|
||||
Route::get('/get-province', 'getProvinces')->name('get_provinces');
|
||||
Route::get('/get-regency/{id}', 'getRegencies')->name('get_regencies');
|
||||
Route::get('/get-district/{id}', 'getDistricts')->name('get_districts');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue