浏览代码

FD3-576 se muestra el campo host asociado solo si no es hostType Cablemodem

Espinoza Guillermo 7 年之前
父节点
当前提交
966081325e

+ 2 - 1
src/HostBundle/EventListener/AdminDHCPOption.php

@@ -55,8 +55,9 @@ class AdminDHCPOption
                     }
                     sort($freeIP);
                     $fieldOptions['choices'] = array_combine($freeIP, $freeIP);
+                    $fieldOptions['choice_translation_domain'] = false;
                     $mapper->add($opt, ChoiceType::class, $fieldOptions);
-                    unset($fieldOptions['choices']);
+                    unset($fieldOptions['choices'], $fieldOptions['choice_translation_domain']);
                     
                     continue;
                 }

+ 1 - 0
src/HostBundle/Resources/config/services.yml

@@ -7,6 +7,7 @@ services:
             - { name: sonata.admin, manager_type: orm, group: Host, label: Host, label_catalogue: HostBundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
         calls:
             - [setTranslationDomain, [HostBundle]]
+            - [setTemplate, [edit, "HostBundle:CRUD:edit.html.twig"]]
         public: true
 
     sonata.admin.host_type:

+ 33 - 0
src/HostBundle/Resources/views/CRUD/edit.html.twig

@@ -0,0 +1,33 @@
+{% extends "@SonataAdmin/CRUD/edit.html.twig" %}
+
+{% block javascripts %}
+
+{{ parent() }}
+
+<script type="text/javascript">
+
+$(document).ready(function() {
+
+    showHostField();
+
+    $("select[id$='hostType']").on('change', showHostField);
+
+});
+
+function showHostField()
+{
+    var $hostTypeField = $("select[id$='hostType'] :selected");
+    var $hostField = $("div.form-group[id$='host']");
+
+    if ($hostTypeField.html() === 'Cablemodem') {
+        $hostField.hide();
+    } else {
+        $hostField.show();
+    }
+
+    return false;
+}
+
+</script>
+
+{% endblock javascripts %}

+ 26 - 33
src/KeaBundle/Admin/Lease4Admin.php

@@ -55,36 +55,15 @@ class Lease4Admin extends BaseAdmin
     {
         $listMapper
             ->add('address')
-            ->add('hwaddr', null, [
-                'template' => 'BaseAdminBundle:CRUD:show_entity.html.twig',
-                'data' => [
-                    'class' => Host::class,
-                    'field' => 'mac',
-                    'action' => 'list',
-                ],
-            ])
             ->add('client_id')
-            ->add('pool', null, [
-                'template' => 'KeaBundle:CRUD:lease_pool_ipv4.html.twig',
-                'data' => [
-                    'class' => Pool::class,
-                    'field' => 'name',
-                ],
-            ])
-            ->add('subnet', null, [
-                'template' => 'KeaBundle:CRUD:lease_subnet_ipv4.html.twig',
-                'data' => [
-                    'class' => SubNet::class,
-                    'field' => 'address',
-                ],
-            ])
             ->add('valid_lifetime')
-            ->add('expire')
-            ->add('_action', null, array(
+            ->add('expire');
+            
+        $this->addFields($listMapper);
+            
+        $listMapper->add('_action', null, array(
                 'actions' => array(
                     'show' => array(),
-                    'edit' => array(),
-                    'delete' => array(),
                 ),
             ))
         ;
@@ -97,14 +76,31 @@ class Lease4Admin extends BaseAdmin
     {
         $showMapper
             ->add('address')
-            ->add('hwaddr')
             ->add('client_id')
+            ->add('valid_lifetime')
+            ->add('expire')
+        ;
+        
+        $this->addFields($showMapper, 'show');
+    }
+    
+    protected function addFields($mapper, $action = 'list')
+    {
+        $mapper
+            ->add('hwaddr', null, [
+                'template' => 'BaseAdminBundle:CRUD:show_entity.html.twig',
+                'data' => [
+                    'class' => Host::class,
+                    'field' => 'mac',
+                    'action' => $action,
+                ],
+            ])
             ->add('pool', null, [
                 'template' => 'KeaBundle:CRUD:lease_pool_ipv4.html.twig',
                 'data' => [
                     'class' => Pool::class,
                     'field' => 'name',
-                    'action' => 'show',
+                    'action' => $action,
                 ],
             ])
             ->add('subnet', null, [
@@ -112,12 +108,9 @@ class Lease4Admin extends BaseAdmin
                 'data' => [
                     'class' => SubNet::class,
                     'field' => 'address',
-                    'action' => 'show',
+                    'action' => $action,
                 ],
-            ])
-            ->add('valid_lifetime')
-            ->add('expire')
-        ;
+            ]);
     }
     
     /**