1(function (Drupal, $, once, Cookies) { 2 Drupal.behaviors.Popin_localite = { 3 attach: function (context, settings) { 4 var $elements = once('Popin_localite', "#popin-localite", context); 5 $elements.forEach(element => { 6 // on vérifie si le mail existe 7 $('input#popin-localite-email-input').on('keyup', function (event) { 8 var value = $(this).val(); 9 if ( value.length > 1 ) { 10 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)) { // on prépare l'envoie en vérifiant si l'email est valide 11 setTimeout(function () { 12 // on envoie la requete pour savoir si l'utilisateur existe 13 var url = '/api/verif_user/' + value; 14 var settings = { 15 "url": url, 16 "method": "GET", 17 "headers": { 18 "Content-Type": "application/json", 19 }, 20 }; 21 $.ajax(settings).done(function (response) { 22 if (response.data.has_account) { // si le compte existe 23 $('.div-sous-section-2 span.error-text').show(); 24 $('.div-sous-section-2 input#popin-localite-email-input').css({ 25 "border-color": "red", 26 "border-width": "2px" 27 }); 28 $('.div-sous-section-2 .button').attr('data-valid', false); 29 } else { 30 $('.div-sous-section-2 span.error-text').hide(); 31 $('.div-sous-section-2 input#popin-localite-email-input').attr('style', ''); 32 $('.div-sous-section-2 .button').attr('data-valid', true); 33 } 34 console.log(response.data.has_account, response.data); 35 }); 36 }, 1000); 37 } 38 } else { 39 $('.div-sous-section-2 .button').attr('data-valid', false); 40 } 41 }) 42 // on vérifie si le cp existe 43 $('input#popin-localite-cp-input').on('keyup', function(event) { 44 var value = $(this).val(); 45 if ( value.length === 5 ) { 46 setTimeout(function () { 47 // on envoie la requete pour savoir si le CP existe 48 var url = '/api/verif_cp/' + value; 49 var settings = { 50 "url": url, 51 "method": "GET", 52 "headers": { 53 "Content-Type": "application/json", 54 }, 55 }; 56 $.ajax(settings).done(function (response) { 57 if (!response.data.exist) { // si le cp n'existe pas 58 $('.popin-middle-section-3 span.error-text').show(); 59 $('.div-sous-section-3 input#popin-localite-cp-input').css({ 60 "border-color": "red", 61 "border-width": "2px" 62 }); 63 $('.div-sous-section-3 .button').attr('data-valid', false); 64 } else { 65 $('.popin-middle-section-3 span.error-text').hide(); 66 $('.div-sous-section-3 input#popin-localite-cp-input').attr('style', ''); 67 $('.div-sous-section-3 .button').attr('data-valid', true); 68 } 69 console.log(response.data.has_account, response.data); 70 }); 71 }, 500); 72 } else { 73 $('.div-sous-section-3 .button').attr('data-valid', false); 74 } 75 }) 76 // on ajoute un cadre rouge en cas d'erreur 77 $(".button").on('click', function () { 78 var data_function = $(this).attr("data-function"); 79 if (data_function === "cp") { 80 var value = $('input#popin-localite-cp-input').val(); 81 if (value.length !== 5) { 82 $(this).closest('.div-sous-section-3 .input-section-3').addClass('input-error'); 83 } 84 } 85 }); 86 // on affiche la pop up additionnel avec la bonne section 87 $('a.next-step').on('click', function (e) { 88 if ($(e.target).attr('data-valid') === 'true') { 89 open_popup_additionnel($(e.target).attr('data-destination')); 90 if ( $(e.target).attr('data-destination') === '1' ) { 91 var value = $(e.target).prev('input').val(); 92 // on envoie le cp 93 var url = '/api/set_commune/' + value; 94 var settings = { 95 "url": url, 96 "method": "GET", 97 "headers": { 98 "Content-Type": "application/json", 99 }, 100 }; 101 $.ajax(settings).done(function (response) { 102 // On cree le cookie avec la commune 103 if ( Cookies.get("flk_commune") ) { 104 Cookies.set("flk_commune", response.data.term); 105 }
106 // do some magic tricks 107 }); 108 var form = new FormData(); 109 form.append("cp", value); 110 send_request_to_stat(form) 111 }; 112 if ($(e.target).attr('data-destination') === '2') { // on envoie les infos en stat si l'utilisateur passe 113 var form = new FormData(); 114 form.append("jepasse", true); 115 send_request_to_stat(form) 116 } 117 } 118 }) 119 // On gere la selection du secteur 120 $('li.button-ville').on('click', function(){ 121 var cp_secteur_id = $(this).attr("data-ip"); 122 var secteur = $(this).html(); 123 // On cree le cookie avec la commune 124 if (Cookies.get("flk_commune") || $('body').hasClass('role-administrator')) { 125 Cookies.set("flk_commune", cp_secteur_id); 126 var form = new FormData(); 127 form.append("secteur", secteur); 128 send_request_to_stat(form); 129 // window.location.href = "/"; 130 } 131 }) 132 // on renvoie vers le formulaire de création de compte 133 $('a.next-step-register').on('click', function (e) { 134 if ($(e.target).attr('data-valid') === 'true') { 135 window.location.href = "/user/register?popin=true&email=" + $('#popin-localite-email-input').val(); 136 } 137 }) 138 }); 139 140 function open_popup_additionnel(section) { 141 $('#popin-localite-additionnel').addClass('initialised'); 142 $('#popin-localite-additionnel').addClass('active'); 143 $('#popin-localite-additionnel').attr('data-section-show', section) 144 $('#popin-localite').removeClass('initialised'); 145 $('#popin-localite').removeClass('active'); 146 if ($('body').hasClass('role-administrator')) { 147 $('#popin-localite').attr('data-enable-admin', 0); 148 } 149 } 150 151 152 function close_popin() { 153 $('#popin-localite').removeClass('initialised'); 154 $('#popin-localite').removeClass('active'); 155 $('#popin-localite').attr('data-enable-admin', 0) 156 $('#popin-localite-additionnel').removeClass('initialised'); 157 $('#popin-localite-additionnel').removeClass('active'); 158 } 159 160 function send_request_to_stat(form) { 161 var settings = { 162 "url": "/api/popin_stat", 163 "method": "POST", 164 "timeout": 0, 165 "processData": false, 166 "mimeType": "multipart/form-data", 167 "contentType": false, 168 "data": form 169 }; 170 $.ajax(settings).done(function (response) { 171 console.clear(); 172 console.log('stat :', response); 173 var responseParse = JSON.parse(response); 174 if ( responseParse.data.secteur ) { 175 // on récupère la reponse et on lance le rechargement de la page 176 if (!$('body').hasClass('role-administrator')) { 177 window.location.href = "/"; 178 } else { 179 close_popin() 180 } 181 } 182 return responseParse; 183 }); 184 } 185 } 186 }; 187 188 Drupal.behaviors.Popin_localite_additionnel = { 189 attach: function (context, settings) { 190 var $elements2 = once('Popin_localite_additionnel', "#popin-localite-additionnel", context); 191 $elements2.forEach(element => { 192 $('#popin-localite-additionnel').find('.popin-close').on('click', function(){ 193 $('#popin-localite-additionnel').removeClass('initialised'); 194 $('#popin-localite-additionnel').removeClass('active'); 195 if ( !$('body').hasClass('role-administrator') ) { 196 window.location.href = "/"; 197 } 198 }) 199 }); 200 } 201 } 202})(Drupal, jQuery, once, Cookies);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.