1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- {% extends "@SonataAdmin/CRUD/edit.html.twig" %}
- {% block javascripts %}
- {{ parent() }}
- <script type="text/javascript">
- var $fixedIP = false;
- var $initHostTypeId = false;
- $(document).ready(function() {
- {% if object.getFixedAddress() is not null or object.getFixedAddress() != "" %}
- $fixedIP = "{{object.getFixedAddress()}}";
- {% endif %}
-
- {% if object.getHostType() is not null %}
- $initHostTypeId = {{object.getHostType().getId()}};
- {% endif %}
-
- showHostField();
- $("select[id$='hostType']").on('change', showHostField);
-
- });
- // Al seleccionar tipo Cablemodem oculto el campo Host
- // de lo contrario lo muestro y selecciono la primer option
- // luego actualizo las fixed IP según el tipo de host
- function showHostField()
- {
- var $hostTypeField = $("select[id$='hostType'] :selected");
- var $hostField = $("div.form-group[id$='host']");
- var $hostSelect = $("select[id$='host']");
-
- if ($hostTypeField.html() === 'Cablemodem') {
- if ($hostSelect.find("option[value='']").length == 0) {
- $hostSelect.prepend('<option value=""></option>');
- }
- $hostSelect.val(null).trigger('change');
-
- $hostField.hide();
- } else {
- if ($hostSelect.find("option[value='']").length) {
- $hostSelect.find("option[value='']").remove();
- }
- var val = $hostSelect.find("option").first().attr('value');
- $hostSelect.val(val).trigger('change');
-
- $hostField.show();
- }
-
- updateFixedIPs();
- return false;
- }
- function updateFixedIPs()
- {
- var $hostTypeField = $("select[id$='hostType'] :selected");
- var $hostTypeId = $hostTypeField.val();
-
- var option = '<option value=""></option>';
-
- if (($hostTypeId == $initHostTypeId) && $fixedIP != false) {
- option = `<option value="${$fixedIP}" selected>${$fixedIP}</option>`;
- $("div[id$='_fixed_address'] a span.select2-chosen").html($fixedIP);
- } else {
- $("div[id$='_fixed_address'] a span.select2-chosen").html('');
- }
- $.ajax({
- url: '{{ path ('post_host_ipv4_range') }}',
- type: 'POST',
- data: {id: $hostTypeId},
- success: function(data) {
-
- $('select[id$="_fixed_address"]').html(option);
- if (data.ips) {
- $.each(data.ips, function (index, value) {
- $('select[id$="_fixed_address"]').append('<option value="' + value + '">' + value + '</option>');
- });
- }
-
- return false;
- }
- });
- }
- </script>
- {% endblock javascripts %}
|