git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_PROFIND_Aterrizaje/trunk@17 db07b8d6-80f3-1c4e-84de-227a4fed3af2
361 lines
14 KiB
JavaScript
361 lines
14 KiB
JavaScript
$(document).ready(function(){
|
|
profind_login.init();
|
|
profind_registro.init();
|
|
|
|
profind_recuperar_password.init();
|
|
profind_cambiar_password.init();
|
|
});
|
|
|
|
profind_login = {
|
|
init: function() {
|
|
var enviar_login = function() {
|
|
var form = $("#entrarForm");
|
|
form.find(":submit").attr("disabled", true);
|
|
form.find(":submit").addClass('btn-striped');
|
|
$('#entrarForm .resultado').children().remove();
|
|
$.ajax({
|
|
url: form.attr('action'),
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
data : form.serialize()+'&ajax=login-form',
|
|
success: function(data, textStatus, XMLHttpRequest) {
|
|
form.find(":submit").removeClass('btn-striped');
|
|
form.find(":submit").attr("disabled", false);
|
|
if (data.status == '200') {
|
|
window.location.href = data.redirect;
|
|
}
|
|
else {
|
|
if (data != null && typeof data == 'object') {
|
|
$.each(data, function(key, value){
|
|
jQuery('<label/>', {
|
|
text: value
|
|
}).addClass('error').appendTo('#entrarForm .resultado');
|
|
});
|
|
}
|
|
}
|
|
},
|
|
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
|
form.find(":submit").removeClass('btn-striped');
|
|
form.find(":submit").attr("disabled", false);
|
|
jQuery('<label/>', {
|
|
text: 'Error de comunicación con el servidor'
|
|
}).addClass('error').appendTo('#entrarForm .resultado');
|
|
}
|
|
});
|
|
return false;
|
|
};
|
|
|
|
$("#entrarForm").validate({
|
|
onfocusout: false,
|
|
onkeyup: false,
|
|
onclick: false,
|
|
rules:{
|
|
FormularioLogin_email:{
|
|
required:true,
|
|
email: true
|
|
},
|
|
FormularioLogin_password:{
|
|
required:true
|
|
}
|
|
},
|
|
messages:{
|
|
FormularioLogin_email:{
|
|
required:"Introduzca su e-mail",
|
|
email:"Indique un e-mail válido"
|
|
},
|
|
FormularioLogin_password:{
|
|
required:"Indique su contraseña"
|
|
}
|
|
},
|
|
errorClass: "error help-inline",
|
|
errorElement: "span",
|
|
highlight:function(element, errorClass, validClass) {
|
|
$(element).parents('.control-group').addClass('error');
|
|
},
|
|
unhighlight: function(element, errorClass, validClass) {
|
|
$(element).parents('.control-group').removeClass('error');
|
|
},
|
|
submitHandler: enviar_login
|
|
});
|
|
}
|
|
};
|
|
|
|
profind_registro = {
|
|
init: function() {
|
|
|
|
var enviar_registro = function() {
|
|
var form = $("#registroForm");
|
|
form.find(":submit").attr("disabled", true);
|
|
form.find(":submit").addClass('btn-striped');
|
|
$('#registroForm .resultado').children().remove();
|
|
$.ajax({
|
|
url: form.attr('action'),
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
data : form.serialize()+'&ajax=registro-form',
|
|
success: function(data, textStatus, XMLHttpRequest) {
|
|
form.find(":submit").removeClass('btn-striped');
|
|
form.find(":submit").attr("disabled", false);
|
|
if (data.status == '200') {
|
|
form.clearForm();
|
|
$('#msj_info .modal-header h3').text(data.titulo);
|
|
$('#msj_info .modal-body p').text(data.texto);
|
|
$('#msj_info').modal('show');
|
|
}
|
|
else {
|
|
if (data != null && typeof data == 'object') {
|
|
$.each(data, function(key, value){
|
|
jQuery('<label/>', {
|
|
text: value
|
|
}).addClass('error').appendTo('#registroForm .resultado');
|
|
});
|
|
}
|
|
}
|
|
},
|
|
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
|
form.find(":submit").removeClass('btn-striped');
|
|
form.find(":submit").attr("disabled", false);
|
|
jQuery('<label/>', {
|
|
text: 'Error de comunicación con el servidor'
|
|
}).addClass('error').appendTo('#registroForm .resultado');
|
|
}
|
|
});
|
|
return false;
|
|
};
|
|
|
|
$("#registroForm").validate({
|
|
onfocusout: false,
|
|
onkeyup: false,
|
|
onclick: false,
|
|
rules:{
|
|
FormularioRegistro_email:{
|
|
required:true,
|
|
email: true
|
|
},
|
|
FormularioRegistro_password:{
|
|
required:true,
|
|
minlength: 6
|
|
},
|
|
FormularioRegistro_password2:{
|
|
required:true,
|
|
minlength: 6,
|
|
equalTo: "#FormularioRegistro_password"
|
|
},
|
|
FormularioRegistro_acepto:{
|
|
required:true
|
|
}
|
|
},
|
|
messages:{
|
|
FormularioRegistro_email:{
|
|
required:"Introduzca su e-mail",
|
|
email:"Indique un e-mail válido"
|
|
},
|
|
FormularioRegistro_password:{
|
|
required:"Indique una nueva contraseña",
|
|
minlength:"La contraseña debe al menos 6 caracteres"
|
|
},
|
|
FormularioRegistro_password2:{
|
|
required:"Introduzca otra vez la contraseña",
|
|
minlength:"La contraseña debe al menos 6 caracteres",
|
|
equalTo:"La confirmación de contraseña no coincide"
|
|
},
|
|
FormularioRegistro_acepto:""
|
|
},
|
|
errorClass: "error help-inline",
|
|
errorElement: "span",
|
|
highlight:function(element, errorClass, validClass) {
|
|
$(element).parents('.control-group').addClass('error');
|
|
},
|
|
unhighlight: function(element, errorClass, validClass) {
|
|
$(element).parents('.control-group').removeClass('error');
|
|
},
|
|
submitHandler: enviar_registro
|
|
});
|
|
}
|
|
};
|
|
|
|
profind_recuperar_password = {
|
|
init: function() {
|
|
$('a#solicitar_password').click(function(){
|
|
$('#FormularioRecuperar_email').val($('#FormularioLogin_email').val());
|
|
$('#msj_recuperar').modal('show');
|
|
});
|
|
|
|
$('#msj_recuperar .btn-primary').click(function(){
|
|
$("#recuperarForm").submit();
|
|
});
|
|
|
|
var recuperar_password = function() {
|
|
var form = $("#recuperarForm");
|
|
$('#msj_recuperar .btn-primary').addClass('btn-striped');
|
|
$('#msj_recuperar .btn-primary').attr("disabled", true);
|
|
$('#msj_recuperar .resultado').children().remove();
|
|
$.ajax({
|
|
url: form.attr('action'),
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
data : form.serialize()+'&ajax=recuperar-form',
|
|
success: function(data, textStatus, XMLHttpRequest) {
|
|
$('#msj_recuperar .btn-primary').removeClass('btn-striped');
|
|
$('#msj_recuperar .btn-primary').attr("disabled", false);
|
|
if (data.status == '200') {
|
|
form.clearForm();
|
|
$('#msj_recuperar').modal('hide');
|
|
|
|
$('#msj_info .modal-header h3').text(data.titulo);
|
|
$('#msj_info .modal-body p').text(data.texto);
|
|
$('#msj_info').modal('show');
|
|
}
|
|
else {
|
|
if (data != null && typeof data == 'object') {
|
|
$.each(data, function(key, value){
|
|
jQuery('<label/>', {
|
|
text: value
|
|
}).addClass('error').appendTo('#msj_recuperar .resultado');
|
|
});
|
|
}
|
|
}
|
|
},
|
|
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
|
$('#msj_recuperar .btn-primary').removeClass('btn-striped');
|
|
$('#msj_recuperar .btn-primary').attr("disabled", false);
|
|
jQuery('<label/>', {
|
|
text: 'Error de comunicación con el servidor'
|
|
}).addClass('error').appendTo('#msj_recuperar .resultado');
|
|
}
|
|
});
|
|
return false;
|
|
};
|
|
|
|
$("#recuperarForm").validate({
|
|
onfocusout: false,
|
|
onkeyup: false,
|
|
onclick: false,
|
|
rules:{
|
|
FormularioRecuperar_email:{
|
|
required:true,
|
|
email: true
|
|
}
|
|
},
|
|
messages:{
|
|
FormularioRecuperar_email:{
|
|
required:"Introduzca su e-mail en PROFIND",
|
|
email:"Indique un e-mail válido"
|
|
}
|
|
},
|
|
errorClass: "error help-inline",
|
|
errorElement: "span",
|
|
highlight:function(element, errorClass, validClass) {
|
|
$(element).parents('.control-group').addClass('error');
|
|
},
|
|
unhighlight: function(element, errorClass, validClass) {
|
|
$(element).parents('.control-group').removeClass('error');
|
|
},
|
|
submitHandler: recuperar_password
|
|
});
|
|
}
|
|
};
|
|
|
|
profind_cambiar_password = {
|
|
init: function() {
|
|
$('#msj_cambiarpassword .btn-primary').click(function(){
|
|
$("#cambiarPasswordForm").submit();
|
|
});
|
|
|
|
var cambiar_password = function() {
|
|
var form = $("#cambiarPasswordForm");
|
|
$('#msj_cambiarpassword .btn-primary').addClass('btn-striped');
|
|
$('#msj_cambiarpassword .btn-primary').attr("disabled", true);
|
|
$('#msj_cambiarpassword .resultado').children().remove();
|
|
$.ajax({
|
|
url: form.attr('action'),
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
data : form.serialize()+'&ajax=cambiar-password-form-ext',
|
|
success: function(data, textStatus, XMLHttpRequest) {
|
|
$('#msj_cambiarpassword .btn-primary').removeClass('btn-striped');
|
|
$('#msj_cambiarpassword .btn-primary').attr("disabled", false);
|
|
if (data.status == '200') {
|
|
form.clearForm();
|
|
$('#msj_cambiarpassword').modal('hide');
|
|
|
|
$('#msj_info .modal-header h3').text(data.titulo);
|
|
$('#msj_info .modal-body p').text(data.texto);
|
|
$('#msj_info').modal('show');
|
|
}
|
|
else {
|
|
if (data != null && typeof data == 'object') {
|
|
$.each(data, function(key, value){
|
|
jQuery('<label/>', {
|
|
text: value
|
|
}).addClass('error').appendTo('#msj_cambiarpassword .resultado');
|
|
});
|
|
}
|
|
}
|
|
},
|
|
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
|
$('#msj_cambiarpassword .btn-primary').removeClass('btn-striped');
|
|
$('#msj_cambiarpassword .btn-primary').attr("disabled", false);
|
|
jQuery('<label/>', {
|
|
text: 'Error de comunicación con el servidor'
|
|
}).addClass('error').appendTo('#msj_cambiarpassword .resultado');
|
|
}
|
|
});
|
|
return false;
|
|
};
|
|
|
|
$("#cambiarPasswordForm").validate({
|
|
onfocusout: false,
|
|
onkeyup: false,
|
|
onclick: false,
|
|
rules:{
|
|
FormularioCambiarPassword_password:{
|
|
required:true,
|
|
minlength: 6
|
|
},
|
|
FormularioCambiarPassword_password_repetida:{
|
|
required:true,
|
|
minlength: 6,
|
|
equalTo: "#FormularioCambiarPassword_password"
|
|
},
|
|
},
|
|
messages:{
|
|
FormularioCambiarPassword_password:{
|
|
required:"Indique una nueva contraseña",
|
|
minlength:"La contraseña debe al menos 6 caracteres"
|
|
},
|
|
FormularioCambiarPassword_password_repetida:{
|
|
required:"Introduzca otra vez la contraseña",
|
|
minlength:"La contraseña debe al menos 6 caracteres",
|
|
equalTo:"La confirmación de contraseña no coincide"
|
|
},
|
|
},
|
|
errorClass: "error help-inline",
|
|
errorElement: "span",
|
|
highlight:function(element, errorClass, validClass) {
|
|
$(element).parents('.control-group').addClass('error');
|
|
},
|
|
unhighlight: function(element, errorClass, validClass) {
|
|
$(element).parents('.control-group').removeClass('error');
|
|
},
|
|
submitHandler: cambiar_password
|
|
});
|
|
}
|
|
};
|
|
|
|
|
|
$.fn.clearForm = function() {
|
|
return this.each(function() {
|
|
var type = this.type, tag = this.tagName.toLowerCase();
|
|
if (tag == 'form')
|
|
return $(':input',this).clearForm();
|
|
if (type == 'text' || type == 'password' || tag == 'textarea')
|
|
this.value = '';
|
|
else if (type == 'checkbox' || type == 'radio')
|
|
this.checked = false;
|
|
else if (tag == 'select')
|
|
this.selectedIndex = -1;
|
|
});
|
|
};
|
|
|