This commit is contained in:
pbao9
2026-02-03 11:07:47 +07:00
parent 0f9b6ffef2
commit 6178a76eee
18 changed files with 347 additions and 420 deletions
@@ -24,54 +24,45 @@
@push('custom-scripts')
<script>
$(document).ready(function () {
// Prevent multiple initializations using namespace
if (window.vcenterComponentInitialized) {
return;
}
window.vcenterComponentInitialized = true;
// Prevent multiple initializations using namespace
if (window.vcenterComponentInitialized) {
return;
}
window.vcenterComponentInitialized = true;
$('.select2').select2({
width: '100%'
});
$('.select2').select2({
width: '100%'
});
const $vcenter = $('.vcenter_id');
const $datacenter = $('.datacenter_id');
const $host = $('.host_id');
const $vcenter = $('.vcenter_id');
const $datacenter = $('.datacenter_id');
const $host = $('.host_id');
// Disable datacenter and host initially
// Note: In edit view these might be inputs not selects, so this logic might need adjustment if intended for cascading selects.
// For now, keeping logic but ensuring it doesn't break if elements aren't selects.
if ($datacenter.is('select')) {
$datacenter.prop('disabled', true);
}
if ($host.is('select')) {
$host.prop('disabled', true);
}
// Remove existing event handlers and bind new ones with namespace
$vcenter.off('change.vcenterComponent').on('change.vcenterComponent', function () {
const vcenterId = $(this).val();
// Reset and disable datacenter and host if they are selects
if ($datacenter.is('select')) {
$datacenter.html('<option value="">--- Chọn Datacenter ---</option>').prop('disabled', true);
$datacenter.prop('disabled', true);
}
if ($host.is('select')) {
$host.html('<option value="">--- Chọn Host ---</option>').prop('disabled', true);
$host.prop('disabled', true);
}
// Enable datacenter if vcenter is selected
if (vcenterId) {
$vcenter.off('change.vcenterComponent').on('change.vcenterComponent', function () {
const vcenterId = $(this).val();
if ($datacenter.is('select')) {
$datacenter.html('<option value="">--- Chọn Datacenter ---</option>').prop('disabled', true);
}
if ($host.is('select')) {
$host.html('<option value="">--- Chọn Host ---</option>').prop('disabled', true);
}
if (vcenterId) {
if ($datacenter.is('select')) $datacenter.prop('disabled', false);
}
});
if ($vcenter.val()) {
if ($datacenter.is('select')) $datacenter.prop('disabled', false);
}
});
// Trigger initial state
if ($vcenter.val()) {
if ($datacenter.is('select')) $datacenter.prop('disabled', false);
}
});
</script>
@endpush
@endpush