You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
227 lines
10 KiB
227 lines
10 KiB
@section('css') |
|
@parent |
|
<style> |
|
.modal-xl { |
|
max-width: 1140px; |
|
} |
|
</style> |
|
@stop |
|
|
|
@section('js') |
|
@parent |
|
<script> |
|
function EquipmentEditPopUp(id) { |
|
lastModal = 'equipmentEditPopUp' |
|
document.getElementById("equipmentEdit").reset(); |
|
// reloadUnit() |
|
$.ajax({ |
|
url: '/api/itl/road/' + id, |
|
type: 'GET', |
|
dataType: 'json', |
|
success: function(res) { |
|
// console.log(res.data) |
|
|
|
$('#start_num_edit').val(res.data.start_serialnumber) |
|
$('#end_num_edit').val(res.data.end_serialnumber) |
|
$('#location_name_edit').val(res.data.location) |
|
$('#distance_edit').val(res.data.distance) |
|
$('#limit_speed_edit').val(res.data.limit_speed) |
|
$('#outlaw_speed_edit').val(res.data.outlaw_speed) |
|
$('#count_alert_edit').val(res.data.count_alert) |
|
$('#speed_alert_edit').val(res.data.speed_alert) |
|
$('#location_id_edit').val(res.data.location_id) |
|
$('#cert_edit').val(res.data.certificatenumber) |
|
$('#start_cert_edit').val(res.data.start_cert) |
|
$('#end_cert_edit').val(res.data.end_cert) |
|
|
|
$('#saveBtn').attr('onclick', `updateEquipment(${id})`) |
|
$('#equipmentEditPopUp').modal('show') |
|
}, |
|
error: function(err) { |
|
console.log(err) |
|
} |
|
}) |
|
|
|
} |
|
|
|
function updateEquipment(id) { |
|
// Get form data |
|
let formData = $("#equipmentEdit").serializeArray(); |
|
// 如果必填選項修改後為空 則不允許送出 |
|
if ($('#start_num_edit').val() == '' || $('#end_num_edit').val() == '' || $('#outlaw_speed_edit').val() == '' || $('#location_name_edit').val() == '' |
|
|| $('#distance_edit').val() == '' || $('#limit_speed_edit').val() == '' || $('#location_id_edit').val() == '' |
|
|| $('#start_cert_edit').val() == '' || $('#end_cert_edit').val() == '') { |
|
Swal.fire({ |
|
icon: 'error', |
|
title: 'Error', |
|
text: '請填寫所有 * 必填欄位' |
|
}); |
|
return |
|
} |
|
// 起始機號與結束機號不可相同 |
|
if ($('#start_num_edit').val() == $('#end_num_edit').val()) { |
|
Swal.fire({ |
|
icon: 'error', |
|
title: 'Error', |
|
text: '起始機號與結束機號不可相同' |
|
}); |
|
return |
|
} |
|
// 起始日期不可大於結束日期 |
|
if ($('#start_cert_edit').val() > $('#end_cert_edit').val()) { |
|
Swal.fire({ |
|
icon: 'error', |
|
title: 'Error', |
|
text: '證書起始日不可大於證書到期日' |
|
}); |
|
return |
|
} |
|
// Perform Ajax request |
|
$.ajax({ |
|
url: `/api/itl/road/${id}`, // Replace with your actual endpoint |
|
type: "PUT", |
|
data: formData, |
|
success: function(response) { |
|
// Check response and show appropriate message |
|
if (response.success) { |
|
// Show success alert |
|
Swal.fire({ |
|
icon: 'success', |
|
title: 'Success', |
|
text: response.message |
|
}); |
|
// Close the modal |
|
$("#equipmentEditPopUp").modal("hide"); |
|
equipmentTable.ajax.reload(null, false); |
|
} else { |
|
// Show error alert with the error message |
|
Swal.fire({ |
|
icon: 'error', |
|
title: 'Error', |
|
text: response.message |
|
}); |
|
} |
|
}, |
|
error: function(xhr, status, error) { |
|
// Show error alert with the error details |
|
Swal.fire({ |
|
icon: 'error', |
|
title: 'Error', |
|
text: 'An error occurred. Please try again.' |
|
}); |
|
} |
|
}); |
|
} |
|
// assetownership_id on change |
|
$('#assetownership_id').on('change', function() { |
|
// console.log($(this).val()) |
|
if ($(this).val() == 'create') { |
|
unitPopUp('assetownership') |
|
$(this).val('') |
|
} |
|
}) |
|
|
|
// custodyunit_id on change |
|
$('#custodyunit_id').on('change', function() { |
|
if ($(this).val() == 'create') { |
|
unitPopUp('custodyunit') |
|
$(this).val('') |
|
} |
|
}) |
|
</script> |
|
|
|
@endsection |
|
<!-- Modal --> |
|
|
|
<div class="modal fade" id="equipmentEditPopUp" tabindex="-1" aria-labelledby="equipmentEditPopUpLabel" aria-modal="true" |
|
role="dialog"> |
|
<div class="modal-dialog modal-xl"> |
|
<div class="modal-content"> |
|
<div class="modal-header"> |
|
<h5 class="modal-title h4" id="equipmentEditPopUpLabel">設備管理</h5> |
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
|
</div> |
|
<div class="modal-body"> |
|
<form id="equipmentEdit" class="row"> |
|
<!-- Your form fields here --> |
|
<div class="form-group col-3"> |
|
<label for="start_num_edit">入口處編號<span class="text-danger">*</span></label> |
|
<select class="form-select" id="start_num_edit" name="start_num" disabled> |
|
<option value="">請選擇</option> |
|
@if (isset($location)) |
|
@foreach ($location as $item) |
|
<option value="{{ $item->id }}">[{{ $item->serialnumber }}] {{ $item->location }}</option> |
|
@endforeach |
|
@endif |
|
</select> |
|
</div> |
|
|
|
<div class="form-group col-3"> |
|
<label for="end_num_edit">出口處編號<span class="text-danger">*</span></label> |
|
<select class="form-select" id="end_num_edit" name="end_num" disabled> |
|
<option value="">請選擇</option> |
|
@if (isset($location)) |
|
@foreach ($location as $item) |
|
<option value="{{ $item->id }}">[{{ $item->serialnumber }}] {{ $item->location }}</option> |
|
@endforeach |
|
@endif |
|
</select> |
|
</div> |
|
|
|
<div class="form-group col-3"> |
|
<label for="location_name_edit">路段名稱<span class="text-danger">*</span></label> |
|
<input type="text" class="form-control" id="location_name_edit" name="location" disabled> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="distance_edit">距離<span class="text-danger">*</span></label> |
|
<input type="number" class="form-control" id="distance_edit" name="distance" disabled> |
|
</div> |
|
|
|
<div class="form-group col-3"> |
|
<label for="limit_speed_edit">限速<span class="text-danger">*</span></label> |
|
<input type="number" class="form-control" id="limit_speed_edit" name="limit_speed" disabled> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="outlaw_speed_edit">取締限速<span class="text-danger">*</span></label> |
|
<input type="number" class="form-control" id="outlaw_speed_edit" name="outlaw_speed"> |
|
</div> |
|
|
|
<div class="form-group col-3"> |
|
<label for="count_alert_edit">違規數異常警示</label> |
|
<input type="number" class="form-control" id="count_alert_edit" name="count_alert"> |
|
</div> |
|
|
|
<div class="form-group col-3"> |
|
<label for="speed_alert_edit">超速異常警示</label> |
|
<input type="number" class="form-control" id="speed_alert_edit" name="speed_alert"> |
|
</div> |
|
|
|
<div class="form-group col-3"> |
|
<label for="location_id_edit">地點代碼<span class="text-danger">*</span></label> |
|
<input type="text" class="form-control" id="location_id_edit" name="location_id"> |
|
</div> |
|
|
|
<div class="form-group col-3"> |
|
<label for="cert_edit">合格證書<span class="text-danger">*</span></label> |
|
<input type="text" class="form-control" id="cert_edit" name="certificatenumber" disabled> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="start_cert_edit">證書起始日<span class="text-danger">*</span></label> |
|
<input type="date" class="form-control" id="start_cert_edit" name="start_cert" disabled> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="end_cert_edit">證書到期日<span class="text-danger">*</span></label> |
|
<input type="date" class="form-control" id="end_cert_edit" name="end_cert" disabled> |
|
</div> |
|
|
|
<div class="form-group col-12 text-center mt-3"> |
|
<button type="button" class="btn btn-primary" onclick="updateEquipment()" |
|
id="saveBtn">更新</button> |
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button> |
|
</div> |
|
|
|
</form> |
|
</div> |
|
</div> |
|
</div> |
|
</div>
|
|
|