// Administración var administrar = { // Funciones para mostrar por pantalla los diferentes formularios form : { add : function() { this.mostrar('add'); }, edit : function() { this.mostrar('edit'); }, del : function() { this.mostrar('del'); }, delall : function() { this.mostrar('delall'); }, mostrar : function(formulario) { $('#admin_forms input, #admin_forms select').removeClass('invalid'); $('#admin_forms div.input_error').remove(); $('#admin_forms #' + formulario).siblings().hide(); $('#admin_forms #' + formulario).toggle(); } }, // Función encargada de mosrtrar los errores producidos tras la última // petición del administrador mostrarErrores : function(data) { if (data.stderr.error == 'validacion') { $.each(data.stderr.info, function(i, value) { $('input[name=' + i + '], select[name=' + i + ']').addClass('invalid').after('
' + value + '
'; }); mensaje.error('#admin_msg', msg); } }, // Función para el envio del formulario mediante AJAX y el tratamieto de la // respuesta del servidor procesar : function(inputs) { $.post('/admin/proc_form.php', inputs, function(data) { if (data.stderr.error) { administrar.mostrarErrores(data); } else { var msg = 'La base de datos se ha actualizado con éxito, haga click aquí para ver los cambios.'; mensaje.info('#admin_msg', msg); } }, 'json'); } };