$(function() { 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"); } }); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~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 { } }); }); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~TR TO EDIT~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ $("#allRecord").on("click", ".editUser", function() { $(this).toggleClass('fa-edit fa-check'); $(this).toggleClass('editUser confirmEditUser'); for(i=1; i<$("td", $(this).parent().parent()).length-1;i++) { j= $($("td", $(this).parent().parent())[i]); className = j.attr('class'); if(className == "sl") { val = ltrim(j.html()); j.html('') } else { inputOptions = ''; if(className=="pw") inputOptions += 'type="password" data-oldpw="'+ltrim(j.html())+'" '; else if (j.attr('class') == "datene") inputOptions += 'type="date" ' j.html(''); if(className=="pw") { j.append("
le mot de passe comporte entre 8 et 16 caractères parmi a..z A..Z 0..9
") } } } }); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~CONFIRM EDIT~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ $("#allRecord").on("click", ".confirmEditUser", function() { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~CALL BACK DE LA VERIF DE MOT DE PASSE~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ function callBackVerif(data){ var dataToSend = new Object(); //Objet contenant les données à envoyé dataToSend["updatePW"] = (data===true?false:true); if($(".pw input", tr).val() === data || data === true) //Verif du mot de passe si nécesaire { for(i=0; i"+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 that = this; 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", }, }, }).then(callBackVerif); } else swal( "Oops" , "Input don't respect rules !" , "error" ); }); }); //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 function ltrim(str) { if(str == null) return str; return str.replace(/^\s+/g, ''); }