$("input[type='text'], input[type='mail']").each(function(){
$("input[type='text'], input[type='mail'], input[type='date']").each(function(){
data[$(this).attr("id")] = $(this).val();
})
$("textarea").each(function(){
data[$(this).attr("id")] = $(this).text();
})
//VGU ticket N°157184040 le 07/03/2024 => On reformate les date iso au format français
/*$("input[type='date'], input[data-role='datepicker']").each(function(){
var date = $(this).val();
var dateSplit = date.split('/');
var dateFormatee = dateSplit[1] + "-" + dateSplit[0] + "-" + dateSplit[2];
data[$(this).attr("id")] = new Date(dateFormatee);
});*/
$("select").each(function(){
console.log($(this).attr("id") + " : " + $(this).val());
value = $(this).val();
if(typeof $(this).val() == "object" && $(this).val() != null && $(this).val() != ""){
value = value.join(",");
}
data[$(this).attr("id")] = value;
$(this).attr("disabled", "disabled");
})
$("input[type='radio']").each(function(){
data[$(this).attr("name")] = rbf_getFieldValue($(this).attr("name"));
$(this).attr("disabled", "disabled");
});
$("input[type='checkbox']").each(function(){
data[$(this).attr("name")] = $(this).is(":checked");
$(this).attr("disabled", "disabled");
});
//data["R14846954"] = getParam("idDemande");
console.log(data);
console.table(data);
//Création candidature
$.ajax({
type: "POST",
url: "https://talents.elsatis.fr/prod99/api2/custom/applications-create",
headers: { "Api-Key": "aff8b1fe-98d5-4314-bdfd-fb26bc675efa-130753704-118463344" },
data: data,
success: function(response) {
//Si la candidature a été créée correctement
console.log("Candidature envoyée avec succès")
nbFichiersEnvoyes = 0;
nbFichiersJoints = 0;
$("input[type='file']").each(function() {
nbFichiersJoints += $(this)[0].files.length;
});
if (nbFichiersJoints > 0) {
//Récupération de l'id de la candidature créée et ajout des champs fichiers
var idCandidature = response.results;
var inputFiles = $("input[type='file']");
delayAttach(inputFiles, idCandidature);
/* $("input[type='file']").each(function() {
ajoutFichier($(this).attr("id"), idCandidature);
});*/
}
else {
$(".retour-candidature").html(" Merci d'avoir postulé.
Nous avons bien reçu votre candidature.
Vous allez recevoir un email de confirmation de notre part dans quelques minutes. ");
$.ajax({
method: "GET",
url: "https://talents.elsatis.fr/prod99/api2/custom/selectQuery",
data : { "requete": 'SELECT message_candidature_enregistree, url_liste_offres FROM site_annonces WHERE id='+idSupport, "nombreEnregistrement": 1 },
headers: { "Api-Key": "aff8b1fe-98d5-4314-bdfd-fb26bc675efa-130753704-118463344" }
}).done(function(data) {
if (data.code = 200) {
/*
var messageCandidatureEnregistree = data.results.queryResult[0][0];
$('.retour-candidature').html(messageCandidatureEnregistree);
*/
var messageCandidatureEnregistree = data.results.queryResult[0];
$('.retour-candidature').html(messageCandidatureEnregistree[0] + "
Retourner à la liste des offres ");
$("html, body").animate({ scrollTop: $(document).height() }, 200);
}
});
}
},
error: function(xhr, status, error) {
//Si la candidature n'a pas été créée
console.error(error);
$(".retour-candidature").html("Erreur lors de l'envoi de la candidature. Veuillez réessayer ultérieurement. ")
}
});
})
function delayAttach(arr, id){
var count = 1;
jQuery.each(arr, function(index, value){
setTimeout(function(){
ajoutFichier(value.id, id);
}, count * 2000)
count++;
});
}
function testerChampFichier(nomIntegration, libelle){
if(rbf_getFieldValue(nomIntegration) != ""){
var infosFichier = rbf_getFieldValue(nomIntegration).split(".");
var extension = infosFichier[infosFichier.length - 1];
var extensionsAutorisees = ["jpg", "jpeg", "pdf", "doc", "docx", "odt"]
if(extensionsAutorisees.indexOf(extension) < 0){
return 'Erreur sur le champ fichier "' + libelle + '", merci de renseigner une des extensions suivantes : jpg, docx, pdf, odt. ';
}
var fileInput = document.getElementById(nomIntegration);
var file = fileInput.files[0];
var fileSize = file.size;
var fileSizeMB = bytesToMB(fileSize);
if(fileSizeMB > 5){
return 'Erreur sur le champ fichier "' + libelle + '", la taille maximale est de 5Mo. ';
}
}
return "";
}
function bytesToMB(bytes) {
return (bytes / (1024 * 1024)).toFixed(2);
}
function afficherBoutonPostuler(){
console.log("------------------------------- Début afficherBoutonPostuler --------------------------------------------")
var rgpd = $("[name='donnees_personnelles_rgpd']").is(":checked");
var peutPostuler = true;
var champsErreur = "";
$("[id^='fileContainer']").each(function(){
var nomIntegration = $(this).attr("id").replace("fileContainer_", "");
var libelle = $(this).parent().find(".libele-champ").text().replace("*", "");
var messageErreur = testerChampFichier(nomIntegration, libelle);
champsErreur += messageErreur;
if(messageErreur != ""){
peutPostuler = false;
}
});
$(".requiredInput:not('.k-widget')").each(function(){
console.log($(this).attr("name") + " : " + $(this).val());
if($(this).val() == ""){
peutPostuler = false;
if($(this).attr("name") == "cv"){
champsErreur += 'Le champ "CV" est vide. ';
}
else{
var champVide = $("label[for='" + $(this).attr("name") + "']:not(.float-label):visible").text().replace("*", "").trim();
champsErreur += 'Le champ "'+ champVide +'" est vide. ';
}
}
});
if(!rgpd){
peutPostuler = false;
champsErreur += "Merci d'accepter les accords RGPD. "
}
if(champsErreur != "") champsErreur += "
";
console.log(champsErreur);
console.log("Bouton postuler : " + peutPostuler);
if(peutPostuler){
$("#bouton-postuler").show();
$("#erreur-champs").hide();
}
else{
$("#bouton-postuler").hide();
$("#erreur-champs").show();
$("#erreur-champs").html(champsErreur);
}
console.log("------------------------------- Fin afficherBoutonPostuler --------------------------------------------")
}
function ajoutFichier(nomChamp, idCandidature){
//Récupération du fichier, de son type et de son nom
var fichier = document.getElementById(nomChamp).files[0];
if(fichier && fichier != "" && fichier != null && fichier != undefined){
var fichierContentType = fichier.type;
var fichierName = encodeURI(fichier.name);
//Récupération de la base64 du fichier
var reader = new FileReader();
reader.readAsDataURL(fichier);
reader.onload = function () {
var fichier64 = reader.result;
fichier64 = fichier64.split(",")[1];
//Envoi du fichier sur la candidature
$.ajax({
type: "POST",
headers: {
"Content-Type": "application/json",
"Api-Key": "aff8b1fe-98d5-4314-bdfd-fb26bc675efa-130753704-118463344"
},
contentType:"multipart/form-data",
url: "https://talents.elsatis.fr/prod99/api2/custom/applications-attachfile?id="+ idCandidature + "&contentType=" + fichierContentType + "&fileName=" + fichierName + "&fieldName=" + nomChamp,
data: fichier64,
success: function( data ) {
console.log( data );
nbFichiersEnvoyes++;
if (nbFichiersEnvoyes == nbFichiersJoints) {
//$(".retour-candidature").html("Merci d'avoir postulé.
Nous avons bien reçu votre candidature. ");
$.ajax({
method: "GET",
url: "https://talents.elsatis.fr/prod99/api2/custom/selectQuery",
data : { "requete": 'SELECT message_candidature_enregistree, url_liste_offres FROM site_annonces WHERE id='+idSupport, "nombreEnregistrement": 1 },
headers: { "Api-Key": "aff8b1fe-98d5-4314-bdfd-fb26bc675efa-130753704-118463344" }
}).done(function(data) {
if (data.code = 200) {
var messageCandidatureEnregistree = data.results.queryResult[0];
$('.retour-candidature').html(messageCandidatureEnregistree[0] + "
Retourner à la liste des offres ");
$("html, body").animate({ scrollTop: $(document).height() }, 200);
}
});
}
},
error: function(xhr, status, error) {
//Si le fichier n'a pas été envoyé
console.error(error);
$(".retour-candidature").html("Erreur lors de l'envoi d'un fichier de votre candidature. Veuillez réessayer ultérieurement'. ")
}
});
}
}
}
|