1 | /** |
---|
2 | * Funcion para refrescar el captcha |
---|
3 | * @param element Recibe el parametro |
---|
4 | */ |
---|
5 | |
---|
6 | function refresh_captcha(element) { |
---|
7 | $form = $(element).parents('form'); |
---|
8 | var url = location.protocol + "//" + window.location.hostname + ":" + location.port + "/captcha/refresh/"; |
---|
9 | |
---|
10 | $.getJSON(url, {}, function(json) { |
---|
11 | $form.find('input[name="captcha_0"]').val(json.key); |
---|
12 | $form.find('img.captcha').attr('src', json.image_url); |
---|
13 | }); |
---|
14 | |
---|
15 | return false; |
---|
16 | } |
---|
17 | |
---|
18 | /** |
---|
19 | * Función para obtener los usuarios de un evento |
---|
20 | */ |
---|
21 | function get_event_user() { |
---|
22 | var modal = false; |
---|
23 | var pasaporte = $('#id_pasaporte').val(); |
---|
24 | if (pasaporte!='') { |
---|
25 | var routes = $(location).attr('pathname').split('/'); |
---|
26 | var pk = routes[routes.length-1]; |
---|
27 | var url = URL_USUARIO_EVENTO+pk+"/"+pasaporte; |
---|
28 | $.getJSON(url, function(data){ |
---|
29 | if (Object.keys(data).length > 0) { |
---|
30 | construir_datos(data); |
---|
31 | } |
---|
32 | else{ |
---|
33 | simple_modal('Lo sentimos, no esta registrado para firmar'); |
---|
34 | } |
---|
35 | }).fail(function(jqxhr, textStatus, error) { |
---|
36 | simple_modal('Petición fállida' + textStatus + ", " + error); |
---|
37 | }) |
---|
38 | } |
---|
39 | else{ |
---|
40 | simple_modal('Debe ingresar un pasaporte'); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * Función para crear un modal sencillo |
---|
46 | */ |
---|
47 | function simple_modal(mensaje) { |
---|
48 | MaterialDialog.alert( |
---|
49 | mensaje, |
---|
50 | { |
---|
51 | title:'Alerta', |
---|
52 | buttons:{ |
---|
53 | close:{ |
---|
54 | text:'cerrar', |
---|
55 | className:'blue', |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|
59 | ); |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * Función para construir la data del participante |
---|
64 | * @param data Recibe los datos para crear la lista |
---|
65 | */ |
---|
66 | function construir_datos(data) { |
---|
67 | firma = data.firmo; |
---|
68 | data = data.datos; |
---|
69 | $('#datos_paricipante').html(''); |
---|
70 | html = '<ul class="collection">' |
---|
71 | html += '<li class="collection-item"><b>Nombre: </b>'+data.nombres+'</li>'; |
---|
72 | html += '<li class="collection-item"><b>Apellido: </b>'+data.apellidos+'</li>'; |
---|
73 | html += '<li class="collection-item"><b>Pasaporte: </b>'+data.pasaporte+'</li>'; |
---|
74 | html += '<li class="collection-item"><b>Correo: </b>'+data.correo+'</li>'; |
---|
75 | html += '</ul>'; |
---|
76 | html += '<iframe width="700px" height="600px" src="https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/listadopdf/'+data.documento+'">'; |
---|
77 | html += '</iframe><br/>'; |
---|
78 | if (firma==true) { |
---|
79 | html += '<h4 class="red-text center">Ya firmó este documento</h4>' |
---|
80 | } |
---|
81 | else{ |
---|
82 | html += '<a type="button" id="firmar" class="btn waves-effect blue darken-1" onclick="comprobarFirma(\''+data.documento+'\')">'; |
---|
83 | html += '<i class="material-icons left">mode_edit</i> Firmar</a>'; |
---|
84 | } |
---|
85 | $('#datos_paricipante').html(html); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * Función para comprobar firma |
---|
90 | * @param fileId Recibe el id del documento |
---|
91 | */ |
---|
92 | function comprobarFirma(fileId){ |
---|
93 | var routes = $(location).attr('pathname').split('/'); |
---|
94 | var pk = routes[routes.length-1]; |
---|
95 | $.ajax({ |
---|
96 | type: 'GET', |
---|
97 | async: false, |
---|
98 | url:URL_COMPROBAR_FIRMA+pk, |
---|
99 | success: function(datos){ |
---|
100 | if (datos.validate==true) { |
---|
101 | simple_modal(datos.mensaje); |
---|
102 | } |
---|
103 | else{ |
---|
104 | $.ajax({ |
---|
105 | type: 'POST', |
---|
106 | async: false, |
---|
107 | url:URL_COMPROBAR_FIRMA+pk, |
---|
108 | success: function(datos){ |
---|
109 | if (datos.validate==true) { |
---|
110 | ObtenerCertificadoFirmanteMultiples(fileId,pk); |
---|
111 | } |
---|
112 | else{ |
---|
113 | simple_modal("Ocurrió un error al actualizar los datos"); |
---|
114 | } |
---|
115 | }, |
---|
116 | error: function(jqXHR, textStatus, errorThrown){ |
---|
117 | console.log('error: ' + textStatus); |
---|
118 | } |
---|
119 | }); |
---|
120 | } |
---|
121 | }, |
---|
122 | error: function(jqXHR, textStatus, errorThrown){ |
---|
123 | console.log('error: ' + textStatus); |
---|
124 | } |
---|
125 | }); |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * Función para obtener el certificado del participante |
---|
130 | * @param fileId Recibe el id del documento |
---|
131 | * @param pk Recibe el id del evento |
---|
132 | */ |
---|
133 | function ObtenerCertificadoFirmanteMultiples(fileId,pk){ |
---|
134 | var xPos = yPos= signaturePage = ""; |
---|
135 | var lastSignature = false; |
---|
136 | |
---|
137 | $.ajax({ |
---|
138 | type: 'GET', |
---|
139 | async: false, |
---|
140 | url:URL_ULTIMO_FIRMANTE+pk, |
---|
141 | success: function(datos){ |
---|
142 | if (datos.valid==true) { |
---|
143 | xPos = datos.data.posX; |
---|
144 | yPos = datos.data.posY; |
---|
145 | signaturePage = datos.data.page; |
---|
146 | lastSignature = true; |
---|
147 | } |
---|
148 | window.hwcrypto.getCertificate({lang: "en"}).then( |
---|
149 | function(response) { |
---|
150 | var cert = response; |
---|
151 | var parameters = ""; |
---|
152 | parameters = JSON.stringify({ |
---|
153 | "fileId":fileId, |
---|
154 | "certificate":cert.hex, |
---|
155 | "reason":"Certificado", |
---|
156 | "location":"RedGealc", |
---|
157 | "contact":"RedGealc", |
---|
158 | "signatureVisible":"false", |
---|
159 | "signaturePage": signaturePage, |
---|
160 | "xPos": xPos, |
---|
161 | "yPos": yPos, |
---|
162 | "lastSignature":lastSignature |
---|
163 | }); |
---|
164 | |
---|
165 | // ahora llamar al ajax de obtener la resena del pdf |
---|
166 | ObtenerHashPDFServerMultiples(parameters, cert, pk); |
---|
167 | |
---|
168 | }, |
---|
169 | function(err) { |
---|
170 | var error; |
---|
171 | if(err == "Error: user_cancel") { |
---|
172 | error = "El usuario cancelo la operación"; |
---|
173 | } |
---|
174 | else if(err == "Error: no_certificates") { |
---|
175 | error = "No hay certificado disponible"; |
---|
176 | } |
---|
177 | else if(err == "Error: no_implementation") { |
---|
178 | error = "No hay soporte para el manejo del certificado"; |
---|
179 | } |
---|
180 | $.ajax({ |
---|
181 | type: 'POST', |
---|
182 | async: false, |
---|
183 | url:URL_COMPROBAR_FIRMA+pk, |
---|
184 | success: function(datos){ |
---|
185 | console.log(datos); |
---|
186 | }, |
---|
187 | error: function(jqXHR, textStatus, errorThrown){ |
---|
188 | console.log('error: ' + textStatus); |
---|
189 | } |
---|
190 | }); |
---|
191 | simple_modal(error); |
---|
192 | } |
---|
193 | |
---|
194 | ); |
---|
195 | }, |
---|
196 | error: function(jqXHR, textStatus, errorThrown){ |
---|
197 | console.log('error: ' + textStatus); |
---|
198 | } |
---|
199 | }); |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | /** |
---|
204 | * Función para obtener el hash y procesar la informacion |
---|
205 | * @param parameters Recibe los parametros |
---|
206 | * @param cert Recibe los certificados |
---|
207 | * @param pk Recibe el id del evento |
---|
208 | */ |
---|
209 | function ObtenerHashPDFServerMultiples(parameters,cert,pk){ |
---|
210 | |
---|
211 | $.ajax({ |
---|
212 | type: 'POST', |
---|
213 | contentType: 'application/json', |
---|
214 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfsqr", |
---|
215 | dataType: "json", |
---|
216 | data: parameters, |
---|
217 | xhrFields: {withCredentials: true}, |
---|
218 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
219 | success: function(data, textStatus, jqXHR){ |
---|
220 | var json_x = data; |
---|
221 | var hash = json_x['hash']; |
---|
222 | var hashtype = "SHA-256"; |
---|
223 | var lang = "eng"; |
---|
224 | |
---|
225 | //Procesa la información |
---|
226 | window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then( |
---|
227 | function(signature) { |
---|
228 | FinalizarFirmaMultiples(signature.hex, pk); |
---|
229 | }, |
---|
230 | function(err) { |
---|
231 | var error; |
---|
232 | if(err == "Error: user_cancel") { |
---|
233 | error = "El usuario cancelo la operación"; |
---|
234 | } |
---|
235 | else if(err == "Error: no_certificates") { |
---|
236 | error = "No hay certificado disponible"; |
---|
237 | } |
---|
238 | else if(err == "Error: no_implementation") { |
---|
239 | error = "No hay soporte para el manejo del certificado"; |
---|
240 | } |
---|
241 | $.ajax({ |
---|
242 | type: 'POST', |
---|
243 | async: false, |
---|
244 | url:URL_COMPROBAR_FIRMA+pk, |
---|
245 | success: function(datos){ |
---|
246 | console.log(datos); |
---|
247 | }, |
---|
248 | error: function(jqXHR, textStatus, errorThrown){ |
---|
249 | console.log('error: ' + textStatus); |
---|
250 | } |
---|
251 | }); |
---|
252 | simple_modal(error); |
---|
253 | }); |
---|
254 | |
---|
255 | }, |
---|
256 | error: function(jqXHR, textStatus, errorThrown){ |
---|
257 | console.log('ajax error function: ' + jqXHR.responseText); |
---|
258 | } |
---|
259 | |
---|
260 | }); |
---|
261 | } |
---|
262 | |
---|
263 | /** |
---|
264 | * Función para enviar la firma al servidor |
---|
265 | * @param signature Recibe la firma |
---|
266 | * @param pk Recibe el id del evento |
---|
267 | */ |
---|
268 | function FinalizarFirmaMultiples(signature, pk){ |
---|
269 | |
---|
270 | $.ajax({ |
---|
271 | type: 'POST', |
---|
272 | contentType: 'application/json', |
---|
273 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas", |
---|
274 | dataType: 'json', |
---|
275 | data: JSON.stringify({"signature":signature}), |
---|
276 | xhrFields: {withCredentials: true}, |
---|
277 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
278 | success: function(data, textStatus, jqXHR){ |
---|
279 | actualizar_participante(data['signedFileId']); |
---|
280 | $.ajax({ |
---|
281 | type: 'POST', |
---|
282 | async: false, |
---|
283 | url:URL_COMPROBAR_FIRMA+pk, |
---|
284 | success: function(datos){ |
---|
285 | console.log(datos); |
---|
286 | }, |
---|
287 | error: function(jqXHR, textStatus, errorThrown){ |
---|
288 | console.log('error: ' + textStatus); |
---|
289 | } |
---|
290 | }); |
---|
291 | }, |
---|
292 | error: function(jqXHR, textStatus, errorThrown){ |
---|
293 | console.log('error en pdfs/resenas: ' + textStatus); |
---|
294 | $.ajax({ |
---|
295 | type: 'POST', |
---|
296 | async: false, |
---|
297 | url:URL_COMPROBAR_FIRMA+pk, |
---|
298 | success: function(datos){ |
---|
299 | console.log(datos); |
---|
300 | }, |
---|
301 | error: function(jqXHR, textStatus, errorThrown){ |
---|
302 | console.log('error: ' + textStatus); |
---|
303 | } |
---|
304 | }); |
---|
305 | } |
---|
306 | }); |
---|
307 | |
---|
308 | } |
---|
309 | |
---|
310 | /** |
---|
311 | * Función para actualizar los datos del participante |
---|
312 | * @param id_documento Recibe el id del documento |
---|
313 | */ |
---|
314 | function actualizar_participante(id_documento) { |
---|
315 | var pasaporte = $('#id_pasaporte').val(); |
---|
316 | var routes = $(location).attr('pathname').split('/'); |
---|
317 | var pk = routes[routes.length-1]; |
---|
318 | |
---|
319 | $.post(URL_ACTUALIZAR_PARTICIPACION,{'event_id':pk,'pasaporte':pasaporte,'serial':id_documento}) |
---|
320 | .done(function(data){ |
---|
321 | if (data.validate==true) { |
---|
322 | simple_modal(data.mensaje); |
---|
323 | $('#firmar').remove(); |
---|
324 | } |
---|
325 | else{ |
---|
326 | simple_modal(data.mensaje); |
---|
327 | } |
---|
328 | }) |
---|
329 | .fail(function(err){ |
---|
330 | console.log(err); |
---|
331 | }); |
---|
332 | } |
---|