2018-12-30 17:41:15 +01:00
|
|
|
$(function() {
|
2018-12-30 19:53:28 +01:00
|
|
|
passwordPatern=/^[a-zA-Z0-9]{8,16}$/;
|
|
|
|
loginPatern=/^[a-z]{8,16}$/
|
|
|
|
mailPatern=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;//https://emailregex.com/
|
|
|
|
$("#allRecord").on("keyup", ".pw input", function(){
|
|
|
|
if(passwordPatern.test($(this).val()) || $(this).val() == "")
|
|
|
|
{
|
|
|
|
$(this).css("background-color", "");
|
|
|
|
$('div', $(this).parent()).css("display", "none");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$(this).css("background-color", "red");
|
|
|
|
$('div', $(this).parent()).css("display", "block");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$("#allRecord").on("keyup", ".email input", function(){
|
|
|
|
if(mailPatern.test($(this).val()))
|
|
|
|
{
|
|
|
|
$(this).css("background-color", "");
|
|
|
|
$('div', $(this).parent()).css("display", "none");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$(this).css("background-color", "red");
|
|
|
|
$('div', $(this).parent()).css("display", "block");
|
|
|
|
}
|
|
|
|
});
|
2018-12-30 21:26:55 +01:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
/*~~~~~~~~~~~~~~~~TR TO DEL~~~~~~~~~~~~~~~~*/
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
$("#allRecord").on("click", ".delUser", function() {
|
|
|
|
tr = $(this).parent().parent();
|
|
|
|
var login = "";
|
|
|
|
var sl = "";
|
|
|
|
if(tr.find("i.editUser").length !== 0)
|
|
|
|
{
|
|
|
|
sl = ltrim($('.sl', tr).html())
|
|
|
|
login = $('.login', tr).html();
|
|
|
|
}
|
|
|
|
else if(tr.find("i.confirmEditUser").length !== 0)
|
|
|
|
{
|
|
|
|
sl = $('.sl select', tr).val();
|
|
|
|
login = $('.login', tr).html();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
swal("error");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
console.log(sl);
|
|
|
|
if(sl == "10")
|
|
|
|
{
|
|
|
|
swal( "Oops" , "You can't del user with sl 10" , "error" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
login = ltrim(login);
|
|
|
|
swal({
|
|
|
|
title: "Are you sure to del "+login+" ?",
|
|
|
|
text: "Once deleted, you will not be able to recover this!",
|
|
|
|
icon: "warning",
|
|
|
|
buttons: true,
|
|
|
|
dangerMode: true,
|
|
|
|
})
|
|
|
|
.then((willDelete) => {
|
|
|
|
if (willDelete) {
|
|
|
|
$.post("post.php", {userToDel: login}, function(){
|
|
|
|
tr.remove();
|
|
|
|
swal("Poof! "+login+" has been deleted!", {
|
|
|
|
icon: "success",
|
|
|
|
});
|
|
|
|
})
|
|
|
|
} else {
|
2018-12-30 19:53:28 +01:00
|
|
|
|
2018-12-30 21:26:55 +01:00
|
|
|
}
|
|
|
|
});
|
2018-12-30 19:53:28 +01:00
|
|
|
|
2018-12-30 21:26:55 +01:00
|
|
|
|
|
|
|
});
|
2018-12-30 18:09:11 +01:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
/*~~~~~~~~~~~~~~~~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');
|
2018-12-30 19:53:28 +01:00
|
|
|
for(i=1; i<$("td", $(this).parent().parent()).length-1;i++)
|
2018-12-30 17:52:46 +01:00
|
|
|
{
|
|
|
|
j= $($("td", $(this).parent().parent())[i]);
|
2018-12-30 18:41:58 +01:00
|
|
|
className = j.attr('class');
|
|
|
|
if(className == "sl")
|
|
|
|
{
|
|
|
|
val = ltrim(j.html());
|
|
|
|
j.html('<select>\
|
|
|
|
<option value="1" '+(val=="1"?'selected':'')+'>1</option>\
|
|
|
|
<option value="5" '+(val=="5"?'selected':'')+'>5</option>\
|
|
|
|
<option value="10" '+(val=="10"?'selected':'')+'>10</option>\
|
|
|
|
</select>')
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
inputOptions = '';
|
|
|
|
if(className=="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 19:53:28 +01:00
|
|
|
if(className=="pw")
|
|
|
|
{
|
|
|
|
j.append("<div>le mot de passe comporte entre 8 et 16 caractères parmi a..z A..Z 0..9</div>")
|
|
|
|
}
|
2018-12-30 18:41:58 +01:00
|
|
|
}
|
2018-12-30 17:52:46 +01:00
|
|
|
}
|
2018-12-30 17:41:15 +01:00
|
|
|
});
|
2018-12-30 18:09:11 +01:00
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
/*~~~~~~~~~~~~~~~~CONFIRM EDIT~~~~~~~~~~~~~~~~*/
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
2018-12-30 17:41:15 +01:00
|
|
|
$("#allRecord").on("click", ".confirmEditUser", function() {
|
2018-12-30 18:09:11 +01:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
/*~~~~~~~~~~~~~~~~CALL BACK DE LA VERIF DE MOT DE PASSE~~~~~~~~~~~~~~~~*/
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
2018-12-30 17:41:15 +01:00
|
|
|
function callBackVerif(data){
|
2018-12-30 18:09:11 +01:00
|
|
|
var dataToSend = new Object(); //Objet contenant les données à envoyé
|
2018-12-30 17:41:15 +01:00
|
|
|
dataToSend["updatePW"] = (data===true?false:true);
|
2018-12-30 18:09:11 +01:00
|
|
|
if($(".pw input", tr).val() === data || data === true) //Verif du mot de passe si nécesaire
|
2018-12-30 17:41:15 +01:00
|
|
|
{
|
2018-12-30 18:09:11 +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');
|
2018-12-30 18:09:11 +01:00
|
|
|
if(className == "pw" && data === true)
|
2018-12-30 18:41:58 +01:00
|
|
|
value = $('input,select', j).data("oldpw");
|
2018-12-30 19:53:28 +01:00
|
|
|
else if(className=="login")
|
|
|
|
value = ltrim(j.html());
|
2018-12-30 17:41:15 +01:00
|
|
|
else
|
2018-12-30 18:41:58 +01:00
|
|
|
value = $('input,select', j).val();
|
2018-12-30 17:41:15 +01:00
|
|
|
dataToSend[className] = value;
|
|
|
|
}
|
|
|
|
$.post("post.php", dataToSend, function(data){
|
|
|
|
try {
|
|
|
|
if(data.return == true)
|
|
|
|
{
|
2018-12-30 19:53:28 +01:00
|
|
|
for(i=1; 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
|
2018-12-30 18:41:58 +01:00
|
|
|
value = $('input,select', j).val();
|
2018-12-30 17:41:15 +01:00
|
|
|
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" );
|
|
|
|
}
|
|
|
|
}
|
2018-12-30 18:09:11 +01:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
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;
|
2018-12-30 19:53:28 +01:00
|
|
|
if(mailPatern.test($(".email input", tr).val()) && (passwordPatern.test($(".pw input", tr).val()) || $(".pw input", tr).val() ==""))
|
|
|
|
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",
|
|
|
|
},
|
2018-12-30 17:41:15 +01:00
|
|
|
},
|
2018-12-30 19:53:28 +01:00
|
|
|
}).then(callBackVerif);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
swal( "Oops" , "Input don't respect rules !" , "error" );
|
2018-12-30 17:41:15 +01:00
|
|
|
});
|
|
|
|
});
|
2018-12-30 18:09:11 +01:00
|
|
|
|
|
|
|
//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, '');
|
|
|
|
}
|