/* Orginal Page: http://thecodeplayer.com/walkthrough/jquery-multi-step-form-with-progress-bar */ //jQuery time var current_fs, next_fs, previous_fs; //fieldsets var left, opacity, scale; //fieldset properties which we will animate var animating; //flag to prevent quick multi-click glitches var paso=0; var ides={}; function todoCargado() { $(".next").click(function(){ var tarjeta=$(this); //alert(JSON.stringify(datos)); if(paso==0) grabaCEO(tarjeta); else if(paso==1) grabaMonedas(tarjeta); }); $(".previous").click(function(){ if(animating) return false; animating = true; current_fs = $(this).parent(); previous_fs = $(this).parent().prev(); //de-activate current step on progressbar $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active"); //show the previous fieldset previous_fs.show(); //hide the current fieldset with style current_fs.animate({opacity: 0}, { step: function(now, mx) { //as the opacity of current_fs reduces to 0 - stored in "now" //1. scale previous_fs from 80% to 100% scale = 0.8 + (1 - now) * 0.2; //2. take current_fs to the right(50%) - from 0% left = ((1-now) * 50)+"%"; //3. increase opacity of previous_fs to 1 as it moves in opacity = 1 - now; current_fs.css({'left': left}); previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity}); }, duration: 800, complete: function(){ current_fs.hide(); animating = false; }, //this comes from the custom easing plugin easing: 'easeInOutBack' }); }); $(".submit").click(function(){ return false; }); } function grabaCEO(tarjeta) { var datos={"correo": $("input[name='email']").val(), "usuario":$("input[name='usuario']").val(), "clave":$("input[name='pass']").val(), "empresa":$("input[name='empresa']").val()}; console.log(datos); jQuery.ajax({ type: 'POST', contentType: 'application/json; charset=utf-8', url: 'codigo/saveDatos.php?datos='+JSON.stringify(datos), data: JSON.stringify(datos), success: function(data) { ides=JSON.parse(data); console.log("ID EMPRESA="+ides.idEmpresa); $("span[name='empresa2']").html( $("input[name='empresa']").val()+", S.L." ); paso++; siguiente(tarjeta); } }); } function grabaMonedas(tarjeta) { var monedas={}; $("div[name='datosDiv']").each(function (){ var numero=$(this).attr("num"); console.log("Tié güevos ... "+numero); var a1=$(this).find("input[name='nombre']").val(); // Nombre if( !(a1==='undefined') && a1!="" ) { var a2=$(this).find("input[name='valor']").val(); // Valor var a3=$(this).find("select[name='referencia']").val(); // Referencia var a5=$("div[name='descDiv"+numero+"'] input").val(); // Subyacente: descripción de la moneda monedas["num"+numero]={"nombre":a1,"valor":a2,"referencia":a3,"subyacente":a5}; } console.log(monedas); }); console.log(monedas); //console.log(monedas.num1); var datos={"idEmpresa":ides["idEmpresa"],"monedas":monedas,"monedaBase": $("select[name='monedaBase']").val()}; console.log(datos); jQuery.ajax({ type: 'POST', dataType:'json', data:datos, url: 'codigo/saveMonedas.php', success: function(data) { console.log(data); paso++; siguiente(tarjeta); } }); } function grabaEmpleados(tarjeta) { var empleados={}; $("div[name='datosEmpl']").each(function (){ var numero=$(this).attr("num"); var a1=$(this).find("input[name='login']").val(); // Nombre if( !(a1==='undefined') && a1!="" ) { var a2=$(this).find("input[name='clave']").val(); // Valor var a3=$(this).find("select[name='foto']").val(); // Referencia //var a5=$("div[name='descDiv"+numero+"'] input").val(); // Más datos del empleado TODO empleados["num"+numero]={"login":a1,"clave":a2,"foto":a3}; } }); console.log(empleados); var datos={"idEmpresa":ides["idEmpresa"],"empleados":empleados}; jQuery.ajax({ type: 'POST', dataType:'json', data:datos, url: 'codigo/saveEmpleados.php', success: function(data) { console.log(data); paso++; siguiente(tarjeta); } }); } function siguiente(tarjeta) { if(animating) return false; animating = true; current_fs = tarjeta.parent(); next_fs = tarjeta.parent().next(); //activate next step on progressbar using the index of next_fs $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active"); //show the next fieldset next_fs.show(); //hide the current fieldset with style current_fs.animate({opacity: 0}, { step: function(now, mx) { //as the opacity of current_fs reduces to 0 - stored in "now" //1. scale current_fs down to 80% scale = 1 - (1 - now) * 0.2; //2. bring next_fs from the right(50%) left = (now * 50)+"%"; //3. increase opacity of next_fs to 1 as it moves in opacity = 1 - now; current_fs.css({'transform': 'scale('+scale+')'}); next_fs.css({'left': left, 'opacity': opacity}); }, duration: 800, complete: function(){ current_fs.hide(); animating = false; }, //this comes from the custom easing plugin easing: 'easeInOutBack' }); } var numMon=1; function masMoneda() { numMon++; var aux="
"+$("div[name='datosDiv'][num='1']").html()+"
"; aux=aux.replace("(0)", "("+numMon+")"); $( "#titulos" ).after( aux ); //$("div[name='descDiv1']").find("a") //$(aux).appendTo("#divisas"); //$("div[name='descDiv1']").clone().attr( "name", "descDiv"+numMon ).appendTo("#divisas"); } var numEmpl=1; function masEmpleados() { numEmpl++; var aux="
"+$("div[name='datosEmpl'][num='1']").html()+"
"; aux=aux.replace("(0)", "("+numEmpl+")"); $( "#titulosEmpl" ).after( aux ); } function addCCY_REF(valor) { removeCCY_REF(valor); $("select[name='referencia']").each(function(){ $(this).append(""); }); } function removeCCY_REF(valor) { $("select[name='referencia']").each(function(){ $(this).find("option[value='new_" + valor+ "']").remove(); }); } function borrar(num) { console.log("div:not('.slick-cloned') Caca = "+num); removeCCY_REF( $( "div[name='datosDiv'][num='"+num+"']" ).find("input[name='nombre']").val() ); if(num>1) $( "div[name='datosDiv'][num='"+num+"']" ).remove(); console.log("Borrando "+num); } function borrarEmpl(num) { if(num>1) $( "div[name='datosEmpl'][num='"+num+"']" ).remove(); console.log("Borrando "+num); } function fileSelected() { var file = document.getElementById('fileToUpload').files[0]; displayAsImage3(file, "preview"); if (file) { var fileSize = 0; if (file.size > 1024 * 1024) fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB'; else fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB'; document.getElementById('fileName').innerHTML = 'Name: ' + file.name; document.getElementById('fileSize').innerHTML = 'Size: ' + fileSize; document.getElementById('fileType').innerHTML = 'Type: ' + file.type; } } function uploadFile() { var xhr = new XMLHttpRequest(); var fd = new FormData(); fd.append('idTarea', datos.idTarea); fd.append('idMoneda', datos.AAA_ID_MONEDA); fd.append('precio', datos.AAA_PRECIO); fd.append('foto', "-1"); var count = document.getElementById('camara').files.length; for (var index = 0; index < count; index ++) { var file = document.getElementById('camara').files[index]; fd.append('myFile', file); } /* event listners */ xhr.upload.addEventListener("progress", uploadProgress, false); xhr.addEventListener("load", uploadComplete, false); xhr.addEventListener("error", uploadFailed, false); xhr.addEventListener("abort", uploadCanceled, false); /* Be sure to change the url below to the url of your upload server side script */ xhr.open("POST", "capturaFoto.php"); xhr.send(fd); } function uploadProgress(evt) { if (evt.lengthComputable) { var percentComplete = Math.round(evt.loaded * 100 / evt.total); document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%'; } else { document.getElementById('progressNumber').innerHTML = 'unable to compute'; } } function uploadComplete(evt) { /* This event is raised when the server send back a response */ alert(evt.target.responseText); } function uploadFailed(evt) { alert("There was an error attempting to upload the file."); } function uploadCanceled(evt) { alert("The upload has been canceled by the user or the browser dropped the connection."); } //document.createElement("img") function displayAsImage3(file, containerid) { if (typeof FileReader !== "undefined") { var container = document.getElementById(containerid), img = $( "#fotis" ).get( 0 ), reader; container.appendChild(img); reader = new FileReader(); reader.onload = (function (theImg) { return function (evt) { theImg.src = evt.target.result; }; }(img)); reader.readAsDataURL(file); } }