include("lib.prototype"); include("fitbank.proc.clases"); include("fitbank.util"); /** * Namespace Enlace - Define funciones de conexión con el servidor. */ var Enlace = { /** * Usado para guardar los datos en caso de tener que hacer un submit con * archivos. */ callbacks: {}, /** * Funcion envia un submit al servidor. * * @param contexto Contexto sobre el que se ejecuta las acciones * @param opciones Objeto que puede tener estas propiedades: * - tipo: Tipo del pedido * - paginacion: Indica si se debe cambiar de pagina (-1, 0, 1, * null=volver a la página 1) * - callback: Funcion a ser llamada despues de recibir respuesta * @param posSubir Usado internamente despues de un submit de archivos. * @param fullQuery Indica si se debe ejecutar un query completo en una nueva ventana. * * @return true si no hubo problemas o false si hubo problemas */ submit: function(contexto, opciones, posSubir) { opciones = Object.extend({ tipo: null, paginacion: 0, callback: function() {}, target: null, action: null, skipFiles: false, params: $H(), fullQuery: false }, opciones); var files = Form.getInputs(contexto.form, "file"); if (!opciones.target && (opciones.tipo == GeneralRequestTypes.CONSULTA || posSubir || !files.length)) { if (Enlace.idProceso) { Estatus.finalizarProceso("OK", Enlace.idProceso); } contexto.idProceso = Estatus.iniciarProceso( Util.getMensaje(Mensajes, "fitbank.enlace.PROCESANDO")); var fullQueryNewWindow = opciones.fullQuery && !opciones.paginacion; var secondaryId = Math.round(Math.random() * 10000); var request = new Ajax.Request("proc/" + opciones.tipo, { parameters: $H({ _contexto: !fullQueryNewWindow && contexto.id || secondaryId, _contextoPadre: fullQueryNewWindow && contexto.id || "", _controlConFoco: contexto.formulario.controlConFoco, _registroActivo: contexto.formulario.registroActivo, _paginacion: opciones.paginacion, _fullQuery: opciones.fullQuery }).merge(opciones.params).toQueryString() + "&" + Form.serialize(contexto.form), onSuccess: function(response) { var error = response.responseJSON && response.responseJSON.codigo || ""; if (!Util.isError(error.toLowerCase())) { error = ""; } if (fullQueryNewWindow) { var iframe = new Element("iframe", { src: "entorno-min.html" }); iframe.onload = function() { var cw = Util.getContentWindow(iframe); cw.c.id = secondaryId; cw.c.mostrarFormSimple(opciones, response); cw.c.setupAutoScroll(); cw.onbeforeunload = function() {} } var ef = $$(".entorno-html")[0]; var w = parseInt(ef.getStyle("maxWidth")); iframe.setStyle({ width: (w - 40) + "px", height: ef.getStyle("maxHeight") }); var v = new Ventana({ contenido: iframe, titulo: c.formulario.titulo, verFondo: false, w: w - 30, movable: false }); c.resize(iframe); v.ver(); Estatus.finalizarProceso(Util.getMensaje(Mensajes, "fitbank.contexto.RESULTADO_NUEVA_VENTANA"), c.idProceso); } else { if (response.responseJSON) { opciones.drawHtml = response.responseJSON.drawHtml || false; contexto.loadValues(response, error, opciones); if (response.responseJSON.notifica) { NotificacionesComentarios.consultar(contexto, opciones); } } else { Estatus.finalizarProceso("", contexto.idProceso, (Mobile?"processing":"ok")); } if (!error) { opciones.callback(opciones); } } }, onFailure: contexto.onError.bind(contexto), onException: rethrow }); Estatus.getProceso(contexto.idProceso).setRequest(request); } else { if (files.length && !opciones.skipFiles) { Enlace.idProceso = Estatus.iniciarProceso( Util.getMensaje(Mensajes, "fitbank.enlace.CARGANDO_ARCHIVOS")); Enlace.callbacks[Enlace.idProceso] = function() { Enlace.submit(contexto, opciones, true); }; opciones.action = "proc/subir"; } else { Enlace.idProceso = null; } var params = $H({ _contexto: contexto.id, _proceso: Enlace.idProceso }).merge(opciones.params); var action = contexto.form.action; contexto.form.onsubmit = "return true;"; contexto.form.action = opciones.action + "?" + params.toQueryString(); contexto.form.target = opciones.target || "entorno-iframe-ajax"; contexto.form.method = "POST"; contexto.form.enctype = (files.length && !opciones.skipFiles) ? "multipart/form-data" : ""; contexto.form.submit(); contexto.form.action = action; contexto.form.onsubmit = "return false;"; } } };