mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 05:21:55 -06:00
Toggle VLANGroup scope selector fields
This commit is contained in:
parent
d82f2e289a
commit
6287f75e67
@ -1141,7 +1141,8 @@ class IPAddressFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterFo
|
|||||||
class VLANGroupForm(BootstrapMixin, CustomFieldModelForm):
|
class VLANGroupForm(BootstrapMixin, CustomFieldModelForm):
|
||||||
scope_type = ContentTypeChoiceField(
|
scope_type = ContentTypeChoiceField(
|
||||||
queryset=ContentType.objects.filter(model__in=VLANGROUP_SCOPE_TYPES),
|
queryset=ContentType.objects.filter(model__in=VLANGROUP_SCOPE_TYPES),
|
||||||
required=False
|
required=False,
|
||||||
|
widget=StaticSelect2
|
||||||
)
|
)
|
||||||
region = DynamicModelChoiceField(
|
region = DynamicModelChoiceField(
|
||||||
queryset=Region.objects.all(),
|
queryset=Region.objects.all(),
|
||||||
|
@ -35,3 +35,79 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block javascript %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
// TODO: Employ form field attrs to clean up this mess
|
||||||
|
let scope_type = $('#id_scope_type');
|
||||||
|
scope_type.change(function() {
|
||||||
|
let label = this.options[this.selectedIndex].text;
|
||||||
|
if (label.endsWith('region')) {
|
||||||
|
$('#id_region').parents('.form-group').show();
|
||||||
|
$('#id_sitegroup').parents('.form-group').hide();
|
||||||
|
$('#id_site').parents('.form-group').hide();
|
||||||
|
$('#id_location').parents('.form-group').hide();
|
||||||
|
$('#id_rack').parents('.form-group').hide();
|
||||||
|
$('#id_clustergroup').parents('.form-group').hide();
|
||||||
|
$('#id_cluster').parents('.form-group').hide();
|
||||||
|
} else if (label.endsWith('site group')) {
|
||||||
|
$('#id_region').parents('.form-group').hide();
|
||||||
|
$('#id_sitegroup').parents('.form-group').show();
|
||||||
|
$('#id_site').parents('.form-group').hide();
|
||||||
|
$('#id_location').parents('.form-group').hide();
|
||||||
|
$('#id_rack').parents('.form-group').hide();
|
||||||
|
$('#id_clustergroup').parents('.form-group').hide();
|
||||||
|
$('#id_cluster').parents('.form-group').hide();
|
||||||
|
} else if (label.endsWith('site')) {
|
||||||
|
$('#id_region').parents('.form-group').show();
|
||||||
|
$('#id_sitegroup').parents('.form-group').show();
|
||||||
|
$('#id_site').parents('.form-group').show();
|
||||||
|
$('#id_location').parents('.form-group').hide();
|
||||||
|
$('#id_rack').parents('.form-group').hide();
|
||||||
|
$('#id_clustergroup').parents('.form-group').hide();
|
||||||
|
$('#id_cluster').parents('.form-group').hide();
|
||||||
|
} else if (label.endsWith('location')) {
|
||||||
|
$('#id_region').parents('.form-group').show();
|
||||||
|
$('#id_sitegroup').parents('.form-group').show();
|
||||||
|
$('#id_site').parents('.form-group').show();
|
||||||
|
$('#id_location').parents('.form-group').show();
|
||||||
|
$('#id_rack').parents('.form-group').hide();
|
||||||
|
$('#id_clustergroup').parents('.form-group').hide();
|
||||||
|
$('#id_cluster').parents('.form-group').hide();
|
||||||
|
} else if (label.endsWith('rack')) {
|
||||||
|
$('#id_region').parents('.form-group').show();
|
||||||
|
$('#id_sitegroup').parents('.form-group').show();
|
||||||
|
$('#id_site').parents('.form-group').show();
|
||||||
|
$('#id_location').parents('.form-group').show();
|
||||||
|
$('#id_rack').parents('.form-group').show();
|
||||||
|
$('#id_clustergroup').parents('.form-group').hide();
|
||||||
|
$('#id_cluster').parents('.form-group').hide();
|
||||||
|
} else if (label.endsWith('cluster group')) {
|
||||||
|
$('#id_region').parents('.form-group').hide();
|
||||||
|
$('#id_sitegroup').parents('.form-group').hide();
|
||||||
|
$('#id_site').parents('.form-group').hide();
|
||||||
|
$('#id_location').parents('.form-group').hide();
|
||||||
|
$('#id_rack').parents('.form-group').hide();
|
||||||
|
$('#id_clustergroup').parents('.form-group').show();
|
||||||
|
$('#id_cluster').parents('.form-group').hide();
|
||||||
|
} else if (label.endsWith('cluster')) {
|
||||||
|
$('#id_region').parents('.form-group').hide();
|
||||||
|
$('#id_sitegroup').parents('.form-group').hide();
|
||||||
|
$('#id_site').parents('.form-group').hide();
|
||||||
|
$('#id_location').parents('.form-group').hide();
|
||||||
|
$('#id_rack').parents('.form-group').hide();
|
||||||
|
$('#id_clustergroup').parents('.form-group').show();
|
||||||
|
$('#id_cluster').parents('.form-group').show();
|
||||||
|
} else {
|
||||||
|
$('#id_region').parents('.form-group').hide();
|
||||||
|
$('#id_sitegroup').parents('.form-group').hide();
|
||||||
|
$('#id_site').parents('.form-group').hide();
|
||||||
|
$('#id_location').parents('.form-group').hide();
|
||||||
|
$('#id_rack').parents('.form-group').hide();
|
||||||
|
$('#id_clustergroup').parents('.form-group').hide();
|
||||||
|
$('#id_cluster').parents('.form-group').hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
scope_type.change();
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user