Files
2016-02-21 14:28:40 +01:00

127 lines
3.6 KiB
JavaScript
Executable File

function modify_account()
{
var input_list = new Array();
var test_pass = true;
$('form#form_data input,select').each(function() {
if ( this.type != 'button' ) {
input_list.push(this.id);
}
});
for (var i = 0; i < input_list.length; i++)
{
// Verifying the syntax of inputs
var param = input_list[i];
if ( !value_verify(param) ) {
test_pass = false;
$('#'+param).css({'border' : '1px '+color_nok+' solid'});
$('#'+param).animate({ backgroundColor : background_nok }, 500);
} else {
$('#'+param).css({'border' : '1px '+color_ok+' solid'})
$('#'+param).animate({ backgroundColor : background_ok }, 500);
}
}
// If all inputs are OK, send req to ajax.php
if ( test_pass ) {
var post_data = $('form#form_data input,select').serialize();
$.ajax({
url: 'ajax.xhtml?id=updateAccount',
data: post_data,
type: 'POST',
start: $('form#form_data input,select').attr('disabled','disabled'),
error: function(responseText) { alert(critical_error);},
success: function(responseText){display_modification_data(responseText);},
});
}
} // end of modify_account
function display_modification_data(ressource)
{
if ( $('#result_data').css('display') != 'none') {
$('#result_data').slideUp(200);
$("#result_data p[id*='return_code_']").css('display', 'none');
}
if (ressource == 'critical_error') {
alert(critical_error);
return;
}
ressource = eval(ressource);
for (var i = 0; i < ressource.length; i++)
{
$('#return_code_'+ressource[i]).css('display', '');
}
$('form#form_data input,select').attr('disabled','');
$('#result_data').slideDown(500);
} // End of display_modification
// ---------------------------------------------------------------------------- //
function modify_password()
{
var input_list = new Array();
var test_pass = true;
$('form#form_password input').each(function() {
if ( this.type != 'button' ) {
input_list.push(this.id);
}
});
for (var i = 0; i < input_list.length; i++)
{
var param = input_list[i];
if ( !value_verify(param) ) {
test_pass = false;
$('#'+param).css({'border' : '1px '+color_nok+' solid'});
$('#'+param).animate({ backgroundColor : background_nok }, 500);
} else {
$('#'+param).css({'border' : '1px '+color_ok+' solid'})
$('#'+param).animate({ backgroundColor : background_ok }, 500);
}
}
if ( test_pass ) {
var post_data = $('form#form_password input').serialize();
$.ajax({
url: 'ajax.xhtml?id=updatePassword',
data: post_data,
type: 'POST',
start: $('form#form_password input').attr('disabled','disabled'),
error: function(responseText) { alert(critical_error);},
success: function(responseText){display_modification_password(responseText);},
});
}
} // end of modify_password
function display_modification_password(ressource)
{
if ( $('#result_password').css('display') != 'none') {
$('#result_password').slideUp(200);
$("#result_password p[id*='return_code_password_']").css('display', 'none');
}
if (ressource == 'critical_error') {
alert(critical_error);
return;
}
ressource = eval(ressource);
for (var i = 0; i < ressource.length; i++)
{
$('#return_code_password_'+ressource[i]).css('display', '');
}
$('form#form_password input').attr('disabled','');
$('#result_password').slideDown(500);
} // End of display_modification
// ----------------------------------------------------------------------------------- //
function checkPassword()
{
alert('debug');
var post_password = $('form#form_password input[name="password"]').serialize();
alert(post_password);
// $.ajax{
// url: 'ajax.xhtml?id=checkPassword',
// data:
// }
}