1 | $("#Form-Format-Visible").on('submit', function() { |
---|
2 | //var formData = new FormData(document.getElementById("form")); |
---|
3 | var formData = new FormData(); |
---|
4 | |
---|
5 | formData.append("upload", $("#file-sign-ft_Vble")[0].files[0]); |
---|
6 | |
---|
7 | $.ajax({ |
---|
8 | //url: "https://192.168.12.125:8443/Murachi/0.1/archivos", |
---|
9 | url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos", |
---|
10 | type: "post", |
---|
11 | dataType: "json", |
---|
12 | data: formData, |
---|
13 | cache: false, |
---|
14 | contentType: false, |
---|
15 | processData: false, |
---|
16 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
17 | success: function(response) { |
---|
18 | //alert(JSON.stringify(response)); |
---|
19 | var html = manejoJsonPDF(JSON.stringify(response)); |
---|
20 | document.getElementById("respuesta").innerHTML = html; |
---|
21 | |
---|
22 | // identificador del archivo en el servidor |
---|
23 | var fileId = response.fileId.toString(); |
---|
24 | var cert; |
---|
25 | |
---|
26 | window.hwcrypto.getCertificate({lang: "en"}).then(function(response) { |
---|
27 | var cert = response; |
---|
28 | |
---|
29 | var parameters = JSON.stringify({ |
---|
30 | "fileId":fileId, |
---|
31 | "certificate":cert.hex, |
---|
32 | "reason":"Certificado", |
---|
33 | "location":"CENDITEL", |
---|
34 | "contact":"582746574336", |
---|
35 | "signatureVisible":"true", |
---|
36 | "page": VALOR_PAGE, |
---|
37 | "coord_x": VALOR_X, |
---|
38 | "coord_y": VALOR_Y |
---|
39 | }); |
---|
40 | |
---|
41 | // ahora llamar al ajax de obtener la resena del pdf |
---|
42 | $.ajax({ |
---|
43 | type: 'POST', |
---|
44 | contentType: 'application/json', |
---|
45 | //url:"https://192.168.12.125:8443/Murachi/0.1/archivos/pdfs", |
---|
46 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs", |
---|
47 | dataType: "json", |
---|
48 | data: parameters, |
---|
49 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
50 | success: function(data, textStatus, jqXHR){ |
---|
51 | var json_x = data; |
---|
52 | var hash = json_x['hash']; |
---|
53 | //alert("hash recibido del servidor "+hash); |
---|
54 | |
---|
55 | var hashtype = "SHA-256"; |
---|
56 | var lang = "eng"; |
---|
57 | |
---|
58 | window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then(function(signature) { |
---|
59 | |
---|
60 | $.ajax({ |
---|
61 | type: 'POST', |
---|
62 | contentType: 'application/json', |
---|
63 | //url:"https://192.168.12.125:8443/Murachi/0.1/archivos/pdfs/resenas", |
---|
64 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas", |
---|
65 | dataType: 'json', |
---|
66 | data: JSON.stringify({"signature":signature.hex}), |
---|
67 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
68 | success: function(data, textStatus, jqXHR){ |
---|
69 | |
---|
70 | alert('Archivo firmado correctamente: ' + data['signedFileId']); |
---|
71 | |
---|
72 | var linkToDownload = "<a href=\"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>"; |
---|
73 | //alert(linkToDownload); |
---|
74 | document.getElementById("respuesta").innerHTML = linkToDownload; |
---|
75 | |
---|
76 | }, |
---|
77 | error: function(jqXHR, textStatus, errorThrown){ |
---|
78 | alert('error en pdfs/resenas: ' + textStatus); |
---|
79 | $("#respuesta").html("error en pdfs/resenas: " + textStatus); |
---|
80 | } |
---|
81 | }); |
---|
82 | |
---|
83 | }, function(err) { |
---|
84 | log_text("sign() failed: " + err); |
---|
85 | |
---|
86 | var error; |
---|
87 | log_text("sign() failed: " + err); |
---|
88 | if(err == "Error: user_cancel") { |
---|
89 | alert("sign() failed: El usuario cancelo la operación"); |
---|
90 | error = "El usuario cancelo la operación"; |
---|
91 | } |
---|
92 | else if(err == "Error: no_certificates") { |
---|
93 | alert("sign() failed: No hay certificado disponible"); |
---|
94 | error = "No hay certificado disponible"; |
---|
95 | } |
---|
96 | else if(err == "Error: no_implementation") { |
---|
97 | alert("sign() failed: No hay soporte para el manejo del certificado"); |
---|
98 | error = "No hay soporte para el manejo del certificado"; |
---|
99 | } |
---|
100 | |
---|
101 | //alert("sign() failed: " + err); |
---|
102 | $("#respuesta").html("sign() failed: " + error); |
---|
103 | }); |
---|
104 | |
---|
105 | }, |
---|
106 | error: function(jqXHR, textStatus, errorThrown){ |
---|
107 | //alert('error: ' + textStatus); |
---|
108 | //var responseText = jQuery.parseJSON(jqXHR.responseText); |
---|
109 | alert('ajax error function: ' + jqXHR.responseText); |
---|
110 | $("#respuesta").html("error function: " + jqXHR.responseText); |
---|
111 | } |
---|
112 | |
---|
113 | }); |
---|
114 | |
---|
115 | }, function(err) { |
---|
116 | log_text("getCertificate() failed: " + err); |
---|
117 | var error; |
---|
118 | if(err == "Error: user_cancel") { |
---|
119 | alert("getCertificate() failed: El usuario cancelo la operación" ); |
---|
120 | error = "El usuario cancelo la operación"; |
---|
121 | } |
---|
122 | else if(err == "Error: no_certificates") { |
---|
123 | alert("getCertificate() failed: No hay certificado disponible") ; |
---|
124 | error = "No hay certificado disponible"; |
---|
125 | } |
---|
126 | else if(err == "Error: no_implementation") { |
---|
127 | alert("getCertificate() failed: No hay soporte para el manejo del certificado"); |
---|
128 | error = "No hay soporte para el manejo del certificado"; |
---|
129 | } |
---|
130 | //alert("getCertificate() failed: " + err); |
---|
131 | $("#respuesta").html("getCertificate() failed: " + error); |
---|
132 | }); |
---|
133 | |
---|
134 | }, |
---|
135 | error: function(response) { |
---|
136 | //Que se ejecuta cuando finalice la petición de con error |
---|
137 | $("#respuesta").html('Error...!!!'); |
---|
138 | alert("ocurrio un error") |
---|
139 | } |
---|
140 | }); |
---|
141 | |
---|
142 | }); |
---|