Ver código fonte

#33 prevent form field edition from onu and nap entities

Espinoza Guillermo 6 anos atrás
pai
commit
c1a86001aa

+ 40 - 7
src/FTTHBundle/Admin/NAPAdmin.php

@@ -54,16 +54,45 @@ class NAPAdmin extends BaseAdmin
      * @param FormMapper $formMapper
      */
     protected function configureFormFields(FormMapper $formMapper)
-    {
+    {   
+        $id = $this->getSubject()->getId();
+        $disabled = is_null($id) ? false : 'disabled';
+        if ($id) {
+            $this->get('session')->getFlashBag()->add('warning', $this->trans('warning.disabled.fields'));
+        }
+
         $formMapper
             ->tab('default')
             ->with('')
             ->add('name')
-            ->add('parent')
-            ->add('olt')
-            ->add('slot', null, array('attr' => array('min' => 0)))
-            ->add('capacity', null, array('attr' => array('min' => 0)))
-            ->add('link', null, array('attr' => array('min' => 0)))
+            ->add('parent', null, [
+                'attr' => [
+                    'disabled' => $disabled,
+                ],
+            ])
+            ->add('olt', null, [
+                'attr' => [
+                    'disabled' => $disabled,
+                ],
+            ])
+            ->add('slot', null, [
+                'attr' => [
+                    'min' => 0,
+                    'disabled' => $disabled,
+                ],
+            ])
+            ->add('capacity', null, [
+                'attr' => [
+                    'min' => 0,
+                    'disabled' => $disabled,
+                ],
+            ])
+            ->add('link', null, [
+                'attr' => [
+                    'min' => 0,
+                    'disabled' => $disabled,
+                ],
+            ])
             ->add('address', 'text', [
                 'required' => false,
             ])
@@ -71,7 +100,11 @@ class NAPAdmin extends BaseAdmin
             ->end()
             ->tab('Avanzado')
             ->with('Config')
-            ->add('extraData')
+            ->add('extraData', null, [
+                'attr' => [
+                    'disabled' => $disabled,
+                ],
+            ])
             ->end()
             ->end();
     }

+ 45 - 10
src/FTTHBundle/Admin/ONUAdmin.php

@@ -116,6 +116,13 @@ class ONUAdmin extends WorkflowBaseAdmin
     protected function configureFormFields(FormMapper $formMapper)
     {
         $subject = $this->getSubject();
+        $id = $subject->getId();
+        $disabled = is_null($id) ? false : 'disabled';
+        $flashbag = $this->get('session')->getFlashBag();
+        if ($id) {
+            $flashbag->add('warning', $this->trans('warning.disabled.fields'));
+        }
+
         $em = $this->get("doctrine.orm.entity_manager");
 
         // busco el ONU template si se pasa como parámetro
@@ -143,7 +150,7 @@ class ONUAdmin extends WorkflowBaseAdmin
         ];
 
         // Editando la ONU o hay template base o pasado como parámetro
-        if ($subject->getId() || $template) {
+        if ($id || $template) {
             $olt = $subject->getOlt();
 
             // Según el modelo de OLT se muestran algunos campos específicos
@@ -162,7 +169,6 @@ class ONUAdmin extends WorkflowBaseAdmin
         }
 
         if ($template && $this->isCurrentRoute('create')) {
-            $flashbag = $this->get('session')->getFlashBag();
             $flashbag->add("warning", $this->trans("msg_use_template_onu_in_create_onu_ftth"));
         }
 
@@ -185,7 +191,8 @@ class ONUAdmin extends WorkflowBaseAdmin
                     ->add('clientId')
                     ->add('ponSerialNumber', null, array(
                         'attr' => array(
-                            'style' => 'text-transform: uppercase;'
+                            'style' => 'text-transform: uppercase;',
+                            'disabled' => $disabled,
                         )));
         if ($this->hasParameter('show.onu.activationCode') && $this->getParameter('show.onu.activationCode') == true) {
             $formMapper->add('activationCode');
@@ -210,8 +217,15 @@ class ONUAdmin extends WorkflowBaseAdmin
                                         return $value->getOlt()->getName();
                                     }
                                 },
-                            ))
-                    ->add('model')
+                                'attr' => [
+                                    'disabled' => $disabled,
+                                ],
+                                ))
+                    ->add('model', null, [
+                        'attr' => [
+                            'disabled' => $disabled,
+                        ],
+                    ])
                     ->add('comments')
                 ->end()
             ->end()
@@ -227,15 +241,29 @@ class ONUAdmin extends WorkflowBaseAdmin
                             'style' => 'text-transform: uppercase;',
                             'readonly' => 'readonly'
                         )))
-                    ->add('olt','hidden', array('attr' => array("hidden" => true)))
-                    ->add('position')
+                    ->add('olt','hidden', array(
+                        'attr' => array(
+                            "hidden" => true
+                    )))
+                    ->add('position', null, [
+                        'attr' => [
+                            'disabled' => $disabled,
+                        ],
+                    ])
                     ->add('ip')
-                    ->add('mac')
+                    ->add('mac', null, [
+                        'attr' => [
+                            'disabled' => $disabled,
+                        ],
+                    ])
                     ->add('radiusAuth', 'choice', [
                         'choices' => [
                             'Pon Serial Number' => 'psn',
                             'MAC Address' => 'mac'
-                        ]
+                        ],
+                        'attr' => [
+                            'disabled' => $disabled,
+                        ],
                     ])
                 ->end()
                 ->with('Huawei', ['class' => "col-md-12 {$hidden['Huawei']} olt_mark Huawei"])
@@ -245,10 +273,17 @@ class ONUAdmin extends WorkflowBaseAdmin
                         'allow_delete' => true,
                         'required' => false,
                         'by_reference' => false,
+                        'attr' => [
+                            'disabled' => $disabled,
+                        ],
                     ))
                 ->end()
                 ->with('ZTE', ['class' => "col-md-12 {$hidden['ZTE']} olt_mark ZTE"])
-                    ->add('vlan')
+                    ->add('vlan', null, [
+                        'attr' => [
+                            'disabled' => $disabled,
+                        ],
+                    ])
                     ->add('vlanProfile', null, $optionsZTEV4)
                     ->add('onuProfile', null, $optionsZTEV4)
                     ->add('trafficProfileIn')

+ 13 - 0
src/FTTHBundle/Form/NAPType.php

@@ -4,6 +4,8 @@ namespace FTTHBundle\Form;
 
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\Form\FormEvent;
+use Symfony\Component\Form\FormEvents;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 
 class NAPType extends AbstractType
@@ -21,6 +23,17 @@ class NAPType extends AbstractType
             ->add('tenancyId')
             ->add('capacity')
         ;
+
+        $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
+            $nap = $event->getData();
+            $form = $event->getForm();
+    
+            if ($nap && null !== $nap->getId()) {
+                $form->remove('olt');
+                $form->remove('capacity');
+                $form->remove('extraData');
+            }
+        });
     }
 
     /**

+ 17 - 0
src/FTTHBundle/Form/ONUType.php

@@ -105,6 +105,23 @@ class ONUType extends AbstractType
 
             }
         );
+
+        $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
+            $onu = $event->getData();
+            $form = $event->getForm();
+    
+            if ($onu && null !== $onu->getId()) {
+                $form->remove('mac');
+                $form->remove('serialNumber');
+                $form->remove('ponSerialNumber');
+                $form->remove('ponSerialNumberAux');
+                $form->remove('nap');
+                $form->remove('olt');
+                $form->remove('model');
+                $form->remove('position');
+                $form->remove('vlan');
+            }
+        });
     }
 
     /**

+ 2 - 1
src/FTTHBundle/Resources/translations/FTTHBundle.es.yml

@@ -413,4 +413,5 @@ Stats: Estadísticas
 Show stats: Mostrar detalle
 Set 0 to disable autodiscovery or set a x number to scan each x minutes the ONUs connected but without configuration: Seleccione 0 para deshabilitar la función 'Autodiscovery' o seleccione un valor x para escanear cada x minutos las ONUs conectadas pero sin configurar. 
 Profile to set the ONUs by autodiscovery: Perfíl con el cual se configurarán las ONUs mediante Autodiscovery.
-errors.duplicate_mac_key: La MAC se encuentra asignada a otra ONU
+errors.duplicate_mac_key: La MAC se encuentra asignada a otra ONU
+warning.disabled.fields: Para evitar problemas en la configuración, algunos campos fueron deshabilitados