mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-18 17:52:21 -06:00
Compare commits
1 Commits
20383-rack
...
21118-site
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8cbfe94fba |
@@ -722,9 +722,6 @@ class DeviceForm(TenancyForm, PrimaryModelForm):
|
|||||||
if position:
|
if position:
|
||||||
self.fields['position'].widget.choices = [(position, f'U{position}')]
|
self.fields['position'].widget.choices = [(position, f'U{position}')]
|
||||||
|
|
||||||
# Clear face field when rack is cleared
|
|
||||||
self.fields['face'].widget.attrs['ts-clear-field'] = 'rack'
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleForm(ModuleCommonForm, PrimaryModelForm):
|
class ModuleForm(ModuleCommonForm, PrimaryModelForm):
|
||||||
device = DynamicModelChoiceField(
|
device = DynamicModelChoiceField(
|
||||||
|
|||||||
@@ -211,12 +211,16 @@ def sync_cached_scope_fields(instance, created, **kwargs):
|
|||||||
for model in (Prefix, Cluster, WirelessLAN):
|
for model in (Prefix, Cluster, WirelessLAN):
|
||||||
qs = model.objects.filter(**filters)
|
qs = model.objects.filter(**filters)
|
||||||
|
|
||||||
|
# Bulk update cached fields to avoid O(N) performance issues with large datasets.
|
||||||
|
# This does not trigger post_save signals, avoiding spurious change log entries.
|
||||||
|
objects_to_update = []
|
||||||
for obj in qs:
|
for obj in qs:
|
||||||
# Recompute cache using the same logic as save()
|
# Recompute cache using the same logic as save()
|
||||||
obj.cache_related_objects()
|
obj.cache_related_objects()
|
||||||
obj.save(update_fields=[
|
objects_to_update.append(obj)
|
||||||
'_location',
|
|
||||||
'_site',
|
if objects_to_update:
|
||||||
'_site_group',
|
model.objects.bulk_update(
|
||||||
'_region',
|
objects_to_update,
|
||||||
])
|
['_location', '_site', '_site_group', '_region']
|
||||||
|
)
|
||||||
|
|||||||
8
netbox/project-static/dist/netbox.js
vendored
8
netbox/project-static/dist/netbox.js
vendored
File diff suppressed because one or more lines are too long
6
netbox/project-static/dist/netbox.js.map
vendored
6
netbox/project-static/dist/netbox.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -1,4 +1,3 @@
|
|||||||
import TomSelect from 'tom-select';
|
|
||||||
import { getElements } from '../util';
|
import { getElements } from '../util';
|
||||||
|
|
||||||
function handleFormSubmit(): void {
|
function handleFormSubmit(): void {
|
||||||
@@ -9,37 +8,6 @@ function handleFormSubmit(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize clear-field dependencies.
|
|
||||||
* When a field with ts-clear-field attribute's parent field is cleared, this field will also be cleared.
|
|
||||||
*/
|
|
||||||
function initClearFieldDependencies(): void {
|
|
||||||
// Find all fields with ts-clear-field attribute
|
|
||||||
for (const field of getElements<HTMLSelectElement>('[ts-clear-field]')) {
|
|
||||||
const parentFieldName = field.getAttribute('ts-clear-field');
|
|
||||||
if (!parentFieldName) continue;
|
|
||||||
|
|
||||||
// Find the parent field
|
|
||||||
const parentField = document.querySelector<HTMLSelectElement>(`[name="${parentFieldName}"]`);
|
|
||||||
if (!parentField) continue;
|
|
||||||
|
|
||||||
// Listen for changes on the parent field
|
|
||||||
parentField.addEventListener('change', () => {
|
|
||||||
// If parent field is cleared, also clear this dependent field
|
|
||||||
if (!parentField.value || parentField.value === '') {
|
|
||||||
// Check if this field uses TomSelect
|
|
||||||
const tomselect = (field as HTMLSelectElement & { tomselect?: TomSelect }).tomselect;
|
|
||||||
if (tomselect) {
|
|
||||||
tomselect.clear();
|
|
||||||
} else {
|
|
||||||
// Regular select field
|
|
||||||
field.value = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach event listeners to each form's submit/reset buttons.
|
* Attach event listeners to each form's submit/reset buttons.
|
||||||
*/
|
*/
|
||||||
@@ -60,7 +28,4 @@ export function initFormElements(): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize clear-field dependencies
|
|
||||||
initClearFieldDependencies();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user