Commit dbcf0672 authored by Maël Kervella's avatar Maël Kervella Committed by Pierre Cadart

Gère l'affichage dynamique des choix d'ip en fonction du machine_type

Enlève toutes les options au loading de la page si JS activé
Ajoute des options quand le machine_type change grâce aux associations machien_type -> ip reçues
parent cd8d600a
......@@ -38,6 +38,30 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% bootstrap_form_errors domainform %}
{% endif %}
<script>
var type_to_ipv4 = {
type: [{% for type, iplist in type_to_ipv4.items %}"{{ type }}",{% endfor %}],
iplist: [{% for type, iplist in type_to_ipv4.items %}
[{% for ip in iplist %} {id:"{{ ip.id }}", ip:"{{ ip.ipv4 }}"},
{% endfor %}], {% endfor %}
]
}
$(document).ready(function() {
$("#id_ipv4").html("<option value='' selected='selected'>Choisisez un type de machine d'abord</options>");
$("#id_type").change(function() {
var val = $(this).val();
var options = "<option value='' selected='selected'>Assignation automatique de l'ipv4</option>";
for (var i = 0; i < type_to_ipv4.type.length; i++) {
if (type_to_ipv4.type[i] == val) {
for (var j = 0; j < type_to_ipv4.iplist[i].length; j++) {
options += "<option value='"+type_to_ipv4.iplist[i][j].id+"'>"+type_to_ipv4.iplist[i][j].ip+"</option>";
}
}
}
$("#id_ipv4").html(options)
});
});
</script>
<form class="form" method="post">
{% csrf_token %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment