var bMobile = false;
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { bMobile = true; }
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var bGeneralError = false;
(function($) {
$(document).ready(function() {
var myURL = window.location.pathname.replace('/pasonw', '');
myURL = myURL.replace('/', '');
var aParams = myURL.split('-');
var sOrigin = aParams[0];
console.log ( 'File: index' );
//var $button = $("li a[title='Mi Viaje']"),
var $button = $("#hdr_miviaje,#menu_miviaje");
var ql_bg = '#quick-login-bg';
var ql_pnl = '#quick-login-panel';
var pS_bg = '#darkenwrapper';
var $buttonNews = $("#newsletterregister2");
if ( sOrigin!="gestion" ) {
if ($(pS_bg).length) {
ql_bg = pS_bg;
}
$button.click(function(e){
//console.log("Button");
e.preventDefault();
$(ql_bg + ', ' + ql_pnl).fadeIn(300);
$("#quick-login-bg").attr('style', 'display: block;');
});
/*
var $buttonResponsive = $(".wsmenu-click");
$buttonResponsive.click(function(e){
//console.log("ButtonResponsive");
e.preventDefault();
$(ql_bg + ', ' + ql_pnl).fadeIn(300);
$("#quick-login-bg").attr('style', 'display: block;');
});
*/
$buttonNews.click(function(e){
//console.log("ButtonNews");
e.preventDefault();
$(ql_bg + ', ' + ql_pnl).fadeIn(300);
$("#quick-login-bg").attr('style', 'display: block;');
});
$(ql_bg + ', #quick-login-panel .close').click(function () {
//console.log("Button Close");
$(ql_bg + ', ' + ql_pnl).fadeOut(300);
$("#quick-login-bg").attr('style', 'display: none;');
});
// Enter Key
$(document).keypress(function(event){
if (event.which=='13') {
event.preventDefault();
}
});
// ESC Key
$(document).keyup(function(event){
if(event.which=='27'){
//$(ql_bg + ', ' + ql_pnl).fadeOut(300);
//$("#quick-login-bg").attr('style', 'display: none;');
}
});
}
btnWeb();
//console.log ( window.location.pathname.replace('/pasonw/', '') );
if ( sOrigin=="gestion" ) {
/*
$(ql_bg + ', ' + ql_pnl).fadeIn(300);
$("#quick-login-bg").attr('style', 'display: block;');
*/
validate(myURL);
} else if ( getParameterByName('validate')!="" ) {
$(ql_bg + ', ' + ql_pnl).fadeIn(300);
$("#quick-login-bg").attr('style', 'display: block;');
validate( 'init-' + getParameterByName('validate') );
} else {
validate('init');
}
btnCallback();
});
})(jQuery);
function btnWeb () {
console.log("Web");
$("#newsletterregister2").each(function(){
//console.log("Newsletter "+this.id);
$("#"+this.id).off('click').click(function(e){
e.preventDefault();
bGeneralError = false;
console.log("newsletterregister2 Clicked");
validate("newsletterregister2");
console.log("Validating newsletterregister2");
});
});
$(".btnReserva").each(function(){
//console.log("Book "+this.id);
$("#"+this.id).off('click').click(function(e){
e.preventDefault();
bGeneralError = false;
//console.log("Book Clicked "+this.id);
validate("booking-"+this.id.replace("VM","")); // 20230619 Botón Header Versión Móvil
validate("booking-"+this.id.replace("V",""));
//console.log("Validating booking-"+this.id);
});
});
$(".btnDeseo").each(function(){
//console.log("whislist "+this.id);
$("#"+this.id).off('click').click(function(e){
e.preventDefault();
bGeneralError = false;
validate("wishlist-"+this.id.replace("W",""));
});
});
}
function validate(sAction,bPartialField='') {
console.log(sAction);
if ( bGeneralError==true ) {
console.log ("General Error. Review");
return false;
}
if ( sAction!="init" ) {
var ql_bg = '#quick-login-bg';
var ql_pnl = '#quick-login-panel';
$(ql_bg + ', ' + ql_pnl).fadeIn(300);
}
var myobject = $("#appForm");
var data = myobject.serialize();
console.log (data);
data += ( $('#token').length ) ? "&token=" + $("#token").val() : "";
data += ( $('#tokenize').length ) ? "&tokenize=" + $("#tokenize").val() : "";
data += '&action=' + sAction;
data += '&path=' + window.location.pathname;
console.log( "Action: " + sAction + ' - ' + bPartialField );
console.log( "Data: " + data );
if ( sAction!="" || ( sAction=="serviceme" && data=="" ) ) {
$.ajax({
url: 'https://www.pasonoroeste.com/oficinator/releases/20231212/class/user_callback.php',
type: 'POST',
data: data,
cache: false,
beforeSend: function() {
$("#info").html('');
$("#info").fadeOut();
if ( sAction=="login" ) {
$("#login").html('Comprobando datos
');
if ( sAction=="logout" ) { $("#miviaje").css('background-color','transparent'); }
}
},
success: function (response) {
var iFadeIn = 0;
var bAction = true;
var aResponse;
aResponse = response.split('|');
var url = "";
console.log( "Action: " + sAction );
console.log( "Response: " + response );
if ( bPartialField!='' ) {
if ( aResponse[0]=="ok" ) {
console.log ("Partial: " + bPartialField + " > " + aResponse[4]);
if ( aResponse[4]=="" ) {
$("#"+bPartialField).html("");
} else {
$("#"+bPartialField).html(aResponse[4]);
}
}
} else {
switch ( aResponse[0] ) {
case "ok":
case "formwindow":
break;
case "redirect":
url = aResponse[6];
$(location).attr('href',url);
break;
case "newwindow":
url = aResponse[6];
console.log(url);
window.open(url, '_blank');
break;
case "error":
case "warning":
break;
default:
bAction = false;
$("#info").fadeIn(iFadeIn, function(){ $("#info").html(""); });
$("#appbody").html("");
$("#myitems").html("");
console.log( "No Action: " + aResponse[0] );
}
// App Header
$("#appmenu").html(aResponse[2]);
$("#appfooter").html(aResponse[5]);
if ( bAction==true ) {
// App
//$("#info").fadeIn(iFadeIn, function(){ $("#info").html(aResponse[3]); });
if (aResponse[3]!="") {
appDGC(aResponse[3]);
}
$("#appbody").html(aResponse[4]);
$("#myitems").html(aResponse[1]);
// Header (button)
$("#miviaje").css("background-color", "");
if ( $('#token').length ) {
if ( $("#token").val()!="" ) {
$("#miviaje").attr('style', 'background-color: #5a9ad1 !important');
}
}
switch ( aResponse[0] ) {
case "formwindow":
if ( $("#my_payment").length ) {
//setTimeout(' $("#my_payment")[0].click(); ', 3000 );
}
break;
default:
}
var mywidth = 50;
if ( !bMobile && $(window).width()>768 ) {
mywidth = ( aResponse[7]=="" || aResponse[7]==0 ) ? 40 : aResponse[7];
} else {
mywidth = 95;
}
// App Width
//https://www.w3schools.com/jquery/eff_animate.asp
$("#quick-login-panel").animate({ "width": mywidth + "%"}, 1500);
// App Log
$("#mylog").html(aResponse[8]);
switch ( sAction ) {
case "start":
if ( 1 ) {
}
break;
default:
}
}
}
$("#"+sAction).prop("disabled",false);
btnCallback();
}
});
} else {
console.log("Fatal Error");
exit;
}
return false;
}
function checkMySession2025() {
var aResponse = "";
$.ajax({
url: 'https://www.pasonoroeste.com/oficinator/releases/20231212/class/modes.php',
type: 'POST',
dataType: "html",
data: {
action: 'checkAppSession',
},
success: function (response)
{
var aResponse = response.split("|");
var iNextCheck = 30;
if ( aResponse[0]=="ERROR" ) {
console.log(aResponse[1]);
} else if ( aResponse[0]=="OK" ) {
iNextCheck = 10;
if ( aResponse[2]!="" ) {
console.log(aResponse[1]);
eval(aResponse[2]);
}
}
setTimeout(function() {
checkMySession2025();
}, iNextCheck*1000);
},
error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + errortext); },
async: false
});
}
setTimeout(function() {
checkMySession2025();
}, 3000);
function btnCallback() {
windowHeight = $(window).height();
windowWidth = $(window).width();
console.log("btnCallback");
var ql_bg = '#quick-login-bg', ql_pnl = '#quick-login-panel';
/*documentHeight = $(document).height();
documentWidth = $(document).width();
screenHeight = screen.height;
screenWidth = screen.width;
windowHeightAvailable = window.innerHeight;
windowWidthAvailable = window.innerWidth;*/
appHeaderHeight = ( $(".mytheme1header").height() == 0 ) ? $(".mytheme1header").height() : 40;
appHeaderWidth = $(".mytheme1header").width();
appFooterHeight = ( $(".mytheme1footer").height() == 0 ) ? $(".mytheme1footer").height() : 40;
appFooterWidth = $(".mytheme1footer").width();
var calcMaxHeight = ( windowHeight-appHeaderHeight-appFooterHeight-45 ); // 10px por encima y por abajo. 10px del margin appbody a appheader y 10px del margin appbody a appfooter
$(".scroll").css('maxHeight', calcMaxHeight + 'px');
if ( windowWidth<900 ) {
calcMaxWidth = windowWidth-20;
$("#quick-login-panel").css('width', calcMaxWidth + 'px');
} else {
calcMaxWidth = windowWidth;
}
/*alertDGC( "Window: H: " + windowHeight + " W: " + windowWidth + "
" +
"App Header: H: " + appHeaderHeight + " W: " + '' + "
" +
"App Footer: H: " + appFooterHeight + " W: " + '' + "
" +
"App Calc: H: " + calcMaxHeight + " W: " + calcMaxWidth);
*/
/*
alertDGC( "Window: H: " + windowHeight + " W: " + windowWidth + "
" +
"App Header: H: " + appHeaderHeight + " W: " + '' + "
" +
"App Footer: H: " + appFooterHeight + " W: " + '' + "
" +
"App Calc: H: " + calcMaxHeight + " W: " + calcMaxWidth + "
" +
"Document: H: " + documentHeight + " W: " + documentWidth + "
" +
"Screen: H: " + screenHeight + " W: " + screenWidth);
});*/
$('button[id^="verdatos"]').off('click').click(function(e){
e.preventDefault();
var sId = this.id;
var i = sId.replace("verdatos", '');
$('div[id^="datousuario"]').removeClass("data-selected");
$('button[id^="verdatos"]').removeClass("btn-selected");
$("#datousuario" + i).addClass("data-selected");
$("#verdatos" + i).addClass("btn-selected");
});
jQuery('.mDetalle').each(function(){
var data = jQuery(this).attr('data-url');
var aData = data.split("-");
var type = aData.shift();
var destination = aData.join("-");
var contenido = jQuery(this).html();
jQuery(this).replaceWith(jQuery(''+contenido+''));
});
$("#appForm .ajCheck").each(function(){
//console.log ( $(this).attr("name") + ' > ' + this.id );
$("#"+this.id).on('click', function () {
console.log("callAjax(" + $(this.id) + ",'checkbox')");
callAjax(this.id,'checkbox');
});
});
$("#appForm .ajCheckDisable").each(function(){
//console.log ( $(this).attr("name") + ' > ' + this.id );
$("#"+this.id).on('click', function () {
console.log("callAjax(" + this.id + ",'checkbox','disable')");
callAjax(this.id,'checkbox','disable');
});
});
$("#appForm .ajInput").each(function(){
var bInputError;
bInputError = false;
//console.log ( $(this).attr("name") + ' > ' + this.id );
$("#"+this.id).on('change', function () {
console.log("try to change '" + $("#"+this.id).attr("name") + "' > callAjax(" + $(this.id) + ",'input')");
var sName = $("#"+this.id).attr("name");
if ( sName=="iban_coordinador" || sName=="iban_viajero" ) {
var myiban = $("#"+this.id).val()
var myibanTmp = myiban.replaceAll(" ", "");
if ( myibanTmp!="" && fn_ValidateIBAN(myibanTmp) == false ) {
bInputError = true;
alertDGC("
IBAN Incorrecto
- El IBAN debe ser español (comienza por ES)
- El IBAN debe estar asociado a tu nombre","dgcMensajeLeft");
var bgColor = "#FF0000";
$("#"+this.id).css("background-color", bgColor);
/*
$("#"+this.id).fadeTo("slow", 0.5, function() {
$("#"+this.id).fadeTo("slow", 1, function() {
$("#"+this.id).css("background-color", '');
});
});
*/
} else {
$("#"+this.id).val(myibanTmp);
bInputError = false;
}
}
if ( bInputError==false ) {
$("#"+this.id).css("background-color", '');
callAjax(this.id,'input');
console.log("changed '" + $("#"+this.id).attr("name") + "' > callAjax(" + $(this.id) + ",'input')");
}
});
});
$("#appForm .ajInputDate").each(function(){
//console.log ( $(this).attr("name") + ' > ' + this.id );
$("#"+this.id).on('change', function () {
console.log("callAjax(" + $(this.id) + ",'input_date')");
callAjax(this.id,'input_date');
});
});
$("#appForm button").each(function(btn){
var sId = this.id;
var disabled = $("#"+sId).is(":disabled");
var invalidClass = ( $(this).hasClass("btn-datos") || $(this).hasClass("btn-multiselect") );
/* var invalidClass = ( $(this).hasClass("btn-datos") || $(this).hasClass("btn-multiselect") ); */
if ( invalidClass ) {
// MultiSelect o Datos
}
if ( $(this).hasClass("submitFormAuto") ) {
console.log ( 'Btn Form Auto (' + sId + ')' );
validate(sId);
}
if ( !disabled && ( sId!='get-order' && sId!='close' && sId!='closeFooter' && sId!='openLog' && sId!='closeLog' && !invalidClass ) ) {
//console.log(sId);
if ( $( "#"+sId ).hasClass( "btnSeguro" ) || $( "#"+sId ).hasClass( "btnSeguroDbl" ) || $( "#"+sId ).hasClass( "btnExternalLink" ) ) {
//console.log(sId + " > Seguro");
} else {
$("#"+sId).off('click').click(function(e){
if ( $(this).hasClass("submitFormAuto") ) {
e.stopPropagation();
e.preventDefault();
console.log ( 'Btn Form Clicked (' + sId + ')' );
validate(sId);
} else if ( $(this).hasClass("submitForm") ) {
e.stopPropagation();
e.preventDefault();
console.log ( 'Btn Form Clicked (' + sId + ')' );
var myValidation;
myValidation = validateMyJS();
if ( myValidation!="" ) {
alert (myValidation);
console.log("Validation failed...");
} else {
console.log("Validation completed. Submitting...");
var formData = new FormData();
formData.append( 'token', $("#MyToken").val() );
formData.append( 'type', $("#MyType").val() );
for ( var i=0; i<10; i++ ) {
if ( $('#MyForm'+i).length ) {
if ( $('#MyForm'+i).is(':checkbox') ) {
if ( document.getElementById('MyForm' + i).checked ) {
formData.append( 'formdata'+i, 1 );
} else {
formData.append( 'formdata'+i, 0 );
}
} else {
formData.append( 'formdata'+i, $('#MyForm'+i).val() );
}
}
//console.log( 'formdata' + i + ' -> ' + $('#MyForm'+i).val() );
}
alertDGC ('Guardando Información. Espera ...
');
$("#btnAceptar").hide();
$("#saving").text("Guardando. Espera por favor ...");
$.ajax({
url: "releases/20231212/class/user_save.php", // Save Data
type: 'POST',
data: formData,
async: false, // Stop here until get response back
cache: false,
contentType: false,
processData: false,
success: function(response) {
console.log ("Success: "+ response);
var aReason;
aReason = response.split('|');
if ( aReason[0]!="ok" ) {
if ( aReason[0]=="warning" ) {
$("#saving").text(aReason[1]);
} else {
var sReasonTxt = "";
if ( aReason[1]=="" ) {
sReasonTxt = "Error: ha habido un fallo al guardar";
} else {
sReasonTxt = "Error: " + aReason[1];
}
console.log(sReasonTxt);
alertDGC(sReasonTxt);
}
$("#btnAceptar").show();
$("#saving_icon").hide();
} else {
console.log ("Información guardada");
//$("#saving").text("Información Guardada");
$("#MyDataSaved").val('saved');
}
//console.log ("Status Response: " + aReason[0]);
if ( aReason[0]=="ok" ) {
if ( $('#fileToUpload1' ).length ) {
//console.log ( $('#fileToUpload1' ).length );
var MyFileData = $('#fileToUpload1').prop('files')[0];
if ( MyFileData==undefined ) {
console.log ("No hay imagen");
$("#saving").html("Guardado correctamente
");
$("#saving_icon").hide();
} else {
//status.setURL(aReason[1],aReason[3]);
setTimeout( function() {
// Bucle para dar tiempo ...
var iTime=0;
while ( $("#MyDataSaved").val()=="" && iTime<5000 ) {
iTime++;
//console.log ( iTime + ' ' + $("#MyDataSaved").val() );
}
if ( iTime>10000 ) {
alertDGC ("Expiró el tiempo. Vuelve a intentarlo");
console.log ("Expiró el tiempo. Vuelve a intentarlo");
} else {
console.log("callUploadAjax (1)");
callUploadAjax(1);
}
}, 1000);
}
} else {
$("#saving").html("Guardado correctamente
");
$("#saving_icon").hide();
dgcTiempo = 3000;
$('.dgcAlert').animate({opacity:0},dgcTiempo);
setTimeout("$('.dgcAlert').remove()",dgcTiempo);
console.log("#"+$("#MyType").val());
$("#"+$("#MyType").val()).removeClass("btnMgmtGlowing");
$("#"+$("#MyType").val()).addClass("btnMgmtStop");
$("#"+$("#MyType").val()).text($("#"+$("#MyType").val()).text().replace("Guardar", "Guardado"));
}
}
},
error: function(response) {
alertDGC ("Error: "+ response);
}
});
}
} else {
e.preventDefault();
/* Extra Validations */
switch (sId) {
case "bookingdata":
if ( $("#bookingcondiciones").prop("checked")==false ) {
bGeneralError = true;
$(this).prop("disabled",false);
alertDGC("Antes de continuar, debes marcar la casilla para confirmar que has leído y aceptas el contrato");
btnWeb();
} else {
bGeneralError = false;
}
break;
case "newsletterregister":
if ( $("#acceptance_newsletter").prop("checked")==false ) {
bGeneralError = true;
$(this).prop("disabled",false);
alertDGC("Antes de continuar, debes aceptar la política de privacidad.");
btnWeb();
} else {
bGeneralError = false;
}
break;
default:
}
if ( bGeneralError==false ) {
//console.log("Ok. Validating " + sId);
$("#"+sId).prop("disabled",true);
validate(sId);
//console.log("Validated->"+sId);
} else {
console.log ("Error. Stop validating " + sId);
}
}
});
}
}
});
$("#openLog").off('click').click(function(e){
e.preventDefault();
$("#quick-log-bg, #quick-log-panel").fadeIn(300);
$("#quick-log-bg").attr('style', 'display: block;');
});
$("#closeLog").off('click').click(function(e){
e.preventDefault();
$("#quick-log-bg, #quick-log-panel").fadeOut(300);
$("#quick-log-bg").attr('style', 'display: none;');
});
$("#closeFooter").off('click').click(function(e){
e.preventDefault();
//console.log("Button Close");
$(ql_bg + ', ' + ql_pnl).fadeOut(300);
$("#quick-login-bg").attr('style', 'display: none;');
});
$("#Alogout").off('click').click(function(e){
e.preventDefault();
var ql_bg = '#quick-login-bg';
var ql_pnl = '#quick-login-panel';
$(ql_bg + ', ' + ql_pnl).fadeIn(300);
$("#quick-login-bg").attr('style', 'display: block;');
validate('logout');
});
$(".viewall").off('click').click(function(e){
e.preventDefault();
var sId = this.id.substr(3);
console.log(sId);
var x = document.getElementById(sId);
if (x.type==='password') {
x.type = 'text';
} else {
x.type = 'password';
}
});
$(".btn-my-travels").off('click').click(function(e){
switch ( this.id ) {
case "vuelos_info":
case "payment_trf":
case "payment_tpv":
console.log ("Botón Travel " + this.id);
break;
default:
e.preventDefault();
validate(this.id);
console.log("Validating ... " + this.id);
}
});
$('button[id^="travellerview"]').off('click').click(function(e){
e.preventDefault();
var sId = this.id.replace("travellerview-","");
console.log ( "travellerview[" + sId + "]" );
//$('button[id^="travellerview-"]').removeClass("btn-selected");
$('button[id^="travellerview-"]').addClass("btn-unselected");
$('div[id^="travellerdetail-"]').hide();
if ( sId!="new" && sId!="pending" && sId!="past" ) {
$('#travellerdetail-'+sId).text("Buscando Reserva ...");
validate('travellerview-'+sId,'travellerdetail-'+sId);
/*
if ( $('#travellerdetail-'+sId).html().trim()=="" ) {
validate('travellerview-'+sId,'travellerdetail-'+sId);
}
*/
}
$('#travellerview-'+sId).removeClass("btn-unselected");
$('#travellerview-'+sId).addClass("btn-selected");
$('#travellerdetail-'+sId).show();
});
$("#password, #username").keypress(function(e) {
if(e.which == 13) {
e.preventDefault();
validate('login');
}
});
$("#firstname, #lastname, #vatdocument, #vatnr, #email, #phone").keypress(function(e) {
if(e.which == 13) {
e.preventDefault();
validate('userregister');
}
});
}
jQuery(function($) {
$.datepicker.regional['es'] = {
closeText: 'Cerrar',
prevText: '< Ant',
nextText: 'Sig >',
currentText: 'Hoy',
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'],
dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sáb'],
dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sá'],
weekHeader: 'Sm',
dateFormat: 'dd/mm/yy',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ''
};
$.datepicker.setDefaults($.datepicker.regional['es']);
$( function() {
$( document ).tooltip();
} );
});
function fn_ValidateIBAN(IBAN) {
IBAN = IBAN.toUpperCase();
IBAN = IBAN.trim();
IBAN = IBAN.replace(/\s/g, "");
var letra1,letra2,num1,num2;
var isbanaux;
var numeroSustitucion;
if ( IBAN.length!=24 ) { return false; }
letras = IBAN.substring(0, 2);
if ( letras!="ES" ) {
return false;
}
letra1 = IBAN.substring(0, 1);
letra2 = IBAN.substring(1, 2);
num1 = getnumIBAN(letra1);
num2 = getnumIBAN(letra2);
isbanaux = String(num1) + String(num2) + IBAN.substring(2);
isbanaux = isbanaux.substring(6) + isbanaux.substring(0,6);
resto = modulo97(isbanaux);
if ( resto==1 ) {
return true;
} else {
return false;
}
}
function modulo97(iban) {
var parts = Math.ceil(iban.length/7);
var remainer = "";
for (var i = 1; i <= parts; i++) { remainer = String(parseFloat(remainer+iban.substr((i-1)*7, 7))%97); }
return remainer;
}
function getnumIBAN(letra) {
ls_letras = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
return ls_letras.search(letra) + 10;
}
function callAjax( iField, sType='', sPosted='', sExtraValue='' ) {
var this_name = $("#"+iField).attr("name");
var this_position = "";
var newValue = "¿¿??";
var bSave = true;
switch ( sType ) {
case "checkbox":
newValue = $( "#"+iField+":checked" ).length;
console.log ( "checkbox(" + newValue + ")" );
break;
case "input":
newValue = $("#"+iField).val();
console.log ( iField + " input(" + newValue + ") " + "Extra:[" + sExtraValue + "]" );
break;
case "input_date":
this_name = $("#"+iField).attr("name").slice(0, -1);
this_position = $("#"+iField).attr("name").slice(-1);
var newValue1;
var newValue2;
var newValue3;
newValue1 = $("[name='"+this_name+"1']").val();
newValue2 = $("[name='"+this_name+"2']").val();
newValue3 = $("[name='"+this_name+"3']").val();
if ( newValue1=="" || newValue2=="" || newValue3=="" ) {
bSave = false;
console.log ( this_name + "> ERROR > input_date(" + newValue3 + "-" + newValue2 + "-" + newValue1 + ")" );
} else {
newValue = newValue3 + "-" + newValue2 + "-" + newValue1;
console.log ( this_name + " > input_date(" + newValue3 + "-" + newValue2 + "-" + newValue1 + ")" );
}
break;
default:
newValue = $("#"+iField).val();
}
console.log ( "CallAjax: " + iField + " Value: '" + newValue + "'" );
if ( bSave==false ) {
console.log ("No se guarda");
} else if ( newValue=="¿¿??" ) {
alertDGC("No se ha podido guardar el último cambio");
} else {
console.log ("Guardando '"+iField+"': Espera ...");
$.ajax({
url: 'https://www.pasonoroeste.com/oficinator/releases/20231212/class/modes.php',
type: 'POST',
dataType: "html",
data: {
token: '',
action : 'externalupdate',
id: iField,
newvalue: newValue,
extravalue: sExtraValue
},
success: function(response) {
var aReason;
aReason = response.split('|');
console.log ( aReason[0] );
console.log ( aReason[1] );
var bgColor = "";
if ( aReason[0]=="error" ) {
bgColor = "#e5afaf";
if ( aReason[1]=="" ) {
alertDGC("ERROR!");
} else {
alertDGC(aReason[1]);
}
if ( sType=="checkbox" ) {
if ( newValue==1 ) {
$('#'+iField).prop('checked', false);
} else {
$('#'+iField).prop('checked', true);
}
}
} else {
console.log ( "Guardado '" + iField + "'" );
bgColor = ( aReason[0]=="warning" ) ? "#ffcc00" : "#8dc70a";
if ( sType=="checkbox" ) {
if ( newValue==1 ) {
$('#'+iField).prop('checked', true);
} else {
$('#'+iField).prop('checked', false);
}
}
switch ( sPosted ) {
case "disable":
$("#"+iField).prop( "disabled", true );
break;
default:
}
// Funcionalidades Especiales
//console.log ( this_name + ' ' + newValue );
if ( ( this_name=="insurancecancel" || this_name=="insurancebasic" ) && newValue==1 ) {
$(".booking_seguro").removeClass("bg_red");
}
if ( this_name=="bookingcondiciones" && newValue==1 ) {
$("#div_condiciones").removeClass("bg_red");
}
if ( this_name=="bookingprivacidad" && newValue==1 ) {
$("#div_privacidad").removeClass("bg_red");
}
if ( this_name=="bookingconfirmadatos" && newValue==1 ) {
$("#div_confimadatos").removeClass("bg_red");
$("[name='firstname']").prop( "disabled", true );
$("[name='lastname']").prop( "disabled", true );
$("[name='birthdate_1']").prop( "disabled", true );
$("[name='birthdate_2']").prop( "disabled", true );
$("[name='birthdate_3']").prop( "disabled", true );
$("[name='country']").prop( "disabled", true );
$("[name='province']").prop( "disabled", true );
$("[name='city']").prop( "disabled", true );
$("[name='postal-code']").prop( "disabled", true );
$("[name='domicilio']").prop( "disabled", true );
$("[name='iban_coordinador']").prop( "disabled", true );
}
if ( this_name=="merchand_conf" && newValue==1 ) {
$("#div_envio_confimadatos").removeClass("bg_red");
$("[name='province']").prop( "disabled", true );
$("[name='city']").prop( "disabled", true );
$("[name='postal-code']").prop( "disabled", true );
$("[name='domicilio']").prop( "disabled", true );
}
/*
switch ( this_name ) {
case "insurancecancel":
case "insurancebasic":
case "bookingconfirmadatos":
case "bookingcondiciones":
case "bookingprivacidad":
if ( aReason[2]=="Ready For Payment" ) {
$("div").removeClass("booking_payment");
console.log( this_name + ': ' + aReason[2] );
}
break;
default:
}
*/
}
$( "#"+iField).css("background-color", bgColor);
$( "#"+iField).fadeTo("slow", 0.5, function() {
$( "#"+iField).fadeTo("slow", 1, function() {
$( "#"+iField).css("background-color", '');
});
});
},
error: function(response) {
alert ("Error: "+ response);
}
});
}
}
function callUploadAjax( iField ) {
console.log ( "CallUploadAjax " + iField + " Type: " + $("#MyType").val() );
if ( $('#fileToUpload' + iField ).length ) {
var MyFileData = $('#fileToUpload'+iField).prop('files')[0];
var MyFilePath = $('#fileToUpload'+iField).val();
var MyFileExt = MyFilePath.substr(MyFilePath.lastIndexOf('.')+1,MyFilePath.length);
console.log("Data:" +MyFileData);
console.log("Path: " + MyFilePath);
console.log("Ext: " + MyFileExt);
var MyFormData = new FormData();
// Mando los screenshot "on the fly" o el fichero "raw"
var allImages = $('#screenshots').find('img');
if ( allImages.length==0 ){
MyFormData.append( 'file_data', MyFileData );
console.log( 'File(s) ready to send' );
} else {
for ( var i=0; i < allImages.length; i++ ) {
MyFormData.append('file_data', allImages[i].src);
}
console.log( 'Screenshot(s) ready to send' );
}
MyFormData.append( 'type', $("#MyType").val() );
MyFormData.append( 'token', $("#MyToken").val() );
MyFormData.append( 'aux1', $("#MyForm0").val() );
//var status = new createStatusbar(obj); //Using this we can set progress.
//status.setText("Wait");
//status.setFileNameSize(files[i].name,files[i].size);
//sendFileToServer(fd,status,idx);
console.log ("Guardando fichero (" + iField + "). Espera ...");
$("#saving").text("Guardando fichero (" + iField + "). Espera ...");
$.ajax({
url: "https://www.pasonoroeste.com/api/dropbox/uploadFile.php", // Full Path -> ¡¡Relative Path NOT WORKING!!
type: 'POST',
data: MyFormData,
async: true,
cache: false,
contentType: false,
processData: false,
success: function(response) {
/*for (var pair of MyFormData.entries()) {
console.log(pair[0]+ ', ' + pair[1]);
}*/
var aReason;
aReason = response.split('|');
console.log (aReason[0]);
console.log (aReason[1]);
if ( aReason[0]=="error" ) {
if ( aReason[1]=="" ) {
alertDGC("ERROR!");
} else {
alertDGC(aReason[1]);
}
} else {
iField += 1;
console.log ( "Guardado Documento (" + iField + ")" );
$("#saving").text("Guardado fichero. Espera ...");
if ( $('#fileToUpload' + iField ).length ) {
console.log ("Guardando fichero (" + iField + "). Espera ...");
callUploadAjax(iField);
} else {
console.log ( "Todos los Ficheros guardados (" + iField + ")" );
$("#saving").text("Guardado correctamente");
dgcTiempo = 5000;
$('.dgcAlert').animate({opacity:0},dgcTiempo);
setTimeout("$('.dgcAlert').remove()",dgcTiempo);
console.log("#"+$("#MyType").val());
$("#"+$("#MyType").val()).removeClass("btnMgmtGlowing");
$("#"+$("#MyType").val()).addClass("btnMgmtStop");
$("#"+$("#MyType").val()).text($("#"+$("#MyType").val()).text().replace("Guardar", "Guardado"));
}
}
},
error: function(response) {
alert ("Error: "+ response);
}
});
}
}
// Window Size
var iWidth = window.innerWidth;
var iHeight = window.innerHeight;
//alert ( "W:" + iWidth + "H:" + iHeight );
// Upload screenshot
var settings = {
max_width: 320,
max_height: 320
};
function automationCallback() {
// Click Get Input File/Image
$('input[id^="fileToUpload"]').on('click', function() {
var iBtnNumber = this.id.substr(-1);
console.log ("Open Input Upload (" + iBtnNumber + ")" );
});
// File/Image Uploaded
$('input[id^="fileToUpload"]').on('change', function() {
var iBtnNumber = this.id.substr(-1);
console.log ("Image Upload (" + iBtnNumber + ")" );
var MyFilePath = $('#fileToUpload'+iBtnNumber).val();
var MyFileExt = MyFilePath.substr(MyFilePath.lastIndexOf('.')+1,MyFilePath.length);
console.log(MyFilePath);
console.log(MyFileExt);
// Valid Images (JPG, PNG)
if ( MyFileExt!="jpg" && MyFileExt!="png" ) {
console.log ( MyFileExt + " File Uploaded (" + iBtnNumber + ")" );
$("#btnFileToUpload"+iBtnNumber).removeClass("btnMgmtGlowing");
$("#btnFileToUpload"+iBtnNumber).addClass("btnMgmtStop");
} else {
// Image on the fly
const canvas = document.querySelector("#canvas");
const screenshotsContainer = document.querySelector("#screenshots");
var img = new Image();
var oFileInput = document.getElementById('fileToUpload'+iBtnNumber);
var count = oFileInput.files.length;
for ( var i=0; i 102400 ) {
console.log ( "Image too big ("+Math.ceil(file.size/1024)+"Kb / max 100kb)" );
} else {
console.log ( file.size );
}
if ( file.type.match('image.*') ) {
var reader = new FileReader();
reader.readAsDataURL(file); // Read in the image file as a data URL
reader.onload = function(evt) {
if( evt.target.readyState == FileReader.DONE ) {
img.src = evt.target.result;
img.onload = () => canvas.getContext("2d").drawImage(img, 0, 0);
//console.log( 'W: ' + img.width + ' H: ' + img.height );
img.onload = () => screenshotsContainer.prepend(resize_image(img,MyFileExt));
}
};
} else {
alert("Error: Image expected!");
}
$("#btnFileToUpload"+iBtnNumber).removeClass("btnMgmtGlowing");
$("#btnFileToUpload"+iBtnNumber).addClass("btnMgmtStop");
}
}
});
}
resize_image = function(img,thisExtension) {
var ctx = canvas.getContext("2d");
var canvasCopy = document.createElement("canvas");
var copyContext = canvasCopy.getContext("2d");
var ratio = 1;
var imgWidth = ( img.width==0 ) ? settings.max_width : img.width;
var imgHeight = ( img.height==0 ) ? settings.max_height : img.height;
console.log( imgWidth + '[' + img.width + ']' + ' ' + imgHeight + '[' + img.height + ']' );
var imgType = ( imgWidth>imgHeight ) ? 'horizontal' : 'vertical';
if ( imgType=="horizontal" ) {
if( imgWidth > settings.max_width ) {
ratio = settings.max_width / imgWidth;
}
} else {
if ( imgHeight > settings.max_height ) {
ratio = settings.max_height / imgHeight;
}
}
canvasCopy.width = imgWidth;
canvasCopy.height = imgHeight;
copyContext.drawImage(img, 0, 0);
canvas.width = imgWidth * ratio;
canvas.height = imgHeight * ratio;
ctx.drawImage(canvasCopy, 0, 0, canvasCopy.width, canvasCopy.height, 0, 0, canvas.width, canvas.height);
//console.log( canvasCopy.width + ' ' + canvasCopy.height + ' - ' + canvas.width + ' ' + canvas.height);
// https://developer.mozilla.org/es/docs/Web/API/HTMLCanvasElement/toDataURL
/* VIDEO
canvas.width = myVideo.videoWidth;
canvas.height = myVideo.videoHeight;
canvas.getContext("2d").drawImage(video, 0, 0);
*/
if ( thisExtension=="png" ) { // PNG
const img = document.createElement("img");
img.src = canvas.toDataURL("image/png");
screenshotsContainer.prepend(img);
} else if ( thisExtension=="jpg" ) { // JPG
const img = document.createElement("img");
img.src = canvas.toDataURL("image/jpeg");
}
console.log( "Image resized to W: "+canvas.width+" H: "+canvas.height+"" );
if ( parent.document.getElementById('profileavatar') ) {
parent.document.getElementById('profileavatar').removeAttribute('src', '');
parent.document.getElementById('profileavatar').setAttribute('src', img.src);
}
return img;
};