projetphp/script.js

103 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-12-30 17:41:15 +01:00
$(function() {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~TR TO EDIT~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
2018-12-30 17:41:15 +01:00
$("#allRecord").on("click", ".editUser", function() {
2018-12-30 17:52:46 +01:00
$(this).toggleClass('fa-edit fa-check');
$(this).toggleClass('editUser confirmEditUser');
for(i=0; i<$("td", $(this).parent().parent()).length-1;i++)
{
j= $($("td", $(this).parent().parent())[i]);
inputOptions = '';
if(j.attr('class')=="pw")
inputOptions += 'type="password" data-oldpw="'+ltrim(j.html())+'" ';
else if (j.attr('class') == "datene")
inputOptions += 'type="date" '
j.html('<input '+inputOptions+' value="'+(j.attr('class')=="pw"?'':ltrim(j.html()))+'" />');
}
2018-12-30 17:41:15 +01:00
});
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~CONFIRM EDIT~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
2018-12-30 17:41:15 +01:00
$("#allRecord").on("click", ".confirmEditUser", function() {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~CALL BACK DE LA VERIF DE MOT DE PASSE~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
2018-12-30 17:41:15 +01:00
function callBackVerif(data){
var dataToSend = new Object(); //Objet contenant les données à envoyé
2018-12-30 17:41:15 +01:00
dataToSend["updatePW"] = (data===true?false:true);
if($(".pw input", tr).val() === data || data === true) //Verif du mot de passe si nécesaire
2018-12-30 17:41:15 +01:00
{
for(i=0; i<tds.length-1;i++) //Analyse de chaque td
2018-12-30 17:41:15 +01:00
{
j= $(tds[i]);
className = j.attr('class');
if(className == "pw" && data === true)
2018-12-30 17:41:15 +01:00
value = $('input', j).data("oldpw");
else
value = $('input', j).val();
dataToSend[className] = value;
}
$.post("post.php", dataToSend, function(data){
try {
if(data.return == true)
{
for(i=0; i<tds.length-1;i++) //On change les input en pure html
2018-12-30 17:41:15 +01:00
{
j= $(tds[i]);
className = j.attr('class');
if(className == "pw")
value = data.pw;
else
value = $('input', j).val();
dataToSend[className] = value;
j.html(value);
}
swal("all done");
$(that).toggleClass('fa-check fa-edit');
$(that).toggleClass('confirmEditUser editUser');
}
else
swal(data);
} catch (e) {
swal( "Oops" , "Something went wrong!<br>"+e , "error" );
}
console.log(data.return)
}, "json");
}
else {
swal( "Oops" , "Password don't match !" , "error" );
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
tds = $("td", $(this).parent().parent()); //Récupère les td concernant le click
tr = $(this).parent().parent(); //Récupère le tr concernant le click
2018-12-30 17:41:15 +01:00
that = this;
if ($(".pw input", tr).val() === "") {
callBackVerif(true);
}
else {
swal({
closeOnClickOutside: false,
closeOnEsc: false,
content: {
element: "input",
attributes: {
placeholder: "Confirmer le mot de passe",
type: "password",
},
},
}).then(callBackVerif);
}
});
});
//J'avais plein d'espace a droite en récupérent mon innerHTML
//https://stackoverflow.com/questions/24282158/removing-the-white-space-at-the-start-of-the-string
2018-12-30 17:41:15 +01:00
function ltrim(str) {
if(str == null) return str;
return str.replace(/^\s+/g, '');
}