include("lib.prototype"); include("lib.onload"); include("lib.jquery"); include("lib.jquerynoconflicts"); include("lib.nprogress"); include("fitbank.proc.parametros"); include("fitbank.util"); include("fitbank.evento"); /** * Namespace Ingreso - Contiene las funciones para la página de ingreso. */ var Ingreso = { /** * Inicializa el formulario de ingeso. * * @private */ init: function() { if (Parametros['fitbank.ingreso.WEBKIT'] == "true" && !Prototype.Browser.WebKit) { window.location.href = "navegador.html"; return; } document.disableContextMenu(); Ingreso.formulario = $("ingreso"); if (!Ingreso.formulario) { return; } Ingreso.activa = $("activa"); Ingreso.usuario = Ingreso.formulario.select("input[type=text]")[0]; Ingreso.officeBankingId = Ingreso.formulario.select("input[type=text]")[1]; Ingreso.clave = Ingreso.formulario.select("input[type=password]")[0]; Ingreso.cierre = $("cierre"); Ingreso.useKeypad = $("useKeypad"); Ingreso.officeBanking = $("officeBanking"); Ingreso.claveImagen = $("claveImagen"); Ingreso.imagen = $("imagen"); Ingreso.showImage = $("showImage"); Ingreso.links = $("links"); // Obtener datos de ingreso de formulario de la p�gina padre if (window.opener && window.opener.Ingreso) { Ingreso.datos = window.opener.Ingreso.datos; window.opener.Ingreso.datos = null; } Ingreso.formulario.action = "proc/sig"; Ingreso.formulario.method = "POST"; Ingreso.formulario.onsubmit = Ingreso.ingresar.curry(false, false); Ingreso.progreso = new Element("img", { className: "ingreso-progreso", src: "img/progreso.gif" }); Ingreso.progreso.hide(); Ingreso.formulario.insert( { after: Ingreso.progreso }); Ingreso.formulario.insert(new Element("input", { type: "hidden", name: "_contexto", value: "sig" })); if ($('mas_opciones')) { $('mas_opciones').on("click", Element.toggle.curry($('opciones'))); } // Forzar cierre $('forzar').on("click", function() { new Ajax.Request("proc/cad", { onComplete: function() { location.reload(); } }); }); var keypad = Parametros['fitbank.ingreso.KEYPAD'] == "true"; var numpad = Parametros['fitbank.ingreso.NUMPAD'] == "true"; var links = Parametros['fitbank.ingreso.LINKS'] == "true"; var image = Parametros['fitbank.ingreso.IMAGE'] == "true"; Ingreso.useKeypad.on("click", function() { if (keypad) { Ingreso.keypad(); } else if (numpad) { Ingreso.numpad(); } }); Ingreso.officeBanking.on("click", function() { Ingreso.toggleOfficeBanking(); }); Ingreso.initNames(true); if (!keypad) { Ingreso.useKeypad.checked = false; Ingreso.useKeypad.hide(); Ingreso.useKeypad.next().hide(); Ingreso.officeBanking.checked = false; Ingreso.officeBanking.hide(); Ingreso.officeBanking.next().hide(); } if (links) { Ingreso.links.show(); } if (image) { Ingreso.showImage.show(); Ingreso.claveImagen.hide(); Ingreso.showImage.on("click", function(e) { $E(e).cancelar(); new Ajax.Request("proc/imagen", { parameters: { _contexto: "sig", rand: Math.random(), usuario: Ingreso.usuario.value, ruc: Ingreso.officeBankingId.value }, onSuccess: function(transport) { var json = transport.responseJSON; Ingreso.imagen.update(new Element("label").update(json.mensaje)); if (!json.error) { Ingreso.showImage.hide(); Ingreso.usuario.readOnly = true; if (json.imagen && json.imagen != "") { Ingreso.imagen.insert(new Element("img", { src: "data:image/png;base64," + json.imagen })); } Ingreso.claveImagen.show(); } } }); }); } }, /** * Función que inicializa los names de los elementos. */ initNames: function(init) { var json = { error: true }; new Ajax.Request("proc/names", { asynchronous: false, parameters: { _contexto: "sig", rand: Math.random(), init: (init && !Ingreso.datos) ? "true" : "" }, onSuccess: function(transport) { json = transport.responseJSON; } }); if (json.error) { document.location.href = "error.html#" + json.id; Ingreso.formulario.hide(); return false; } if (json.activa) { Ingreso.activa.show(); Ingreso.formulario.hide(); return false; } Ingreso.usuario.name = json.nameUsuario || Math.random(); Ingreso.usuario.previous("label").setAttribute("for", Ingreso.usuario.name); Ingreso.officeBankingId.name = json.nameOfficeBankingId || Math.random(); Ingreso.officeBankingId.previous("label").setAttribute("for", Ingreso.officeBankingId.name); Ingreso.clave.name = json.nameClave || Math.random(); Ingreso.clave.previous("label").setAttribute("for", Ingreso.clave.name); if (Ingreso.datos) { Ingreso.usuario.value = Ingreso.datos.usuario; Ingreso.clave.value = Ingreso.datos.clave; Ingreso.ingresar(true, true); } else { if (init && Parametros['fitbank.ingreso.KEYPAD'] == "true") { Ingreso.keypad(); Ingreso.useKeypad.checked = true; Ingreso.useKeypad.hide(); Ingreso.useKeypad.next().hide(); } else if (init && Parametros['fitbank.ingreso.NUMPAD'] == "true") { Ingreso.numpad(); Ingreso.useKeypad.checked = true; Ingreso.useKeypad.hide(); Ingreso.useKeypad.next().hide(); } Ingreso.formulario.show(); Ingreso.formulario.focusFirstElement(); } return true; }, /** * Abre una nueva ventana. * * @param usuario Usuario (opcional) * @param clave Clave (opcional) * * @private */ abrir: function(usuario, clave) { if (screen.width < 1024 || screen.height < 768) { if (!confirm("Su pantalla no cumple con los requerimientos mínimos" + " de resolución de 1024x768." + " ¿Desea continuar abriendo la aplicación con esta resolución?")) { return false; } } if (usuario && clave) { Ingreso.datos = { usuario: usuario, clave: clave }; } var nombre = ("ventana_" + Math.random() * 10000000000).substring(0, 15); var url = modularjs.basePath + "../ingreso.html"; if (Prototype.Browser.IE) { var width = screen.availWidth; var height = screen.availHeight - 10; window.open(url, nombre, "width=" + width + "px,height=" + height + "px,left=0,top=0,resizable=yes"); } else { window.open(url, nombre, "fullscreen=yes, menubar=no, status=no"); } return nombre; }, /** * Genera un teclado con letras y numeros. * * @private */ keypad: function() { var currentKeypad = Ingreso.formulario.select(".keypad")[0]; if (currentKeypad) { Ingreso.clave.value = ""; Ingreso.clave.readOnly = Ingreso.useKeypad.checked; if (Ingreso.useKeypad.checked) { Ingreso.clave.handler.start(); } else { Ingreso.clave.handler.stop(); } currentKeypad.toggle(); return; } var botones = new Element('div', { className: 'keypad' }); new ObjectRange(0, 9).each(function(i) { var boton = new Element('button', { onclick: "return false;" }).setStyle({ backgroundImage: 'url("img/proc/img_tecla/' + i + '.png?_contexto=sig&rand=' + Math.random() + '")' }); boton.on('click', function() { Ingreso.clave.value = Ingreso.clave.value + "" + i; }); botones.insert(boton); }); new ObjectRange('a', 'z').each(function(i) { var boton = new Element('button', { onclick: "return false;" }).update(i.toUpperCase()); boton.on('click', function() { Ingreso.clave.value = Ingreso.clave.value + "" + i; }); botones.insert(boton); }); var boton = new Element('button', { onclick: "return false;" }).update('<'); boton.on('click', function() { Ingreso.clave.value = Ingreso.clave.value.substring(0, Ingreso.clave.value.length - 1); }); botones.insert(boton); Ingreso.clave.insert({after: botones}); Ingreso.clave.handler = Ingreso.clave.on('keypress', function(e) { new Evento(e).cancelar(); return false; }); Ingreso.clave.value = ""; Ingreso.clave.readOnly = true; }, /** * Genera un teclado solo con numeros. * * @private */ numpad: function() { var currentNumpad = Ingreso.formulario.select(" .numpad")[0]; if (currentNumpad) { Ingreso.clave.value = ""; Ingreso.clave.readOnly = Ingreso.useKeypad.checked; if (Ingreso.useKeypad.checked) { Ingreso.clave.handler.start(); } else { Ingreso.clave.handler.stop(); } currentNumpad.toggle(); return; } var botones = new Element('div', { className: 'numpad' }); new ObjectRange(0, 9).each(function(i) { var boton = new Element('button', { onclick: "return false;" }).setStyle({ backgroundImage: 'url("img/proc/img_tecla/' + i + '.png?_contexto=sig&rand=' + Math.random() + '")' }); boton.on('click', function() { Ingreso.clave.value = Ingreso.clave.value + "" + i; }); botones.insert(boton); }); var borrarUno = new Element('button', { onclick: "return false;" }).update('<'); borrarUno.on('click', function() { Ingreso.clave.value = Ingreso.clave.value.substring(0, Ingreso.clave.value.length - 1); }); botones.insert(borrarUno); var borrarTodo = new Element('button', { onclick: "return false;" }).update('#'); borrarTodo.on('click', function() { Ingreso.clave.value = ""; }); botones.insert(borrarTodo); Ingreso.clave.insert({after: botones}); Ingreso.clave.handler = Ingreso.clave.on('keypress', function(e) { new Evento(e).cancelar(); return false; }); Ingreso.clave.value = ""; Ingreso.clave.readOnly = true; }, /** * Muestra informacion para ingreso por Office Banking * * @private */ toggleOfficeBanking: function() { Ingreso.officeBankingId.value = ""; Ingreso.officeBankingId.toggle(); Ingreso.officeBankingId.previous("label").toggle(); }, /** * Ejecuta el proceso de ingreso. * * @private */ ingresar: function(submit, noInit) { if (!noInit && !Ingreso.initNames(false)) { return false; } (function() { Ingreso.formulario.hide(); if(!Mobile) { Ingreso.progreso.show(); } else { NProgress.start(); NProgress.set(parseFloat("0." + (Math.floor(Math.random() * 8) + 1))); } if (submit) { Ingreso.formulario.submit(); } Ingreso.usuario.value = ""; Ingreso.clave.value = ""; Ingreso.cierre.checked = false; Ingreso.useKeypad.checked = false; }).defer(); return true; }, /** * Sale de la pagina actual y va a una pagina con un mensaje de nueva ventana. * * @private */ cerrar: function() { document.location.href = "postingreso.html"; } }; addOnLoad(Ingreso.init);