var fieldEmail = $('#email_address'); var fieldLastName = $('#last_name'); var fieldFirstName = $('#first_name'); var output = $('#outputt'); /** * Send email to membership request */ var sendEmailMembership = function () { // Display loading GIF openPopupLoading("#membership"); var email = fieldEmail.val(); var Cgu = document.getElementById('Cgu').checked; $.ajax({ url: 'controller/membership-mailing.php', type: 'POST', data: {email: email, Cgu: Cgu}, /** * @return integer */ success: function (result) { if (result == -1) { let translation = "Veuillez renseigner les champs obligatoires"; if (locale === "en") { translation = "Please fill in the required fields"; } if (locale === 'ar') { translation = "يرجى ملء الحقول المطلوبة"; } M.toast({html: translation}, 4000); } else if (result == -2) { let translation = "Format de l'adresse email non valide"; if (locale === "en") { translation = "Invalid email address format"; } if (locale === 'ar') { translation = "تنسيق عنوان البريد الإلكتروني غير صالح"; } M.toast({html: translation}, 4000); } else if (result == -3) { let translation = "Une erreur est survenue, merci de réessayer plus tard"; if (locale === "en") { translation = "An error has occurred, please try again later"; } if (locale === 'ar') { translation = "لقد حدث خطأ، رجاء أعد المحاولة لاحقا"; } M.toast({html: translation}, 4000); } else if (result == -5) { let translation = "Veuillez accepter de recevoir notre actualité par mail"; if (locale === "en") { translation = "Please accept to receive our news by email"; } if (locale === 'ar') { translation = "يرجى الموافقة على تلقي أخبارنا عبر البريد الإلكتروني"; } M.toast({html: translation}, 4000); } else if (result == 1) { let translation = "Cette adresse email est déjà enregistrée"; if (locale === "en") { translation = "This email address is already registered"; } if (locale === 'ar') { translation = "هذا البريد الالكتروني مسجل سابقا"; } M.toast({html: translation}, 4000); fieldEmail.val(''); } else if (result == 2) { hideOverlay() output.hide(); eraseForm(); let translation = "Merci de votre inscription"; if (locale === "en") { translation = "Thank you for registering"; } if (locale === 'ar') { translation = "نشكرك على التسجيل"; } M.toast({html: translation}, 4000); } else { hideOverlay() output.html(result); } }, error: function (xhr, status, error) { alert(error.message); } }); }; /** * Ouvre la popup de chargement * * @param parentClass */ function openPopupLoading(parentClass) { $(parentClass + " .loading-box").show(); } /** * Remet à zéro le formulaire */ function eraseForm() { $('input[type=text]').each(function () { $(this).val(''); }); $('input[type=email]').each(function () { $(this).val(''); }); $('textarea').each(function () { $(this).val(''); }); }