8
0
Fork 0
mirror of https://gitlab.federez.net/re2o/re2o synced 2024-07-04 05:04:06 +00:00

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
This commit is contained in:
Maël Kervella 2017-10-02 23:54:53 +00:00 committed by Pierre Cadart
parent cd8d600ada
commit dbcf067296

View file

@ -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 %}