Changeset d76b369 in prototipo_portal_2018


Ignore:
Timestamp:
Aug 27, 2015, 11:48:26 AM (9 years ago)
Author:
antonioaraujob <antonioaraujob@…>
Branches:
master
Children:
6e6193c
Parents:
51b96ce
Message:

Modificaciones en archivo index.html para ejecutar tipo de firma de acuerdo al radioButton seleccionado: PDF o BDOC.

Location:
WebContent
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • WebContent/index.html

    r51b96ce rd76b369  
    205205            e.preventDefault();
    206206            var f = $(this);
    207            
    208             //alert("se presiono firmar")
     207            // inicio control de los botones radio en el formulario firmar (pdf,bdoc)-------------------------------------------- 
     208            //alert("manejo de JsonPDF");
     209           
     210        // FIRMA DE PDF
     211            if(document.SignFormat.optradio[0].checked) // chequea si el botón radio PDF esta seleccionado y entra a la sección en caso contrario va al otro if (botón radio BDOC)
     212                {
     213                alert(document.SignFormat.optradio[0].value);
     214                        //alert("se presiono firmar pdf")
    209215           
    210216            //var formData = new FormData(document.getElementById("verificar"));
     
    215221            //formData.append(f.attr("name"), $(this)[0].files[0]);
    216222           
     223            //alert("antes de ajax");
     224           
    217225            $.ajax({
    218                 //url: "https://192.168.12.125:8443/Murachi/0.1/archivos",               
    219                 url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos",
     226                url: "https://192.168.12.125:8443/Murachi/0.1/archivos",               
     227                //url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos",
    220228                type: "post",
    221229                dataType: "json",
     
    257265                                                                type: 'POST',
    258266                                                                contentType: 'application/json',                               
    259                                                                 //url:"https://192.168.12.125:8443/Murachi/0.1/archivos/pdfs",
    260                                                                 url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs",
     267                                                                url:"https://192.168.12.125:8443/Murachi/0.1/archivos/pdfs",
     268                                                                //url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs",
    261269                                                                dataType: "json",
    262270                                                                data: parameters,               
     
    280288                                                                                        type: 'POST',
    281289                                                                                        contentType: 'application/json',
    282                                                                                         //url:"https://192.168.12.125:8443/Murachi/0.1/archivos/pdfs/resenas",
    283                                                                                         url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas",
     290                                                                                        url:"https://192.168.12.125:8443/Murachi/0.1/archivos/pdfs/resenas",
     291                                                                                        //url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas",
    284292                                                                                        dataType: 'json',
    285293                                                                                        data: JSON.stringify({"signature":signature.hex}),
     
    293301                                                                                               
    294302                                                                                                alert("ver respuesta");
    295                                                                                                 //var linkToDownload = "<a href=\"https://192.168.12.125:8443/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>";
     303                                                                                                var linkToDownload = "<a href=\"https://192.168.12.125:8443/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>";
    296304                                                                                                //var linkToDownload = "<a href=\"https://172.16.137.11:8443/Murachi/murachi/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>";
    297                                                                                                 var linkToDownload = "<a href=\"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>";
     305                                                                                                //var linkToDownload = "<a href=\"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>";
    298306                                                                                                //alert(linkToDownload);
    299307                                                                                                document.getElementById("respuesta").innerHTML = linkToDownload; 
     
    362370                                        }
    363371            });
     372                }
     373       
     374        // FIRMA DE BDOC               
     375            if(document.SignFormat.optradio[1].checked) //chequea si el botón radio BDOC esta seleccionado y entra
     376            {
     377                alert(document.SignFormat.optradio[1].value);
     378                        //alert("se presiono firmar")
     379           
     380            //var formData = new FormData(document.getElementById("verificar"));
     381            var formData = new FormData();
     382           
     383            //formData.append("dato", "valor");
     384            // TODO: identificar una manera de pasar varios archivos a la vez
     385            formData.append("upload", $("#file-sign")[0].files[0]);
     386           
     387           
     388           
     389            $.ajax({
     390                url: "https://192.168.12.125:8443/Murachi/0.1/archivos/bdocs/cargas",
     391                //url: "https://172.16.137.11:8443/Murachi/murachi/archivos",               
     392                //url: "https://172.16.137.11:8443/JAXRS-Murachi/murachi/archivos",
     393                //url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos",
     394                type: "post",
     395                dataType: "json",
     396                data: formData,
     397                cache: false,
     398                contentType: false,
     399                                processData: false,
     400                                success: function(response) {
     401                                                //alert(JSON.stringify(response));
     402                                               
     403                                                //var aux = JSON.stringify(response);
     404                                                //alert("aux: " + aux);
     405
     406                                                // identificador del archivo en el servidor
     407                                                var fileId = response.containerId.toString();
     408                                                //alert("fileId: "+ fileId);
     409                                               
     410                                                // seleccionar certificado del firmante
     411                                                //alert("va a seleccionar certificado");
     412                                                var cert;
     413                                                window.hwcrypto.getCertificate({lang: "en"}).then(function(response) {
     414                                                        var cert = response;
     415                                                        //log_text("Using certificate:\n" + hexToPem(response.hex));
     416                                                                                                       
     417                                                        //alert("cert: "+ cert.hex);
     418                                                       
     419                                                        var parameters = JSON.stringify({
     420                                                                "fileId":fileId,
     421                                                                "certificate":cert.hex,
     422                                                                "city":"Rubio",
     423                                                                "state":"Tachira",
     424                                                                "postalCode":"1234",
     425                                                                "country":"Venezuela",
     426                                                                "role":"Militar",
     427                                                                "addSignature":false
     428                                                                });
     429                                                       
     430                                                        // ahora llamar al ajax de obtener la resena del bdoc
     431                                                        $.ajax({
     432                                                                type: 'POST',
     433                                                                contentType: 'application/json',                               
     434                                                                //url:"https://192.168.12.125:8443/Murachi/0.1/archivos/bdocs",
     435                                                                url:"https://192.168.12.125:8443/Murachi/0.1/archivos/bdocs/firmas/pre",
     436                                                                //url:"https://172.16.137.11:8443/Murachi/murachi/archivos/pdfs",
     437                                                                //url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs",
     438                                                                dataType: "json",
     439                                                                data: parameters,               
     440                                                                success: function(data, textStatus, jqXHR){
     441                                                                        var json_x = data;
     442                                                                        var hash = json_x['hash'];
     443                                                                        //alert("hash recibido del servidor "+hash);
     444                                                                       
     445                                                                        var hashtype = "SHA-256";
     446                                                                        var lang = "eng";
     447                                                                       
     448                                                                        window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then(function(signature) {
     449                                                                               
     450                                                                                //var signature = response.hex.match(/.{1,64}/g).join("\n");
     451                                                                        //log_text("Generated signature:\n" + response.hex.match(/.{1,64}/g).join("\n"));
     452                                                                        //log_text("Generated signature:\n" + signature.hex);
     453                                                                       
     454                                                                        //alert("valor de la firma: " + signature.hex);                                                                 
     455                                                                       
     456                                                                        $.ajax({
     457                                                                                        type: 'POST',
     458                                                                                        contentType: 'application/json',
     459                                                                                        //url:"https://192.168.12.125:8443/Murachi/0.1/archivos/bdocs/resenas",
     460                                                                                        url:"https://192.168.12.125:8443/Murachi/0.1/archivos/bdocs/firmas/post",
     461                                                                                        //url:"https://172.16.137.11:8443/Murachi/murachi/archivos/pdfs/resenas",
     462                                                                                        //url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas",
     463                                                                                        dataType: 'json',
     464                                                                                        data: JSON.stringify({"signature":signature.hex, "containerId":fileId}),
     465                                                                                        success: function(data, textStatus, jqXHR){
     466                                                                                                /*
     467                                                                                                var json_x = data;
     468                                                                                                var msg = json_x['message'];                                                                                           
     469                                                                                                alert('Archivo firmado en el servidor: ' + msg);
     470                                                                                                */
     471                                                                                                alert('Archivo firmado correctamente: ' + data['signedFileId']);
     472                                                                                               
     473                                                                                                alert("ver respuesta");
     474                                                                                                var linkToDownload = "<a href=\"https://192.168.12.125:8443/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>";
     475                                                                                                //var linkToDownload = "<a href=\"https://172.16.137.11:8443/Murachi/murachi/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>";
     476                                                                                                //var linkToDownload = "<a href=\"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>";
     477                                                                                                //alert(linkToDownload);
     478                                                                                                document.getElementById("respuesta").innerHTML = linkToDownload; 
     479                                                                                               
     480                                                                                               
     481                                                                                                //descargar el archivo
     482                                                                                                /*
     483                                                                                                //var urlToDownload =   "https://192.168.12.125:8443/Murachi/murachi/archivos/descargas/" + data['signedFileId'];
     484                                                                                                $.ajax({
     485                                                                                                        type: 'GET',
     486                                                                                                        contentType: false,
     487                                                                                                        url: "https://192.168.12.125:8443/Murachi/murachi/archivos/descargas/" + data['signedFileId'],
     488                                                                                                        dataType: false,
     489                                                                                                        data: false,
     490                                                                                                        success: function(data, textStatus, jqXHR){
     491                                                                                                                alert("descargo el archivo");
     492                                                                                                        },
     493                                                                                                        error: function(jqXHR, textStatus, errorThrown){
     494                                                                                                                alert('error en descarga de archivo: ' + textStatus);
     495                                                                                                                $("#respuesta").html("error en descarga de archivo: " + textStatus);
     496                                                                                                        }
     497                                                                                                });
     498                                                                                                */
     499                                                                                                // fin de descarga de archivo
     500                                                                                                                                                                                               
     501                                                                                               
     502                                                                                        },
     503                                                                                        error: function(jqXHR, textStatus, errorThrown){
     504                                                                                                alert('error en /bdocs/resenas: ' + textStatus);
     505                                                                                                $("#respuesta").html("error en /bdocs/resenas: " + textStatus);
     506                                                                                        }
     507                                                                                });
     508                                                                                                                       
     509                                                                        }, function(err) {
     510                                                                                log_text("sign() failed: " + err);
     511                                                                                alert("sign() failed: " + err);
     512                                                                                $("#respuesta").html("sign() failed: " + err);
     513                                                                });
     514                                                                       
     515                                                                },                                                             
     516                                                                error: function(jqXHR, textStatus, errorThrown){
     517                                                                        //alert('error: ' + textStatus);
     518                                                                        //var responseText = jQuery.parseJSON(jqXHR.responseText);
     519                                                                        alert('ajax error function: ' + jqXHR.responseText);
     520                                                                        $("#respuesta").html("error function: " + jqXHR.responseText);
     521                                                                }
     522                                                               
     523                                                        });
     524                                                                                                               
     525                                                }, function(err) {
     526                                                        log_text("getCertificate() failed: " + err);
     527                                                        alert("getCertificate() failed: " + err);
     528                                                        $("#respuesta").html("getCertificate() failed: " + err);
     529                                                });
     530                                                                                               
     531                },
     532                //error: function(response) {
     533                error: function(xhr, status, error) {
     534                        //Que se ejecuta cuando finalice la petición de con error
     535                                        $("#respuesta").html('Error...!!!');
     536                       
     537                                        alert(xhr.responseText);
     538                                        alert(error);
     539                       
     540                                        alert("ocurrio un error en cargas");
     541                                       
     542                                       
     543                                               
     544                                }
     545            });
     546               
     547               
     548            }
     549               
     550            //fin de control de los botones radio en el formulario firmar (pdf,bdoc)----------------------------------------------
     551
     552       
     553           
    364554        });
    365555    });
     
    562752           
    563753            $.ajax({
    564                 //url: "https://192.168.12.125:8443/Murachi/murachi/archivos/firmados",
     754                url: "https://192.168.12.125:8443/Murachi/0.1/archivos/firmados",
    565755                //url: "https://172.16.137.11:8443/Murachi/murachi/archivos/firmados",               
    566756                //url: "https://172.16.137.11:8443/JAXRS-Murachi/murachi/archivos",
    567                 url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/firmados",
     757                //url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/firmados",
    568758                type: "post",
    569759                dataType: "json",
     
    590780       
    591781       
    592         <!--Función que cactura el evento del button reset del formulario verificar
     782        <!--Función que captura el evento del button reset del formulario verificar
    593783                y limpia el div respuesta (tabla de la verificación de la firmna)-->
    594784       
     
    601791        </script>
    602792       
    603          <!--Función que cactura el evento del button reset del formulario firmar
     793         <!--Función que captura el evento del button reset del formulario firmar
    604794            y limpia el div respuesta (tabla de la firma)-->
    605795       <script>
     
    671861        </script>
    672862
     863        <!--Funcion para el manejo de la extensión de los archivos en el momento de firmar de acuerdo a la selección del tipo de formato de firma
     864            electronica que se vaya a utilizar señalada en el button radio (pdf,bdoc)-->
     865
     866       <script>
     867                function manejoExtension() {
     868                        if(document.SignFormat.optradio[0].checked)
     869                                document.getElementById("file-sign").accept=".pdf";
     870                        else
     871                            document.getElementById("file-sign").accept=".*";
     872                        }
     873     </script>
    673874
    674875
     
    692893                                                <h1>Firmar Electrónicamente</h1>
    693894                                                <div class="container kv-main">
     895                                                    <form enctype="multipart/form-data" action="https://192.168.12.125:8443/Murachi/0.1/archivos" method="post" id="firmar" name="SignFormat">
    694896                                                        <!-- <form enctype="multipart/form-data" action="https://192.168.12.125:8443/Murachi/murachi/archivos" method="post" id="firmar"> -->
    695897                                                        <!-- <form enctype="multipart/form-data" action="https://172.16.137.11:8443/Murachi/murachi/archivos" method="post" id="firmar">  -->
    696                                                         <form enctype="multipart/form-data" action="https://murachi.cenditel.gob.ve/Murachi/0.1/archivos" method="post" id="firmar">
     898                                                        <!-- <form enctype="multipart/form-data" action="https://murachi.cenditel.gob.ve/Murachi/0.1/archivos" method="post" id="firmar" name="SignFormat"> -->
    697899                                                                <h2>Formato para la Firma</h2>
    698900                                                                <p>Seleccione el tipo de formato que va a utilizar para firmar electrónicamente</p>                     
    699901                                                                <div class="radio">
    700                                                                         <label><input type="radio" name="optradio">PDF</label>
     902                                                                        <label><input type="radio" name="optradio" value="pdf" checked >PDF</label>
    701903                                                                </div>
    702904                                                                <div class="radio">
    703                                                                         <label><input type="radio" name="optradio">BDOC</label>
     905                                                                        <label><input type="radio" name="optradio" value="bdoc" >BDOC</label>
    704906                                                                </div>
    705907                                                                <br>
    706                                                         <input id="file-sign" class="file" type="file" multiple data-min-file-count="1" name="upload">
     908                                                        <input id="file-sign" class="file" type="file" multiple data-min-file-count="1" onclick="manejoExtension()" name="upload" >
    707909                                                                <br>
    708910                                                                <button type="submit" class="btn btn-primary">Enviar</button>
    709911                                                                <button type="reset" id="reset"  class="btn btn-default">Limpiar</button>
    710912                                                                <br>
    711                                                                 <br>
    712                                                                 <div id="respuesta"> </div>
     913                                <br>
     914                                <div id="respuesta"> </div>
    713915
    714916                                                        </form>
     
    722924                                                <h1>Verificar la firma electrónica</h1>
    723925                                                <div class="container kv-main">
    724                                                         <!-- <form enctype="multipart/form-data" action="https://192.168.12.125:8443/Murachi/murachi/archivos/firmados" method="post" id="verificar"> -->
     926                                                        <form enctype="multipart/form-data" action="https://192.168.12.125:8443/Murachi/0.1/archivos/firmados" method="post" id="verificar">
    725927                                                        <!-- <form enctype="multipart/form-data" action="https://172.16.137.11:8443/Murachi/murachi/archivos/firmados" method="post" id="verificar"> -->
    726                                                         <form enctype="multipart/form-data" action="https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/firmados" method="post" id="verificar">
     928                                                        <!-- <form enctype="multipart/form-data" action="https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/firmados" method="post" id="verificar">  -->
    727929                                                                <input id="file-check-sign" class="file" type="file" multiple data-min-file-count="1" name="upload">
    728930                                                                <br>
Note: See TracChangeset for help on using the changeset viewer.