From 3d8622d46b4b033513cd336791113c7b04b79bdf Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 1 Nov 2021 14:08:54 -0300 Subject: [PATCH] agregar experiencias adicionales --- curriculumsearch/src/main/resources/static/main.js | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ curriculumsearch/src/main/webapp/jsp/postulante-form.jsp | 85 ++++--------------------------------------------------------------------------------- 2 files changed, 102 insertions(+), 81 deletions(-) create mode 100644 curriculumsearch/src/main/resources/static/main.js diff --git a/curriculumsearch/src/main/resources/static/main.js b/curriculumsearch/src/main/resources/static/main.js new file mode 100644 index 0000000..4dc54ed --- /dev/null +++ b/curriculumsearch/src/main/resources/static/main.js @@ -0,0 +1,98 @@ +var cont_experiencia = 0; +let cont_estudios = 0; +let cont_tecnologia = 0; +function agregarFieldExpierncia(evt){ + + const btn = evt.target + cont_experiencia++; + + const nee = document.createElement("div") + nee.innerHTML = ` + + + + + + + + + + + `; + nee.className = "mb-3 col-5" + form.insertBefore(nee,btn) +} +function serializeJSON (form) { + // Create a new FormData object + const formData = new FormData(form); + + // Create an object to hold the name/value pairs + const pairs = {}; + const experiencias = [{}]; + const estudios = [{}]; + const tecnologias = [{}]; + + // Add each name/value pair to the object + for (const [name, value] of formData) { + //los atributos no primitivos tiene una nomenclatura distinta en sus names + //ej.: experiencia-4-institucion == experencias[4].institucion + let codificacion = name.split("-") + if(codificacion.length==1){ + pairs[name] = value + } + else{ + switch (codificacion[0]) { + case "experiencia": + if(experiencias[codificacion[1]]==null) experiencias[codificacion[1]]={}; + experiencias[codificacion[1]][codificacion[2]] = value + break; + case "estudio": + if(estudios[codificacion[1]]==null) estudios[codificacion[1]]={}; + estudios[codificacion[1]][codificacion[2]] = value + break; + case "tecnologia": + if(tecnologias[codificacion[1]]==null) tecnologias[codificacion[1]]={}; + tecnologias[codificacion[1]][codificacion[2]] = value + break; + + default: + break; + } + } + } + pairs["experiencias"] = experiencias + pairs["estudios"] = estudios + pairs["tecnologias"] = tecnologias + + // Return the JSON string + return JSON.stringify(pairs, null, 2); +} + +async function postData(url = '', data = {}) { + // Default options are marked with * + const response = await fetch(url, { + method: 'POST', // *GET, POST, PUT, DELETE, etc. + mode: 'cors', // no-cors, *cors, same-origin + cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached + credentials: 'same-origin', // include, *same-origin, omit + headers: { + 'Content-Type': 'application/json' + // 'Content-Type': 'application/x-www-form-urlencoded', + }, + redirect: 'follow', // manual, *follow, error + referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url + body: data // body data type must match "Content-Type" header + }); + return response; // parses JSON response into native JavaScript objects +} + +form = document.querySelector("form"); +form.addEventListener("submit",(evt)=>{ + + postData('postulante', serializeJSON(form)) + .then(response => { + console.log(response); // JSON data parsed by `data.json()` call + location.replace(response.url); + }); + evt.preventDefault(); +} ); \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp index 1ce4723..0669817 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp @@ -67,7 +67,7 @@ -
+
@@ -82,7 +82,8 @@
-
+ + @@ -96,84 +97,6 @@ --> - + \ No newline at end of file -- libgit2 0.26.0