Parcourir la source

Closes #1414: Selecting a site from the rack filters automatically updates the available rack groups

Jeremy Stretch il y a 7 ans
Parent
commit
babe42ef35
1 fichiers modifiés avec 33 ajouts et 0 suppressions
  1. 33 0
      netbox/templates/dcim/rack_list.html

+ 33 - 0
netbox/templates/dcim/rack_list.html

@@ -25,3 +25,36 @@
     </div>
 </div>
 {% endblock %}
+
+{% block javascript %}
+<script type="text/javascript">
+$(document).ready(function() {
+
+    var site_list = $('#id_site');
+    var rack_group_list = $('#id_group_id');
+
+    // Update rack group and rack options based on selected site
+    site_list.change(function() {
+        var selected_sites = $(this).val();
+        if (selected_sites) {
+
+            // Update rack group options
+            rack_group_list.empty();
+            $.ajax({
+                url: netbox_api_path + 'dcim/rack-groups/?limit=500&site=' + selected_sites.join('&site='),
+                dataType: 'json',
+                success: function (response, status) {
+                    $.each(response["results"], function (index, group) {
+                        var option = $("<option></option>").attr("value", group.id).text(group.name);
+                        rack_group_list.append(option);
+                    });
+                }
+            });
+
+        }
+    });
+
+});
+</script>
+{% endblock %}
+