Rev 1831 | Rev 2332 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
//+----------------------------------------------------------------------------------------------------------+// Initialisation de Jquery mobile$(document).on('mobileinit', function() {$.mobile.defaultPageTransition = 'fade';});$(document).on('online', function(event) {console.log('online');miseAJourObs();});function changerPage(id, event) {$.mobile.changePage(id);event.stopPropagation();event.preventDefault();}//+----------------------------------------------------------------------------------------------------------+// Gestion des paramètres URLvar modal_recherche = false;$.urlParam = function(name){var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);return (results == null) ? 0 : decodeURIComponent(results[1]);}function recupererParametresUrl() {$('#referentiel').val(($.urlParam('ref') == 0) ? NOM_SCI_REFERENTIEL : $.urlParam('ref'));$('#nom').html(($.urlParam('nom_sci') == 0) ? '' : $.urlParam('nom_sci'));$('#nom-sci-select').val(($.urlParam('nom_sci') == 0) ? '' : $.urlParam('nom_sci'));$('#num-nom-select').val(($.urlParam('num_nom') == 0) ? 0 : $.urlParam('num_nom'));}$(document).ready(function() {$('#geolocaliser').on('vclick', obtenirPosition);$('body').on('pagebeforeshow', '#infos', obtenirDate);$('body').on('pageshow', '#saisie', function(event) {if (!modal_recherche) {obtenirPosition(event);recupererParametresUrl();} else {modal_recherche = false;}});$('body').on('pagehide', '#saisie-popup', function() {modal_recherche = true;});});//+----------------------------------------------------------------------------------------------------------+// Géolocalisation et date du jourvar gps = navigator.geolocation;function obtenirPosition(event) {event.stopImmediatePropagation();event.stopPropagation();event.preventDefault();obtenirDate();geolocaliser();}function geolocaliser() {if (gps) {navigator.geolocation.getCurrentPosition(surSuccesGeoloc, surErreurGeoloc);} else {var erreur = {code:'0', message: 'Géolocalisation non supportée par le navigateur'};surErreurGeoloc(erreur);}}function surSuccesGeoloc(position){if (position) {var lat = position.coords.latitude;var lng = position.coords.longitude;$('#lat').html(lat);$('#lng').html(lng);console.log('Geolocation SUCCESS');var url_service = SERVICE_NOM_COMMUNE_URL;var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng);$.ajax({url : urlNomCommuneFormatee,type : 'GET',dataType : 'jsonp',success : function(data) {console.log('NOM_COMMUNE found.');$('#location').html(data['nom']);$('#code-insee').val(data['codeINSEE']);},complete : function() {var texte = ($('#location').html() == '') ? TEXTE_HORS_LIGNE : $('#location').html();$('#location').html(texte);}});}}function surErreurGeoloc(error){alert('Echec de la géolocalisation, code: ' + error.code + ' message: '+ error.message);}function obtenirDate() {var d = new Date();var jour = d.getDate();var mois = d.getMonth()+1;var annee = d.getFullYear();var aujourdhui =( (''+jour).length < 2 ? '0' : '') + jour + '/' +( (''+mois).length < 2 ? '0' : '') + mois + '/' +annee;$('#date').html(aujourdhui);$('#annee').html(annee);}//+----------------------------------------------------------------------------------------------------------+// Local Storage$(document).ready(function() {$('#sauver-obs').on('click', ajouterObs);$('#valider-photos').on('click', ajoutPhoto);$('body').on('pageshow', '#liste', chargerListeObs);$('body').on('pageshow', '#transmission', miseAJourObs);});var bdd = window.localStorage,index_obs = (bdd.getItem('index_obs') == null) ? 1 : bdd.getItem('index_obs'),index_photos = (bdd.getItem('index_photos') == null) ? 1 : bdd.getItem('index_photos');//bdd.clear();var db;function initOpenDB() {try {if (!window.openDatabase) {//alert("L'ajout de photos n'est pas supporté.");} else {var shortName = 'CEL';var version = '1.0';var displayName = 'TB | CEL web';var maxSize = 1024 * 1024;db = openDatabase(shortName, version, displayName, maxSize);console.log(displayName + ' ' + maxSize);return db;}} catch (e) {if (e == 2) {//alert("Invalid database version.");} else {//alert("Unknown error " + e + ".");}return;}}initOpenDB();if (db !== undefined) {db.transaction(function(tx) {//tx.executeSql('DROP TABLE IMG');tx.executeSql('CREATE TABLE IF NOT EXISTS IMG (id unique, num unique, nom, parent, base64, miniature)');});}console.log(bdd);function ajouterObs(event) {if ($('#nom').html() != '') {var obs = {num:TEXTE_OBS,maj:0,date:'',referentiel:'',lat:'', lng:'',commune:'', code_insee: 0,nom:'',nom_sci_select:'',nn_select:'',nom_sci_retenu:'',nn_retenu:'',num_taxon:'',famille:''};obs.num += index_obs++;obs.date = $('#date').html();obs.referentiel = $('#referentiel').val();obs.lat = $('#lat').html();obs.lng = $('#lng').html();obs.commune = $('#location').html();obs.code_insee = $('#code-insee').val();obs.nom = $('#nom').html();obs.referentiel = $('#referentiel').val();obs.nom_sci_select = $('#nom-sci-select').val();obs.nn_select = $('#num-nom-select').val();var cle = obs.num;sauvegarderObs(cle, obs);bdd.setItem('index_obs', index_obs);effacerFormulaire();changerPage('#liste', event);} else {var txt = 'Aucune espèce saisie !';$('#obs-saisie-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>').fadeIn(0).delay(1600).fadeOut('slow');changerPage('#saisie', event);}}function sauvegarderObs(cle, obs) {var val = JSON.stringify(obs),poids = JSON.stringify(bdd).length + val.length;if (poids > 2621940) {$('#cache-plein').popup('open');}bdd.setItem(cle, val);}function effacerFormulaire() {$('#lat').html('');$('#lng').html('');$('#location').html('');}function chargerListeObs() {$('#liste-obs').empty();var nbre = bdd.length;for (var i = 0; i < nbre; i++) {var cle = bdd.key(i);if (cle.indexOf(TEXTE_OBS) !== -1) {var obs = JSON.parse(bdd.getItem(cle));console.log(obs);$('#liste-obs').prepend('<li>'+'<a href="#" onclick="detailsObs(this);" data-split-icon="next" data-split-theme="a" title="Voir la fiche" data-obs-num="' + obs.num + '">' +'<strong>' + obs.nom + '</strong> <br />' + obs.date +((obs.commune == TEXTE_HORS_LIGNE || obs.commune == '') ? '' : (' à ' + obs.commune)) +'</a>'+'<a href="#" onclick="supprimerObs(this);" title="Supprimer l\'observation" ' +'data-obs-num="' + obs.num + '">' +'Supprimer'+'</a>'+'</li>');}$('#liste-obs').listview('refresh');}}function supprimerObs(data) {var cle_obs = data.getAttribute('data-obs-num'),obs = JSON.parse(bdd.getItem(cle_obs)),nbre = bdd.length,a_supprimer = new Array();if (db !== undefined) {db.transaction(function(tx) {tx.executeSql('DELETE FROM IMG WHERE parent LIKE ?', [cle_obs]);});}bdd.removeItem(cle_obs);var txt = 'Observation n°' + obs.num.substring(TEXTE_OBS.length) + ' supprimée.';$('#obs-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>').fadeIn(0).delay(1600).fadeOut('slow');chargerListeObs();}function detailsObs(data) {if (db !== undefined) {var num_obs = data.getAttribute('data-obs-num');var obs = JSON.parse(bdd.getItem(num_obs));$('#id-obs').html(obs.num);var texte = '<strong>' + obs.nom + '</strong> vue le ' + obs.date;texte += (obs.commune == TEXTE_HORS_LIGNE || obs.commune == '') ? '' : ' à ' + obs.commune;$('#details-obs').html(texte);$.mobile.changePage('#observation');afficherPhotos(obs.num);} else {var texte ='L\'accès à l\'ajout de photos n\'est pas supporté.';$('#obs-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + texte + '</p>').fadeIn(0).delay(1600).fadeOut('slow');}}function ajoutPhoto() {var id_obs = $('#id-obs').html();if (id_obs != '') {$.each($('#pic').get(0).files, function(index, valeur) {//*var reader = new FileReader();reader.addEventListener('loadend', function () {var photo_nom = valeur.name,arr_nom = photo_nom.split("."),dernier = arr_nom.length - 1;if (arr_nom[dernier].toUpperCase() != "JPG" && arr_nom[dernier].toUpperCase() != "JPEG") {$('#pic').val('');var txt = 'Seuls les fichiers .JPG ou .JPEG sont acceptés.';$('#photo-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>').fadeIn(0).delay(1600).fadeOut('slow');} else {var photo = {num: TEXTE_PHOTO,nom: '',parent: '',base64: 0,miniature: ''};photo.num += index_photos++;photo.nom = photo_nom;photo.parent = id_obs;photo.base64 = reader.result;bdd.setItem('index_photos', index_photos);var img = new Image(),miniature = null;img.src = photo.base64;img.alt = photo.nom;img.onload = function() {miniature = transformerImgEnCanvas(this, 100, 100, false, 'white');db.transaction(function(tx) {tx.executeSql('SELECT * FROM IMG', [], function(tx, results) {var taille = results.rows.length + 1;tx.executeSql('INSERT INTO IMG'+ ' (id, parent, nom, base64, num, miniature)'+ ' VALUES (?, ?, ?, ?, ?, ?)',[taille, photo.parent, photo.nom, photo.base64, photo.num, miniature]);});});afficherPhotos(id_obs);}}}, false);reader.readAsDataURL(valeur);});}}function afficherPhotos(num_obs) {$('#pic').val('');$('#photos-obs').empty();if (num_obs != '') {db.readTransaction(function(tx) {tx.executeSql('SELECT * FROM IMG WHERE parent LIKE ?', [num_obs], function(tx, results) {var nbre = results.rows.length;for (var i = 0; i < nbre; i++) {photo = results.rows.item(i);$('#photos-obs').prepend('<li>'+'<a href="#" onclick="afficherVue(this);" data-ajax="false" data-role="button" data-inline="true" data-photo-num="' + photo.num + '">' +'<img src="' + photo.miniature + '" />' +photo.nom +'</a>' +'<a href="#" onclick="supprimerPhoto(this);" title="Supprimer la photo" ' +'data-icon="delete" data-photo-num="' + photo.num + '" data-photo-parent="' + num_obs + '"' +'data-theme="c">' +'Supprimer cette photo' +'</a>' +'</li>');}$('#photos-obs').listview('refresh');}, null);});}}function afficherVue(data) {var cle_photo = data.getAttribute('data-photo-num');db.readTransaction(function(tx) {tx.executeSql('SELECT * FROM IMG WHERE num LIKE ?', [cle_photo], function(tx, results) {var photo = results.rows.item(0);$('#photo-zoom-infos').html('<img class="photo-popup" width="80%" src="' + photo.base64 + '" />');$('#photo-zoom').popup('open').on('popupafterclose', function(event) {event.stopImmediatePropagation();event.stopPropagation();event.preventDefault();});});});}function supprimerPhoto(data) {var cle_photo = data.getAttribute('data-photo-num'),parent = data.getAttribute('data-photo-parent');db.transaction(function(tx) {tx.executeSql('DELETE FROM IMG WHERE num LIKE ?', [cle_photo]);});/*var txt = photo.num + ' supprimée.';$('#photo-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>').fadeIn(0).delay(1600).fadeOut('slow');*/afficherPhotos(parent);}function miseAJourObs() {console.log('majObs');var nbre = bdd.length;for (var i = 0; i < nbre; i++) {var cle = bdd.key(i);if (cle.indexOf(TEXTE_OBS) !== -1) {var obs = JSON.parse(bdd.getItem(cle));if (obs.maj == 0) {var maj = 1;if (obs.commune == TEXTE_HORS_LIGNE || obs.commune == '') {var url_service = SERVICE_NOM_COMMUNE_URL;var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng);jQuery.ajax({url: urlNomCommuneFormatee,type : 'GET',dataType : 'jsonp',success: function(data) {obs.commune = data['nom'];obs.code_insee = data['codeINSEE'];},error: function() {maj = 0;},async: false});}if (obs.nom_sci_retenu == '') {jQuery.ajax({url: '/service:eflore:0.1/' + obs.referentiel + '/noms?'+ 'masque.nn=' + obs.nn_select+ '&retour.champs=num_taxonomique',success: function(data) {var cle = '',compteur = 0;for (name in data['resultat']) {if (compteur == 0) {cle = name;}compteur++;}obs.num_taxon = data['resultat'][cle]['num_taxonomique'];jQuery.ajax({url: '/service:eflore:0.1/' + obs.referentiel + '/noms?'+ 'masque.nt=' + obs.num_taxon+ '&retour.champs=famille'+ '&retour.tri=retenu',type : 'GET',dataType : 'jsonp',success: function(data) {var cle = '';for (name in data['resultat']) {if (data['resultat'][name]['retenu'] == 'true') {cle = name;break;}}obs.famille = data['resultat'][cle]['famille'];obs.nom_sci_retenu = data['resultat'][cle]['nom_sci'];obs.nn_retenu = cle;},error: function() {maj = 0;},async: false});},async: false});}obs.maj = maj;}sauvegarderObs(obs.num, obs);}}}//+----------------------------------------------------------------------------------------------------------+// Gestion des photosfunction transformerImgEnCanvas(img, thumbwidth, thumbheight, crop, background) {var canvas = document.getElementById('photo-canvas');canvas.width = thumbwidth;canvas.height = thumbheight;var dimensions = calculerDimensions(img.width, img.height, thumbwidth, thumbheight);if (crop) {canvas.width = dimensions.w;canvas.height = dimensions.h;dimensions.x = 0;dimensions.y = 0;}cx = canvas.getContext('2d');cx.clearRect(0, 0, thumbwidth, thumbheight);if (background !== 'transparent') {cx.fillStyle = background;cx.fillRect(0, 0, thumbwidth, thumbheight);}cx.drawImage(img, dimensions.x, dimensions.y, dimensions.w, dimensions.h);return afficherMiniature(canvas);}function calculerDimensions(imagewidth, imageheight, thumbwidth, thumbheight) {var w = 0, h = 0, x = 0, y = 0, zoom = 1,widthratio = imagewidth / thumbwidth,heightratio = imageheight / thumbheight,maxratio = Math.max(widthratio, heightratio);if (maxratio > 1) {w = imagewidth / maxratio;h = imageheight / maxratio;} else {w = imagewidth;h = imageheight;}x = (thumbwidth - w) / 2;y = (thumbheight - h) / 2;zoom = (maxratio > 10) ? (2.6*(maxratio / 10)) : 1;h *= zoom;return {w:w, h:h, x:x, y:y};}function afficherMiniature(canvas) {return canvas.toDataURL('image/jpeg' , 0.8);}//+----------------------------------------------------------------------------------------------------------+// Autocomplétion des noms latinsvar recherche = '';$(document).on('pageinit', '#saisie', function() {$('#liste-noms-latins').on('listviewbeforefilter', function(e, data) {var $input = $(data.input);recherche = $input.val();$input.keyup(function() {clearTimeout($.data(this, 'timer'));var wait = setTimeout(lancerRecherche, DELAI_RECHERCHE);$(this).data('timer', wait);});});});function lancerRecherche() {var $ul = $('#liste-noms-latins'),html = '';$ul.html('');if (recherche && recherche.length > 2) {afficherChargement();$ul.html('<li><div class="ui-loader"><span class="ui-icon ui-icon-loading"></span></div></li>');$ul.listview('refresh');$.ajax({ }).then(function() {for (index in BDTFX) {var espece = BDTFX[index],nom_sci = espece['nom_sci'],num_nom = espece['num_nom'],auteur = espece['auteur'],annee = espece['annee'],nom_sci_complet = nom_sci + ((auteur == '' || auteur == null) ? '' : (' ' + auteur)) + ((annee == '' || annee == null) ? '' : (' (' + annee + ')'));if (nom_sci !== '') {var arr_nom_sci = nom_sci.split(' '),arr_recherche = recherche.split(' ');if (arr_nom_sci[1] !== undefined) {nom_sci_recherche = arr_nom_sci[1];if (arr_nom_sci[1].toLowerCase() == 'x') {nom_sci_recherche = arr_nom_sci[2];}} else {nom_sci_recherche = arr_nom_sci[0];}if ((arr_nom_sci[0].toLowerCase().substring(0, arr_recherche[0].length)) == arr_recherche[0].toLowerCase()) {var flag = true;if (arr_recherche[1] !== undefined) {flag = ( (nom_sci_recherche.toLowerCase().substring(0, arr_recherche[1].length)) == arr_recherche[1].toLowerCase() );}if (flag) {html += '<li>'+ '<a href="#" data-nom-sci="' + nom_sci + '" data-num-nom="' + num_nom + '" '+ ' data-auteur="' + auteur + '" data-nom-sci-complet="' + nom_sci_complet+ '" data-nom-sci-referentiel="bdtfx"'+ '" class="noms-latins" >'+ nom_sci_complet+ '</a>'+ '</li>';}}}}$.mobile.loading('hide');$ul.html(html);$ul.listview('refresh');$ul.trigger('updatelayout');$('.noms-latins').on('click', choisirEspece);});}}function afficherChargement() {var $this = $('#recherche-chargement'),theme = $this.jqmData('theme') || $.mobile.loader.prototype.options.theme,msg = $this.jqmData('msgtext') || $.mobile.loader.prototype.options.text,textVisible = $this.jqmData('textvisible') || $.mobile.loader.prototype.options.textVisible,textonly = !!$this.jqmData('textonly');html = $this.jqmData('html') || '';$.mobile.loading('show', {text: msg,textVisible: textVisible,theme: theme,textonly: textonly,html: html});}function choisirEspece(event) {var espece = event.currentTarget,auteur = espece.getAttribute('data-auteur'),referentiel = espece.getAttribute('data-nom-sci-referentiel'),nom_sci = espece.getAttribute('data-nom-sci'),nom_sci_complet = espece.getAttribute('data-nom-sci-complet')num_nom = espece.getAttribute('data-num-nom');$('#nom').html(nom_sci_complet);$('#referentiel').val(referentiel);$('#nom-sci-select').val(nom_sci);$('#num-nom-select').val(num_nom);$('#liste-noms-latins').html('');$('#saisie-popup').dialog('close');}//+----------------------------------------------------------------------------------------------------------+// Manifest Cachevar appCache = window.applicationCache;appCache.addEventListener('updateready', function() {if (appCache.status === appCache.UPDATEREADY) {surMiseAJourCache();}});function surMiseAJourCache() {appCache.swapCache();if (confirm('Une nouvelle version de ce site est disponible. Mettre à jour ?')) {window.location.reload();}}//+----------------------------------------------------------------------------------------------------------+//Transmission données$(document).ready(function() {$('#transmettre-obs').on('click', transmettreObs);});function transmettreObs() {var msg = '';if (recupererStatutIdentite() == 'true') {if (verifierConnexion()) {var nbre = bdd.length;for (var i = 0; i < nbre; i++) {var cle = bdd.key(i);if (cle.indexOf('obs') !== -1) {var obs = JSON.parse(bdd.getItem(cle));stockerObsData(obs);}}var observations = $('#details-obs').data();if (observations == undefined || jQuery.isEmptyObject(observations)) {msg = 'Aucune observation à transmettre.';} else {msg = 'Transmission en cours...';observations['projet'] = TAG_PROJET;observations['tag-obs'] = '';observations['tag-img'] = '';var utilisateur = new Object();utilisateur.id_utilisateur = ($('#id-utilisateur').val() == '') ? bdd.getItem('utilisateur.id') : $('#id-utilisateur').val();utilisateur.prenom = ($('#prenom-utilisateur').val() == '') ? bdd.getItem('utilisateur.prenom') : $('#prenom-utilisateur').val();utilisateur.nom = ($('#nom-utilisateur').val() == '') ? bdd.getItem('utilisateur.nom') : $('#nom-utilisateur').val();utilisateur.courriel = ($('#courriel').val() == '') ? bdd.getItem('utilisateur.courriel') : $('#courriel').val();observations['utilisateur'] = utilisateur;envoyerObsAuCel(observations);}} else {msg = 'Aucune connexion disponible. Merci de réessayer ultérieurement.';}} else {msg = 'Merci de vérifier et de confirmer votre adresse e-mail avant de transmettre vos observations.';}if (msg != '') {$('#identification-infos').html('<p class="reponse">' + msg + '</p>').fadeIn(0).delay(2000).fadeOut('slow');}}function verifierConnexion() {return ( ('onLine' in navigator) && (navigator.onLine));}function stockerObsData(obs) {var img_noms = new Array(),img_codes = new Array();if (db !== undefined) {db.transaction(function(tx) {tx.executeSql('SELECT * FROM IMG WHERE parent LIKE ?', [obs.num], function(tx, results) {var nbre = results.rows.length;for (var i = 0; i < nbre; i++) {photo = results.rows.item(i);img_noms.push(photo.nom);img_codes.push(photo.base64);}}, null);});}$('#details-obs').data(obs.num, {'date' : obs.date,'notes' : '','nom_sel' : obs.nom,'num_nom_sel' : obs.nn_select,'nom_ret' : obs.nom_sci_retenu,'num_nom_ret' : obs.nn_retenu,'num_taxon' : obs.num_taxon,'famille' : obs.famille,'referentiel' : obs.referentiel,'latitude' : obs.lat,'longitude' : obs.lng,'commune_nom' : obs.commune,'commune_code_insee' : obs.code_insee,'lieudit' : '','station' : '','milieu' : '',//Ajout des champs images'image_nom' : img_noms,'image_b64' : img_codes});}function envoyerObsAuCel(observations) {//console.log(observations);var erreurMsg = "";$.ajax({url : SERVICE_SAISIE_URL,type : "POST",data : observations,dataType : "json",beforeSend : function() {console.log('before send');},success : function(data, textStatus, jqXHR) {console.log('Transmission SUCCESS.');},statusCode : {500 : function(jqXHR, textStatus, errorThrown) {erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";}},error : function(jqXHR, textStatus, errorThrown) {erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";try {reponse = jQuery.parseJSON(jqXHR.responseText);if (reponse != null) {$.each(reponse, function (cle, valeur) {erreurMsg += valeur + "\n";});}} catch(e) {erreurMsg += "L'erreur n'était pas en JSON.";}},complete : function(jqXHR, textStatus) {console.log('complete');console.log(jqXHR);}});}//+---------------------------------------------------------------------------------------------------------+//IDENTITÉ$(document).ready(function() {$('#courriel').on('blur', requeterIdentite);$('#courriel').on('keypress', function(event) {if (event.which == 13) {requeterIdentite(event);}});$('body').on('pagebeforeshow', '#transmission', completerCompte);$('body').on('pagebeforeshow', '#identification-popup', testerLancementRequeteIdentite);$('#valider-courriel').on('vmousedown', requeterIdentite);$('#valider-identification').on('vmousedown', confirmerIdentification);});function completerCompte() {if (bdd.getItem('utilisateur.courriel') != null) {var courriel = bdd.getItem('utilisateur.courriel');$('#identification-texte').html(TEXTE_OUI_COMPTE);$('#utilisateur-compte').html(courriel);$('#identification-btn * .ui-btn-text').html('Modifier le compte');} else {$('#identification-texte').html(TEXTE_NON_COMPTE);$('#identification-btn * .ui-btn-text').html('Ajouter un compte');}}function testerLancementRequeteIdentite(event) {if (bdd.getItem('utilisateur.courriel') != null) {var courriel = bdd.getItem('utilisateur.courriel');$('#courriel').val(courriel);if (recupererStatutIdentite() == 'true') {$('#courriel-confirmation').val(courriel);}}if (bdd.getItem('utilisateur.nom') != null) {$('#nom-utilisateur').val(bdd.getItem('utilisateur.nom'));}if (bdd.getItem('utilisateur.prenom') != null) {$('#prenom-utilisateur').val(bdd.getItem('utilisateur.prenom'));}if (bdd.getItem('utilisateur.id') != null) {$('#id-utilisateur').val(bdd.getItem('utilisateur.id'));}event.preventDefault();event.stopPropagation();}function recupererStatutIdentite() {return bdd.getItem('utilisateur.identite');}function confirmerIdentification(event) {confirmerCourriel();changerPage('#transmission', event);}function confirmerCourriel() {bdd.setItem('utilisateur.identite', false);if (validerCourriel($('#courriel').val())) {if ($('#courriel').val() == $('#courriel-confirmation').val()) {bdd.setItem('utilisateur.identite', true);}} else {$('#identification-infos').html('<p class="reponse">Adresse e-mail invalide.</p>').fadeIn(0).delay(2000).fadeOut('slow');}}function requeterIdentite(event) {var courriel = $('#courriel').val();if (validerCourriel(courriel)) {miseAJourCourriel();var urlAnnuaire = SERVICE_ANNUAIRE + courriel;$.ajax({url : urlAnnuaire,type : 'GET',success : function(data, textStatus, jqXHR) {console.log('Annuaire SUCCESS : ' + textStatus);if (data != undefined && data[courriel] != undefined) {var infos = data[courriel];$('#id-utilisateur').val(infos.id);$('#prenom-utilisateur').val(infos.prenom);$('#nom-utilisateur').val(infos.nom);$('#courriel-confirmation').val(courriel);$('#prenom-utilisateur, #nom-utilisateur, #courriel-confirmation').attr('disabled', 'disabled');if ($('#courriel-memoire').is(':checked')) {bdd.setItem('utilisateur.prenom', $("#prenom-utilisateur").val());bdd.setItem('utilisateur.nom', $("#nom-utilisateur").val());bdd.setItem('utilisateur.id', $("#id-utilisateur").val());}} else {surErreurCompletionCourriel();}},error : function(jqXHR, textStatus, errorThrown) {console.log('Annuaire ERREUR : ' + textStatus);surErreurCompletionCourriel();},complete : function(jqXHR, textStatus) {console.log('Annuaire COMPLETE : ' + textStatus);$('#zone-prenom-nom').removeClass('hidden');$('#zone-courriel-confirmation').removeClass('hidden');}});}event.preventDefault();event.stopPropagation();}function validerCourriel(email) {var regex = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i),flag = regex.test(email);console.log('Valid email ? (', email, ') : ', flag);return flag;}function miseAJourCourriel() {if ($('#courriel-memoire').is(':checked')) {bdd.setItem('utilisateur.courriel', $("#courriel").val());}}function surErreurCompletionCourriel() {$('#id-utilisateur').val('');$('#prenom-utilisateur, #nom-utilisateur, #courriel-confirmation').removeAttr('disabled');}