mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 04:58:16 -06:00
Merge disabled_indicator into option_attrs
This commit is contained in:
parent
87d92f8ee4
commit
f155e3c3d5
@ -30,7 +30,9 @@ def get_cable_form(a_type, b_type):
|
||||
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
|
||||
queryset=term_cls.objects.all(),
|
||||
label=term_cls._meta.verbose_name.title(),
|
||||
disabled_indicator='_occupied',
|
||||
option_attrs={
|
||||
'disabled': '_occupied',
|
||||
},
|
||||
query_params={
|
||||
'device_id': f'$termination_{cable_end}_device',
|
||||
'kind': 'physical', # Exclude virtual interfaces
|
||||
@ -52,7 +54,9 @@ def get_cable_form(a_type, b_type):
|
||||
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
|
||||
queryset=term_cls.objects.all(),
|
||||
label=_('Power Feed'),
|
||||
disabled_indicator='_occupied',
|
||||
option_attrs={
|
||||
'disabled': '_occupied',
|
||||
},
|
||||
query_params={
|
||||
'power_panel_id': f'$termination_{cable_end}_powerpanel',
|
||||
}
|
||||
@ -72,7 +76,9 @@ def get_cable_form(a_type, b_type):
|
||||
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
|
||||
queryset=term_cls.objects.all(),
|
||||
label=_('Side'),
|
||||
disabled_indicator='_occupied',
|
||||
option_attrs={
|
||||
'disabled': '_occupied',
|
||||
},
|
||||
query_params={
|
||||
'circuit_id': f'$termination_{cable_end}_circuit',
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/racks/{{rack}}/elevation/',
|
||||
attrs={
|
||||
'disabled-indicator': 'device',
|
||||
'ts-disabled-field': 'device',
|
||||
'data-dynamic-params': '[{"fieldName":"face","queryParam":"face"}]'
|
||||
},
|
||||
)
|
||||
|
BIN
netbox/project-static/dist/netbox.js
vendored
BIN
netbox/project-static/dist/netbox.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -34,6 +34,7 @@ export class DynamicTomSelect extends TomSelect {
|
||||
// Override any field names set as widget attributes
|
||||
this.valueField = this.input.getAttribute('ts-value-field') || this.settings.valueField;
|
||||
this.labelField = this.input.getAttribute('ts-label-field') || this.settings.labelField;
|
||||
this.disabledField = this.input.getAttribute('ts-disabled-field') || this.settings.disabledField;
|
||||
this.parentField = this.input.getAttribute('ts-parent-field') || null;
|
||||
this.depthField = this.input.getAttribute('ts-depth-field') || '_depth';
|
||||
this.descriptionField = this.input.getAttribute('ts-description-field') || 'description';
|
||||
@ -155,6 +156,9 @@ export class DynamicTomSelect extends TomSelect {
|
||||
let parent: Dict = data[this.parentField] as Dict;
|
||||
option['parent'] = parent[this.labelField];
|
||||
}
|
||||
if (data[this.disabledField]) {
|
||||
option['disabled'] = data[this.disabledField];
|
||||
}
|
||||
return option
|
||||
}
|
||||
|
||||
|
@ -49,10 +49,6 @@ export function initDynamicSelects(): void {
|
||||
// Disable local search (search is performed on the backend)
|
||||
searchField: [],
|
||||
|
||||
// Reference the disabled-indicator attr on the <select> element to determine
|
||||
// the name of the attribute which indicates whether an option should be disabled
|
||||
disabledField: select.getAttribute('disabled-indicator') || undefined,
|
||||
|
||||
// Load options from API immediately on focus
|
||||
preload: 'focus',
|
||||
|
||||
|
@ -63,7 +63,7 @@ class DynamicModelChoiceMixin:
|
||||
initial_params: A dictionary of child field references to use for selecting a parent field's initial value
|
||||
null_option: The string used to represent a null selection (if any)
|
||||
disabled_indicator: The name of the field which, if populated, will disable selection of the
|
||||
choice (optional)
|
||||
choice (DEPRECATED: pass `option_attrs={'disabled': '$fieldname'}` instead)
|
||||
option_attrs: A mapping of <option> template variables to their API data keys (optional)
|
||||
selector: Include an advanced object selection widget to assist the user in identifying the desired object
|
||||
"""
|
||||
@ -103,12 +103,13 @@ class DynamicModelChoiceMixin:
|
||||
for var, accessor in self.option_attrs.items():
|
||||
attrs[f'ts-{var}-field'] = accessor
|
||||
|
||||
# Set the disabled indicator, if any
|
||||
# TODO: Remove in v4.1
|
||||
# Legacy means of specifying the disabled indicator
|
||||
if self.disabled_indicator is not None:
|
||||
attrs['disabled-indicator'] = self.disabled_indicator
|
||||
attrs['ts-disabled-field'] = self.disabled_indicator
|
||||
|
||||
# Attach any static query parameters
|
||||
if (len(self.query_params) > 0):
|
||||
if len(self.query_params) > 0:
|
||||
widget.add_query_params(self.query_params)
|
||||
|
||||
# Include object selector?
|
||||
|
@ -108,7 +108,9 @@ class WirelessLinkForm(TenancyForm, NetBoxModelForm):
|
||||
'kind': 'wireless',
|
||||
'device_id': '$device_a',
|
||||
},
|
||||
disabled_indicator='_occupied',
|
||||
option_attrs={
|
||||
'disabled': '_occupied',
|
||||
},
|
||||
label=_('Interface')
|
||||
)
|
||||
site_b = DynamicModelChoiceField(
|
||||
@ -148,7 +150,9 @@ class WirelessLinkForm(TenancyForm, NetBoxModelForm):
|
||||
'kind': 'wireless',
|
||||
'device_id': '$device_b',
|
||||
},
|
||||
disabled_indicator='_occupied',
|
||||
option_attrs={
|
||||
'disabled': '_occupied',
|
||||
},
|
||||
label=_('Interface')
|
||||
)
|
||||
comments = CommentField()
|
||||
|
Loading…
Reference in New Issue
Block a user