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.
220 lines
10 KiB
220 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/device/' + id, |
|
type: 'GET', |
|
dataType: 'json', |
|
success: function(res) { |
|
// console.log(res.data) |
|
|
|
$('#equipment_serialnumber_edit').val(res.data.serialnumber) |
|
$('#equipment_videonumber_edit').val(res.data.videonumber) |
|
$('#equipment_brand_edit').val(res.data.brand) |
|
$('#equipment_model_edit').val(res.data.model) |
|
$('#equipment_precinct_edit').val(res.data.precinct) |
|
$('#equipment_station_edit').val(res.data.station) |
|
$('#custodyunit_id').val(res.data.custodyunit_id) |
|
$('#assetownership_id').val(res.data.assetownership_id) |
|
$('#buydate_edit').val(res.data.buydate) |
|
$('#activatedate_edit').val(res.data.activatedate) |
|
$('#equipment_locationid_edit').val(res.data.locationid) |
|
$('#equipment_location_edit').val(res.data.location) |
|
// textarea text |
|
$('#equipment_remark_edit').text(res.data.comment) |
|
|
|
$('#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 ($('#equipment_serialnumber_edit').val() == '' || $('#equipment_location_edit').val() == '' || $( |
|
'#equipment_precinct_edit').val() == '' || $('#equipment_station_edit').val() == '') { |
|
Swal.fire({ |
|
icon: 'error', |
|
title: 'Error', |
|
text: '請填寫所有 * 必填欄位' |
|
}); |
|
return |
|
} |
|
// Perform Ajax request |
|
$.ajax({ |
|
url: `/api/itl/device/${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="equipment_serialnumber_edit">設備編號<span class="text-danger">*</span></label> |
|
<input type="text" class="form-control" id="equipment_serialnumber_edit" name="serialnumber"> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="equipment_location_edit">設置地點<span class="text-danger">*</span></label> |
|
<input type="text" class="form-control" id="equipment_location_edit" name="location"> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="equipment_precinct_edit">分局<span class="text-danger">*</span></label> |
|
<input type="text" class="form-control" id="equipment_precinct_edit" name="precinct" |
|
required> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="equipment_station_edit">派出所<span class="text-danger">*</span></label> |
|
<input type="text" class="form-control" id="equipment_station_edit" name="station" required> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="equipment_videonumber_edit">攝影機器號<span class="text-danger">*</span></label> |
|
<input type="text" class="form-control" id="equipment_videonumber_edit" |
|
name="videonumber"> |
|
</div> |
|
|
|
<div> |
|
<hr> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="equipment_brand_edit">廠牌</label> |
|
<input type="text" class="form-control" id="equipment_brand_edit" name="brand"> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="equipment_model_edit">型號</label> |
|
<input type="text" class="form-control" id="equipment_model_edit" name="model"> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="assetownership_id">財產所屬單位</label> |
|
<select class="form-control" name="assetownership_id" id="assetownership_id"> |
|
<option value="">請選擇</option> |
|
<option value="create">...新增</option> |
|
<option value="" disabled>────────────</option> |
|
@if (isset($assetownership)) |
|
@foreach ($assetownership as $item) |
|
<option value="{{ $item->id }}">{{ $item->name }}</option> |
|
@endforeach |
|
@endif |
|
</select> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="custodyunit_id">保管單位</label> |
|
<select class="form-control" name="custodyunit_id" id="custodyunit_id"> |
|
<option value="">請選擇</option> |
|
<option value="create">...新增</option> |
|
<option value="" disabled>────────────</option> |
|
@if (isset($custodyunit)) |
|
@foreach ($custodyunit as $item) |
|
<option value="{{ $item->id }}">{{ $item->name }}</option> |
|
@endforeach |
|
@endif |
|
</select> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="buydate_edit">購入日期</label> |
|
<input type="date" class="form-control" id="buydate_edit" name="buydate"> |
|
</div> |
|
<div class="form-group col-3"> |
|
<label for="activatedate_edit">啟用日期</label> |
|
<input type="date" class="form-control" id="activatedate_edit" name="activatedate"> |
|
</div> |
|
|
|
|
|
<div class="form-group col-3"> |
|
<label for="equipment_locationid_edit">地點編號</label> |
|
<input type="text" class="form-control" id="equipment_locationid_edit" name="locationid"> |
|
</div> |
|
<div class="form-group col-12"> |
|
<label for="equipment_remark_edit">備註</label> |
|
<textarea class="form-control" name="comment" id="equipment_remark_edit" cols="30" rows="3"></textarea> |
|
</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>
|
|
|