Browse Source

Se agrego un control para que el serialnumber tenga una longuitud de 12/16 en javascript

Se cambio para que los campos ponserialnumberaux y serial number queden como readonly

Se paso el calculo del ponserialnumberaux y serialnumber a partir del identificador, del ONUAdmin al prepersist/preupdate de la entidad
gabriel 6 years ago
parent
commit
da3bb344c8

+ 4 - 79
src/FTTHBundle/Admin/ONUAdmin.php

@@ -209,11 +209,13 @@ class ONUAdmin extends WorkflowBaseAdmin
                 ->with('ONU')
                     ->add('serialNumber', null, array(
                         'attr' => array(
-                            'style' => 'text-transform: uppercase;'
+                            'style' => 'text-transform: uppercase;',
+                            'readonly' => 'readonly'
                         )))
                     ->add('ponSerialNumberAux', null, array(
                         'attr' => array(
-                            'style' => 'text-transform: uppercase;'
+                            'style' => 'text-transform: uppercase;',
+                            'readonly' => 'readonly'
                         )))
                     ->add('olt','hidden', array('attr' => array("hidden" => true)))
                     ->add('position')
@@ -620,7 +622,6 @@ class ONUAdmin extends WorkflowBaseAdmin
     public function preUpdate($onu)
     {
         $onu->setOlt($onu->getNap()->getOlt());
-        $this->correctSerialNumber($onu);
 
         if((boolean) $this->getForm()->get('tr069_exist')->getData()) {
             $ssid = ($this->getForm()->get('tr069_ssid')->getData()) ?? null;
@@ -650,82 +651,6 @@ class ONUAdmin extends WorkflowBaseAdmin
     public function prePersist($onu)
     {
         $onu->setOlt($onu->getNap()->getOlt());
-        $this->correctSerialNumber($onu);
-    }
-
-    public function correctSerialNumber($onu) {
-
-        $ponSerialNumber = $onu->getPonSerialNumber(); //Identificador
-
-        $serialNumber = $onu->getSerialNumber();
-        $ponSerialNumberAux = $onu->getPonSerialNumberAux();
-
-        if(strlen($ponSerialNumber) == 12 || strlen($ponSerialNumber) == 16) {
-
-            if(is_null($serialNumber) || empty($serialNumber)) {
-                if(strlen($ponSerialNumber) == 16) {
-                    // It is a serial number > set serial number
-                    $onu->setSerialNumber($ponSerialNumber);
-                } else {
-                    // It is a pon serial number > convert vendor id from string to hexa and set serial number
-                    $vendoId = $this->str2hex(substr($ponSerialNumber,0,4));
-                    $rest = substr($ponSerialNumber,4);
-                    $sn = strtolower($vendoId.$rest);
-                    $onu->setSerialNumber($sn);
-                }
-            }
-
-            if(is_null($ponSerialNumberAux) || empty($ponSerialNumberAux)) {
-                if(strlen($ponSerialNumber) == 16) {
-                    // It is a serial number > convert vendor id from hexa to string and set pon serial number
-                    $_vendor = substr($ponSerialNumber,0,8);
-                    $hex = strtoupper($_vendor);
-
-                    $isNumeric = true;
-                    for($i=0;$i<strlen($hex);$i+=2) {
-                        if(!is_numeric(substr($hex,$i,2))) {
-                            $isNumeric = false;
-                            break;
-                        }
-                    }
-                    if($isNumeric) { //hexa check
-                        $vendoId = $this->hex2str($hex);
-                        $rest = substr($ponSerialNumber,8);
-                        $psn = strtolower($vendoId.$rest);
-                        $onu->setPonSerialNumberAux($psn);
-                    } else {
-                        $onu->setPonSerialNumberAux($ponSerialNumber);
-                    }
-                } else {
-                    // It is a pon serial number > set pon serial number
-                    $onu->setPonSerialNumberAux($ponSerialNumber);
-                }
-            }
-        } else {
-            if(is_null($serialNumber) || empty($serialNumber))
-                $onu->setSerialNumber($ponSerialNumber);
-
-            if(is_null($ponSerialNumberAux) || empty($ponSerialNumberAux))
-                $onu->setPonSerialNumberAux($ponSerialNumber);
-        }
-    }
-
-    function hex2str($hex) {
-        $hex = strtoupper($hex);
-        $str = "";
-        for($i=0;$i<strlen($hex);$i+=2)
-            $str .= chr(hexdec(substr($hex,$i,2)));
-
-        return $str;
-    }
-
-    function str2hex($string){
-        $string = strtoupper($string);
-        $hex = "";
-        for ($i=0; $i < strlen($string); $i++)
-            $hex .= dechex(ord($string[$i]));
-
-        return $hex;
     }
 
     /**

+ 91 - 5
src/FTTHBundle/Entity/ONU.php

@@ -20,6 +20,7 @@ use JMS\Serializer\Annotation as JMS;
 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 use Symfony\Component\Validator\Constraints as Assert;
 use Symfony\Component\Workflow\Exception\ExceptionInterface;
+use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
 
 /**
  * ONU
@@ -34,6 +35,7 @@ use Symfony\Component\Workflow\Exception\ExceptionInterface;
  * @ValidatorAssert\Device
  *
  * @FTTHAssert\Position
+ * @HasLifecycleCallbacks
  */
 class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, SoftDeleteInterface
 {
@@ -708,7 +710,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
 
         return $this;
     }
-    
+
     /**
      * Get ponSerialNumberAux
      *
@@ -729,7 +731,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         $servicePort->setOnu($this);
         $servicePort->setOlt($this->olt);
         $this->servicePorts[] = $servicePort;
-        
+
         return $this;
     }
 
@@ -743,7 +745,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         $servicePort->setOnu(null);
         $servicePort->setOlt(null);
         $this->servicePorts->removeElement($servicePort);
-        
+
         return $this;
     }
 
@@ -767,7 +769,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
             $servicePort->setOlt($this->olt);
         }
         $this->servicePorts = $servicePorts;
-        
+
         return $this;
     }
 
@@ -1028,7 +1030,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
     {
         return $this->onuProfile;
     }
-    
+
     /**
      * @return string
      */
@@ -1039,4 +1041,88 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         }, $this->servicePorts->toArray()));
     }
 
+    /**
+     * @ORM\PrePersist()
+     */
+    public function prePersist()
+    {
+        $this->correctSerialNumber();
+    }
+
+    /**
+     * @ORM\PreUpdate()
+     */
+    public function preUpdate()
+    {
+        $this->correctSerialNumber();
+    }
+
+    public function correctSerialNumber() {
+
+        $ponSerialNumber = $this->getPonSerialNumber(); //Identificador
+
+        $serialNumber = $this->getSerialNumber();
+        $ponSerialNumberAux = $this->getPonSerialNumberAux();
+
+        if(strlen($ponSerialNumber) == 12 || strlen($ponSerialNumber) == 16) {
+
+            if(is_null($serialNumber) || empty($serialNumber)) {
+                if(strlen($ponSerialNumber) == 16) {
+                    // It is a serial number > set serial number
+                    $this->setSerialNumber($ponSerialNumber);
+                } else {
+                    // It is a pon serial number > convert vendor id from string to hexa and set serial number
+                    $vendoId = $this->str2hex(substr($ponSerialNumber,0,4));
+                    $rest = substr($ponSerialNumber,4);
+                    $sn = strtolower($vendoId.$rest);
+                    $this->setSerialNumber($sn);
+                }
+            }
+
+            if(is_null($ponSerialNumberAux) || empty($ponSerialNumberAux)) {
+                if(strlen($ponSerialNumber) == 16) {
+                    // It is a serial number > convert vendor id from hexa to string and set pon serial number
+                    $_vendor = substr($ponSerialNumber,0,8);
+                    $hex = strtoupper($_vendor);
+
+                    $isNumeric = true;
+                    for($i=0;$i<strlen($hex);$i+=2) {
+                        if(!is_numeric(substr($hex,$i,2))) {
+                            $isNumeric = false;
+                            break;
+                        }
+                    }
+                    if($isNumeric) { //hexa check
+                        $vendoId = $this->hex2str($hex);
+                        $rest = substr($ponSerialNumber,8);
+                        $psn = strtolower($vendoId.$rest);
+                        $this->setPonSerialNumberAux($psn);
+                    } else {
+                        $this->setPonSerialNumberAux($ponSerialNumber);
+                    }
+                } else {
+                    // It is a pon serial number > set pon serial number
+                    $this->setPonSerialNumberAux($ponSerialNumber);
+                }
+            }
+        }
+    }
+
+    function hex2str($hex) {
+        $hex = strtoupper($hex);
+        $str = "";
+        for($i=0;$i<strlen($hex);$i+=2)
+            $str .= chr(hexdec(substr($hex,$i,2)));
+
+        return $str;
+    }
+
+    function str2hex($string){
+        $string = strtoupper($string);
+        $hex = "";
+        for ($i=0; $i < strlen($string); $i++)
+            $hex .= dechex(ord($string[$i]));
+
+        return $hex;
+    }
 }

+ 36 - 20
src/FTTHBundle/Resources/views/ONU/form.html.twig

@@ -4,12 +4,14 @@
 {% block formactions %}
     {{ parent() }}
 
-    <script src="{{ asset('bundles/baseadmin') }}/ace_editor/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
-    <script src="{{ asset('bundles/baseadmin') }}/ace_editor/textarea-as-ace-editor.js" type="text/javascript" charset="utf-8"></script>
+    <script src="{{ asset('bundles/baseadmin') }}/ace_editor/src-noconflict/ace.js" type="text/javascript"
+            charset="utf-8"></script>
+    <script src="{{ asset('bundles/baseadmin') }}/ace_editor/textarea-as-ace-editor.js" type="text/javascript"
+            charset="utf-8"></script>
 
     <style type="text/css" media="screen">
         .ace_editor {
-            height: 450px!important;
+            height: 450px !important;
             border: 1px solid #CCCCCC;
         }
     </style>
@@ -49,8 +51,7 @@
 
         // Al seleccionar una OLT se muestra la config avanzada
         // según la marca del modelo
-        function ajax_olt_model_mark()
-        {
+        function ajax_olt_model_mark() {
             var olt = $('[id="{{ admin.uniqid }}_olt"]').val();
             $.ajax({
                 url: '{{ path('ajax_olt_model_mark') }}',
@@ -60,7 +61,7 @@
                 },
                 success: function (result) {
                     $('.olt_mark').addClass('hidden');
-                    $('.'+result.mark).removeClass('hidden');
+                    $('.' + result.mark).removeClass('hidden');
 
                     $('.zte_v4').addClass('hidden');
                     // El modelo de OLT es ZTE V4, entonces muestro los campos
@@ -70,16 +71,15 @@
                 }
             });
         }
-        
+
         // ajax_olt_model_mark();
         {#$('[id="{{ admin.uniqid }}_olt"]').on('click', ajax_olt_model_mark);#}
-        
+
         {# Se chequea la position si esta libre, según el nap seleccionado #}
-        
+
         $('#{{ admin.uniqid ~ "_position" }}').on('change', checkPosition);
-        
-        function checkPosition()
-        {
+
+        function checkPosition() {
             $('#{{ admin.uniqid ~ "_position" }}').parent().find('#error_position').remove();
             var $position = $('#{{ admin.uniqid ~ "_position" }}').val();
             var $nap = $('#{{ admin.uniqid ~ "_nap" }}').val();
@@ -97,7 +97,7 @@
                             message = '{{ 'error_onu_position'|trans({}, 'FTTHBundle') }}';
                             div = '<div id="error_position" class="alert alert-danger alert-dismissable">\
                             <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>'
-                            + message + '</div>'
+                                + message + '</div>'
                             $('#{{ admin.uniqid ~ "_position" }}').parent().append(div);
                         }
                     }
@@ -241,12 +241,11 @@
                 });
             }
         }
-        
-        
+
+
         // Al cambiar un valor de ONU Template se envía como parámetro el id
         // y se recarga la página
-        function onuTemplateReloadPage()
-        {
+        function onuTemplateReloadPage() {
             if ($('#{{ admin.uniqid  ~ "_onuTemplate" }}')) {
                 var onuTemplateId = $('#{{ admin.uniqid  ~ "_onuTemplate" }}').val();
                 var url = '{{ path('admin_ftth_onu_create') }}';
@@ -266,11 +265,11 @@
                 }
             }
         }
+
         $('#{{ admin.uniqid  ~ "_onuTemplate" }}').on('change', onuTemplateReloadPage);
 
         // Al seleccionar un NAP se selecciona la OLT y se debe cargar la configuracion avanzada
-        function ajax_nap_olt()
-        {
+        function ajax_nap_olt() {
             var nap = $('[id="{{ admin.uniqid }}_nap"]').val();
             $.ajax({
                 url: '{{ path('ajax_nap_olt') }}',
@@ -280,7 +279,7 @@
                     id: nap
                 },
                 success: function (result) {
-                    if(result && result.result > 0){
+                    if (result && result.result > 0) {
                         $('[id="{{ admin.uniqid }}_olt"]').val(result.result);
                         ajax_olt_model_mark();
                     } else {
@@ -294,6 +293,23 @@
         $('[id="{{ admin.uniqid }}_nap"]').on('click', ajax_nap_olt);
         ajax_nap_olt();
         ajax_olt_model_mark();
+
+        function checkLengthPonSerialNumber() {
+            var obj = $('[id="{{ admin.uniqid }}_ponSerialNumber"]');
+            var objClas = $('[required="required"][class*="form-group"][id*="ponSerialNumber"]');
+            var pon = obj.val();
+            var claseError = " has-error";
+            var clas = objClas.attr('class');
+            if (pon && (pon.length == 12 || pon.length == 16)) {
+                objClas.attr('class', objClas.attr('class').replace(claseError, ""));
+            } else {
+                // addClassError(id, claseError);
+                if (clas.indexOf(claseError) === -1) {
+                    objClas.attr('class', clas + claseError);
+                }
+            }
+        }
+        $('[id="{{ admin.uniqid }}_ponSerialNumber"]').on('blur', checkLengthPonSerialNumber);
     </script>
 
 {% endblock %}