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.
168 lines
6.4 KiB
168 lines
6.4 KiB
@section('css') |
|
@parent |
|
<style> |
|
.modal-xl { |
|
max-width: 1140px; |
|
} |
|
</style> |
|
@stop |
|
|
|
@section('js') |
|
@parent |
|
<script> |
|
function reloadUnit(){ |
|
// 取得selcected option |
|
let custodyunit_id = $('#custodyunit_id').val() |
|
let assetownership_id = $('#assetownership_id').val() |
|
|
|
let custodyunit_id_create = $('#custodyunit_id_create').val() |
|
let assetownership_id_create = $('#assetownership_id_create').val() |
|
|
|
// 如果是create就 = '' |
|
if (custodyunit_id == 'create') { |
|
custodyunit_id = '' |
|
} |
|
if (assetownership_id == 'create') { |
|
assetownership_id = '' |
|
} |
|
if (custodyunit_id_create == 'create') { |
|
custodyunit_id_create = '' |
|
} |
|
if (assetownership_id_create == 'create') { |
|
assetownership_id_create = '' |
|
} |
|
|
|
$.ajax({ |
|
url: '/api/device/unit', |
|
type: 'GET', |
|
dataType: 'json', |
|
data: { |
|
type: 'custodyunit' |
|
}, |
|
success: function(res) { |
|
let html = '<option value="">請選擇</option><option value="create">...新增</option><option value="" disabled>────────────</option>' |
|
res.data.forEach(element => { |
|
html += `<option value="${element.id}">${element.name}</option>` |
|
}); |
|
$('#custodyunit_id').html(html) |
|
$('#custodyunit_id_create').html(html) |
|
$('#custodyunit_id').val(custodyunit_id) |
|
$('#custodyunit_id_create').val(custodyunit_id_create) |
|
}, |
|
error: function(err) { |
|
console.log(err) |
|
} |
|
}) |
|
|
|
$.ajax({ |
|
url: '/api/device/unit', |
|
type: 'GET', |
|
dataType: 'json', |
|
data: { |
|
type: 'assetownership' |
|
}, |
|
success: function(res) { |
|
let html = '<option value="">請選擇</option><option value="create">...新增</option><option value="" disabled>────────────</option>' |
|
res.data.forEach(element => { |
|
html += `<option value="${element.id}">${element.name}</option>` |
|
}); |
|
$('#assetownership_id').html(html) |
|
$('#assetownership_id_create').html(html) |
|
$('#assetownership_id').val(assetownership_id) |
|
$('#assetownership_id_create').val(assetownership_id_create) |
|
|
|
}, |
|
error: function(err) { |
|
console.log(err) |
|
} |
|
}) |
|
} |
|
|
|
function unitPopUp(type) { |
|
document.getElementById("unitForm").reset(); |
|
$(`#${lastModal}`).modal("hide"); |
|
$('#unitPopUpLabel').text(type == 'custodyunit' ? '新增保管單位' : '新增財產所屬單位') |
|
$('#createUnitBtn').attr('onclick', `updateUnit('${type}')`) |
|
$('#unitPopUp').modal('show') |
|
} |
|
|
|
function updateUnit(type) { |
|
// Get form data |
|
let formData = $("#unitForm").serialize(); |
|
formData += '&type=' + type |
|
|
|
// Perform Ajax request |
|
$.ajax({ |
|
url: `/api/device/unit`, // Replace with your actual endpoint |
|
type: "POST", |
|
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 |
|
$("#unitPopUp").modal("hide"); |
|
reloadUnit() |
|
// last modal show |
|
$(`#${lastModal}`).modal("show"); |
|
} 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.' |
|
}); |
|
} |
|
}); |
|
} |
|
$("#unitPopUp").on("hide.bs.modal", function() { |
|
// console.log("hey! How dare to close me !"); |
|
$(`#${lastModal}`).modal("show"); |
|
// your function after closing modal goes here |
|
}) |
|
</script> |
|
|
|
@endsection |
|
<!-- Modal --> |
|
|
|
<div class="modal fade" id="unitPopUp" tabindex="-1" aria-labelledby="unitPopUpLabel" 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="unitPopUpLabel"></h5> |
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
|
</div> |
|
<div class="modal-body"> |
|
<form id="unitForm" class="row"> |
|
|
|
<!-- Your form fields here --> |
|
<div class="form-group col-12"> |
|
<label for="unit_name">單位名稱</label> |
|
<input type="text" class="form-control" id="unit_name" name="name"> |
|
</div> |
|
|
|
|
|
<div class="form-group col-12 text-center mt-3"> |
|
<button type="button" class="btn btn-primary" id="createUnitBtn">新增</button> |
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button> |
|
</div> |
|
|
|
</form> |
|
</div> |
|
</div> |
|
</div> |
|
</div>
|
|
|