/* 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="