浏览代码

FD3-748 Se arregla el listado de FixedIPs

Maximiliano Schvindt 6 年之前
父节点
当前提交
dd31fb0985
共有 1 个文件被更改,包括 34 次插入18 次删除
  1. 34 18
      src/HostBundle/Resources/views/CRUD/edit.html.twig

+ 34 - 18
src/HostBundle/Resources/views/CRUD/edit.html.twig

@@ -5,9 +5,19 @@
 {{ 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);
@@ -35,25 +45,31 @@ function updateFixedIPs()
     var $hostTypeField = $("select[id$='hostType'] :selected");
     var $hostTypeId = $hostTypeField.val();
     
-    if ($hostTypeId) {
-        $.ajax({
-            url: '{{ path ('post_host_ipv4_range') }}',
-            type: 'POST',
-            data: {
-                id: $hostTypeId,
-            },
-            success: function(data) {
-                $('select[id$="_fixed_address"]').html('<option value=""></option>');
-                if (data.ips) {
-                    $.each(data.ips, function (index, value) {
-                        $('select[id$="_fixed_address"]').append('<option value="' + value + '">' + value + '</option>');
-                    });
-                }
-                
-                return false;
-            },
-        });
+    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>