/************************************************************************************ * Gestion du portrait ***********************************************************************************/ let previewPortrait = $('#PERS_IMAGE_PRW_PORTRAIT'); // id of the preview image let ImageFilePortrait = ""; new AjaxUpload('uploadedImgPortrait', { action: '/rest-ws/personne//portrait', name: 'imagePortrait', onSubmit: function(file, extension) { previewPortrait.attr('src', '/images/loading.gif');}, onComplete: function(file, response) { console.debug(response); if (response == "KO") { if (!ModeCreation) CadreMiseAJourStatutAjax('personne01', response); } else { previewPortrait.on('load', function(){ previewPortrait.unbind(); } ); previewPortrait.attr('src', '/rest-ws/personne//portrait'); if (!ModeCreation) MiseAjourProfil(); else document.getElementById('PERS_IMAGE_PORTRAIT').value = '/rest-ws/personne//portrait'; $('#uploadedImgPortrait').val(response); } } } ); function SupprimerPortrait() { // demander confirmation if (window.confirm("Etes-vous certain de vouloir supprimer votre photo ?")) { Ajax.CallRESTWS("/rest-ws/personne//portrait", null, RetourSupprimerPortrait, "DELETE"); } } function RetourSupprimerPortrait(response) { if (response.status == 200) { document.getElementById('uploadedImgPortrait').value = ""; document.getElementById('PERS_IMAGE_PRW_PORTRAIT').src = "/images/personnes/blank.png"; } else { LudinantesWindow.displayError("Erreur XX " + response.status, "XXXXX"); } RetourMiseAjourProfil(response); } /************************************************************************************ * Gestion de l'avatar ***********************************************************************************/ let previewAvatar = $('#PERS_IMAGE_PRW_AVATAR'); // id of the preview image let ImageFileAvatar = ""; new AjaxUpload('uploadedImgAvatar', { action: '/rest-ws/personne//avatar', name: 'imageAvatar', onSubmit: function(file, extension) { previewAvatar.attr('src', '/images/loading.gif');}, onComplete: function(file, response) { previewAvatar.on('load', function(){ previewPortrait.unbind(); } ); previewAvatar.attr('src', '/rest-ws/personne//avatar'); if (!ModeCreation) MiseAjourProfil(); else document.getElementById('PERS_IMAGE_AVATAR').value = '/rest-ws/personne//avatar'; $('#uploadedImgAvatar').val('/rest-ws/personne//avatar'); } } ); function SupprimerAvatar() { // demander confirmation if (window.confirm("Etes-vous certain de vouloir supprimer votre avatar ?")) { Ajax.CallRESTWS("/rest-ws/personne//avatar", null, RetourSupprimerAvatar, "DELETE"); } } function RetourSupprimerAvatar(response) { if (response.status == 200) { document.getElementById('uploadedImgAvatar').value = ""; document.getElementById('PERS_IMAGE_PRW_AVATAR').src = "/images/personnes/blank_avatar.png"; } else { LudinantesWindow.displayError("Erreur XX " + response.status, "XXXXX"); } RetourMiseAjourProfil(response); } /************************************************************************************ * Gestion du pseudo (test de dispo) ***********************************************************************************/ let PseudoOK = true; let PseudoKO = ""; function TestPseudo() { var Params = { "pseudo": document.getElementById("PERS_PSEUDO").value } Ajax.CallRESTWS("/rest-ws/personne/testpseudo", Params, RetTestPseudo, "POST"); } function RetTestPseudo(response) { PseudoOK = (response.status == 200); if (PseudoOK) document.getElementById("PERS_PSEUDO").style.color = "black"; else { PseudoKO = response.data.data; document.getElementById("PERS_PSEUDO").style.color = "red"; } } /************************************************************************************ * Validation des saisies ***********************************************************************************/ function ValiderProfil() { let Erreurs = ""; if (document.getElementById("PERS_NOM").value.length < 2) Erreurs += "Le nom doit comporter au moins deux caractéres\n"; if (document.getElementById("PERS_PRENOM").value.length < 2) Erreurs += "Le prénom doit comporter au moins deux caractéres\n"; if (document.getElementById("PERS_PSEUDO").value.length > 50) Erreurs += "Le pseudonyme doit comporter au plus cinquante caractéres\n"; if (document.getElementById("PERS_COURRIEL").value.length > 100) Erreurs += "L'adresse électronique doit comporter au plus cent caractéres\n"; let re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z])?)$/i; if (!re.test(document.getElementById("PERS_COURRIEL").value)) Erreurs += "L'adresse électronique n'est pas valide\n"; if (document.getElementById("PERS_TELEPHONE").value.length == 0) Erreurs += "Le numéro de téléphone est obligatoire\n"; else if (document.getElementById("PERS_TELEPHONE").value.replace(" ", "").length != 10) Erreurs += "Le numéro de téléphone doit comporter 10 chiffres\n"; if (!isNumeric(document.getElementById("PERS_TELEPHONE").value)) Erreurs += "Le numéro de téléphone doit étre numérique\n"; /*if (document.getElementById("PERS_DISCORD").value != '' && document.getElementById("PERS_DISCORD").value.match(/.+#\d{1,6}/i) == null) Erreurs += "Le nom d'utilisateur Discord est incorrect. Il doit être de la forme Pseudo#1234\n";*/ if (!PseudoOK) Erreurs += PseudoKO + "\n"; return Erreurs; }